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

Dpkg::BuildOptions: change API so that an empty value can be properly supported

No value results in a hash item with undef value while an empty value
results in a hash ite with an empty value.

Update the non-regression tests accordingly. Also update dpkg-buildpackage
that was using defined instead of exists to test the existence of an
option.
Raphaël Hertzog лет назад: 16
Родитель
Сommit
cfdeb7e01f
3 измененных файлов с 18 добавлено и 16 удалено
  1. 7 6
      scripts/Dpkg/BuildOptions.pm
  2. 2 2
      scripts/dpkg-buildpackage.pl
  3. 9 8
      scripts/t/300_Dpkg_BuildOptions.t

+ 7 - 6
scripts/Dpkg/BuildOptions.pm

@@ -34,13 +34,14 @@ sub parse {
             next;
         }
 
-	my ($k, $v) = ($1, $3 || '');
+	my ($k, $v) = ($1, $3);
 
 	# Sanity checks
-	if ($k =~ /^(noopt|nostrip|nocheck)$/ && length($v)) {
-	    $v = '';
-	} elsif ($k eq 'parallel' && $v !~ /^-?\d+$/) {
-	    next;
+	if ($k =~ /^(noopt|nostrip|nocheck)$/ && defined($v)) {
+	    $v = undef;
+	} elsif ($k eq 'parallel')  {
+	    $v = "" if not defined($v);
+	    next if $v !~ /^\d*$/;
 	}
 
 	$opts{$k} = $v;
@@ -59,7 +60,7 @@ sub set {
         $new->{$k} = $v;
     }
 
-    my $env = join(" ", map { $new->{$_} ? $_ . "=" . $new->{$_} : $_ } sort keys %$new);
+    my $env = join(" ", map { defined($new->{$_}) ? $_ . "=" . $new->{$_} : $_ } sort keys %$new);
 
     $ENV{DEB_BUILD_OPTIONS} = $env;
     return $env;

+ 2 - 2
scripts/dpkg-buildpackage.pl

@@ -257,7 +257,7 @@ if ($signcommand) {
 
 my $build_opts = Dpkg::BuildOptions::parse();
 if ($parallel) {
-    $parallel = $build_opts->{parallel} if (defined $build_opts->{parallel});
+    $parallel = $build_opts->{parallel} if exists $build_opts->{parallel};
     $ENV{MAKEFLAGS} ||= '';
     if ($parallel eq '-1') {
 	$ENV{MAKEFLAGS} .= " -j";
@@ -268,7 +268,7 @@ if ($parallel) {
     Dpkg::BuildOptions::set($build_opts);
 }
 
-my $default_flags = defined $build_opts->{noopt} ? "-g -O0" : "-g -O2";
+my $default_flags = exists $build_opts->{noopt} ? "-g -O0" : "-g -O2";
 my %flags = ( CPPFLAGS => '',
 	      CFLAGS   => $default_flags,
 	      CXXFLAGS => $default_flags,

+ 9 - 8
scripts/t/300_Dpkg_BuildOptions.t

@@ -33,15 +33,16 @@ $ENV{DEB_BUILD_OPTIONS} = 'noopt foonostripbar parallel=3 bazNOCHECK';
 my $dbo = Dpkg::BuildOptions::parse();
 
 my %dbo = (
-	   noopt => '',
-	   foonostripbar => '',
+	   noopt => undef,
+	   foonostripbar => undef,
 	   parallel => 3,
 	   );
 my %dbo2 = (
-	    no => '',
-	    opt => '',
-	    'no-strip' => '',
-	    nocheck => '',
+	    no => undef,
+	    opt => undef,
+	    'no-strip' => undef,
+	    nocheck => undef,
+	    parallel => '',
 	   );
 
 
@@ -52,7 +53,7 @@ $dbo = Dpkg::BuildOptions::parse('no opt no-strip parallel = 5 nocheck');
 is_deeply($dbo, \%dbo2, 'parse (param)');
 
 $dbo->{parallel} = 5;
-$dbo->{noopt} = '';
+$dbo->{noopt} = undef;
 
 my $env = Dpkg::BuildOptions::set($dbo, 1);
 
@@ -60,6 +61,6 @@ is($ENV{DEB_BUILD_OPTIONS}, $env, 'set (return value)');
 is_deeply(Dpkg::BuildOptions::parse(), $dbo, 'set (env)');
 
 $ENV{DEB_BUILD_OPTIONS} = 'foobar';
-$dbo = { noopt => '' };
+$dbo = { noopt => undef };
 $env = Dpkg::BuildOptions::set($dbo, 0);
 is($env, "foobar noopt", 'set (append)');