X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debian%2FDebhelper%2FDh_Buildsystems.pm;h=f6c123c5800bad09a7e1990e701e6bc041ccd898;hb=8ceb2df1b9e3368e765076b23ee0ecd4a2532a46;hp=3b150bd11062bbf8b325ef3bf362c24a8c691815;hpb=141b5cea6a5ab4efee9d0994b84b88ac2e4c5bf5;p=debhelper.git diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm index 3b150bd..f6c123c 100644 --- a/Debian/Debhelper/Dh_Buildsystems.pm +++ b/Debian/Debhelper/Dh_Buildsystems.pm @@ -1,4 +1,4 @@ -# A module for loading and managing debhelper build system class. +# A module for loading and managing debhelper build system classes. # This module is intended to be used by all dh_auto_* programs. # # Copyright: © 2009 Modestas Vainius @@ -14,22 +14,25 @@ use File::Spec; use base 'Exporter'; our @EXPORT=qw(&buildsystems_init &buildsystems_do &load_buildsystem &load_all_buildsystems); +use constant BUILD_STEPS => qw(configure build test install clean); + # Historical order must be kept for backwards compatibility. New # build systems MUST be added to the END of the list. our @BUILDSYSTEMS = ( - "autoconf", - "perl_makemaker", - "makefile", - "python_distutils", - "perl_build", - "cmake", + "autoconf", + "perl_makemaker", + "makefile", + "python_distutils", + "perl_build", + "cmake", + "ant", ); my $opt_buildsys; my $opt_sourcedir; my $opt_builddir; my $opt_list; -my $opt_help_buildsys; +my $opt_parallel; sub create_buildsystem_instance { my $system=shift; @@ -47,9 +50,35 @@ sub create_buildsystem_instance { if (!exists $bsopts{sourcedir} && defined $opt_sourcedir) { $bsopts{sourcedir} = ($opt_sourcedir eq "") ? undef : $opt_sourcedir; } + if (!exists $bsopts{parallel}) { + $bsopts{parallel} = $opt_parallel; + } return $module->new(%bsopts); } +# Autoselect a build system from the list of instances +sub autoselect_buildsystem { + my $step=shift; + my $selected; + my $selected_level = 0; + + foreach my $inst (@_) { + # Only derived (i.e. more specific) build system can be + # considered beyond the currently selected one. + next if defined $selected && !$inst->isa(ref $selected); + + # If the build system says it is auto-buildable at the current + # step and it can provide more specific information about its + # status than its parent (if any), auto-select it. + my $level = $inst->check_auto_buildable($step); + if ($level > $selected_level) { + $selected = $inst; + $selected_level = $level; + } + } + return $selected; +} + # Similar to create_build system_instance(), but it attempts to autoselect # a build system if none was specified. In case autoselection fails, undef # is returned. @@ -62,24 +91,22 @@ sub load_buildsystem { } else { # Try to determine build system automatically - for $system (@BUILDSYSTEMS) { - my $inst = create_buildsystem_instance($system, @_); - if ($inst->check_auto_buildable($step)) { - return $inst; - } + my @buildsystems; + foreach $system (@BUILDSYSTEMS) { + push @buildsystems, create_buildsystem_instance($system, @_); } + return autoselect_buildsystem($step, @buildsystems); } - return; } sub load_all_buildsystems { my $incs=shift || \@INC; my (%buildsystems, @buildsystems); - for my $inc (@$incs) { + foreach my $inc (@$incs) { my $path = File::Spec->catdir($inc, "Debian/Debhelper/Buildsystem"); if (-d $path) { - for my $module_path (glob "$path/*.pm") { + foreach my $module_path (glob "$path/*.pm") { my $name = basename($module_path); $name =~ s/\.pm$//; next if exists $buildsystems{$name}; @@ -88,8 +115,8 @@ sub load_all_buildsystems { } } - # Push standard debhelper build systems first - for my $name (@BUILDSYSTEMS) { + # Standard debhelper build systems first + foreach my $name (@BUILDSYSTEMS) { error("standard debhelper build system '$name' could not be found/loaded") if not exists $buildsystems{$name}; push @buildsystems, $buildsystems{$name}; @@ -97,7 +124,7 @@ sub load_all_buildsystems { } # The rest are 3rd party build systems - for my $name (keys %buildsystems) { + foreach my $name (keys %buildsystems) { my $inst = $buildsystems{$name}; $inst->{thirdparty} = 1; push @buildsystems, $inst; @@ -108,6 +135,8 @@ sub load_all_buildsystems { sub buildsystems_init { my %args=@_; + + my $max_parallel=-1; # unlimited # Available command line options my %options = ( @@ -123,81 +152,57 @@ sub buildsystems_init { "l" => \$opt_list, "list" => \$opt_list, - "help-buildsystem" => \$opt_help_buildsys, + "max-parallel=i" => \$max_parallel, ); $args{options}{$_} = $options{$_} foreach keys(%options); Debian::Debhelper::Dh_Lib::init(%args); + set_parallel($max_parallel); +} + +sub set_parallel { + my $max=shift; + + $opt_parallel=1; + + if (exists $ENV{DEB_BUILD_OPTIONS}) { + # Parse parallel=n tag + foreach my $opt (split(/\s+/, $ENV{DEB_BUILD_OPTIONS})) { + if ($opt =~ /^parallel=([-\d]+)$/) { + my $n=$1; + if ($n > 0 && ($max == -1 || $n < $max)) { + $opt_parallel = $n; + } + else { + $opt_parallel = $max; + } + } + } + } } sub buildsystems_list { my $step=shift; - # List build systems (including auto and specified status) - my ($auto, $specified); my @buildsystems = load_all_buildsystems(); - for my $inst (@buildsystems) { - my $is_specified = defined $opt_buildsys && $opt_buildsys eq $inst->NAME(); + my $auto = autoselect_buildsystem($step, grep { ! $_->{thirdparty} } @buildsystems); + my $specified; + + # List build systems (including auto and specified status) + foreach my $inst (@buildsystems) { if (! defined $specified && defined $opt_buildsys && $opt_buildsys eq $inst->NAME()) { - $specified = $inst->NAME(); - } - elsif (! defined $auto && ! $inst->{thirdparty} && $inst->check_auto_buildable($step)) { - $auto = $inst->NAME(); + $specified = $inst; } - printf("%s - %s", $inst->NAME(), $inst->DESCRIPTION()); + printf("%-20s %s", $inst->NAME(), $inst->DESCRIPTION()); print " [3rd party]" if $inst->{thirdparty}; print "\n"; } print "\n"; - print "Auto-selected: $auto\n" if defined $auto; - print "Specified: $specified\n" if defined $specified; + print "Auto-selected: ", $auto->NAME(), "\n" if defined $auto; + print "Specified: ", $specified->NAME(), "\n" if defined $specified; print "No system auto-selected or specified\n" if ! defined $auto && ! defined $specified; } -sub help_buildsystem { - my $step=shift; - - # Print build system help page to standard output - - my $inst = load_buildsystem($opt_buildsys, $step); - if ($inst) { - my $pmfile = ref $inst; - $pmfile =~ s#::#/#g; - $pmfile = $INC{"$pmfile.pm"}; - - # Display help with perldoc if it is installed and output is - # a tty - my $perldoc; - if (-t STDOUT) { - eval "use Pod::Perldoc"; - $perldoc = "Pod::Perldoc" if (!$@); - } - if ($perldoc) { - $perldoc = new Pod::Perldoc(); - $perldoc->{args} = [ '-oman', - '-w', 'section=7" "--name=dh_auto_'.lc($inst->NAME()), - '-w', 'center=Dh_auto build system documentation', - '-w', 'release=', - '-F', $pmfile ]; - $perldoc->process(); - } - else { - # No perldoc on the system. Use Pod::Usage to emit simple text - eval "use Pod::Usage"; - pod2usage( -message => "Help page for the ".$inst->NAME()." build system\n" . - '<' . '-'x74 . '>', - -input => $pmfile, -exitval => 'NOEXIT', - -verbose => 2, -noperldoc => 1 ); - print '<', '-'x74, '>', "\n"; - } - return 0; - } - else { - print STDERR "No system auto-selected or specified. Try using --buildsystem option\n"; - return 1; - } -} - sub buildsystems_do { my $step=shift; @@ -206,7 +211,7 @@ sub buildsystems_do { $step =~ s/^dh_auto_//; } - if (grep(/^\Q$step\E$/, qw{configure build test install clean}) == 0) { + if (grep(/^\Q$step\E$/, BUILD_STEPS) == 0) { error("unrecognized build step: " . $step); } @@ -215,10 +220,6 @@ sub buildsystems_do { exit 0; } - if ($opt_help_buildsys) { - exit help_buildsystem($step); - } - my $buildsystem = load_buildsystem($opt_buildsys, $step); if (defined $buildsystem) { $buildsystem->pre_building_step($step); @@ -228,4 +229,4 @@ sub buildsystems_do { return 0; } -1; +1