diff options
author | Modestas Vainius <modestas@vainius.eu> | 2009-10-28 15:49:34 -0400 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2009-10-28 15:49:34 -0400 |
commit | dace0773fe5f66fdf040f54383322e21a65fa1e8 (patch) | |
tree | d03e084c1980708e31773b1b422cfec4e5546c7d /Debian/Debhelper/Dh_Lib.pm | |
parent | 834d95aaba24e5cee1c5a74078a09443f5e122a7 (diff) |
Support parallel building in makefile buildsystem
1) Add routine to Dh_Lib (used by dh and makefile.pm) which is capable of
detecting make jobserver and job control options from the MAKEFLAGS environment
variable. It also generates and returns a clean up MAKEFLAGS from these
options.
2) Add --parallel option to build system framework which allows source packages
to specify that they support parallel building. Optional value for this option is
the number of maximum parallel process to allow. However, the actual number of
parallel process (if any) for the specific build is determined from
DEB_BUILD_OPTIONS env variable as specified by Debian Policy.
By default (no --parallel option) parallel is neither enabled nor disabled
(depends on the external environment). However, dh may pass --parallel to
dh_auto_* implicitly in case 4) described below.
3) Add parallel support for makefile buildsystem. This implementation
forcefully starts a new make job server (or disables parallel) for the number
of process requested. If --parallel was not passed to the build system at all,
the build system will only clean up MAKEFLAGS from stale jobserver options to
avoid pointless make warnings.
4) If dh detects that it is being run by dpkg-buildpackage -jX and it is NOT
run with "+" prefix from debian/rules (i.e. jobserver is not reachable), it
enables --parallel implicitly. This closes: #532805.
Signed-off-by: Modestas Vainius <modestas@vainius.eu>
Diffstat (limited to 'Debian/Debhelper/Dh_Lib.pm')
-rw-r--r-- | Debian/Debhelper/Dh_Lib.pm | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index 2d1934be..ebf7db7e 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -16,7 +16,7 @@ use vars qw(@ISA @EXPORT %dh); &compat &addsubstvar &delsubstvar &excludefile &package_arch &is_udeb &udeb_filename &debhelper_script_subst &escape_shell &inhibit_log &load_log &write_log &dpkg_architecture_value - &sourcepackage); + &sourcepackage &get_make_jobserver_status); my $max_compat=7; @@ -205,6 +205,46 @@ sub _error_exitcode { } } +# A helper subroutine for detecting (based on MAKEFLAGS) if make jobserver +# is enabled, if it is available or MAKEFLAGS contains "jobs" option. +# It returns current status (jobserver, jobserver-unavailable or jobs-N where +# N is number of jobs, 0 if infinite) and MAKEFLAGS cleaned up from +# job control options. +sub get_make_jobserver_status { + my $jobsre = qr/(?:^|\s)(?:(?:-j\s*|--jobs(?:=|\s+))(\d+)?|--jobs)\b/; + my $status = ""; + my $makeflags; + + if (exists $ENV{MAKEFLAGS}) { + $makeflags = $ENV{MAKEFLAGS}; + if ($makeflags =~ /(?:^|\s)--jobserver-fds=(\d+)/) { + $status = "jobserver"; + if (!open(my $in, "<&", "$1")) { + # Job server is unavailable + $status .= "-unavailable"; + } + else { + close $in; + } + # Clean makeflags up + $makeflags =~ s/(?:^|\s)--jobserver-fds=\S+//g; + $makeflags =~ s/(?:^|\s)-j\b//g; + } + elsif (my @m = ($makeflags =~ /$jobsre/g)) { + # Job count is specified in MAKEFLAGS. Whenever make reads it, a new + # jobserver will be started. Job count returned is 0 if infinite. + $status = "jobs-" . (defined $m[$#m] ? $m[$#m] : "0"); + # Clean makeflags up from "jobs" option(s) + $makeflags =~ s/$jobsre//g; + } + } + if ($status) { + # MAKEFLAGS could be unset if it is empty + $makeflags = undef if $makeflags =~ /^\s*$/; + } + return wantarray ? ($status, $makeflags) : $status; +} + # Run a command that may have a huge number of arguments, like xargs does. # Pass in a reference to an array containing the arguments, and then other # parameters that are the command and any parameters that should be passed to |