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

[SCM] Debian package checker branch, master, updated. 2.5.4-77-gd2ce5b1



The following commit has been merged in the master branch:
commit d2ce5b1aed84be1998f6a1605ffc0b9ad1d21bd3
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Dec 23 20:31:35 2011 +0100

    Created new module for handling architectures
    
    The new API handles some basic queries like checking if a string
    is a known architecture or architecture wildcard.  It can also
    expand an wildcards and check if a wildcard contains an a given
    architecture.
    
    Also moved data/fields/architectures to data/common.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/fields b/checks/fields
index 882e5e2..8587b13 100644
--- a/checks/fields
+++ b/checks/fields
@@ -30,13 +30,13 @@ use Dpkg::Version qw(version_check);
 
 use Util;
 
+use Lintian::Architecture qw(:all);
 use Lintian::Data ();
 use Lintian::Check qw(check_maintainer);
 use Lintian::Relation ();
 use Lintian::Relation::Version qw(versions_compare);
 use Lintian::Tags qw(tag);
 
-our $KNOWN_ARCHS = Lintian::Data->new('fields/architectures');
 our $KNOWN_ESSENTIAL = Lintian::Data->new('fields/essential');
 our $KNOWN_METAPACKAGES = Lintian::Data->new('fields/metapackages');
 our $NO_BUILD_DEPENDS = Lintian::Data->new('fields/no-build-depends');
