Просмотр исходного кода

dpkg-buildflags: support a "strip" operation

The strip operation is useful to drop some options from the
returned build flags.
Raphaël Hertzog лет назад: 15
Родитель
Сommit
48468397af
3 измененных файлов с 41 добавлено и 2 удалено
  1. 2 1
      debian/changelog
  2. 10 0
      man/dpkg-buildflags.1
  3. 29 1
      scripts/Dpkg/BuildFlags.pm

+ 2 - 1
debian/changelog

@@ -93,7 +93,8 @@ dpkg (1.16.1) UNRELEASED; urgency=low
   * dpkg-buildflags now supports "--export=configure" to output compilation
     flags on a single line with double quotes as delimiter of the various
     values. It also uses DEB_<flag>_MAINT_<op> to let the maintainer
-    extend the build flags to use.
+    extend the build flags to use. Last but not least, it can now also strip
+    options from the returned build flags.
 
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520

+ 10 - 0
man/dpkg-buildflags.1

@@ -29,6 +29,9 @@ The configuration files can contain two types of directives:
 .BI SET " flag value"
 Override the flag named \fIflag\fP to have the value \fIvalue\fP.
 .TP
+.BI STRIP " flag value"
+Strip from the flag named \fIflag\fP all the build flags listed in \fIvalue\fP.
+.TP
 .BI APPEND " flag value"
 Extend the flag named \fIflag\fP by appending the options given in \fIvalue\fP.
 A space is prepended to the appended value if the flag's current value is non-empty.
@@ -136,6 +139,13 @@ by package maintainers to change the resulting build flags.
 This variable can be used to force the value returned for the given
 \fIflag\fP.
 .TP
+.BI DEB_ flag _STRIP
+.TQ
+.BI DEB_ flag _MAINT_STRIP
+This variable can be used to provide a space separated list of options
+that will be stripped from the set of flags returned for the given
+\fIflag\fP.
+.TP
 .BI DEB_ flag _APPEND
 .TQ
 .BI DEB_ flag _MAINT_APPEND

+ 29 - 1
scripts/Dpkg/BuildFlags.pm

@@ -127,6 +127,10 @@ sub load_environment_config {
 	if (exists $ENV{$envvar}) {
 	    $self->set($flag, $ENV{$envvar}, "env");
 	}
+	$envvar = "DEB_" . $flag . "_STRIP";
+	if (exists $ENV{$envvar}) {
+	    $self->strip($flag, $ENV{$envvar}, "env");
+	}
 	$envvar = "DEB_" . $flag . "_APPEND";
 	if (exists $ENV{$envvar}) {
 	    $self->append($flag, $ENV{$envvar}, "env");
@@ -152,6 +156,10 @@ sub load_maintainer_config {
 	if (exists $ENV{$envvar}) {
 	    $self->set($flag, $ENV{$envvar}, undef);
 	}
+	$envvar = "DEB_" . $flag . "_MAINT_STRIP";
+	if (exists $ENV{$envvar}) {
+	    $self->strip($flag, $ENV{$envvar}, undef);
+	}
 	$envvar = "DEB_" . $flag . "_MAINT_APPEND";
 	if (exists $ENV{$envvar}) {
 	    $self->append($flag, $ENV{$envvar}, undef);
@@ -193,6 +201,24 @@ sub set {
     $self->{origin}->{$flag} = $src if defined $src;
 }
 
+=item $bf->strip($flag, $value, $source)
+
+Update the build flag $flag by stripping the flags listed in $value and
+record its origin as $source (if defined).
+
+=cut
+
+sub strip {
+    my ($self, $flag, $value, $src) = @_;
+    foreach my $tostrip (split(/\s+/, $value)) {
+	next unless length $tostrip;
+	$self->{flags}->{$flag} =~ s/(^|\s+)\Q$tostrip\E(\s+|$)/ /g;
+    }
+    $self->{flags}->{$flag} =~ s/^\s+//g;
+    $self->{flags}->{$flag} =~ s/\s+$//g;
+    $self->{origin}->{$flag} = $src if defined $src;
+}
+
 =item $bf->append($flag, $value, $source)
 
 Append the options listed in $value to the current value of the flag $flag.
@@ -245,7 +271,7 @@ sub update_from_conffile {
         chomp;
         next if /^\s*#/; # Skip comments
         next if /^\s*$/; # Skip empty lines
-        if (/^(append|prepend|set)\s+(\S+)\s+(\S.*\S)\s*$/i) {
+        if (/^(append|prepend|set|strip)\s+(\S+)\s+(\S.*\S)\s*$/i) {
             my ($op, $flag, $value) = ($1, $2, $3);
             unless (exists $self->{flags}->{$flag}) {
                 warning(_g("line %d of %s mentions unknown flag %s"), $., $file, $flag);
@@ -253,6 +279,8 @@ sub update_from_conffile {
             }
             if (lc($op) eq "set") {
                 $self->set($flag, $value, $src);
+            } elsif (lc($op) eq "strip") {
+                $self->strip($flag, $value, $src);
             } elsif (lc($op) eq "append") {
                 $self->append($flag, $value, $src);
             } elsif (lc($op) eq "prepend") {