]> git.donarmstrong.com Git - debhelper.git/blobdiff - Dh_Lib.pm
r1539: fix tag name
[debhelper.git] / Dh_Lib.pm
index fb02a5dd8aed3dab4d66141b4ff458c2a344969a..e74e8ccbcbb6a5ae06bd924e061b494970ab9f4b 100644 (file)
--- a/Dh_Lib.pm
+++ b/Dh_Lib.pm
@@ -12,8 +12,11 @@ use vars qw(@ISA @EXPORT %dh);
 @ISA=qw(Exporter);
 @EXPORT=qw(&init &doit &complex_doit &verbose_print &error &warning &tmpdir
            &pkgfile &pkgext &isnative &autoscript &filearray &GetPackages
+           &xargs
            %dh);
 
+my $max_compat=2;
+
 sub init {
        # If DH_OPTIONS is set, prepend it @ARGV.
        if (defined($ENV{DH_OPTIONS})) {
@@ -121,6 +124,41 @@ sub complex_doit {
        }                       
 }
 
+# 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
+# it each time.
+sub xargs {
+       my $args=shift;
+
+        # The kernel can accept command lines up to 20k worth of characters.
+       my $command_max=20000;
+
+       # Figure out length of static portion of command.
+       my $static_length=0;
+       foreach (@_) {
+               $static_length+=length($_)+1;
+       }
+       
+       my @collect=();
+       my $length=$static_length;
+       foreach (@$args) {
+               if (length($_) + 1 + $static_length > $command_max) {
+                       error("This command is greater than the maximum command size allowed by the kernel, and cannot be split up further. What on earth are you doing? \"@_ $_\"");
+               }
+               $length+=length($_) + 1;
+               if ($length < $command_max) {
+                       push @collect, $_;
+               }
+               else {
+                       doit(@_,@collect) if $#collect > -1;
+                       @collect=();
+                       $length=$static_length;
+               }
+       }
+       doit(@_,@collect) if $#collect > -1;
+}
+
 # Print something if the verbose flag is on.
 sub verbose_print { my $message=shift;
        if ($dh{VERBOSE}) {
@@ -151,14 +189,31 @@ sub dirname { my $fn=shift;
        return $fn;
 }
 
+# Pass in a number, will return true iff the current compatability level
+# is equal to that number.
+sub compat {
+       my $num=shift;
+       
+       my $c=1;
+       if (defined $ENV{DH_COMPAT}) {
+               $c=$ENV{DH_COMPAT};
+       }
+
+       if ($c > $max_compat) {
+               error("Sorry, but $max_compat is the highest compatability level of debhelper currently supported.");
+       }
+
+       return ($c == $num);
+}
+
 # Pass it a name of a binary package, it returns the name of the tmp dir to
 # use, for that package.
-# This is for back-compatability with the debian/tmp tradition.
 sub tmpdir { my $package=shift;
        if ($dh{TMPDIR}) {
                return $dh{TMPDIR};
        }
-       elsif ($package eq $dh{MAINPACKAGE}) {
+       elsif (compat(1) && $package eq $dh{MAINPACKAGE}) {
+               # This is for back-compatability with the debian/tmp tradition.
                return "debian/tmp";
        }
        else {
@@ -173,10 +228,10 @@ sub tmpdir { my $package=shift;
 # the main package, it will look for debian/foo, and if found, return that.
 # Failing that, it will return nothing.
 sub pkgfile { my $package=shift; my $filename=shift;
-       if (-e "debian/$package.$filename") {
+       if (-f "debian/$package.$filename") {
                return "debian/$package.$filename";
        }
-       elsif ($package eq $dh{MAINPACKAGE} && -e "debian/$filename") {
+       elsif ($package eq $dh{MAINPACKAGE} && -f "debian/$filename") {
                return "debian/$filename";
        }
        return "";
@@ -241,11 +296,11 @@ sub autoscript { my $package=shift; my $script=shift; my $filename=shift; my $se
                $infile="$ENV{DH_AUTOSCRIPTDIR}/$filename";
        }
        else {
-               if (-e "/usr/lib/debhelper/autoscripts/$filename") {
-                       $infile="/usr/lib/debhelper/autoscripts/$filename";
+               if (-e "/usr/share/debhelper/autoscripts/$filename") {
+                       $infile="/usr/share/debhelper/autoscripts/$filename";
                }
                else {
-                       error("/usr/lib/debhelper/autoscripts/$filename does not exist");
+                       error("/usr/share/debhelper/autoscripts/$filename does not exist");
                }
        }
 
@@ -261,7 +316,7 @@ sub filearray { my $file=shift;
        my @ret;
        open (DH_FARRAY_IN,"<$file") || error("cannot read $file: $1");
        while (<DH_FARRAY_IN>) {
-               push @ret,split(/\s/,$_);
+               push @ret,split(' ',$_);
        }
        close DH_FARRAY_IN;