Ver código fonte

dpkg-buildflags: support a "strip" operation

The strip operation is useful to drop some options from the
returned build flags.
Raphaël Hertzog 15 anos atrás
pai
commit
48468397af
3 arquivos alterados com 41 adições e 2 exclusões
  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
   * dpkg-buildflags now supports "--export=configure" to output compilation
     flags on a single line with double quotes as delimiter of the various
     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
     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 ]
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520
   * 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"
 .BI SET " flag value"
 Override the flag named \fIflag\fP to have the value \fIvalue\fP.
 Override the flag named \fIflag\fP to have the value \fIvalue\fP.
 .TP
 .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"
 .BI APPEND " flag value"
 Extend the flag named \fIflag\fP by appending the options given in \fIvalue\fP.
 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.
 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
 This variable can be used to force the value returned for the given
 \fIflag\fP.
 \fIflag\fP.
 .TP
 .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
 .BI DEB_ flag _APPEND
 .TQ
 .TQ
 .BI DEB_ flag _MAINT_APPEND
 .BI DEB_ flag _MAINT_APPEND

+ 29 - 1
scripts/Dpkg/BuildFlags.pm

@@ -127,6 +127,10 @@ sub load_environment_config {
 	if (exists $ENV{$envvar}) {
 	if (exists $ENV{$envvar}) {
 	    $self->set($flag, $ENV{$envvar}, "env");
 	    $self->set($flag, $ENV{$envvar}, "env");
 	}
 	}
+	$envvar = "DEB_" . $flag . "_STRIP";
+	if (exists $ENV{$envvar}) {
+	    $self->strip($flag, $ENV{$envvar}, "env");
+	}
 	$envvar = "DEB_" . $flag . "_APPEND";
 	$envvar = "DEB_" . $flag . "_APPEND";
 	if (exists $ENV{$envvar}) {
 	if (exists $ENV{$envvar}) {
 	    $self->append($flag, $ENV{$envvar}, "env");
 	    $self->append($flag, $ENV{$envvar}, "env");
@@ -152,6 +156,10 @@ sub load_maintainer_config {
 	if (exists $ENV{$envvar}) {
 	if (exists $ENV{$envvar}) {
 	    $self->set($flag, $ENV{$envvar}, undef);
 	    $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";
 	$envvar = "DEB_" . $flag . "_MAINT_APPEND";
 	if (exists $ENV{$envvar}) {
 	if (exists $ENV{$envvar}) {
 	    $self->append($flag, $ENV{$envvar}, undef);
 	    $self->append($flag, $ENV{$envvar}, undef);
@@ -193,6 +201,24 @@ sub set {
     $self->{origin}->{$flag} = $src if defined $src;
     $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)
 =item $bf->append($flag, $value, $source)
 
 
 Append the options listed in $value to the current value of the flag $flag.
 Append the options listed in $value to the current value of the flag $flag.
@@ -245,7 +271,7 @@ sub update_from_conffile {
         chomp;
         chomp;
         next if /^\s*#/; # Skip comments
         next if /^\s*#/; # Skip comments
         next if /^\s*$/; # Skip empty lines
         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);
             my ($op, $flag, $value) = ($1, $2, $3);
             unless (exists $self->{flags}->{$flag}) {
             unless (exists $self->{flags}->{$flag}) {
                 warning(_g("line %d of %s mentions unknown flag %s"), $., $file, $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") {
             if (lc($op) eq "set") {
                 $self->set($flag, $value, $src);
                 $self->set($flag, $value, $src);
+            } elsif (lc($op) eq "strip") {
+                $self->strip($flag, $value, $src);
             } elsif (lc($op) eq "append") {
             } elsif (lc($op) eq "append") {
                 $self->append($flag, $value, $src);
                 $self->append($flag, $value, $src);
             } elsif (lc($op) eq "prepend") {
             } elsif (lc($op) eq "prepend") {