Hi!

On Tue, 2014-05-13 at 21:38:15 +0900, Hideki Yamane wrote:
> Package: dpkg-dev
> Version: 1.17.9
> Severity: wishlist
> Tags: patch

>  Recently I've watched openSUSE conference video and they uses %{?_smp_flags} 
>  rpm macro to detect multi CPU cores to be enabled to do parallel building
>  package.
> 
>  http://presentations.nordisch.org/packaging-oSC2014/#/13
> 
> 
>  Then, I'd like to introduce such feature (not manually specify -j<job 
> number>,
>  but automatically uses all CPUs and run multiple make) to dpkg-buildpackage,
>  patch attached.

> Pros)
>  - Automatically use all CPU cores to build package, faster build.

You can get something similar, but not exactly the same, with
«dpkg-buildpackage -j». But I see that's not clearly documented in
the man page, although the --help output says «-j[<jobs>]», I'll be
documenting that behaviour in the man page.

> Cons)
>  - It may introduce FTBFS to some packages (e.g. Bug#694726), but it should
>    be fixed, right? ;)

I don't think enabling this by default is a good idea, this was
discussed in the policy bug report (AFAIR) when defining the parallel
behaviour, and I'm (in principle) not planning on changing that.

I'd be possibly open to adding a way to set the value of -j to the
number of cores, say -jauto for example. Ok, this was trivial to
implement, and attached is a patch doing that, if that is enough for
you, I'll clean it up, to make it more robust, document it and add it
for 1.17.10.

Thanks,
Guillem
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index 08295bf..a541316 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/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(.*)$/) {
 	@rootcommand = split /\s+/, $1;
@@ -352,6 +352,7 @@ if ($signcommand) {
 
 if (defined $parallel) {
     $parallel = $build_opts->get('parallel') if $build_opts->has('parallel');
+    $parallel = int qx(getconf _NPROCESSORS_ONLN) if $parallel eq 'auto';
     $ENV{MAKEFLAGS} ||= '';
     $ENV{MAKEFLAGS} .= " -j$parallel";
     $build_opts->set('parallel', $parallel);

Reply via email to