]> git.donarmstrong.com Git - debhelper.git/commitdiff
Improvements in DH_OPTIONS handling and DH_AUTO_OPTIONS envvar support.
authorModestas Vainius <modestas@vainius.eu>
Mon, 8 Jun 2009 18:32:27 +0000 (21:32 +0300)
committerModestas Vainius <modestas@vainius.eu>
Mon, 8 Jun 2009 20:01:02 +0000 (23:01 +0300)
* DH_AUTO_OPTIONS is like existing DH_OPTIONS, just only for dh_auto
  stuff. This also avoids "explosion" of separate DH_AUTO_* environment
  variables (i.e. exports in debian/rules) and encourages usage of dh_auto
  command line option names. DH_AUTO_OPTIONS is passed via "extra_args" to
  Dh_Lib::init() (API addition).
* When splitting options from DH_OPTIONS and its flavours, allow arguments
  to include whitespaces if they are escaped with backslash (\) (see
  split_options_string()). Document this in debhelper.pod.
* Short option for --buildsystem is -c (aka class).
* Provide API to cancel option specs from default debhelper options.
  It will be used in the feature.

Debian/Debhelper/Dh_Buildsystems.pm
Debian/Debhelper/Dh_Getopt.pm
Debian/Debhelper/Dh_Lib.pm
debhelper.pod

index 80b66887c2e8a62133ec2d155c3acc56a982fa4f..be29ac5ce36272a009acab878d5f5fe80ab3dd77 100644 (file)
@@ -65,27 +65,23 @@ sub load_buildsystem {
 sub buildsystems_init {
        my %args=@_;
 
-       # TODO: Not documented in the manual pages yet.
-       # Initialize options from environment variables
-       if (exists $ENV{DH_AUTO_BUILDDIRECTORY}) {
-               $opt_builddir = $ENV{DH_AUTO_BUILDDIRECTORY};
-       }
-       if (exists $ENV{DH_AUTO_BUILDSYSTEM}) {
-               $opt_buildsys = $ENV{DH_AUTO_BUILDSYSTEM};
-       }
-
        # Available command line options
        my %options = (
            "b:s" => \$opt_builddir,
            "builddirectory:s" => \$opt_builddir,
 
-           "m=s" => \$opt_buildsys,
+           "c=s" => \$opt_buildsys,
            "buildsystem=s" => \$opt_buildsys,
 
            "l" => \$opt_list,
            "--list" => \$opt_list,
        );
-       map { $args{options}{$_} = $options{$_} } keys(%options);
+       $args{options}{$_} = $options{$_} foreach keys(%options);
+
+       # Pass options from the DH_AUTO_OPTIONS environment variable
+       if (defined $ENV{DH_AUTO_OPTIONS}) {
+               $args{extra_args} = $ENV{DH_AUTO_OPTIONS};
+       }
        Debian::Debhelper::Dh_Lib::init(%args);
 }
 
index 5585a54ceca1f8b6efcb595ac2c694762a10fcef..bddc06b8102bd3aaf63e43cb7f0dee9e581c3451 100644 (file)
@@ -71,9 +71,9 @@ sub NonOption {
 
 sub getoptions {
        my $array=shift;
-       my %options=%{shift()} if ref $_[0];
+       my $extraoptions=shift;
 
-       Getopt::Long::GetOptionsFromArray($array,
+       my %options=(
                "v" => \$dh{VERBOSE},
                "verbose" => \$dh{VERBOSE},
 
@@ -137,24 +137,42 @@ sub getoptions {
                
                "ignore=s" => \&AddIgnore,
 
-               %options,
-
                "<>" => \&NonOption,
-       )
+       );
+       
+       # Merge extra options and cancel default ones as needed (undef)
+       if (defined $extraoptions) {
+               for my $opt (keys %$extraoptions) {
+                       if (defined $extraoptions->{$opt}) {
+                               $options{$opt}=$extraoptions->{$opt};
+                       }
+                       else {
+                               delete $options{$opt};
+                       }
+               }
+       }
+
+       Getopt::Long::GetOptionsFromArray($array, %options);
+}
+
+sub split_options_string {
+       my $str=shift;
+
+       $str=~s/^\s+//;
+       return map { $_=~s/\\(\s)/$1/g; $_=~s/\s+$//g; $_ } split(/(?<!\\)\s+/,$str);
 }
 
 # Parse options and set %dh values.
 sub parseopts {
        my $options=shift;
+       my $extra_args=shift;
        
        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});
+               @ARGV_extra=split_options_string($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");
@@ -183,15 +201,22 @@ sub parseopts {
        # to be parsed like @ARGV, but with unknown options
        # skipped.
        if (defined $ENV{DH_OPTIONS}) {
-               $ENV{DH_OPTIONS}=~s/^\s+//;
-               $ENV{DH_OPTIONS}=~s/\s+$//;
-               @ARGV_extra=split(/\s+/,$ENV{DH_OPTIONS});
+               @ARGV_extra=split_options_string($ENV{DH_OPTIONS});
                my $ret=getoptions(\@ARGV_extra, $options);
                if (!$ret) {
                        warning("warning: ignored unknown options in DH_OPTIONS");
                }
        }
 
+       if (defined $extra_args) {
+               my @extra_opts=split_options_string($extra_args);
+               my $ret=getoptions(\@extra_opts, $options);
+               if (!$ret) {
+                       warning("warning: ignored unknown options");
+               }
+               push @ARGV_extra, @extra_opts;
+       }
+
        my $ret=getoptions(\@ARGV, $options);
        if (!$ret) {
                warning("warning: unknown options will be a fatal error in a future debhelper release");
index 28a90f7bdad16b37900c7021d9b055f2d8f6388b..b3162d07ae9a77cc2844d73291e4b09436acbfe1 100644 (file)
@@ -29,10 +29,10 @@ sub init {
        # Getopt::Long, which I'd prefer to avoid loading at all if possible.
        if ((defined $ENV{DH_OPTIONS} && length $ENV{DH_OPTIONS}) ||
            (defined $ENV{DH_INTERNAL_OPTIONS} && length $ENV{DH_INTERNAL_OPTIONS}) ||
-           grep /^-/, @ARGV) {
+           (defined $params{extra_args}) || grep /^-/, @ARGV) {
                eval "use Debian::Debhelper::Dh_Getopt";
                error($@) if $@;
-               Debian::Debhelper::Dh_Getopt::parseopts($params{options});
+               Debian::Debhelper::Dh_Getopt::parseopts($params{options}, $params{extra_args});
        }
 
        # Another way to set excludes.
index 388453c3005c2442b3c026cc9eea3ecf324cdc6a..8c232d2859bac1e3caac44cfed1beefb7a63cf21 100644 (file)
@@ -491,8 +491,14 @@ Anything in this variable will be prepended to the command line arguments
 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
+Arguments are separated by whitespaces unless a whitespace is escaped
+with a backslash character (\). Then the whitespace is treated literally.
+Likewise, the backslash character is treated literally unless it is followed
+by a single whitespace. If a backslash is followed by two or more spaces,
+it will be considered as the last symbol of the argument.
+
+DH_OPTIONS 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.