summaryrefslogtreecommitdiff
path: root/Debian/Debhelper/Dh_Lib.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-10-28 16:45:12 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-10-28 17:02:41 -0400
commit76719d85abaa3a536af862b0aac2307d735e84d8 (patch)
tree130293bc255d0fd6840bb7c9e8d39cb5def2d6db /Debian/Debhelper/Dh_Lib.pm
parent4fb1f3b2d64a2faa9d961205b1c32f83028172c8 (diff)
split get_make_jobserver_status into two functions
I disliked the complexity of the return values, and the boilerplate code that followed the two calls to the function, to clean/unset MAKEFLAGS. To solve both, I refactored it into two functions, one simply tests to see if a jobserver is specified but unavailable, while the other cleans/unsets MAKEFLAGS. This loses the ability to pull the jobs-N count out of MAKEFLAGS, but that was not currently used.
Diffstat (limited to 'Debian/Debhelper/Dh_Lib.pm')
-rw-r--r--Debian/Debhelper/Dh_Lib.pm59
1 files changed, 25 insertions, 34 deletions
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 602b77f..ac0d8ab 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -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 &get_make_jobserver_status);
+ &sourcepackage &is_make_jobserver_unavailable &clean_makeflags);
my $max_compat=7;
@@ -794,44 +794,35 @@ sub debhelper_script_subst {
}
}
-# A helper subroutine for detecting (based on MAKEFLAGS) if make jobserver
-# is enabled, if it is available or MAKEFLAGS contains "jobs" option.
-# It returns current status (jobserver, jobserver-unavailable or jobs-N where
-# N is number of jobs, 0 if infinite) and MAKEFLAGS cleaned up from
-# job control options.
-sub get_make_jobserver_status {
- my $jobsre = qr/(?:^|\s)(?:(?:-j\s*|--jobs(?:=|\s+))(\d+)?|--jobs)\b/;
- my $status = "";
- my $makeflags;
+# 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}) {
- $makeflags = $ENV{MAKEFLAGS};
- if ($makeflags =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
- $status = "jobserver";
- if (!open(my $in, "<&", "$1")) {
- # Job server is unavailable
- $status .= "-unavailable";
- }
- else {
- close $in;
- }
- # Clean makeflags up
- $makeflags =~ s/(?:^|\s)--jobserver-fds=\S+//g;
- $makeflags =~ s/(?:^|\s)-j\b//g;
+ if ($ENV{MAKEFLAGS} =~ /(?:^|\s)--jobserver-fds=(\d+)/) {
+ $ENV{MAKEFLAGS} =~ s/(?:^|\s)--jobserver-fds=\S+//g;
+ $ENV{MAKEFLAGS} =~ s/(?:^|\s)-j\b//g;
}
- elsif (my @m = ($makeflags =~ /$jobsre/g)) {
- # Job count is specified in MAKEFLAGS. Whenever make reads it, a new
- # jobserver will be started. Job count returned is 0 if infinite.
- $status = "jobs-" . (defined $m[$#m] ? $m[$#m] : "0");
- # Clean makeflags up from "jobs" option(s)
- $makeflags =~ s/$jobsre//g;
+ else {
+ $ENV{MAKEFLAGS} =~ s/(?:^|\s)(?:(?:-j\s*|--jobs(?:=|\s+))(\d+)?|--jobs)\b//g;
}
+ delete $ENV{MAKEFLAGS} if $ENV{MAKEFLAGS} =~ /^\s*$/;
}
- if ($status) {
- # MAKEFLAGS could be unset if it is empty
- $makeflags = undef if $makeflags =~ /^\s*$/;
- }
- return wantarray ? ($status, $makeflags) : $status;
}
1