&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_jobserver_makeflags);
my $max_compat=7;
grep /^-/, @ARGV) {
eval "use Debian::Debhelper::Dh_Getopt";
error($@) if $@;
- Debian::Debhelper::Dh_Getopt::parseopts($params{options});
+ Debian::Debhelper::Dh_Getopt::parseopts(%params);
}
# Another way to set excludes.
# Check if packages to build have been specified, if not, fall back to
# the default, doing them all.
if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
- push @{$dh{DOPACKAGES}},@allpackages;
+ push @{$dh{DOPACKAGES}}, getpackages('both');
}
# Check to see if -P was specified. If so, we can only act on a single
}
}
-# 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;
-
- 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;
- }
- 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;
- }
- }
- if ($status) {
- # MAKEFLAGS could be unset if it is empty
- $makeflags = undef if $makeflags =~ /^\s*$/;
- }
- return wantarray ? ($status, $makeflags) : $status;
-}
-
# Run a command that may have a huge number of arguments, like xargs does.
# Pass in a reference to an array containing the arguments, and then other
# parameters that are the command and any parameters that should be passed to
}
}
-# 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.
}
}
- if ($c < 4 && ! $warned_compat) {
+ if ($c <= 4 && ! $warned_compat) {
warning("Compatibility levels before 5 are deprecated.");
$warned_compat=1;
}
# 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, $_;
}
}
# Returns a list of packages in the control file.
-# Pass "arch" or "indep" to specify arch-dependant or
-# independant. If nothing is specified, returns all packages.
+# Pass "arch" or "indep" to specify arch-dependant (that will be built
+# for the system's arch) or independant. If nothing is specified,
+# returns all packages. Also, "both" returns the union of "arch" and "indep"
+# 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);
}
if ($package &&
- (($type eq 'indep' && $arch eq 'all') ||
- ($type eq 'arch' && ($arch eq 'any' ||
+ ((($type eq 'indep' || $type eq 'both') && $arch eq 'all') ||
+ (($type eq 'arch' || $type eq 'both') && ($arch eq 'any' ||
($arch ne 'all' &&
samearch(buildarch(), $arch)))) ||
! $type)) {
}
}
+# 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