]> git.donarmstrong.com Git - debhelper.git/commitdiff
dh_builddeb: support for parallel builds of debs
authorGergely Nagy <algernon@madhouse-project.org>
Sun, 17 Jul 2011 18:48:05 +0000 (20:48 +0200)
committerJoey Hess <joey@kitenet.net>
Sun, 17 Jul 2011 19:57:58 +0000 (15:57 -0400)
Implement support for parallel deb builds, when DEB_BUILD_OPTIONS has
parallels=N - limiting the number of forked processes to N.

Requested-By: Kari Pahula <kaol@debian.org>
Signed-Off-By: Gergely Nagy <algernon@madhouse-project.org>
dh_builddeb

index b15c943669c82c4f030969d71fdb765c9b1ae15d..26e127464a36ee75c25bd0b7fcea5d74c6b0f4d8 100755 (executable)
@@ -63,30 +63,55 @@ else {
        $dh{FILENAME}="/$dh{FILENAME}";
 }
 
+my $processes=1;
+my $max_procs=1;
+if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS}=~/parallel=(\d+)/) {
+       $max_procs=$1;
+}
+
 foreach my $package (@{$dh{DOPACKAGES}}) {
-       my $tmp=tmpdir($package);
-       if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
-               if (! compat(5)) {
-                       complex_doit("find $tmp $dh{EXCLUDE_FIND} | xargs rm -rf");
+       my $pid=0;
+
+       if ($max_procs > 1) {
+               while ($processes > $max_procs) {
+                       wait;
+                       $processes--;
+               }
+               $pid=fork();
+       }
+
+       if ($pid == 0) {
+               my $tmp=tmpdir($package);
+               if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
+                       if (! compat(5)) {
+                               complex_doit("find $tmp $dh{EXCLUDE_FIND} | xargs rm -rf");
+                       }
+                       else {
+                               # Old broken code here for compatibility. Does not
+                               # remove everything.
+                               complex_doit("find $tmp -name $_ | xargs rm -rf")
+                                       foreach split(":", $ENV{DH_ALWAYS_EXCLUDE});
+                       }
+               }
+               if (! is_udeb($package)) {
+                       doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$dh{FILENAME});
                }
                else {
-                       # Old broken code here for compatibility. Does not
-                       # remove everything.
-                       complex_doit("find $tmp -name $_ | xargs rm -rf")
-                               foreach split(":", $ENV{DH_ALWAYS_EXCLUDE});
+                       my $filename=$dh{FILENAME};
+                       if (! $filename) {
+                               $filename="/".udeb_filename($package);
+                       }
+                       doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$filename);
                }
-       }
-       if (! is_udeb($package)) {
-               doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$dh{FILENAME});
-       }
-       else {
-               my $filename=$dh{FILENAME};
-               if (! $filename) {
-                       $filename="/".udeb_filename($package);
+               exit (0) if ($max_procs > 1);
+       } else {
+               if (!defined $pid) {
+                       error("fork failed!");
                }
-               doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$filename);
+               $processes++;
        }
 }
+while (($max_procs > 0) && (wait != -1)) {}
 
 =head1 SEE ALSO