From: Frank Lichtenheld Date: Sun, 23 Sep 2007 18:24:51 +0000 (+0200) Subject: dpkg-buildpackage: Add new option -j[] X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a19946b71970f7854f9b15cc639b1a4039e902ff;p=dpkg dpkg-buildpackage: Add new option -j[] Works like the make options of the same name. It will be passed to debian/rules in the MAKEFLAGS environment variable. Also the parallel= DEB_BUILD_OPTIONS option will be honored and set correctly. The finally used value is determined by the following order: -j > DEB_BUILD_OPTIONS > MAKEFLAGS. Based on an idea by Robert Millan . --- diff --git a/ChangeLog b/ChangeLog index 4356ebee..0362a3ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-09-23 Frank Lichtenheld + + * scripts/dpkg-buildpackage.pl: Add new option + -j[] that works like the make option of + the same name. It will be passed to debian/rules in + the MAKEFLAGS environment variable. Also the + parallel= DEB_BUILD_OPTIONS option will be honored + and set correctly. The finally used value is determined by the + following order: -j > DEB_BUILD_OPTIONS > MAKEFLAGS. + Based on an idea by Robert Millan . + * scripts/Dpkg/BuildOptions.pm: Added. Support code + for DEB_BUILD_OPTIONS handling by dpkg-buildpackage. + * scripts/Makefile.am: Adapt. + 2007-09-23 Jari Aalto * scripts/dpkg-source.pl ($diff_ignore_default_regexp): Add @@ -13,7 +27,7 @@ * scripts/Dpkg.pm: Make the regex for determining $progname more robust. - + * scripts/dpkg-buildpackage.sh: Move to... * scripts/dpkg-buildpackage.pl: Convert from Shell to Perl. diff --git a/debian/changelog b/debian/changelog index 1d822c95..6984a8eb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,10 @@ dpkg (1.14.7) UNRELEASED; urgency=low [ Frank Lichtenheld ] * Add _MTN to dpkg-source -i default regex. Suggested by Jari Aalto. * Convert dpkg-buildpackage to a Perl script. + * dpkg-buildpackage accepts a -j option now which will set + MAKEFLAGS(-j) and DEB_BUILD_OPTIONS(parallel=) accordingly. + parallel= in DEB_BUILD_OPTIONS will be passed to MAKEFLAGS as + well. Based on an idea by Robert Millan. Closes: #440636 [ Updated dpkg translations ] * Basque (Piarres Beobide). Closes: #440859 diff --git a/man/ChangeLog b/man/ChangeLog index 53112da5..8ecb9324 100644 --- a/man/ChangeLog +++ b/man/ChangeLog @@ -1,3 +1,8 @@ +2007-09-23 Frank Lichtenheld + + * dpkg-buildpackage.1: Document the new -j + option. + 2007-09-23 Peter Karlsson * po/sv.add: Fixed typo. diff --git a/man/dpkg-buildpackage.1 b/man/dpkg-buildpackage.1 index 89e4a62f..e7a67577 100644 --- a/man/dpkg-buildpackage.1 +++ b/man/dpkg-buildpackage.1 @@ -47,6 +47,17 @@ Specify the Debian architecture we build for. The architecture of the machine we build on is determined automatically, and is also the default for the host machine. .TP +.BI \-j jobs +Number of jobs allowed to be run simultaneously, equivalent to the +.BR make (1) +option of the same name. Will add itself to the MAKEFLAGS +environment variable, which should cause all subsequent make +invocations to inherit the option. Also adds \fBparallel=\fP\fIjobs\fP +to the DEB_BUILD_OPTIONS environment variable which allows +debian/rules files to use this information for their own purposes. +If no \fB-j\fP option is given, an existing value for \fBparallel\fP will be +honoured and added to MAKEFLAGS. +.TP .BI \-v version Use changelog information from all versions strictly later than .IR version . diff --git a/scripts/Dpkg/BuildOptions.pm b/scripts/Dpkg/BuildOptions.pm new file mode 100644 index 00000000..3ca38b95 --- /dev/null +++ b/scripts/Dpkg/BuildOptions.pm @@ -0,0 +1,38 @@ +package Dpkg::BuildOptions; + +use strict; +use warnings; + +sub parse { + my ($env) = @_; + + $env ||= $ENV{DEB_BUILD_OPTIONS}; + + unless ($env) { return {}; } + + my %opts; + if ($env =~ s/(noopt|nostrip),?//ig) { + $opts{lc $1} = ''; + } elsif ($env =~ s/(parallel)=(-?\d+),?//ig) { + $opts{lc $1} = $2; + } + + return \%opts; +} + +sub set { + my ($opts, $overwrite) = @_; + + my $env = $overwrite ? '' : $ENV{DEB_BUILD_OPTIONS}||''; + if ($env) { $env .= ',' } + + while (my ($k, $v) = each %$opts) { + if ($v) { + $env .= "$k=$v,"; + } else { + $env .= "$k,"; + } + } +} + +1; diff --git a/scripts/Makefile.am b/scripts/Makefile.am index ed194dce..87ea0603 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -55,6 +55,7 @@ CLEANFILES = \ perllibdir = $(PERL_LIBDIR) nobase_dist_perllib_DATA = \ + Dpkg/BuildOptions.pm \ Dpkg/Gettext.pm \ Dpkg.pm diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl index bb40e934..73b7e9a7 100644 --- a/scripts/dpkg-buildpackage.pl +++ b/scripts/dpkg-buildpackage.pl @@ -8,6 +8,7 @@ use File::Basename; use Dpkg; use Dpkg::Gettext; +use Dpkg::BuildOptions; push (@INC, $dpkglibdir); require 'controllib.pl'; @@ -39,6 +40,7 @@ Options: -p -d do not check build dependencies and conflicts. -D check build dependencies and conflicts. + -j[] specify jobs to run simultaniously } passed to debian/rules -k the key to use for signing. -sgpg the sign-command is called like GPG. -spgp the sign-command is called like PGP. @@ -95,7 +97,7 @@ if ( ( ($ENV{GNUPGHOME} && -e $ENV{GNUPGHOME}) my ($admindir, $signkey, $forcesigninterface, $usepause, $noclean, $warnable_errors, $sourcestyle, $cleansource, $binaryonly, $sourceonly, $since, $maint, - $changedby, $desc); + $changedby, $desc, $parallel); my (@checkbuilddep_args, @passopts, @tarignore); my $checkbuilddep = 1; my $signsource = 1; @@ -115,6 +117,8 @@ while (@ARGV) { exit 0; } elsif (/^--admindir=(.*)$/) { $admindir = $1; + } elsif (/^-j(\d*)$/) { + $parallel = $1 || '-1'; } elsif (/^-r(.*)$/) { $rootcommand = $1; } elsif (/^-p(.*)$/) { @@ -209,6 +213,22 @@ if ($signcommand && ($signinterface !~ /^(gpg|pgp)$/)) { warning(_g("unknown sign command, assuming pgp style interface")); } +if ($parallel || $ENV{DEB_BUILD_OPTIONS}) { + my $build_opts = Dpkg::BuildOptions::parse(); + + $parallel ||= $build_opts->{parallel}; + if (defined $parallel) { + $ENV{MAKEFLAGS} ||= ''; + if ($parallel eq '-1') { + $ENV{MAKEFLAGS} .= " -j"; + } else { + $ENV{MAKEFLAGS} .= " -j$parallel"; + } + } + $build_opts->{parallel} = $parallel; + Dpkg::BuildOptions::set($build_opts); +} + my $cwd = cwd(); my $dir = basename($cwd); @@ -309,7 +329,7 @@ if ($checkbuilddep) { } if (system('dpkg-checkbuilddeps', @checkbuilddep_args)) { - warning(_g("Build dependencies/conflicts unsatisfied; aborting.\n")); + warning(_g("Build dependencies/conflicts unsatisfied; aborting.")); warning(_g("(Use -d flag to override.)")); exit 3; }