]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Getopt.pm
fix bad interaction between -O and ignore_unknown_options
[debhelper.git] / Debian / Debhelper / Dh_Getopt.pm
index 6e5cacdd9c0bf941779fe65e1e314df810a018e3..fddbd89a28dd9ba99f20cd96166c58e48e140d64 100644 (file)
@@ -28,17 +28,14 @@ sub AddPackage { my($option,$value)=@_;
                push @{$dh{DOPACKAGES}}, getpackages('indep');
                $dh{DOINDEP}=1;
        }
-       elsif ($option eq 'a' or $option eq 'arch') {
+       elsif ($option eq 'a' or $option eq 'arch' or
+              $option eq 's' or $option eq 'same-arch') {
                push @{$dh{DOPACKAGES}}, getpackages('arch');
                $dh{DOARCH}=1;
        }
        elsif ($option eq 'p' or $option eq 'package') {
                push @{$dh{DOPACKAGES}}, $value;
        }
-       elsif ($option eq 's' or $option eq 'same-arch') {
-               push @{$dh{DOPACKAGES}}, getpackages('same');
-               $dh{DOSAME}=1;
-       }
        else {
                error("bad option $option - should never happen!\n");
        }
@@ -71,15 +68,10 @@ sub NonOption {
 
 sub getoptions {
        my $array=shift;
-       my %options=%{shift()} if ref $_[0];
-       
-       my $oldwarn;
-       if ($ENV{DH_IGNORE_UNKNOWN_OPTIONS}) {
-               $oldwarn=$SIG{__WARN__};
-               $SIG{__WARN__}=sub {};
-       }
+       my %params=@_;
 
-       my $ret=Getopt::Long::GetOptionsFromArray($array,
+       my @test;
+       my %options=(   
                "v" => \$dh{VERBOSE},
                "verbose" => \$dh{VERBOSE},
 
@@ -139,18 +131,38 @@ sub getoptions {
                
                "ignore=s" => \&AddIgnore,
 
-               %options,
+               "O=s" => sub { push @test, $_[1] },
+             
+               (ref $params{options} ? %{$params{options}} : ()) ,
 
                "<>" => \&NonOption,
        );
 
-       if ($ENV{DH_IGNORE_UNKNOWN_OPTIONS}) {
+       if ($params{test}) {
+               foreach my $key (keys %options) {
+                       $options{$key}=sub {};
+               }
+       }
+
+       my $oldwarn;
+       if ($params{test}) {
+               $oldwarn=$SIG{__WARN__};
+               $SIG{__WARN__}=sub {};
+       }
+       my $ret=Getopt::Long::GetOptionsFromArray($array, %options);
+       if ($oldwarn) {
                $SIG{__WARN__}=$oldwarn;
-               return 1;
        }
-       else {
-               return $ret;
+
+       foreach my $opt (@test) {
+               # Try to parse an option, but ignore it
+               # if it is not known.
+               if (getoptions([$opt], %params, test => 1)) {
+                       getoptions([$opt], %params);
+               }
        }
+
+       return $ret;
 }
 
 sub split_options_string {
@@ -161,7 +173,7 @@ sub split_options_string {
 
 # Parse options and set %dh values.
 sub parseopts {
-       my $options=shift;
+       my %params=@_;
        
        my @ARGV_extra;
 
@@ -169,11 +181,11 @@ sub parseopts {
        # dh through an override target to a command.
        if (defined $ENV{DH_INTERNAL_OPTIONS}) {
                @ARGV_extra=split(/\x1e/, $ENV{DH_INTERNAL_OPTIONS});
-               getoptions(\@ARGV_extra, $options);
+               getoptions(\@ARGV_extra, %params);
 
                # Avoid forcing acting on packages specified in
                # DH_INTERNAL_OPTIONS. This way, -p can be specified
-               # at the command line to act on a specific package, and if
+               # at the command line to act on a specific package, but when
                # nothing is specified, the excludes will cause the set of
                # packages DH_INTERNAL_OPTIONS specifies to be acted on.
                if (defined $dh{DOPACKAGES}) {
@@ -186,21 +198,18 @@ sub parseopts {
                delete $dh{DOPACKAGES};
                delete $dh{DOINDEP};
                delete $dh{DOARCH};
-               delete $dh{DOSAME};
        }
        
-       # DH_OPTIONS can contain additional options
-       # to be parsed like @ARGV, but with unknown options
-       # skipped.
+       # DH_OPTIONS can contain additional options to be parsed like @ARGV
        if (defined $ENV{DH_OPTIONS}) {
                @ARGV_extra=split_options_string($ENV{DH_OPTIONS});
-               my $ret=getoptions(\@ARGV_extra, $options);
+               my $ret=getoptions(\@ARGV_extra, %params);
                if (!$ret) {
                        warning("warning: ignored unknown options in DH_OPTIONS");
                }
        }
 
-       my $ret=getoptions(\@ARGV, $options);
+       my $ret=getoptions(\@ARGV, %params);
        if (!$ret) {
                warning("warning: unknown options will be a fatal error in a future debhelper release");
                #error("unknown option; aborting");
@@ -216,7 +225,7 @@ sub parseopts {
        # want us to act on them all. Note we have to do this before excluding
        # packages out, below.
        if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
-               if ($dh{DOINDEP} || $dh{DOARCH} || $dh{DOSAME}) {
+               if ($dh{DOINDEP} || $dh{DOARCH}) {
                        # User specified that all arch (in)dep package be
                        # built, and there are none of that type.
                        warning("You asked that all arch in(dep) packages be built, but there are none of that type.");