X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debian%2FDebhelper%2FDh_Lib.pm;h=f37ff5188699c09f938a8d365b4ea7f4ce5d87fa;hb=ed15bc2a33381f18113a95e2e855f4cfb82ee6e9;hp=b3162d07ae9a77cc2844d73291e4b09436acbfe1;hpb=b709661d78cf519739b7ed2bd2d69599c3c31459;p=debhelper.git diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index b3162d0..f37ff51 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -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; @@ -29,10 +30,10 @@ sub init { # Getopt::Long, which I'd prefer to avoid loading at all if possible. if ((defined $ENV{DH_OPTIONS} && length $ENV{DH_OPTIONS}) || (defined $ENV{DH_INTERNAL_OPTIONS} && length $ENV{DH_INTERNAL_OPTIONS}) || - (defined $params{extra_args}) || grep /^-/, @ARGV) { + grep /^-/, @ARGV) { eval "use Debian::Debhelper::Dh_Getopt"; error($@) if $@; - Debian::Debhelper::Dh_Getopt::parseopts($params{options}, $params{extra_args}); + Debian::Debhelper::Dh_Getopt::parseopts(%params); } # Another way to set excludes. @@ -175,7 +176,7 @@ sub doit { verbose_print(escape_shell(@_)); if (! $dh{NO_ACT}) { - system(@_) == 0 || _error_exitcode($_[0]); + system(@_) == 0 || _error_exitcode(join(" ", @_)); } } @@ -250,12 +251,11 @@ sub verbose_print { } } -# Output an error message and exit. +# Output an error message and die (can be caught). sub error { my $message=shift; - warning($message); - exit 1; + die basename($0).": $message\n"; } # Output a warning. @@ -312,7 +312,7 @@ sub dirname { } } - if ($c < 4 && ! $warned_compat) { + if ($c <= 4 && ! $warned_compat) { warning("Compatibility levels before 5 are deprecated."); $warned_compat=1; } @@ -576,7 +576,7 @@ sub filedoublearray { # as if we were in the specified directory, so the # filenames that come out are relative to it. if (defined $globdir && ! compat(2)) { - for (map { glob "$globdir/$_" } split) { + foreach (map { glob "$globdir/$_" } split) { s#^$globdir/##; push @line, $_; } @@ -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,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