From 58cc1a2cc662245e053e8a788142a79a31547dd8 Mon Sep 17 00:00:00 2001
From: Niels Thykier <niels@thykier.net>
Date: Thu, 28 Apr 2011 10:49:06 +0200
Subject: [PATCH] Allow simple architecture specific overrides

This patch allows overrides to be architecture specific without
architecture wildcards nor sanity checks of architectures listed.
The new override syntax will be:

[[pkgname] [archlist] [pkgtype]:]<tag>[ extra]

Where [archlist] is the same format* as in the B-D field and the
rest of the fields are known from the current/previous syntax.

* including the [], so [i386 amd64] etc.
---
 debian/changelog                                   |    5 ++
 doc/lintian.xml                                    |    4 +-
 lib/Lintian/Tags.pm                                |   40 +++++++++++++++++--
 .../debian/debian/overrides.lintian-overrides      |    4 ++
 t/tests/overrides/tags                             |    3 +-
 5 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 79707b8..ec80eda 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,11 @@ lintian (2.5.0~rc4) UNRELEASED; urgency=low
       patch without a patch header.  Thanks to Iain Lane for suggestion
       and patch.  (Closes: #588873)
 
+  * lib/Lintian/Tags.pm:
+    + [NT] Allow simple architecture overrides such as [i386] or [!i386].
+      Architecture wildcards are not supported yet.  The actual syntax
+      for the architecture the same as the one used in the Build-Depends.
+      (Closes: #622888)
   * lib/Lintian/ProcessableGroup.pm:
     + [NT] Properly handle if the changes file is located directly in the
       file system root.  Thanks to Trent W. Buck for the bug report.
diff --git a/doc/lintian.xml b/doc/lintian.xml
index feb27d7..3020315 100644
--- a/doc/lintian.xml
+++ b/doc/lintian.xml
@@ -496,8 +496,10 @@ $
       <para>
         The format of the overrides file is simple, it consists of one override per
         line (and may contain empty lines and comments, starting with a <literal>#</literal>, on others):
-        <literal>[<replaceable>&lt;package&gt;</replaceable>[ <replaceable>&lt;type&gt;</replaceable>]: ]<replaceable>&lt;lintian-tag&gt;</replaceable>[
+        <literal>[[<replaceable>&lt;package&gt;</replaceable>][ <replaceable>&lt;archlist&gt;</replaceable>][ <replaceable>&lt;type&gt;</replaceable>]: ]<replaceable>&lt;lintian-tag&gt;</replaceable>[
           [*]<replaceable>&lt;lintian-info&gt;</replaceable>[*]]</literal>.  <replaceable>&lt;package&gt;</replaceable> is the package name;
+        <replaceable>&lt;archlist&gt;</replaceable> is an architecture list
+        in the same format as for the Build-Depends field;
         <replaceable>&lt;type&gt;</replaceable> is one of <literal>binary</literal>, <literal>udeb</literal> and
         <literal>source</literal>,
         and <replaceable>&lt;lintian-info&gt;</replaceable> is all
diff --git a/lib/Lintian/Tags.pm b/lib/Lintian/Tags.pm
index 7f6b4cf..6eee812 100644
--- a/lib/Lintian/Tags.pm
+++ b/lib/Lintian/Tags.pm
@@ -535,13 +535,43 @@ sub file_overrides {
         next if /^(?:\#|\z)/;
         s/\s+/ /go;
         my $override = $_;
-        $override =~ s/^\Q$info->{package}\E( \Q$info->{type}\E)?: //;
-        if ($override eq '' or $override !~ /^[\w.+-]+(?:\s.*)?$/) {
-            tag('malformed-override', $_);
-        } else {
-            my ($tag, $extra) = split(/ /, $override, 2);
+        # The override looks like the following:
+        # [[pkg-name] [arch-list] [pkg-type]:] <tag> [extra]
+        if ($override =~ m/^(?:                 # start optional part
+                  (?:\Q$info->{package}\E)?     # Optionally starts with package name
+                  (?: \s*+ \[([^\]]+?)\])?      # optionally followed by an [arch-list] (like in B-D) -> $1
+                  (?: \s*+ \Q$info->{type}\E)?  # optionally followed by the type
+                :\s++)?                         # end optional part
+                (.+)$/x){                       # <tag-name> [extra] -> $2
+            # Valid - so far at least
+            my ($archlist, $tagdata) = ($1, $2);
+            my ($tag, $extra) = split(m/ /o, $tagdata, 2);
+            if ($archlist) {
+                # parse and figure
+                my (@archs) = split(m/\s++/o, $archlist);
+                my $negated = 0;
+                my $found = 0;
+                foreach my $a (@archs){
+                    $negated++ if $a =~ s/^!//o;
+                    $found = 1 if $a eq $info->{arch};
+                }
+                if ($negated > 0 && scalar @archs != $negated){
+                    # missing a ! somewhere
+                    tag 'malformed-override', $_, 'Inconsistent architecture negation';
+                    next;
+                }
+                # missing wildcard checks and sanity checking archs $arch
+                if ($negated) {
+                    $found = 1 if !$found;
+                } else {
+                    $found = 0 if $found;
+                }
+                next unless $found;
+            }
             $extra = '' unless defined $extra;
             $info->{overrides}{$tag}{$extra} = 0;
+        } else {
+            tag('malformed-override', $_);
         }
     }
     close $file;
diff --git a/t/tests/overrides/debian/debian/overrides.lintian-overrides b/t/tests/overrides/debian/debian/overrides.lintian-overrides
index 16ac4da..85f4278 100644
--- a/t/tests/overrides/debian/debian/overrides.lintian-overrides
+++ b/t/tests/overrides/debian/debian/overrides.lintian-overrides
@@ -1,5 +1,9 @@
 # override without extra information
 manpage-has-bad-whatis-entry
+# Architecture specific override - which is retarded considering
+# it is an arch: all package we are testing >.>
+[i386]: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:12
+[!i386]: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:6
 # exact extra information
 hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:4
 # wildcards
diff --git a/t/tests/overrides/tags b/t/tests/overrides/tags
index bf32a7d..eb5aa2d 100644
--- a/t/tests/overrides/tags
+++ b/t/tests/overrides/tags
@@ -2,6 +2,5 @@ I: overrides: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz 2 more occur
 I: overrides: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:12
 I: overrides: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:13
 I: overrides: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:14
-I: overrides: hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz:6
 I: overrides: unused-override hyphen-used-as-minus-sign usr/share/man/man1/foo.1.gz * more occurrences not shown
-N: 7 tags overridden (1 warning, 6 info)
+N: 8 tags overridden (1 warning, 7 info)
-- 
1.7.4.1

