]> git.donarmstrong.com Git - debhelper.git/commitdiff
Ignore unknown options in DH_OPTIONS. Debhelper will always ignore such options,...
authorJoey Hess <joey@kodama.kitenet.net>
Mon, 15 Dec 2008 03:13:32 +0000 (22:13 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Mon, 15 Dec 2008 03:13:32 +0000 (22:13 -0500)
Debian/Debhelper/Dh_Getopt.pm
Debian/Debhelper/Dh_Lib.pm
debhelper.pod
debian/changelog

index cc15ddde9fb3b55e73d7a4448e66b6faed5f6222..950a37b97a6bac18f40bbbe0482133cff5748c6a 100644 (file)
@@ -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};
 }
 
index 82efc5be241e7e506ea8a7a3b99e008fafe2c3c9..4df64c8748a1b3f98d9abcab5d449eabc905e063 100644 (file)
@@ -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});
        }
 
index 3313d573b650a3d25dae2b93a4b6bdfe32af5cbc..8f9bd1d02a698b0054c0eca1be4b4d6a9ad6aa38 100644 (file)
@@ -477,10 +477,13 @@ Set to 1 to enable no-act mode.
 =item DH_OPTIONS
 
 Anything in this variable will be prepended to the command line arguments
-of all debhelper commands. This is useful in some situations, for example,
-if you need to pass -p to all debhelper commands that will be run. One good
-way to set DH_OPTIONS is by using "Target-specific Variable Values" in your
-debian/rules file. See the make documentation for details on doing this.
+of all debhelper commands. Command-specific options will be ignored by 
+commands that do not support them. 
+
+This is useful in some situations, for example, if you need to pass -p to
+all debhelper commands that will be run. One good way to set DH_OPTIONS is
+by using "Target-specific Variable Values" in your debian/rules file. See
+the make documentation for details on doing this.
 
 =item DH_ALWAYS_EXCLUDE
 
index f2cbe2e3e3f500f719c9c50b7689695b1c8feb36..8f64ffc3517a0f5cdae6d3e5fd9a4ce2dbc7ef56 100644 (file)
@@ -4,6 +4,12 @@ debhelper (7.1.1) UNRELEASED; urgency=low
   * Fix some docs that refered to --srcdir rather than --sourcedir.
     Closes: #504742
   * Add Vcs-Browser field. Closes: #507804
+  * 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.)
 
  -- Joey Hess <joeyh@debian.org>  Mon, 03 Nov 2008 18:50:03 -0500