]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Buildsystems.pm
support unlimited parallel jobs
[debhelper.git] / Debian / Debhelper / Dh_Buildsystems.pm
index 3908145850627160805fd72023844cfafef6b60a..fc06a2ac16a27e3f32583b4d91473c6bf850dce1 100644 (file)
@@ -112,6 +112,8 @@ sub load_all_buildsystems {
 
 sub buildsystems_init {
        my %args=@_;
+       
+       my $max_parallel=-1; # unlimited
 
        # Available command line options
        my %options = (
@@ -127,44 +129,30 @@ sub buildsystems_init {
            "l" => \$opt_list,
            "list" => \$opt_list,
 
-           "j:i" => \$opt_parallel,
-           "parallel:i" => \$opt_parallel,
+           "max-parallel:i" => \$max_parallel,
        );
        $args{options}{$_} = $options{$_} foreach keys(%options);
        Debian::Debhelper::Dh_Lib::init(%args);
+       set_parallel($max_parallel);
+}
 
-       # Post-process parallel building option. Initially $opt_parallel may have
-       # such values:
-       # * undef - no --parallel option was specified. This tells buildsystem class
-       #   not to mess with MAKEFLAGS (with the exception of cleaning MAKEFLAGS
-       #   from pointless unavailable jobserver options to avoid warnings) nor
-       #   enable parallel.
-       # * 1 - --parallel=1 option was specified, hence the package should never be
-       #   built in parallel mode. Cleans MAKEFLAGS if needed.
-       # * 0 - --parallel was specified without interger argument meaning package
-       #   does not want to enforce limit on maximum number of parallel processes.
-       # * N > 1 - --parallel=N was specified where N is the maximum number parallel
-       #   processes the package wants to enforce.
-       # Taken DEB_BUILD_OPTIONS and all this into account, set $opt_parallel to the
-       # number of parallel processes to be used for *this* build.
-       if (defined $opt_parallel) {
-               if ($opt_parallel >= 0 && exists $ENV{DEB_BUILD_OPTIONS}) {
-                       # Parse parallel=n tag
-                       my $n;
-                       foreach my $opt (split(/\s+/, $ENV{DEB_BUILD_OPTIONS})) {
-                               $n = $1 if $opt =~ /^parallel=(\d+)$/;
-                       }
-                       if (defined $n && $n > 0) {
-                               $opt_parallel = $n if $opt_parallel == 0 || $n < $opt_parallel;
+sub set_parallel {
+       my $max=shift;
+
+       $opt_parallel=1;
+
+       if (exists $ENV{DEB_BUILD_OPTIONS}) {
+               # Parse parallel=n tag
+               foreach my $opt (split(/\s+/, $ENV{DEB_BUILD_OPTIONS})) {
+                       if ($opt =~ /^parallel=([-\d]+)$/) {
+                               my $n=$1;
+                               if ($n > 0 && ($max == -1 || $n < $max)) {
+                                       $opt_parallel = $n;
+                               }
+                               else {
+                                       $opt_parallel = $max;
+                               }
                        }
-                       else {
-                               # Invalid value in the parallel tag. Disable.
-                               $opt_parallel = 1;
-                       }
-               }
-               else {
-                       # In case invalid number was passed
-                       $opt_parallel = 1;
                }
        }
 }