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

[SCM] Debian package checker branch, master, updated. 2.5.4-5-g521b775



The following commit has been merged in the master branch:
commit 521b7750b878ee52c44daf4e2738d925ba84e066
Author: Niels Thykier <niels@thykier.net>
Date:   Wed Nov 30 12:01:13 2011 +0100

    Attempt to check packages without basic mandatory fields
    
    Added support for checking (binary) packages without the "Package" and
    "Version" field.  Source packages still have some issues, since
    dpkg-source chokes without the "Source" field (and presumably also the
    "Version" field).
    
    The support for checking packages without these fields was
    (presumably) present in the past, since there are tags for these
    cases.  However, Lintian 2.5.0~rc3 is the first known version to
    definitely refuse such packages.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/changelog-file b/checks/changelog-file
index 9271362..226fae1 100644
--- a/checks/changelog-file
+++ b/checks/changelog-file
@@ -178,7 +178,9 @@ my $version;
 if (defined $info->field('version')) {
     $version = $info->field('version');
 } else {
-    fail 'Unable to determine version!';
+    # We do not know, but we assume it to be non-native
+    # as that is most likely.
+    $version = '0-1';
 }
 
 $native_pkg  = $info->native;
diff --git a/checks/shared-libs b/checks/shared-libs
index 92f0e2d..72cd2ba 100644
--- a/checks/shared-libs
+++ b/checks/shared-libs
@@ -254,11 +254,9 @@ for my $shlib_file (keys %SONAME) {
 }
 
 # 4th step: check shlibs control file
-my $version;
-if (defined $info->field('version')) {
-    $version = $info->field('version');
-}
-my $provides = $pkg . "( = $version)";
+my $version = $info->field('version'); # may be undef in very broken packages
+my $provides = $pkg;
+$provides .= "( = $version)" if defined $version;
 if (defined $info->field('provides')) {
     $provides .= ', ' . $info->field('provides');
 }
diff --git a/collection/index b/collection/index
index c61f610..89f2543 100755
--- a/collection/index
+++ b/collection/index
@@ -32,6 +32,7 @@ use Cwd();
 use File::Spec;
 use Util;
 use Lintian::Command qw(spawn reap);
+use Lintian::Processable::Package;
 
 ($#ARGV == 1) or fail 'syntax: index <pkg> <type>';
 my $pkg = shift;
@@ -57,17 +58,21 @@ sub gather_tarballs {
     my @tarballs;
     my $base;
     my $baserev;
+    my $proc;
     fail "Cannot resolve \"dsc\" link for $pkg or it does not point to a file.\n" unless $file and -e $file;
     (undef, $dir, undef) = File::Spec->splitpath($file);
+    # Use Lintian::Processable::Package to determine source and version as handles missing fields
+    # for us to some extend.
+    $proc = Lintian::Processable::Package->new ('source', $file);
     $data = get_dsc_info($file) or fail "Could not parse dsc file for $pkg.\n";
     #  Version handling is based on Dpkg::Version::parseversion.
-    $version = $data->{'version'};
+    $version = $proc->pkg_src_version;
     if ($version =~ /:/) {
         $version =~ s/^(?:\d+):(.+)/$1/ or fail("bad version number '$version'");
     }
-    $baserev = $data->{'source'} . '_' . $version;
+    $baserev = $proc->pkg_src . '_' . $version;
     $version =~ s/(.+)-(.*)$/$1/;
-    $base = $data->{'source'} . '_' . $version;
+    $base = $proc->pkg_src . '_' . $version;
     for my $fs (split(/\n/,$data->{'files'})) {
         $fs =~ s/^\s*//;
         next if $fs eq '';
diff --git a/debian/changelog b/debian/changelog
index fb4299c..4e5081e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,9 +1,18 @@
 lintian (2.5.5) UNRELEASED; urgency=low
 
+  * checks/changelog-file:
+    + [NT] Allow the version to be missing and assume it to be
+      "0-1".
   * checks/cruft:
     + [NT] Added dh-autoreconf as a build-depends alternative to
       libtool for suppressing ancient-libtool warning.  Thanks to
       Felix Geyer for the report.  (Closes: #650325)
+  * checks/shared-libs:
+    + [NT] Do not assume the version field to be present.
+
+  * collection/index:
+    + [NT] Use Lintian::Processable::Package to determine source
+      name and version.
 
   * data/debhelper/dh_addons-manual:
     + [JW] Add python3-sphinx as provider of sphinxdoc dh sequence.
@@ -11,6 +20,13 @@ lintian (2.5.5) UNRELEASED; urgency=low
     + [JW] Add python3-sphinx as provider of dh_sphinxdoc.
       (Closes: #649640)
 
+  * lib/Lintian/Collect/{Binary,Source}.pm:
+    + [NT] Assume packages to be non-native when it cannot be
+      accurately determined due to missing version field.
+  * lib/Lintian/Processable/Package.pm:
+    + [NT] Use part of the file name as package name if the mandatory
+      "Package" or "Source" fields are missing rather than choking.
+
  -- Niels Thykier <niels@thykier.net>  Tue, 29 Nov 2011 18:42:37 +0100
 
 lintian (2.5.4) unstable; urgency=medium
diff --git a/lib/Lintian/Collect/Binary.pm b/lib/Lintian/Collect/Binary.pm
index 4b42c68..ad05a0e 100644
--- a/lib/Lintian/Collect/Binary.pm
+++ b/lib/Lintian/Collect/Binary.pm
@@ -45,7 +45,13 @@ sub native {
     my ($self) = @_;
     return $self->{native} if exists $self->{native};
     my $version = $self->field('version');
-    $self->{native} = ($version !~ m/-/);
+    if (defined $version) {
+        $self->{native} = ($version !~ m/-/);
+    } else {
+        # We do not know, but assume it to non-native as it is
+        # the most likely case.
+        $self->{native} = 0;
+    }
     return $self->{native};
 }
 
@@ -396,6 +402,9 @@ the list of the files contained in the archive.
 Returns true if the binary package is native and false otherwise.
 Nativeness will be judged by its version number.
 
+If the version number is absent, this will return false (as
+native packages are a lot rarer than non-native ones).
+
 =item index()
 
 Returns a reference to an array of hash references with content
diff --git a/lib/Lintian/Collect/Source.pm b/lib/Lintian/Collect/Source.pm
index 84a22dd..193648e 100644
--- a/lib/Lintian/Collect/Source.pm
+++ b/lib/Lintian/Collect/Source.pm
@@ -85,9 +85,15 @@ sub native {
     } else {
         my $version = $self->field('version');
         my $base_dir = $self->base_dir();
-        $version =~ s/^\d+://;
-        my $name = $self->{name};
-        $self->{native} = (-f "$base_dir/${name}_${version}.diff.gz" ? 0 : 1);
+        if (defined $version) {
+            $version =~ s/^\d+://;
+            my $name = $self->{name};
+            $self->{native} = (-f "$base_dir/${name}_${version}.diff.gz" ? 0 : 1);
+        } else {
+            # We do not know, but assume it to non-native as it is
+            # the most likely case.
+            $self->{native} = 0;
+        }
     }
     return $self->{native};
 }
@@ -387,6 +393,13 @@ file, which this method expects to find in F<debfiles/changelog>.
 =item native()
 
 Returns true if the source package is native and false otherwise.
+This is generally determined from the source format, though in the 1.0
+case the nativeness is determined by looking for the diff.gz (using
+the name of the source package and its version).
+
+If the source format is 1.0 and the version number is absent, this
+will return false (as native packages are a lot rarer than non-native
+ones).
 
 =item relation(FIELD)
 
diff --git a/lib/Lintian/Processable/Package.pm b/lib/Lintian/Processable/Package.pm
index 4c01917..9fcc2fd 100644
--- a/lib/Lintian/Processable/Package.pm
+++ b/lib/Lintian/Processable/Package.pm
@@ -81,11 +81,18 @@ sub _init {
     if ($pkg_type eq 'binary' or $pkg_type eq 'udeb'){
         my $dinfo = get_deb_info ($pkg_path) or
             croak "could not read control data in $pkg_path: $!";
-        my $pkg_name = $dinfo->{package} or
-            croak "$pkg_path ($pkg_type) is missing mandatory \"Package\" field";
+        my $pkg_name = $dinfo->{package};
         my $pkg_src = $dinfo->{source};
         my $pkg_version = $dinfo->{version};
         my $pkg_src_version = $pkg_version;
+
+        unless ($pkg_name) {
+            my $type = $pkg_type;
+            $type = 'deb' if $type eq 'binary';
+            $pkg_name = _derive_name ($pkg_path, $type)
+                or croak "Cannot determine the name of $pkg_path";
+        }
+
         # Source may be left out if it is the same as $pkg_name
         $pkg_src = $pkg_name unless ( defined $pkg_src && length $pkg_src );
 
@@ -101,8 +108,12 @@ sub _init {
         $self->{pkg_src_version} = $pkg_src_version;
     } elsif ($pkg_type eq 'source'){
         my $dinfo = get_dsc_info ($pkg_path) or croak "$pkg_path is not valid dsc file";
-        my $pkg_name = $dinfo->{source} or croak "$pkg_path is missing or has empty source field";
+        my $pkg_name = $dinfo->{source};
         my $pkg_version = $dinfo->{version};
+        unless ($pkg_name) {
+            $pkg_name = _derive_name ($pkg_path, 'dsc')
+                or croak "Cannot determine the name of $pkg_path";
+        }
         $self->{pkg_name} = $pkg_name;
         $self->{pkg_version} = $pkg_version;
         $self->{pkg_arch} = 'source';
@@ -113,9 +124,8 @@ sub _init {
         my $pkg_version = $cinfo->{version};
         my $pkg_name = $cinfo->{source}//'';
         unless ($pkg_name) {
-            # No source field? Derive the name from the file name
-            # lintian_2.5.2_amd64.changes => $pkg_name = 'lintian'
-            ($pkg_name) = ($pkg_path =~ m,.*/([^_/]+)[^/]*+\.changes$,);
+            $pkg_name = _derive_name ($pkg_path, 'changes')
+                or croak "Cannot determine the name of $pkg_path";
         }
         $self->{pkg_name} = $pkg_name;
         $self->{pkg_version} = $pkg_version;
@@ -142,6 +152,18 @@ sub _init {
     return 1;
 }
 
+# _derive_name ($file, $ext)
+#
+# Derive the name from the file name
+#  - the name is the part of the basename up to (and excl.) the first "_".
+#
+# _derivate_name ('somewhere/lintian_2.5.2_amd64.changes', 'changes') eq 'lintian'
+sub _derive_name {
+    my ($file, $ext) = @_;
+    my ($name) = ($file =~ m,(?:.*/)?([^_/]+)[^/]*\.$ext$,);
+    return $name;
+}
+
 =item $proc->info
 
 Overrides info from L<Lintian::Processable>.
diff --git a/t/COVERAGE b/t/COVERAGE
index 32bdc3a..31217cf 100644
--- a/t/COVERAGE
+++ b/t/COVERAGE
@@ -1,5 +1,5 @@
 Last generated 2011-11-30
-Coverage: 775/949 (81.66%), w. legacy tests: 883/949 (93.05%)
+Coverage: 777/949 (81.88%), w. legacy tests: 885/949 (93.26%)
 
 The following tags are not tested by the test suite:
 
@@ -29,9 +29,7 @@ fields aspell-package-not-arch-all
 fields bad-menu-item
 fields doc-package-depends-on-main-package
 fields malformed-python-version
-fields no-package-name
 fields no-source-field
-fields no-version-field
 
 files FSSTND-dir-in-var
 files compressed-symlink-with-wrong-ext
diff --git a/t/templates/debs/skel/Makefile.in b/t/debs/fields-general-missing/Makefile.in
similarity index 89%
copy from t/templates/debs/skel/Makefile.in
copy to t/debs/fields-general-missing/Makefile.in
index c9b9737..139eb3d 100644
--- a/t/templates/debs/skel/Makefile.in
+++ b/t/debs/fields-general-missing/Makefile.in
@@ -1,7 +1,7 @@
 name = {$srcpkg}
 
 all: fix-perm
-	create-deb -o $(name).deb control
+	create-deb --package-name $(name) --package-version {$version} -o $(name).deb control
 
 clean:
 	rm -f *.tar.gz *.deb md5sums debian-binary
diff --git a/t/debs/fields-general-missing/control b/t/debs/fields-general-missing/control
index 64bfdcd..cfc9b2c 100644
--- a/t/debs/fields-general-missing/control
+++ b/t/debs/fields-general-missing/control
@@ -1,5 +1,3 @@
-Package: fields-general-missing
-Version: 1.0
 Section: devel
 Priority: extra
 Depends: some-pkg
diff --git a/t/debs/fields-general-missing/desc b/t/debs/fields-general-missing/desc
index 91ed288..47a034a 100644
--- a/t/debs/fields-general-missing/desc
+++ b/t/debs/fields-general-missing/desc
@@ -1,7 +1,9 @@
 Testname: fields-general-missing
 Sequence: 6000
-Version: 1.0
+Version: 1.0-1
 Description: Test for missing control fields
 Test-For:
   no-architecture-field
   no-maintainer-field
+  no-package-name
+  no-version-field
diff --git a/t/debs/fields-general-missing/tags b/t/debs/fields-general-missing/tags
index 8794a66..da844fc 100644
--- a/t/debs/fields-general-missing/tags
+++ b/t/debs/fields-general-missing/tags
@@ -1,2 +1,4 @@
 E: fields-general-missing: no-architecture-field
 E: fields-general-missing: no-maintainer-field
+E: fields-general-missing: no-package-name
+E: fields-general-missing: no-version-field
diff --git a/t/helpers/bin/create-deb b/t/helpers/bin/create-deb
index 1aec4b7..f3f2af3 100755
--- a/t/helpers/bin/create-deb
+++ b/t/helpers/bin/create-deb
@@ -62,6 +62,8 @@ my %opts = (
     'compression|c=s' => \$val{'compression'},
     'md5sums!' => \$val{'md5sums'},
     'fix-perm!' => \$val{'fix-perm'},
+    'package-name=s' => \$val{'package-name'},
+    'package-version=s' => \$val{'package-version'},
 );
 
 my $cwd;
@@ -80,7 +82,9 @@ die "Unknown compression \"$val{'compression'}\"\n" unless exists $TAR_OPTIONS{$
 
 $val{'auto-build-data'} = 0 if $val{'root'};
 
-die "Cannot find ./control.\n" if $val{'auto-build-data'} && ! -e './control';
+if ($val{'auto-build-data'}) {
+    die "Cannot find ./control.\n" unless ($val{'package-name'} && defined $val{'package-version'}) || -e './control';
+}
 
 # default to "on" unless we are given an md5sums file explicitly
 $val{'md5sums'} = 1 unless defined $val{'md5sums'} || grep { $_ eq 'md5sums'} @ARGV;
@@ -89,12 +93,25 @@ $cwd = Cwd::cwd();
 
 if ($val{'auto-build-data'}) {
     my $data = get_dsc_info('./control');
-    my $pkg = $data->{'package'} || die "Cannot read package name from ./control.\n";
+    my $pkg = $val{'package-name'};
+    my $ver = $val{'package-version'};
+    my $dch = 'changelog';
+    unless ($pkg) {
+        $pkg = $data->{'package'} || die "Cannot read package name from ./control or missing --package-name <name>.\n";
+    }
+    unless (defined $ver) {
+        $ver = $data->{'version'} // die "Cannot read package version from ./control or missing --package-version <v>.\n";
+    }
+    # handle non-native package
+    $dch = 'changelog.Debian' if $ver =~ m/-/o;
     runsystem('mkdir', '-p', "root/usr/share/doc/$pkg");
-    foreach my $file (qw(copyright changelog)) {
-        runsystem('install', '-m', '0644', $file,  "root/usr/share/doc/$pkg/$file") if -e $file;
+
+    foreach my $file ('copyright', $dch) {
+        my $src = $file;
+        $src = 'changelog' if $file eq 'changelog.Debian';
+        runsystem('install', '-m', '0644', $src,  "root/usr/share/doc/$pkg/$file") if -e $src;
     }
-    runsystem('gzip', '-n', '--best', "root/usr/share/doc/$pkg/changelog") if -e './changelog';
+    runsystem('gzip', '-n', '--best', "root/usr/share/doc/$pkg/$dch") if -e "root/usr/share/doc/$pkg/$dch";
     # set root so it works for later :)
     $val{'root'} = 'root/';
 }
@@ -153,6 +170,12 @@ usage: $0 [options] -o <file.deb> [--root <dir>] control-file[... files]
  --[no-]fix-perm         Whether to auto-fix permissions and owner for control
                          files.  Defaults to on.  This will modify the perm of
                          the actual controls passed!
+ --package-name <pkg>    Assume the package name is <pkg>.  This overrides
+                         the value in the control file (and allows said value
+                         to be missing as well).
+ --package-version <v>   Assume the package version is <v>.  This overrides
+                         the value in the control file (and allows said value
+                         to be missing as well).
 
 Creates a deb file from a root directory and some control files.  The
 control files are assumed to be in the current directory or the

-- 
Debian package checker


Reply to: