X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debian%2FDebhelper%2FDh_Getopt.pm;h=257fe6493c8d6de61600dbf3c0f596837c7f5882;hb=00ed6d0cc8f74caf4a591152a97027194304383c;hp=5585a54ceca1f8b6efcb595ac2c694762a10fcef;hpb=66c68aa531bc5a1739be40c25483f036022de7a1;p=debhelper.git diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm index 5585a54..257fe64 100644 --- a/Debian/Debhelper/Dh_Getopt.pm +++ b/Debian/Debhelper/Dh_Getopt.pm @@ -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,9 +68,14 @@ sub NonOption { sub getoptions { my $array=shift; - my %options=%{shift()} if ref $_[0]; + my %params=@_; + + if (! exists $params{bundling} || $params{bundling}) { + Getopt::Long::config("bundling"); + } - Getopt::Long::GetOptionsFromArray($array, + my @test; + my %options=( "v" => \$dh{VERBOSE}, "verbose" => \$dh{VERBOSE}, @@ -121,10 +123,6 @@ sub getoptions { "A" => \$dh{PARAMS_ALL}, "all" => \$dh{PARAMS_ALL}, - "sourcedir=s" => \$dh{SOURCEDIR}, - - "destdir=s" => \$dh{DESTDIR}, - "priority=s" => \$dh{PRIORITY}, "h|help" => \&showhelp, @@ -137,33 +135,64 @@ sub getoptions { "ignore=s" => \&AddIgnore, - %options, + "O=s" => sub { push @test, $_[1] }, + + (ref $params{options} ? %{$params{options}} : ()) , "<>" => \&NonOption, - ) + ); + + if ($params{test}) { + foreach my $key (keys %options) { + $options{$key}=sub {}; + } + } + + 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; + } + + foreach my $opt (@test) { + # Try to parse an option, and skip it + # if it is not known. + if (getoptions([$opt], %params, + ignore_unknown_options => 0, + test => 1)) { + getoptions([$opt], %params); + } + } + + return 1 if $params{ignore_unknown_options}; + return $ret; +} + +sub split_options_string { + my $str=shift; + $str=~s/^\s+//; + return split(/\s+/,$str); } # Parse options and set %dh values. sub parseopts { - my $options=shift; + my %params=@_; my @ARGV_extra; # DH_INTERNAL_OPTIONS is used to pass additional options from # dh through an override target to a command. if (defined $ENV{DH_INTERNAL_OPTIONS}) { - $ENV{DH_INTERNAL_OPTIONS}=~s/^\s+//; - $ENV{DH_INTERNAL_OPTIONS}=~s/\s+$//; - @ARGV_extra=split(/\s+/,$ENV{DH_INTERNAL_OPTIONS}); - my $ret=getoptions(\@ARGV_extra, $options); - if (!$ret) { - warning("warning: unknown options will be a fatal error in a future debhelper release"); - #error("unknown option; aborting"); - } + @ARGV_extra=split(/\x1e/, $ENV{DH_INTERNAL_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}) { @@ -176,26 +205,22 @@ 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}) { - $ENV{DH_OPTIONS}=~s/^\s+//; - $ENV{DH_OPTIONS}=~s/\s+$//; - @ARGV_extra=split(/\s+/,$ENV{DH_OPTIONS}); - my $ret=getoptions(\@ARGV_extra, $options); + @ARGV_extra=split_options_string($ENV{DH_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"); + if (! compat(7)) { + error("unknown option; aborting"); + } } # Check to see if -V was specified. If so, but no parameters were @@ -208,13 +233,13 @@ 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."); exit(0); } - push @{$dh{DOPACKAGES}},getpackages(); + push @{$dh{DOPACKAGES}},getpackages("both"); } # Remove excluded packages from the list of packages to act on. @@ -256,9 +281,4 @@ sub parseopts { @ARGV=@{$dh{ARGV}} if exists $dh{ARGV}; } -sub import { - # Enable bundling of short command line options. - Getopt::Long::config("bundling"); -} - 1