@@ -45,21 +45,6 @@ our $known_build_essential = Lintian::Data->new('fields/build-essential-packages
 our $KNOWN_BINARY_FIELDS = Lintian::Data->new('fields/binary-fields');
 our $KNOWN_UDEB_FIELDS = Lintian::Data->new('fields/udeb-fields');
 
-# Generate the list of valid architecture wildcards.  We can ignore all
-# architectures not containing a - for our purposes and transform any
-# architecture like foo-bar into any-bar and foo-any.  Putting this in a hash
-# will then clean up all the duplicates.
-our %ARCH_WILDCARDS = map {
-    if (/-/) {
-        my ($first, $second) = split ('-', $_, 2);
-        ("$first-any" => 1, "any-$second" => 1);
-    } else {
-        ();
-    }
-} $KNOWN_ARCHS->all;
-$ARCH_WILDCARDS{'linux-any'} = 1;
-$ARCH_WILDCARDS{any} = 1;
-
 our %KNOWN_ARCHIVE_PARTS = map { $_ => 1 }
     ('non-free', 'contrib');
 
@@ -302,9 +287,9 @@ if (not defined $info->field('architecture')) {
     }
     for my $arch (@archs) {
         tag 'unknown-architecture', $arch
-            unless $KNOWN_ARCHS->known($arch) || $ARCH_WILDCARDS{$arch};
+            unless is_arch_or_wildcard ($arch);
         tag 'arch-wildcard-in-binary-package', $arch
-            if ($type eq 'binary' && $ARCH_WILDCARDS{$arch});
+            if ($type eq 'binary' && is_arch_wildcard ($arch));
     }
 
     if ($type eq 'binary') {
@@ -782,7 +767,7 @@ if ($type eq 'source') {
 
                     my $negated = 0;
                     for my $arch (@{$d_arch->[0]}) {
-                        if ($arch eq 'all' || (!$KNOWN_ARCHS->known($arch) && !$ARCH_WILDCARDS{$arch})) {
+                        if ($arch eq 'all' || !is_arch_or_wildcard ($arch)) {
                             tag 'invalid-arch-string-in-source-relation', "$arch [$field: $part_d_orig]"
                         }
                     }
diff --git a/data/fields/architectures b/data/common/architectures
similarity index 100%
rename from data/fields/architectures
rename to data/common/architectures
diff --git a/debian/changelog b/debian/changelog
index 4be990a..f7db5db 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -48,6 +48,7 @@ lintian (2.5.5) UNRELEASED; urgency=low
       wrongly identified as belong to the python section.
     + [NT] Fixed an issue where "doc-pkg-depends-on-main-pkg" would
       only be triggered if it was a "pre-depends" relation.
+    + [NT] Use new Lintian::Architecture API.
   * checks/files:
     + [JW,NT] Skip "Multi-Arch: same" check of gzip files if their
       install path contains the architecture.  (Closes: #650665)
@@ -92,6 +93,8 @@ lintian (2.5.5) UNRELEASED; urgency=low
     + [NT] Removed as they are no longer needed.  They have been
       replaced by a smarter Lintian::Collect.
 
+  * data/{fields => common}/architectures:
+    + [NT] Moved architectures to data/common.
   * data/debhelper/dh_addons-manual:
     + [JW] Add python3-sphinx as provider of sphinxdoc dh sequence.
   * data/debhelper/dh_commands-manual:
@@ -124,6 +127,8 @@ lintian (2.5.5) UNRELEASED; urgency=low
     + [NT] Support new lintian.log format.
     + [NT] Support new override file format with -a.
 
+  * lib/Lintian/Architecture.pm:
+    + [NT] New file.
   * lib/Lintian/Check.pm:
     + [NT] Do not check for missing uploader address as it cannot be
       done reliably anymore.
diff --git a/lib/Lintian/Architecture.pm b/lib/Lintian/Architecture.pm
new file mode 100644
index 0000000..6ef5db2
--- /dev/null
+++ b/lib/Lintian/Architecture.pm
@@ -0,0 +1,182 @@
+# -*- perl -*-
+# Lintian::Architecture
+
+# Copyright (C) 2011 Niels Thykier
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package Lintian::Architecture;
+
+use strict;
+use warnings;
+
+use base 'Exporter';
+our (@EXPORT_OK, %EXPORT_TAGS);
+
+@EXPORT_OK = (qw(
+    is_arch_wildcard
+    is_arch
+    is_arch_or_wildcard
+    expand_arch_wildcard
+    wildcard_includes_arch
+));
+
+%EXPORT_TAGS = (all => \@EXPORT_OK);
+
+
+=head1 NAME
+
+Lintian::Architecture -- Lintian API for handling architectures and wilcards
+
+=head1 SYNOPSIS
+
+ use Lintian::Architecture qw(:all);
+ 
+ print "arch\n" if is_arch ('i386');
+ print "wildcard\n" if is_arch_wildcard ('any');
+ print "either arch or wc\n" if is_arch_or_wildcard ('linux-any');
+ foreach my $arch (expand_arch_wildcard ('any')) {
+     print "any expands to $arch\n";
+ }
+
+=head1 DESCRIPTION
+
+Lintian API for checking and expanding architectures and architecture
+wildcards.
+
+=head1 FUNCTIONS
+
+The following methods are exportable:
+
+=over 4
+
+=cut
+
+# Setup code
+
+my $ARCH_RAW = Lintian::Data->new ('common/architectures');
+
+# Generate the list of valid architecture wildcards.  We can ignore all
+# architectures not containing a - for our purposes and transform any
+# architecture like foo-bar into any-bar and foo-any.  Putting this in a hash
+# will then clean up all the duplicates.
+my $ARCH_WILDCARDS = {};
+
+foreach my $archstr ($ARCH_RAW->all) {
+    my ($os, $arch);
+    next if $archstr eq 'all' or $archstr eq 'any';
+    ($os, $arch) = split /-/, $archstr;
+    unless ($arch) {
+        # Linux archs do not have a "linux-" prefix like other architectures
+        $arch = $os;
+        $os = 'linux';
+    }
+    # map $os-any (e.g. "linux-any") and any-$arch (e.g. "any-amd64") to
+    # the relevant architectures.
+    $ARCH_WILDCARDS->{"$os-any"}->{$archstr} = 1;
+    $ARCH_WILDCARDS->{"any-$arch"}->{$archstr} = 1;
+    $ARCH_WILDCARDS->{'any'}->{$archstr} = 1;
+}
+
+=item is_arch_wildcard ($wc)
+
+Returns a truth value if $wc is an architecture wildcard.
+
+Note: 'any' is considered a wildcard and not an architecture.
+
+=cut
+
+sub is_arch_wildcard {
+    my ($wc) = @_;
+    return exists $ARCH_WILDCARDS->{$wc} ? 1 : 0;
+}
+
+=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.
+
+=cut
+
+sub is_arch {
+    my ($arch) = @_;
+    return 1 if $arch eq 'all';
+    return ($arch ne 'any' && $ARCH_RAW->known($arch)) ? 1 : 0;
+}
+
+=item is_arch_or_wildcard ($arch)
+
+Returns a truth value if $arch is either an architecture or an
+architecture wildcard.
+
+Shorthand for:
+
+ is_arch ($arch) || is_arch_wildcard ($arch)
+
+=cut
+
+sub is_arch_or_wildcard {
+    my ($arch) = @_;
+    return is_arch($arch) || is_arch_wildcard($arch);
+}
+
+=item expand_arch_wildcard ($wc)
+
+Returns a list of architectures that this wildcard expands to.  No
+order is guaranteed (even between calls).  Returned values must not be
+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.
+
+=cut
+
+sub expand_arch_wildcard {
+    my ($wc) = @_;
+    return () unless exists $ARCH_WILDCARDS->{$wc};
+    return keys %{ $ARCH_WILDCARDS->{$wc} };
+}
+
+=item wildcard_include_arch ($wc, $arch)
+
+Returns a truth value if $arch is included in the list of
+architectures that $wc expands to.
+
+This is generally faster than
+
+  grep { $_ eq $arch } expand_arch_wildcard ($wc)
+
+=cut
+
+sub wildcard_includes_arch {
+    my ($wc, $arch) = @_;
+    return exists $ARCH_WILDCARDS->{$wc}->{$arch} ? 1 : 0;
+}
+
+=back
+
+
+
+=cut
+
+1;
+
+# Local Variables:
+# indent-tabs-mode: nil
+# cperl-indent-level: 4
+# End:
+# vim: syntax=perl sw=4 sts=4 sr et
diff --git a/private/refresh-archs b/private/refresh-archs
index dd752a6..c8357bd 100755
--- a/private/refresh-archs
+++ b/private/refresh-archs
@@ -43,7 +43,7 @@ EOF
 { echo "any"; echo "all";
   dpkg-architecture -L; } | sort >> "$f"
 
-mv "$f" "$1"/fields/architectures
+mv "$f" "$1"/common/architectures
 
 
 ### Triplets list ###

-- 
Debian package checker


Reply to: