summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-12-14 22:13:32 -0500
committerJoey Hess <joey@kodama.kitenet.net>2008-12-14 22:13:32 -0500
commite90eebf73099da05ffb1d1e2be30a2eccafd153c (patch)
treecffd293f81abaa33eec275e289accec550a5f5df
parenta0fc3f57b576cd7c88a698330233df26ff13137f (diff)
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.)
-rw-r--r--Debian/Debhelper/Dh_Getopt.pm30
-rw-r--r--Debian/Debhelper/Dh_Lib.pm26
-rw-r--r--debhelper.pod11
-rw-r--r--debian/changelog6
4 files changed, 44 insertions, 29 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});
}
diff --git a/debhelper.pod b/debhelper.pod
index 3313d573..8f9bd1d0 100644
--- a/debhelper.pod
+++ b/debhelper.pod
@@ -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
diff --git a/debian/changelog b/debian/changelog
index f2cbe2e3..8f64ffc3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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