diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-12-14 22:13:32 -0500 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-12-14 22:13:32 -0500 |
commit | e90eebf73099da05ffb1d1e2be30a2eccafd153c (patch) | |
tree | cffd293f81abaa33eec275e289accec550a5f5df /Debian | |
parent | a0fc3f57b576cd7c88a698330233df26ff13137f (diff) | |
download | debhelper-e90eebf73099da05ffb1d1e2be30a2eccafd153c.tar.gz |
Ignore unknown options in DH_OPTIONS. Debhelper will always ignore such options, even when unknown command-line options are converted back to an error. This allows (ab)using DH_OPTIONS to pass command-specific options. (Note that getopt will warn about such unknown options. Eliminating this warning without reimplementing much of Getopt::Long wasn't practical.)
Diffstat (limited to 'Debian')
-rw-r--r-- | Debian/Debhelper/Dh_Getopt.pm | 30 | ||||
-rw-r--r-- | Debian/Debhelper/Dh_Lib.pm | 26 |
2 files changed, 31 insertions, 25 deletions
diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm index cc15ddde..950a37b9 100644 --- a/Debian/Debhelper/Dh_Getopt.pm +++ b/Debian/Debhelper/Dh_Getopt.pm @@ -69,11 +69,11 @@ sub NonOption { push @{$dh{ARGV}}, @_; } -# Parse options and set %dh values. -sub parseopts { +sub getoptions { + my $array=shift; my %options=%{shift()} if ref $_[0]; - my $ret=GetOptions( + Getopt::Long::GetOptionsFromArray($array, "v" => \$dh{VERBOSE}, "verbose" => \$dh{VERBOSE}, @@ -138,8 +138,28 @@ sub parseopts { %options, "<>" => \&NonOption, - ); + ) +} + +# Parse options and set %dh values. +sub parseopts { + my $options=shift; + + # DH_OPTIONS can contain additional options + # to be parsed like @ARGV, but with unknown options + # skipped. + my @ARGV_extra; + 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); + if (!$ret) { + warning("warning: ignored unknown options in DH_OPTIONS"); + } + } + my $ret=getoptions(\@ARGV, $options); if (!$ret) { warning("warning: unknown options will be a fatal error in a future debhelper release"); #error("unknown option; aborting"); @@ -195,7 +215,7 @@ sub parseopts { # Anything left in @ARGV is options that appeared after a -- # These options are added to the U_PARAMS array, while the # non-option values we collected replace them in @ARGV; - push @{$dh{U_PARAMS}}, @ARGV; + push @{$dh{U_PARAMS}}, @ARGV, @ARGV_extra; @ARGV=@{$dh{ARGV}} if exists $dh{ARGV}; } diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index 82efc5be..4df64c87 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -22,28 +22,14 @@ my $max_compat=7; sub init { my %params=@_; - # If DH_OPTIONS is set, prepend it @ARGV. - if (defined($ENV{DH_OPTIONS})) { - # Ignore leading/trailing whitespace. - $ENV{DH_OPTIONS}=~s/^\s+//; - $ENV{DH_OPTIONS}=~s/\s+$//; - unshift @ARGV,split(/\s+/,$ENV{DH_OPTIONS}); - } - - # Check to see if an argument on the command line starts with a dash. - # if so, we need to pass this off to the resource intensive + # Check to see if an option line starts with a dash, + # or DH_OPTIONS is set. + # If so, we need to pass this off to the resource intensive # Getopt::Long, which I'd prefer to avoid loading at all if possible. - my $parseopt=undef; - my $arg; - foreach $arg (@ARGV) { - if ($arg=~m/^-/) { - $parseopt=1; - last; - } - } - if ($parseopt) { + if ((defined $ENV{DH_OPTIONS} && length $ENV{DH_OPTIONS}) || + grep /^-/, @ARGV) { eval "use Debian::Debhelper::Dh_Getopt"; - error($!) if $@; + error($@) if $@; Debian::Debhelper::Dh_Getopt::parseopts($params{options}); } |