Explorar el Código

dpkg-buildpackage: use space as separator in DEB_BUILD_OPTIONS

* scripts/Dpkg/BuildOptions.pm (parse, set): Use space as the
official separator in DEB_BUILD_OPTIONS. Check for validity of
flags and print a warning if a bad option is detected. Rewrote
the logic of set() to avoid adding options twice in non-overwrite
mode.
* scripts/t/300_Dpkg_BuildOptions.t: Fix the test suite to work with
the modified Dpkg::BuildOptions.

Cherry-pick from the master branch: commits
9866c4bafdf147ad764f31e2747f5c1012802b1d and
a8ada212bde12d7fffc5673b0c9ca397b31e1354
Raphael Hertzog hace 18 años
padre
commit
9f484513e4
Se han modificado 3 ficheros con 29 adiciones y 19 borrados
  1. 3 0
      debian/changelog
  2. 15 15
      scripts/Dpkg/BuildOptions.pm
  3. 11 4
      scripts/t/300_Dpkg_BuildOptions.t

+ 3 - 0
debian/changelog

@@ -9,6 +9,9 @@ dpkg (1.14.21) UNRELEASED; urgency=low
   * Handle debian.tar.gz files like diff.gz in dpkg-buildpackage and
     dpkg-genchanges to detect the kind of upload.
   * Add "armel" to /usr/share/dpkg/archtable. Closes: #487768
+  * Modified Dpkg::BuildOptions to recognize and use spaces as separator
+    in DEB_BUILD_OPTIONS (in order to conform with the Debian policy
+    ruling established in #430649).
 
   [ Updated dpkg translations ]
   * Thai (Theppitak Karoonboonyanan). Closes: #488090

+ 15 - 15
scripts/Dpkg/BuildOptions.pm

@@ -3,6 +3,9 @@ package Dpkg::BuildOptions;
 use strict;
 use warnings;
 
+use Dpkg::Gettext;
+use Dpkg::ErrorHandling qw(warning);
+
 sub parse {
     my ($env) = @_;
 
@@ -12,16 +15,16 @@ sub parse {
 
     my %opts;
 
-    foreach (split(/[\s,]+/, $env)) {
-	# FIXME: This is pending resolution of Debian bug #430649
-	/^([a-z][a-z0-9_-]*)(=(\w*))?$/;
+    foreach (split(/\s+/, $env)) {
+	unless (/^([a-z][a-z0-9_-]*)(=(\S*))?$/) {
+            warning(_g("invalid flag in DEB_BUILD_OPTIONS: %s"), $_);
+            next;
+        }
 
 	my ($k, $v) = ($1, $3 || '');
 
 	# Sanity checks
-	if (!$k) {
-	    next;
-	} elsif ($k =~ /^(noopt|nostrip|nocheck)$/ && length($v)) {
+	if ($k =~ /^(noopt|nostrip|nocheck)$/ && length($v)) {
 	    $v = '';
 	} elsif ($k eq 'parallel' && $v !~ /^-?\d+$/) {
 	    next;
@@ -37,18 +40,15 @@ sub set {
     my ($opts, $overwrite) = @_;
     $overwrite = 1 if not defined($overwrite);
 
-    my $env = $overwrite ? '' : $ENV{DEB_BUILD_OPTIONS}||'';
-    if ($env) { $env .= ',' }
-
+    my $new = {};
+    $new = parse() unless $overwrite;
     while (my ($k, $v) = each %$opts) {
-	if ($v) {
-	    $env .= "$k=$v,";
-	} else {
-	    $env .= "$k,";
-	}
+        $new->{$k} = $v;
     }
 
-    $ENV{DEB_BUILD_OPTIONS} = $env if $env;
+    my $env = join(" ", map { $new->{$_} ? $_ . "=" . $new->{$_} : $_ } sort keys %$new);
+
+    $ENV{DEB_BUILD_OPTIONS} = $env;
     return $env;
 }
 

+ 11 - 4
scripts/t/300_Dpkg_BuildOptions.t

@@ -7,7 +7,14 @@ use warnings;
 
 use_ok('Dpkg::BuildOptions');
 
-$ENV{DEB_BUILD_OPTIONS} = 'noopt,foonostripbar,parallel=3,bazNOCHECK';
+{
+    no warnings;
+    # Disable warnings related to invalid values fed during
+    # the tests
+    $Dpkg::ErrorHandling::quiet_warnings = 1;
+}
+
+$ENV{DEB_BUILD_OPTIONS} = 'noopt foonostripbar parallel=3 bazNOCHECK';
 
 my $dbo = Dpkg::BuildOptions::parse();
 
@@ -26,14 +33,14 @@ my %dbo2 = (
 
 is_deeply($dbo, \%dbo, 'parse');
 
-$dbo = Dpkg::BuildOptions::parse('no opt,no-strip,parallel = 5,nocheck');
+$dbo = Dpkg::BuildOptions::parse('no opt no-strip parallel = 5 nocheck');
 
 is_deeply($dbo, \%dbo2, 'parse (param)');
 
 $dbo->{parallel} = 5;
 $dbo->{noopt} = '';
 
-my $env = Dpkg::BuildOptions::set($dbo,1);
+my $env = Dpkg::BuildOptions::set($dbo, 1);
 
 is($ENV{DEB_BUILD_OPTIONS}, $env, 'set (return value)');
 is_deeply(Dpkg::BuildOptions::parse(), $dbo, 'set (env)');
@@ -41,4 +48,4 @@ is_deeply(Dpkg::BuildOptions::parse(), $dbo, 'set (env)');
 $ENV{DEB_BUILD_OPTIONS} = 'foobar';
 $dbo = { noopt => '' };
 $env = Dpkg::BuildOptions::set($dbo, 0);
-is($env, "foobar,noopt,", 'set (append)');
+is($env, "foobar noopt", 'set (append)');