]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Lib.pm
Adjust code to add deprecation warning for compatability level 4. (Man page already...
[debhelper.git] / Debian / Debhelper / Dh_Lib.pm
index c80389d76704adc598e33aa8ab31911175cb9484..960f2721e6444a2fc619bb402a524de2d536ca35 100644 (file)
@@ -16,7 +16,8 @@ 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_jobserver_makeflags);
 
 my $max_compat=7;
 
@@ -175,7 +176,7 @@ sub doit {
        verbose_print(escape_shell(@_));
 
        if (! $dh{NO_ACT}) {
-               system(@_) == 0 || _error_exitcode($_[0]);
+               system(@_) == 0 || _error_exitcode(join(" ", @_));
        }
 }
 
@@ -312,7 +313,7 @@ sub dirname {
                        }
                }
 
-               if ($c < 4 && ! $warned_compat) {
+               if ($c <= 4 && ! $warned_compat) {
                        warning("Compatibility levels before 5 are deprecated.");
                        $warned_compat=1;
                }
@@ -347,12 +348,15 @@ sub tmpdir {
 #
 # It tries several filenames:
 #   * debian/package.filename.buildarch
+#   * debian/package.filename.buildos
 #   * debian/package.filename
-#   * debian/file (if the package is the main package)
-# If --name was specified then tonly the first two are tried, and they must
-# have the name after the pacage name:
+#   * debian/filename (if the package is the main package)
+# If --name was specified then the files
+# must have the name after the package name:
 #   * debian/package.name.filename.buildarch
+#   * debian/package.name.filename.buildos
 #   * debian/package.name.filename
+#   * debian/name.filename (if the package is the main package)
 sub pkgfile {
        my $package=shift;
        my $filename=shift;
@@ -362,6 +366,7 @@ sub pkgfile {
        }
        
        my @try=("debian/$package.$filename.".buildarch(),
+                "debian/$package.$filename.".buildos(),
                 "debian/$package.$filename");
        if ($package eq $dh{MAINPACKAGE}) {
                push @try, "debian/$filename";
@@ -604,7 +609,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;
 }
@@ -621,6 +626,18 @@ sub dpkg_architecture_value {
        }
 }
 
+# Returns the build OS. (Memoized)
+{
+       my $os;
+
+       sub buildos {
+               if (!defined $os) {
+                       $os=dpkg_architecture_value("DEB_HOST_ARCH_OS");
+               }
+               return $os;
+       }
+}
+
 # Passed an arch and a list of arches to match against, returns true if matched
 sub samearch {
        my $arch=shift;
@@ -651,9 +668,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);
@@ -664,12 +680,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="";
@@ -704,10 +714,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="";
@@ -783,4 +795,32 @@ 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 jobserver options from MAKEFLAGS.
+sub clean_jobserver_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;
+               }
+               delete $ENV{MAKEFLAGS} if $ENV{MAKEFLAGS} =~ /^\s*$/;
+       }
+}
+
 1