]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Lib.pm
fix bad interaction between -O and ignore_unknown_options
[debhelper.git] / Debian / Debhelper / Dh_Lib.pm
index ebf7db7e846332e790976682d9ccc96d00f4544a..f37ff5188699c09f938a8d365b4ea7f4ce5d87fa 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 &get_make_jobserver_status);
+           &sourcepackage
+           &is_make_jobserver_unavailable &clean_jobserver_makeflags);
 
 my $max_compat=7;
 
@@ -32,7 +33,7 @@ sub init {
            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.
@@ -205,46 +206,6 @@ sub _error_exitcode {
        }
 }
 
-# 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
@@ -290,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.
@@ -352,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;
                }
@@ -616,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, $_;
                        }
@@ -834,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