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

Bug#648777: lintian: Generalize distribution check



Hello,

Here is an improvement of the patch:

git pull git://git.baby-gnu.org/lintian dad/bad-vendor-distribution-in-changes-file

The changes from the previous patch are:

- Keep the ubuntu specific tag "bad-ubuntu-distribution-in-changes-file"
  for backward compatibility

- Add the new "bad-vendor-distribution-in-changes-file" for vendor
  specific distribution checks.
  To test for vendor specific distribution, the version number must
  contain the vendor or distribution name, for example:
    * 1.2-ubuntu1
    * 2.4+squeeze2
  The name of the vendor is extracted for the
  changelog-file/<vendor>-dists filename.

- Add tests on changes file, the test pass here

Regards.

From ac668a689735a9291fc6cc9bbaf143452b5f668f Mon Sep 17 00:00:00 2001
From: Daniel Dehennin <daniel.dehennin@baby-gnu.org>
Date: Sat, 3 Dec 2011 20:55:29 +0100
Subject: [PATCH] Generalize distribution name check:
 bad-vendor-distribution-in-changes-file.

This patch allow to create a new data/changelog-file/<something>-dists
file to add new valid distribution regexps.

Add the new "bad-vendor-distribution-in-changes-file" tag to catch non
vendor specific distribution missmatch.

Keep the backward compatibility "bad-ubuntu-distribution-in-changes-file"
for ubuntu based version number.

* t/changes/changes-bad-debian-distribution.desc: New test to check bad
  Debian distribution name.
  The version contains a Debian specific distribution to select the proper
  vendor.

* t/changes/changes-bad-debian-distribution.changes.in: Sample changes
  file with the faulty "wispy" distribution.

* t/changes/changes-bad-debian-distribution.tags: The tag must be
  "bad-vendor-distribution-in-changes-file".

* t/changes/changes-bad-distribution.desc: New test to check bad
  cross vendor distribution name, all distribution for all vendors are
  tested.
  The version does not contain any vendor specific distribution name.

* t/changes/changes-bad-distribution.changes.in: Sample changes
  file with the faulty "wispy" distribution.

* t/changes/changes-bad-distribution.tags: The tag must be
  "bad-distribution-in-changes-file".

* checks/changes-file: Use a hash of vendor => regexp to check the
  distribution name.
  Keep the logic of checking vendor or distribution based version number.

* checks/changes-file.desc (Tag): Rename
  "bad-ubuntu-distribution-in-changes-file" to
  "bad-vendor-distribution-in-changes-file" and update description.

* data/changelog-file/debian-dists: Define full regexp instead of only
  base distribution.

* data/changelog-file/ubuntu-dists: Ditoo.
---
 checks/changes-file                                |   43 ++++++++++---------
 checks/changes-file.desc                           |   12 +++++
 data/changelog-file/debian-dists                   |   18 ++++----
 data/changelog-file/ubuntu-dists                   |   16 ++++----
 .../changes-bad-debian-distribution.changes.in     |   12 +++++
 t/changes/changes-bad-debian-distribution.desc     |    6 +++
 t/changes/changes-bad-debian-distribution.tags     |    1 +
 t/changes/changes-bad-distribution.changes.in      |   12 +++++
 t/changes/changes-bad-distribution.desc            |    6 +++
 t/changes/changes-bad-distribution.tags            |    1 +
 10 files changed, 90 insertions(+), 37 deletions(-)
 create mode 100644 t/changes/changes-bad-debian-distribution.changes.in
 create mode 100644 t/changes/changes-bad-debian-distribution.desc
 create mode 100644 t/changes/changes-bad-debian-distribution.tags
 create mode 100644 t/changes/changes-bad-distribution.changes.in
 create mode 100644 t/changes/changes-bad-distribution.desc
 create mode 100644 t/changes/changes-bad-distribution.tags

diff --git a/checks/changes-file b/checks/changes-file
index 5192130..4ecd14f 100644
--- a/checks/changes-file
+++ b/checks/changes-file
@@ -26,12 +26,18 @@ use Util;
 use Lintian::Tags qw(tag);
 use Lintian::Check qw(check_maintainer);
 
