]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Dh_Lib.pm
Memoize architecture comparisons in samearch, and avoid calling dpkg-architecture...
[debhelper.git] / Debian / Debhelper / Dh_Lib.pm
index b96ea3443091b77465c0a093dba9d7172ce8d7a2..421dd99647fa69f5f530493da00857d00925df02 100644 (file)
@@ -65,16 +65,16 @@ sub init {
                $dh{NO_ACT}=1;
        }
 
-       my @allpackages=getpackages();
        # Get the name of the main binary package (first one listed in
        # debian/control). Only if the main package was not set on the
        # command line.
        if (! exists $dh{MAINPACKAGE} || ! defined $dh{MAINPACKAGE}) {
+               my @allpackages=getpackages();
                $dh{MAINPACKAGE}=$allpackages[0];
        }
 
        # Check if packages to build have been specified, if not, fall back to
-       # the default, doing them all.
+       # the default, building all relevant packages.
        if (! defined $dh{DOPACKAGES} || ! @{$dh{DOPACKAGES}}) {
                push @{$dh{DOPACKAGES}}, getpackages('both');
        }
@@ -638,15 +638,34 @@ sub dpkg_architecture_value {
 }
 
 # Passed an arch and a list of arches to match against, returns true if matched
-sub samearch {
-       my $arch=shift;
-       my @archlist=split(/\s+/,shift);
+{
+       my %knownsame;
 
-       foreach my $a (@archlist) {
-               system("dpkg-architecture", "-a$arch", "-i$a") == 0 && return 1;
+       sub samearch {
+               my $arch=shift;
+               my @archlist=split(/\s+/,shift);
+       
+               foreach my $a (@archlist) {
+                       # Avoid expensive dpkg-architecture call to compare
+                       # with a simple architecture name. "linux-any" and
+                       # other architecture wildcards are (currently)
+                       # always hypenated.
+                       if ($a !~ /-/) {
+                               return 1 if $arch eq $a;
+                       }
+                       elsif (exists $knownsame{$arch}{$a}) {
+                               return 1 if $knownsame{$arch}{$a};
+                       }
+                       elsif (system("dpkg-architecture", "-a$arch", "-i$a") == 0) {
+                               return $knownsame{$arch}{$a}=1;
+                       }
+                       else {
+                               $knownsame{$arch}{$a}=0;
+                       }
+               }
+       
+               return 0;
        }
-
-       return 0;
 }
 
 # Returns source package name