[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.10-69-g6cca0e3



The following commit has been merged in the master branch:
commit 6cca0e330f7340ae24756e62ceb03da72328ef80
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Jul 22 15:29:18 2012 +0200

    L::Architecture: Handle aliases and improve doc
    
    Properly handle that (e.g.) amd64 and linux-amd64 are considered
    aliases.  Mention the handling of aliases in the POD doc and reference
    relevant Policy sections.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index d785092..527f085 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -66,6 +66,9 @@ lintian (2.5.11) UNRELEASED; urgency=low
     + [NT] Retire depreciated command line and config options.
     + [NT] Refactor unpackaging into Lintian::Unpacker.
 
+  * lib/Lintian/Architecture.pm:
+    + [NT] Properly handle cases like "linux-amd64" being an
+      alias of "amd64".
   * lib/Lintian/Collect{,/Source}.pm:
     + [NT] Add optional parameter to field (and X_field)
       methods that denotes the default value if a field is
diff --git a/lib/Lintian/Architecture.pm b/lib/Lintian/Architecture.pm
index b506125..cf37468 100644
--- a/lib/Lintian/Architecture.pm
+++ b/lib/Lintian/Architecture.pm
@@ -55,7 +55,30 @@ Lintian::Architecture -- Lintian API for handling architectures and wilcards
 =head1 DESCRIPTION
 
 Lintian API for checking and expanding architectures and architecture
-wildcards.
+wildcards.  The functions are backed by a L<data|Lintian::Data> file,
+so it may be out of date (use private/refresh-archs to update it).
+
+Generally all architecture names are in the format "$os-$arch" and
+wildcards are "$os-any" or "any-$cpu", though there are exceptions:
+
+=over 4
+
+=item * "all" is the "architecture independent" architecture.
+
+Source: Policy §5.6.8 (v3.9.3)
+
+=item * "any" is a wildcard matching any architecture except "all".
+
+Source: Policy §5.6.8 (v3.9.3)
+
+=item * All other cases of "$arch" are short for "linux-$arch"
+
+Source: Policy §11.1 (v3.9.3)
+
+=back
+
+Note that the architecture and cpu name are not always identical
+(example architecture "armhf" has cpu name "arm").
 
 =head1 FUNCTIONS
 
@@ -69,6 +92,9 @@ The following methods are exportable:
 
 # Valid architecture wildcards.
 my %ARCH_WILDCARDS = ();
+# Maps aliases to the "original" arch name.
+# (e.g. "linux-amd64" => "amd64")
+my %ALT_ARCH_NAMES = ();
 
 sub _parse_arch {
     my ($archstr, $raw) = @_;
@@ -78,6 +104,18 @@ sub _parse_arch {
     $ARCH_WILDCARDS{"$os-any"}->{$archstr} = 1;
     $ARCH_WILDCARDS{"any-$arch"}->{$archstr} = 1;
     $ARCH_WILDCARDS{'any'}->{$archstr} = 1;
+    if ($os eq 'linux') {
+        # Per Policy §11.1 (3.9.3):
+        #
+        #"""[architecture] strings are in the format "os-arch", though
+        # the OS part is sometimes elided, as when the OS is Linux."""
+        #
+        # i.e. "linux-amd64" and "amd64" are aliases, so handle them
+        # as such.  Currently, dpkg-architecture -L gives us "amd64"
+        $ALT_ARCH_NAMES{"$os-$arch"} = $archstr;
+        # ... but in case it changes to "linux-amd64", we are prepared.
+        $ALT_ARCH_NAMES{$arch} = $archstr;
+    }
 }
 
 my $ARCH_RAW = Lintian::Data->new ('common/architectures', qr/\s*+\Q||\E\s*+/o,
@@ -85,7 +123,7 @@ my $ARCH_RAW = Lintian::Data->new ('common/architectures', qr/\s*+\Q||\E\s*+/o,
 
 =item is_arch_wildcard ($wc)
 
-Returns a truth value if $wc is an architecture wildcard.
+Returns a truth value if $wc is a known architecture wildcard.
 
 Note: 'any' is considered a wildcard and not an architecture.
 
@@ -99,17 +137,19 @@ sub is_arch_wildcard {
 
 =item is_arch ($arch)
 
-Returns a truth value if $arch is an architecture (but not an
-architecture wildcard).
-
-Note that 'any' is considered a wildcard and not an architecture.
+Returns a truth value if $arch is (an alias of) a Debian machine
+architecture OR the special value "all".  It returns a false value for
+architecture wildcards (including "any") and unknown architectures.
 
 =cut
 
 sub is_arch {
     my ($arch) = @_;
-    return 1 if $arch eq 'all';
-    return ($arch ne 'any' && $ARCH_RAW->known($arch)) ? 1 : 0;
+    return 0 if $arch eq 'any';
+    return 1 if $arch eq 'all'
+        or $ARCH_RAW->known ($arch)
+        or exists $ALT_ARCH_NAMES{$arch};
+    return 0;
 }
 
 =item is_arch_or_wildcard ($arch)
@@ -136,7 +176,10 @@ modified.
 
 Note: This list is based on the architectures in Lintian's data file.
 However, many of these are not supported or used in Debian or any of
-its derivaties.
+its derivatives.
+
+The returned values matches the list generated by dpkg-architecture -L,
+so the returned list may use (e.g.) "amd64" for "linux-amd64".
 
 =cut
 
@@ -148,7 +191,7 @@ sub expand_arch_wildcard {
     return keys %{ $ARCH_WILDCARDS{$wc} };
 }
 
-=item wildcard_include_arch ($wc, $arch)
+=item wildcard_includes_arch ($wc, $arch)
 
 Returns a truth value if $arch is included in the list of
 architectures that $wc expands to.
@@ -157,12 +200,16 @@ This is generally faster than
 
   grep { $_ eq $arch } expand_arch_wildcard ($wc)
 
+It also properly handles cases like "linux-amd64" and "amd64" being
+aliases.
+
 =cut
 
 sub wildcard_includes_arch {
     my ($wc, $arch) = @_;
     # Load the wildcards if it has not been done yet.
     $ARCH_RAW->known ('any') unless %ARCH_WILDCARDS;
+    $arch = $ALT_ARCH_NAMES{$arch} if exists $ALT_ARCH_NAMES{$arch};
     return exists $ARCH_WILDCARDS{$wc}->{$arch} ? 1 : 0;
 }
 

-- 
Debian package checker


Reply to: