Просмотр исходного кода

dpkg-buildpackage: Add support for automatic parallel jobs selection

This adds support to automatically set the number of jobs to be used by
the build process to match the number of online processors, with the new
-j argument «auto».

It will try to infer the number of processors from getconf(1), but the
system might not support the configuration variable, in which case it
will fallback to not having any limit when passing the -j option to
make.
Guillem Jover лет назад: 12
Родитель
Сommit
a4e5d3da5d
3 измененных файлов с 18 добавлено и 4 удалено
  1. 2 0
      debian/changelog
  2. 8 3
      man/dpkg-buildpackage.1
  3. 8 1
      scripts/dpkg-buildpackage.pl

+ 2 - 0
debian/changelog

@@ -33,6 +33,8 @@ dpkg (1.17.10) UNRELEASED; urgency=low
       Based on a patch by Bernhard R. Link <brlink@debian.org>.
       Closes: #746973
     - Document that dpkg-buildpackage(1) -j argument is optional.
+  * Add support for automatic parallel job selection in dpkg-buildpackage,
+    matching currently active processors, when using -jauto. Closes: #748012
 
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).

+ 8 - 3
man/dpkg-buildpackage.1

@@ -145,9 +145,10 @@ no specific profile. Also adds them (as a space separated list) to the
 \fBDEB_BUILD_PROFILES\fP environment variable which allows, for example,
 \fBdebian/rules\fP files to use this information for conditional builds.
 .TP
-.BR \-j [\fIjobs\fP]
-Number of jobs allowed to be run simultaneously, or unlimited number
-if \fIjobs\fP is not specified, equivalent to the
+.BR \-j [\fIjobs\fP|\fBauto\fP]
+Number of jobs allowed to be run simultaneously, number of jobs matching
+the number of online processors if \fBauto\fP is specified, or unlimited
+number if \fIjobs\fP is not specified, equivalent to the
 .BR make (1)
 option of the same name. Will add itself to the \fBMAKEFLAGS\fP
 environment variable, which should cause all subsequent make
@@ -157,6 +158,10 @@ allows debian/rules files to use this information for their own purposes.
 The \fBparallel=\fP\fIjobs\fP or \fBparallel=\fP option in
 \fBDEB_BUILD_OPTIONS\fP environment variable will override the \fB\-j\fP
 value if this option is given.
+Note that the \fBauto\fP value will get replaced by the actual number of
+currently active processors, and as such will not get propagated to any
+child process. If the number of online processors cannot be inferred then
+the code will fallback to using an unlimited number.
 .TP
 .B \-D
 Check build dependencies and conflicts; abort if unsatisfied. This is the

+ 8 - 1
scripts/dpkg-buildpackage.pl

@@ -207,7 +207,7 @@ while (@ARGV) {
 	push @source_opts, $1;
     } elsif (/^--changes-option=(.*)$/) {
 	push @changes_opts, $1;
-    } elsif (/^-j(\d*)$/) {
+    } elsif (/^-j(\d*|auto)$/) {
 	$parallel = $1 || '';
     } elsif (/^-r(.*)$/) {
 	my $arg = $1;
@@ -354,6 +354,13 @@ if ($signcommand) {
 }
 
 if (defined $parallel) {
+    if ($parallel eq 'auto') {
+        # Most Unices.
+        $parallel = qx(getconf _NPROCESSORS_ONLN 2>/dev/null);
+        # Fallback for at least Irix.
+        $parallel = qx(getconf _NPROC_ONLN 2>/dev/null) if $?;
+        chomp $parallel;
+    }
     $parallel = $build_opts->get('parallel') if $build_opts->has('parallel');
     $ENV{MAKEFLAGS} ||= '';
     $ENV{MAKEFLAGS} .= " -j$parallel";