From f897611a77726655aea258af0c4d52a8ce759ebc Mon Sep 17 00:00:00 2001 From: Modestas Vainius Date: Mon, 8 Jun 2009 21:32:27 +0300 Subject: Improvements in DH_OPTIONS handling and DH_AUTO_OPTIONS envvar support. * 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 | 18 ++++++-------- Debian/Debhelper/Dh_Getopt.pm | 47 ++++++++++++++++++++++++++++--------- Debian/Debhelper/Dh_Lib.pm | 4 ++-- 3 files changed, 45 insertions(+), 24 deletions(-) (limited to 'Debian') diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm index 80b66887..be29ac5c 100644 --- a/Debian/Debhelper/Dh_Buildsystems.pm +++ b/Debian/Debhelper/Dh_Buildsystems.pm @@ -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); } diff --git a/Debian/Debhelper/Dh_Getopt.pm b/Debian/Debhelper/Dh_Getopt.pm index 5585a54c..bddc06b8 100644 --- a/Debian/Debhelper/Dh_Getopt.pm +++ b/Debian/Debhelper/Dh_Getopt.pm @@ -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(/(?