Browse Source

dpkg-buildflags: supports a prepend command

This command is particularly useful for package maintainers who don't want
their supplementary flags to take precedence over user submitted flags.
Raphaël Hertzog 15 years ago
parent
commit
8904196d5b
3 changed files with 41 additions and 2 deletions
  1. 4 0
      debian/changelog
  2. 9 1
      man/dpkg-buildflags.1
  3. 28 1
      scripts/Dpkg/BuildFlags.pm

+ 4 - 0
debian/changelog

@@ -65,6 +65,10 @@ dpkg (1.16.1) UNRELEASED; urgency=low
   * dpkg-buildflags parses a supplementary configuration file under the
   * dpkg-buildflags parses a supplementary configuration file under the
     control of the package maintainer: debian/buildflags (or the corresponding
     control of the package maintainer: debian/buildflags (or the corresponding
     architecture/os specific variants).
     architecture/os specific variants).
+  * dpkg-buildflags supports a prepend command to modify the build
+    flags. Particularly useful for package maintainers who don't want
+    their supplementary flags to take precedence over user submitted
+    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

+ 9 - 1
man/dpkg-buildflags.1

@@ -32,8 +32,12 @@ The configuration files can contain two types of directives:
 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 APPEND " flag value"
 .BI APPEND " flag value"
-Extend the flag named \fIflag\fP with 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.
+.TP
+.BI PREPEND " flag value"
+Extend the flag named \fIflag\fP by prepending the options given in \fIvalue\fP.
+A space is appended to the prepended value if the flag's current value is non-empty.
 .P
 .P
 The configuration files can contain comments on lines starting with a hash
 The configuration files can contain comments on lines starting with a hash
 (#). Empty lines are also ignored.
 (#). Empty lines are also ignored.
@@ -128,6 +132,10 @@ This variable can be used to force the value returned for the given
 .BI DEB_ flag _APPEND
 .BI DEB_ flag _APPEND
 This variable can be used to append supplementary options to the value
 This variable can be used to append supplementary options to the value
 returned for the given \fIflag\fP.
 returned for the given \fIflag\fP.
+.TP
+.BI DEB_ flag _PREPEND
+This variable can be used to prepend supplementary options to the value
+returned for the given \fIflag\fP.
 .
 .
 .SH AUTHOR
 .SH AUTHOR
 Copyright \(co 2010-2011 Rapha\[:e]l Hertzog
 Copyright \(co 2010-2011 Rapha\[:e]l Hertzog

+ 28 - 1
scripts/Dpkg/BuildFlags.pm

@@ -132,6 +132,10 @@ sub load_environment_config {
 	if (exists $ENV{$envvar}) {
 	if (exists $ENV{$envvar}) {
 	    $self->append($flag, $ENV{$envvar}, "env");
 	    $self->append($flag, $ENV{$envvar}, "env");
 	}
 	}
+	$envvar = "DEB_" . $flag . "_PREPEND";
+	if (exists $ENV{$envvar}) {
+	    $self->prepend($flag, $ENV{$envvar}, "env");
+	}
     }
     }
 }
 }
 
 
@@ -196,6 +200,24 @@ sub append {
     $self->{origin}->{$flag} = $src if defined $src;
     $self->{origin}->{$flag} = $src if defined $src;
 }
 }
 
 
+=item $bf->prepend($flag, $value, $source)
+
+Prepend the options listed in $value to the current value of the flag $flag.
+Record its origin as $source (if defined).
+
+=cut
+
+sub prepend {
+    my ($self, $flag, $value, $src) = @_;
+    if (length($self->{flags}->{$flag})) {
+        $self->{flags}->{$flag} = "$value " . $self->{flags}->{$flag};
+    } else {
+        $self->{flags}->{$flag} = $value;
+    }
+    $self->{origin}->{$flag} = $src if defined $src;
+}
+
+
 =item $bf->update_from_conffile($file, $source)
 =item $bf->update_from_conffile($file, $source)
 
 
 Update the current build flags based on the configuration directives
 Update the current build flags based on the configuration directives
@@ -213,7 +235,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|set)\s+(\S+)\s+(\S.*\S)\s*$/i) {
+        if (/^(append|prepend|set)\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);
@@ -223,6 +245,8 @@ sub update_from_conffile {
                 $self->set($flag, $value, $src);
                 $self->set($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") {
+                $self->prepend($flag, $value, $src);
             }
             }
         } else {
         } else {
             warning(_g("line %d of %s is invalid, it has been ignored."), $., $file);
             warning(_g("line %d of %s is invalid, it has been ignored."), $., $file);
@@ -286,6 +310,9 @@ sub list {
 New method: $bf->load_package_config(). This method is called last as part
 New method: $bf->load_package_config(). This method is called last as part
 of load_config().
 of load_config().
 
 
+New method: $bf->prepend() very similar to append(). Implement support of
+the prepend operation everywhere.
+
 =head1 AUTHOR
 =head1 AUTHOR
 
 
 Raphaël Hertzog <hertzog@debian.org>
 Raphaël Hertzog <hertzog@debian.org>