]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Lib.pm
split get_make_jobserver_status into two functions
[debhelper.git] / Debian / Debhelper / Dh_Lib.pm
index 28a90f7bdad16b37900c7021d9b055f2d8f6388b..ac0d8ab4a05f7ea6f7aa317b8202b7471ab60bec 100644 (file)
@@ -16,7 +16,7 @@ use vars qw(@ISA @EXPORT %dh);
            &compat &addsubstvar &delsubstvar &excludefile &package_arch
            &is_udeb &udeb_filename &debhelper_script_subst &escape_shell
            &inhibit_log &load_log &write_log &dpkg_architecture_value
-           &sourcepackage);
+           &sourcepackage &is_make_jobserver_unavailable &clean_makeflags);
 
 my $max_compat=7;
 
@@ -175,7 +175,7 @@ sub doit {
        verbose_print(escape_shell(@_));
 
        if (! $dh{NO_ACT}) {
-               system(@_) == 0 || _error_exitcode($_[0]);
+               system(@_) == 0 || _error_exitcode(join(" ", @_));
        }
 }
 
@@ -608,7 +608,7 @@ sub excludefile {
 
 sub dpkg_architecture_value {
        my $var = shift;
-       my $value=`dpkg-architecture -q$var 2>/dev/null` || error("dpkg-architecture failed");
+       my $value=`dpkg-architecture -q$var` || error("dpkg-architecture failed");
        chomp $value;
        return $value;
 }
@@ -630,10 +630,9 @@ sub dpkg_architecture_value {
        my $os;
 
        sub buildos {
-               return $os if defined $os;
-
-               $os=`dpkg-architecture -qDEB_HOST_ARCH_OS 2>/dev/null` || error("dpkg-architecture failed");
-               chomp $os;
+               if (!defined $os) {
+                       $os=dpkg_architecture_value("DEB_HOST_ARCH_OS");
+               }
                return $os;
        }
 }
@@ -668,9 +667,8 @@ sub sourcepackage {
 }
 
 # Returns a list of packages in the control file.
-# Must pass "arch" or "indep" or "same" to specify arch-dependant or
-# -independant or same arch packages. If nothing is specified, returns all
-# packages.
+# Pass "arch" or "indep" to specify arch-dependant or
+# independant. If nothing is specified, returns all packages.
 # As a side effect, populates %package_arches and %package_types with the
 # types of all packages (not only those returned).
 my (%package_types, %package_arches);
@@ -681,12 +679,6 @@ sub getpackages {
        %package_arches=();
        
        $type="" if ! defined $type;
-       
-       # Look up the build arch if we need to.
-       my $buildarch='';
-       if ($type eq 'same') {
-               $buildarch=buildarch();
-       }
 
        my $package="";
        my $arch="";
@@ -721,10 +713,12 @@ sub getpackages {
                                $package_types{$package}=$package_type;
                                $package_arches{$package}=$arch;
                        }
+
                        if ($package &&
                            (($type eq 'indep' && $arch eq 'all') ||
-                            ($type eq 'arch' && $arch ne 'all') ||
-                            ($type eq 'same' && ($arch eq 'any' || samearch($buildarch, $arch))) ||
+                            ($type eq 'arch' && ($arch eq 'any' ||
+                                            ($arch ne 'all' &&
+                                             samearch(buildarch(), $arch)))) ||
                             ! $type)) {
                                push @list, $package;
                                $package="";
@@ -800,4 +794,35 @@ sub debhelper_script_subst {
        }
 }
 
+# Checks if make's jobserver is enabled via MAKEFLAGS, but
+# the FD used to communicate with it is actually not available.
+sub is_make_jobserver_unavailable {
+       if (exists $ENV{MAKEFLAGS} && 
+           $ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+               if (!open(my $in, "<&$1")) {
+                       return 1; # unavailable
+               }
+               else {
+                       close $in;
+                       return 0; # available
+               }
+       }
+
+       return; # no jobserver specified
+}
+
+# Cleans out job control options from MAKEFLAGS.
+sub clean_makeflags {
+       if (exists $ENV{MAKEFLAGS}) {
+               if ($ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+                       $ENV{MAKEFLAGS} =~ s/(?:^|\s)--jobserver-fds=\S+//g;
+                       $ENV{MAKEFLAGS} =~ s/(?:^|\s)-j\b//g;
+               }
+               else {
+                       $ENV{MAKEFLAGS} =~ s/(?:^|\s)(?:(?:-j\s*|--jobs(?:=|\s+))(\d+)?|--jobs)\b//g;
+               }
+               delete $ENV{MAKEFLAGS} if $ENV{MAKEFLAGS} =~ /^\s*$/;
+       }
+}
+
 1