-my $DEBIAN_DISTS = Lintian::Data->new ('changelog-file/debian-dists');
-my $UBUNTU_REGEX;
+use Path::Class;
+
+my %DISTRIBUTION_REGEX;
 {
-    my $ubuntu_dists = Lintian::Data->new ('changelog-file/ubuntu-dists');
-    my $reg_str = join('|', $ubuntu_dists->all);
-    $UBUNTU_REGEX = qr/$reg_str/o;
+    my $changelog_dir = dir($ENV{LINTIAN_ROOT}, 'data', 'changelog-file');
+    while (my $filename = $changelog_dir->next()) {
+        next if $filename->is_dir() or $filename !~ m/.*-dists$/;
+        (my $vendor = $filename->basename) =~ s/^(.*)-dists$/$1/xms;
+        my $distrib_dists = Lintian::Data->new(file('changelog-file', $filename->basename));
+        my $reg_str = join('|', $distrib_dists->all);
+        $DISTRIBUTION_REGEX{$vendor} = qr/$reg_str/;
+    }
 }
 
 sub run {
@@ -57,21 +63,18 @@ if (!$info->field('description') && $info->field('architecture') ne 'source') {
 if (defined $info->field('distribution')) {
     my @distributions = split /\s+/o, $info->field('distribution');
     for my $distribution (@distributions) {
-        if ($distribution eq 'UNRELEASED') {
-            # ignore
-        } elsif ($info->field('version') =~ m/ubuntu|$UBUNTU_REGEX/o
-            or $distribution =~ m/$UBUNTU_REGEX/o) {
-                if ($distribution !~ m/^(?:$UBUNTU_REGEX)(?:-(?:proposed|updates|backports|security))?$/o ) {
-                    tag 'bad-ubuntu-distribution-in-changes-file',
-                        $distribution;
-                }
-        } elsif (! ($DEBIAN_DISTS->known ($distribution)
-                     or ($distribution =~ /^\w+-backports$/)
-                     or ($distribution =~ /^\w+-proposed-updates$/)
-                     or ($distribution =~ /^\w+-security$/)
-                     or ($distribution =~ /^\w+-volatile$/))
-                ) {
-            # bad distribution entry
+        next if ($distribution eq 'UNRELEASED');
+
+        # Vendor specific version?
+        my @vendors = grep { $info->field('version') =~ m/$_|$DISTRIBUTION_REGEX{$_}/xms } keys %DISTRIBUTION_REGEX;
+        if (@vendors and ! grep {$distribution =~ m/$_|$DISTRIBUTION_REGEX{$_}/xms } @vendors) {
+            if ($vendors[0] eq 'ubuntu') {
+                tag 'bad-ubuntu-distribution-in-changes-file', $distribution;
+            } else {
+                tag 'bad-vendor-distribution-in-changes-file', $distribution;
+            }
+        }
+        elsif (! grep { $distribution =~ m/$_|$DISTRIBUTION_REGEX{$_}/xms } keys %DISTRIBUTION_REGEX) {
             tag 'bad-distribution-in-changes-file', $distribution;
         }
     }
diff --git a/checks/changes-file.desc b/checks/changes-file.desc
index ec1391e..dfcc8fe 100644
--- a/checks/changes-file.desc
+++ b/checks/changes-file.desc
@@ -44,6 +44,18 @@ Info: You've specified an unknown target distribution for your upload in
  distribution should be one of precise, oneiric, natty, maverick, lucid,
  karmic, hardy, or dapper.
 
+Tag: bad-vendor-distribution-in-changes-file
+Severity: important
+Certainty: certain
+Info: You've specified an unknown target distribution for your upload in
+ the <tt>debian/changelog</tt> file.
+ .
+ Your version string suggests this package is for a specific vendor
+ but did not match the distributions list for that vendor.
+ .
+ Please check the vendor distribution list under
+ <tt>LINTIAN_ROOT/data/changelog-file/</tt>
+
 Tag: multiple-distributions-in-changes-file
 Severity: important
 Certainty: possible
diff --git a/data/changelog-file/debian-dists b/data/changelog-file/debian-dists
index 589df1c..f5313f8 100644
--- a/data/changelog-file/debian-dists
+++ b/data/changelog-file/debian-dists
@@ -2,15 +2,15 @@
 # aliases
 
 # Codenames
-lenny
-squeeze
-wheezy
-sid
+lenny(?:-(?:backports|proposed-updates|security|volatile))?
+squeeze(?:-(?:backports|proposed-updates|security|volatile))?
+wheezy(?:-(?:backports|proposed-updates|security|volatile))?
+sid(?:-(?:backports|proposed-updates|security|volatile))?
 
 # Aliases
-oldstable
-stable
-testing
-unstable
-experimental
+oldstable(?:-(?:backports|proposed-updates|security|volatile))?
+stable(?:-(?:backports|proposed-updates|security|volatile))?
+testing(?:-(?:backports|proposed-updates|security|volatile))?
+unstable(?:-(?:backports|proposed-updates|security|volatile))?
+experimental(?:-(?:backports|proposed-updates|security|volatile))?
 
diff --git a/data/changelog-file/ubuntu-dists b/data/changelog-file/ubuntu-dists
index 0948ec9..e1517c9 100644
--- a/data/changelog-file/ubuntu-dists
+++ b/data/changelog-file/ubuntu-dists
@@ -1,11 +1,11 @@
 # A list of Ubuntu distributions, used to suppress some checks for Ubuntu
 # packages and to validate Ubuntu distributions.
 
-dapper
-hardy
-karmic
-lucid
-maverick
-natty
-oneiric
-precise
+dapper(?:-(?:proposed|updates|backports|security))?
+hardy(?:-(?:proposed|updates|backports|security))?
+karmic(?:-(?:proposed|updates|backports|security))?
+lucid(?:-(?:proposed|updates|backports|security))?
+maverick(?:-(?:proposed|updates|backports|security))?
+natty(?:-(?:proposed|updates|backports|security))?
+oneiric(?:-(?:proposed|updates|backports|security))?
+precise(?:-(?:proposed|updates|backports|security))?
diff --git a/t/changes/changes-bad-debian-distribution.changes.in b/t/changes/changes-bad-debian-distribution.changes.in
new file mode 100644
index 0000000..7d78256
--- /dev/null
+++ b/t/changes/changes-bad-debian-distribution.changes.in
@@ -0,0 +1,12 @@
+Format: 1.8
+Date: {$date}
+Source: {$srcpkg}
+Binary: {$srcpkg}
+Architecture: source all
+Version: {$version}
+Distribution: wispy
+Urgency: low
+Maintainer: {$author}
+Changed-By: {$author}
+Description:
+ {$srcpkg} - {$description}
diff --git a/t/changes/changes-bad-debian-distribution.desc b/t/changes/changes-bad-debian-distribution.desc
new file mode 100644
index 0000000..f10252a
--- /dev/null
+++ b/t/changes/changes-bad-debian-distribution.desc
@@ -0,0 +1,6 @@
+Testname: changes-bad-debian-distribution
+Sequence: 6000
+Version: 1.0+lenny2
+Description: Test for invalid Debian distribution
+Test-For:
+ bad-vendor-distribution-in-changes-file
diff --git a/t/changes/changes-bad-debian-distribution.tags b/t/changes/changes-bad-debian-distribution.tags
new file mode 100644
index 0000000..f7f7782
--- /dev/null
+++ b/t/changes/changes-bad-debian-distribution.tags
@@ -0,0 +1 @@
+E: changes-bad-debian-distribution changes: bad-vendor-distribution-in-changes-file wispy
diff --git a/t/changes/changes-bad-distribution.changes.in b/t/changes/changes-bad-distribution.changes.in
new file mode 100644
index 0000000..7d78256
--- /dev/null
+++ b/t/changes/changes-bad-distribution.changes.in
@@ -0,0 +1,12 @@
+Format: 1.8
+Date: {$date}
+Source: {$srcpkg}
+Binary: {$srcpkg}
+Architecture: source all
+Version: {$version}
+Distribution: wispy
+Urgency: low
+Maintainer: {$author}
+Changed-By: {$author}
+Description:
+ {$srcpkg} - {$description}
diff --git a/t/changes/changes-bad-distribution.desc b/t/changes/changes-bad-distribution.desc
new file mode 100644
index 0000000..4699575
--- /dev/null
+++ b/t/changes/changes-bad-distribution.desc
@@ -0,0 +1,6 @@
+Testname: changes-bad-distribution
+Sequence: 6000
+Version: 1.0
+Description: Test for invalid non vendor specific distribution
+Test-For:
+ bad-distribution-in-changes-file
diff --git a/t/changes/changes-bad-distribution.tags b/t/changes/changes-bad-distribution.tags
new file mode 100644
index 0000000..ee2d25f
--- /dev/null
+++ b/t/changes/changes-bad-distribution.tags
@@ -0,0 +1 @@
+E: changes-bad-distribution changes: bad-distribution-in-changes-file wispy
-- 
1.7.7.3

-- 
Daniel Dehennin
Récupérer ma clef GPG:
gpg --keyserver pgp.mit.edu --recv-keys 0x6A2540D1

Attachment: pgpzWtNRmfwTD.pgp
Description: PGP signature


Reply to: