From 02bf22b2c4c695fd959f11c0d6a803795e014c2e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 4 Jan 2010 18:41:51 -0500 Subject: solve the dh -Bbuild problem * Add -O option, which can be used to pass options to commands, ignoring options that they do not support. * dh: Use -O to pass user-specified options to the commands it runs. This solves the problem with passing "-Bbuild" to dh, where commands that do not support -B would see a bogus -u option. Closes: #541773 (It also ensures that the commands dh prints out can really be run.) --- Debian/Debhelper/Dh_Getopt.pm | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'Debian/Debhelper') diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm index 0d021072..4df3eed2 100644 --- a/Debian/Debhelper/Dh_Getopt.pm +++ b/Debian/Debhelper/Dh_Getopt.pm @@ -69,15 +69,8 @@ sub NonOption { sub getoptions { my $array=shift; my %params=@_; - my %options=%{$params{options}} if ref $params{options}; - - my $oldwarn; - if ($params{ignore_unknown_options}) { - $oldwarn=$SIG{__WARN__}; - $SIG{__WARN__}=sub {}; - } - my $ret=Getopt::Long::GetOptionsFromArray($array, + my %options=( "v" => \$dh{VERBOSE}, "verbose" => \$dh{VERBOSE}, @@ -137,18 +130,37 @@ sub getoptions { "ignore=s" => \&AddIgnore, - %options, + "O=s" => sub { my($option,$value)=@_; + # Try to parse an option, but ignore it + # if it is not known. + if (getoptions([$value], %params, test => 1)) { + getoptions([$value], %params); + } + }, + + (ref $params{options} ? %{$params{options}} : ()) , "<>" => \&NonOption, ); - if ($params{ignore_unknown_options}) { - $SIG{__WARN__}=$oldwarn; - return 1; + if ($params{test}) { + foreach my $key (keys %options) { + $options{$key}=sub {}; + } } - else { - return $ret; + + my $oldwarn; + if ($params{test} || $params{ignore_unknown_options}) { + $oldwarn=$SIG{__WARN__}; + $SIG{__WARN__}=sub {}; + } + my $ret=Getopt::Long::GetOptionsFromArray($array, %options); + if ($oldwarn) { + $SIG{__WARN__}=$oldwarn; } + + return 1 if $params{ignore_unknown_options}; + return $ret; } sub split_options_string { @@ -171,7 +183,7 @@ sub parseopts { # 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}) { -- cgit v1.2.3