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

[SCM] Debian package checker branch, master, updated. 2.5.1-180-gfd32f8c



The following commit has been merged in the master branch:
commit fd32f8cab3082bca7c108e43d96dde6b455228d3
Author: Niels Thykier <niels@thykier.net>
Date:   Thu Aug 4 13:01:06 2011 +0200

    Deprecated collection/fields in favour of a smarter L::Collect
    
    Lintian::Collect now knows how to find the fields itself and this
    makes collection/fields largely redundant.  All existing checks
    and collections have been updated to not look for the "fields"
    dir in the Lab entry.
    
    collection/fields have been reduced to removing the "fields" dir
    and got "Auto-Remove" enabled to clean up existing static labs.

diff --git a/checks/fields b/checks/fields
index 5a6c1dc..8020e2a 100644
--- a/checks/fields
+++ b/checks/fields
@@ -164,10 +164,6 @@ my $info = shift;
 my $version;
 my $arch_indep;
 
-unless (-d 'fields') {
-	fail("directory in lintian laboratory for $type package $pkg missing: fields");
-}
-
 #---- Format
 
 if ($type eq 'source') {
@@ -945,15 +941,7 @@ while (my ($vcs, $regex) = each %VCS_RECOMMENDED_URIS) {
 
 #----- Field checks (without checking the value)
 
-opendir(FIELDS, 'fields/')
-    or fail("cannot read fields/ directory: $!");
-
-for my $field (readdir FIELDS) {
-	next if ($field eq '.' || $field eq '..');
-
-	# The unpack scripts turn slashes into colons
-	# This is safe since a control field name can't contain colons
-	$field =~ s,:,/,g;
+for my $field (keys %{$info->field}) {
 
 	next if ($field eq 'original-maintainer') and $version =~ /ubuntu/;
 
@@ -969,7 +957,6 @@ for my $field (readdir FIELDS) {
 	tag 'unknown-field-in-control', $field
 	    if ($type eq 'udeb' && ! $KNOWN_UDEB_FIELDS->known($field) && ! $known_obsolete_fields{$field});
 }
-closedir(FIELDS);
 
 }
 
diff --git a/collection/ar-info b/collection/ar-info
index 5a32268..2723ecf 100755
--- a/collection/ar-info
+++ b/collection/ar-info
@@ -31,8 +31,6 @@ use Util qw(fail);
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/source' or fail('ar-info invoked in wrong directory');
-
 unlink('ar-info');
 chdir('unpacked')
     or fail("cannot chdir to unpacked directory: $!");
diff --git a/collection/ar-info.desc b/collection/ar-info.desc
index b7f2eec..5772f6a 100644
--- a/collection/ar-info.desc
+++ b/collection/ar-info.desc
@@ -2,5 +2,5 @@ Collector-Script: ar-info
 Author: Stéphane Glondu <steph@glondu.net>
 Info: This script runs the "ar t" command over all .a files of package.
 Type: binary
-Needs-Info: unpacked, fields, index
+Needs-Info: unpacked, index
 Version: 1
diff --git a/collection/changelog-file b/collection/changelog-file
index 4a91518..4e58c90 100755
--- a/collection/changelog-file
+++ b/collection/changelog-file
@@ -29,8 +29,6 @@ use Util;
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('changelog-file invoked in wrong directory');
-
 unlink('changelog') or fail("cannot remove changelog file: $!")
     if ( -e 'changelog' or -l 'changelog');
 
diff --git a/collection/changelog-file.desc b/collection/changelog-file.desc
index 83640f0..caa6950 100644
--- a/collection/changelog-file.desc
+++ b/collection/changelog-file.desc
@@ -5,4 +5,4 @@ Info: This script copies the <tt>changelog</tt> file and
  directory.
 Type: binary
 Version: 1
-Needs-Info: unpacked, fields
+Needs-Info: unpacked
diff --git a/collection/copyright-file b/collection/copyright-file
index 5a0e922..a5f0aed 100755
--- a/collection/copyright-file
+++ b/collection/copyright-file
@@ -31,8 +31,6 @@ use File::Copy qw(copy);
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('copyright-file invoked in wrong directory');
-
 unlink('copyright');
 
 my $file1 = "unpacked/usr/share/doc/$pkg/copyright";
diff --git a/collection/copyright-file.desc b/collection/copyright-file.desc
index 3ba7317..beda287 100644
--- a/collection/copyright-file.desc
+++ b/collection/copyright-file.desc
@@ -4,4 +4,4 @@ Info: This script copies the <tt>copyright</tt> file of a package into the
  lintian directory.
 Type: binary
 Version: 1
-Needs-Info: unpacked, fields
+Needs-Info: unpacked
diff --git a/collection/debian-readme b/collection/debian-readme
index 5c4397d..416fe4f 100755
--- a/collection/debian-readme
+++ b/collection/debian-readme
@@ -29,8 +29,6 @@ use Util;
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('debian-readme invoked in wrong directory');
-
 if (-f 'README.Debian') {
     unlink('README.Debian') or fail("Could not remove old README.Debian: $!");
 }
diff --git a/collection/debian-readme.desc b/collection/debian-readme.desc
index 5438017..0fd103d 100644
--- a/collection/debian-readme.desc
+++ b/collection/debian-readme.desc
@@ -4,4 +4,4 @@ Info: This script copies the <tt>README.Debian</tt> file of a package into
  the lintian directory.
 Type: binary
 Version: 1
-Needs-Info: unpacked, fields
+Needs-Info: unpacked
diff --git a/collection/diffstat b/collection/diffstat
index 4d6aacc..8085153 100755
--- a/collection/diffstat
+++ b/collection/diffstat
@@ -33,12 +33,13 @@ use Util;
 
 ($#ARGV == 1) or fail('syntax: diffstat <pkg> <type>');
 my $pkg = shift;
+my $data;
+my $ver;
 
--f 'fields/version' or fail('diffstat invoked in wrong directory');
+-f 'dsc' or fail('diffstat invoked in wrong directory');
 
-open (V, '<', 'fields/version') or fail("cannot open fields/version: $!");
-my $ver = <V>; chomp $ver;
-close V;
+$data = get_dsc_info('dsc');
+$ver = $data->{'version'};
 
 unlink('debian-patch') or fail("cannot unlink debian-patch: $!")
     if( -e 'debian-patch' or -l 'debian-patch');
diff --git a/collection/diffstat.desc b/collection/diffstat.desc
index d6ecbc3..a714306 100644
--- a/collection/diffstat.desc
+++ b/collection/diffstat.desc
@@ -4,4 +4,3 @@ Info: This script extracts the Debian diff of a source package, and runs
  diffstat on it, leaving the result in the diffstat output file
 Type: source
 Version: 1
-Needs-info: fields
diff --git a/collection/doc-base-files b/collection/doc-base-files
index 5976ab2..eca85be 100755
--- a/collection/doc-base-files
+++ b/collection/doc-base-files
@@ -30,8 +30,6 @@ use Util;
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('doc-base-files invoked in wrong directory');
-
 
 if (-e 'doc-base') {
     delete_dir('doc-base')
diff --git a/collection/doc-base-files.desc b/collection/doc-base-files.desc
index e82bb01..ee4652d 100644
--- a/collection/doc-base-files.desc
+++ b/collection/doc-base-files.desc
@@ -4,4 +4,4 @@ Info: This script copies the contents of /usr/share/doc-base into the
  lintian doc-base/ directory.
 Type: binary
 Version: 1
-Needs-Info: unpacked, fields
+Needs-Info: unpacked
diff --git a/collection/fields b/collection/fields
index 9394b32..aac9741 100755
--- a/collection/fields
+++ b/collection/fields
@@ -1,6 +1,9 @@
 #!/usr/bin/perl -w
 # fields -- lintian collector script
 
+# DEPRECATED - Lintian::Collect pulls the fields directly from the
+# from the relevant places and caches them.
+
 # Copyright (C) 1998 Christian Schwarz
 #
 # This program is free software; you can redistribute it and/or modify
@@ -21,54 +24,10 @@
 
 use strict;
 use warnings;
-use lib "$ENV{'LINTIAN_ROOT'}/lib";
-use Util;
-
-($#ARGV == 1) or fail('syntax: fields <pkg> <type>');
-my $pkg = shift;
-my $type = shift;
-my $file;
-my $data;
-
-if ($type eq 'changes'){
-    $file = 'changes';
-} elsif ($type eq 'binary' or $type eq 'udeb'){
-    $file = 'control/control';
-} elsif ($type eq 'source') {
-    $file = 'dsc';
-}
-
-if (!defined($file)) {
-    fail("Cannot extract files for $type") unless ($type =~ m/^remove-/);
-} elsif (not -e $file) {
-    fail('fields invoked in the wrong directory');
-}
 
 if (-d 'fields'){
-    delete_dir('fields') or fail('Could not remove old fields directory');
-}
-
-# Exit now if we are just removing.
-exit 0 unless (defined($file));
-
-mkdir('fields', 0777) or fail("mkdir fields: $!");
-
-if ($type eq 'changes' or $type eq 'source'){
-    $data = get_dsc_info($file);
-} elsif ($type eq 'binary' or $type eq 'udeb'){
-    $data = (read_dpkg_control($file))[0];
-    $data->{'source'} or ($data->{'source'} = $data->{'package'});
-}
-
-# create control field files
-for my $field (keys %$data) {
-    my $value = $data->{$field};
-    # checks/fields will convert colons into slashes
-    $field =~ s,/,:,g;
-    my $field_file = "fields/$field";
-    open(F, '>', $field_file) or fail("cannot open file $field_file for writing: $!");
-    print F $value,"\n";
-    close(F) or fail("Could not write $field_file: $!");
+    delete_dir('fields') or die 'Could not remove old fields directory';
 }
 
 exit 0;
+
diff --git a/collection/fields.desc b/collection/fields.desc
index 60d5717..601b61e 100644
--- a/collection/fields.desc
+++ b/collection/fields.desc
@@ -2,5 +2,5 @@ Collector-Script: fields
 Info: This script extracts the contents of the control file into
  fields/<tt>field</tt>.
 Type: binary, udeb, source, changes
-Needs-info: bin-pkg-control
 Version: 1
+Auto-Remove: yes
diff --git a/collection/file-info b/collection/file-info
index 5b7d530..e61acb4 100755
--- a/collection/file-info
+++ b/collection/file-info
@@ -36,8 +36,6 @@ my $last = '';
 my $helper = realpath("$0-helper");
 my $outfile = realpath('./file-info');
 
--f 'fields/source' or fail('file-info invoked in wrong directory');
-
 unlink($outfile);
 
 # Open files before we chdir, since unpacked could be a symlink (at
diff --git a/collection/file-info.desc b/collection/file-info.desc
index d50393a..ac42d69 100644
--- a/collection/file-info.desc
+++ b/collection/file-info.desc
@@ -3,4 +3,4 @@ Author: Richard Braakman <dark@xs4all.nl>
 Info: This script runs the file(1) command over all files of any kind of package.
 Type: binary, udeb, source
 Version: 1
-Needs-Info: unpacked, fields, index
+Needs-Info: unpacked, index
diff --git a/collection/init.d b/collection/init.d
index fa0d8ef..f2a7ef8 100755
--- a/collection/init.d
+++ b/collection/init.d
@@ -29,8 +29,6 @@ use Util;
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('init.d invoked in wrong directory');
-
 if (-e 'init.d') {
     delete_dir('init.d')
 	or fail('cannot rm old init.d directory');
diff --git a/collection/init.d.desc b/collection/init.d.desc
index 9d29608..d56c188 100644
--- a/collection/init.d.desc
+++ b/collection/init.d.desc
@@ -4,4 +4,4 @@ Info: This script copies the etc/init.d directory into the lintian
  directory.
 Type: binary
 Version: 1
-Needs-Info: unpacked, fields
+Needs-Info: unpacked
diff --git a/collection/md5sums b/collection/md5sums
index e513d63..0467dec 100755
--- a/collection/md5sums
+++ b/collection/md5sums
@@ -31,8 +31,6 @@ use Util;
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('md5sums invoked in wrong directory');
-
 unlink('md5sums');
 chdir('unpacked')
     or fail("cannot chdir to unpacked directory: $!");
diff --git a/collection/md5sums.desc b/collection/md5sums.desc
index 2dfdfd7..07349cb 100644
--- a/collection/md5sums.desc
+++ b/collection/md5sums.desc
@@ -3,4 +3,4 @@ Author: Richard Braakman <dark@xs4all.nl>
 Info: This script runs the md5sums(1) over all files in a binary package.
 Type: binary, udeb
 Version: 1
-Needs-Info: unpacked, fields, index
+Needs-Info: unpacked, index
diff --git a/collection/menu-files b/collection/menu-files
index aa2a0a2..aa10a8e 100755
--- a/collection/menu-files
+++ b/collection/menu-files
@@ -29,8 +29,6 @@ use Util;
 my $pkg = shift;
 my $type = shift;
 
--f 'fields/package' or fail('menu-files invoked in wrong directory');
-
 if (-e 'menu') {
     delete_dir('menu')
 	or fail('cannot rm old menu directory');
diff --git a/collection/menu-files.desc b/collection/menu-files.desc
index ee0dd01..cce2451 100644
--- a/collection/menu-files.desc
+++ b/collection/menu-files.desc
@@ -3,4 +3,4 @@ Author: Richard Braakman <dark@xs4all.nl>
 Info: This script copies the contents of /usr/lib/menu into the lintian menu/ directory.
 Type: binary
 Version: 2
-Needs-Info: unpacked, fields
+Needs-Info: unpacked
diff --git a/collection/objdump-info b/collection/objdump-info
index 710a728..c463cad 100755
--- a/collection/objdump-info
+++ b/collection/objdump-info
@@ -26,12 +26,6 @@
 use strict;
 use warnings;
 
-# Sanity check
-unless (-f 'fields/package') {
-    print STDERR 'error: collection script called in wrong directory!\n';
-    exit 2;
-}
-
 my $failed = 0;
 
 open (FILES, '<', 'file-info')
diff --git a/debian/changelog b/debian/changelog
index d69c7bf..e16d8aa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -15,6 +15,7 @@ lintian (2.5.2) UNRELEASED; urgency=low
   * checks/*:
     + [NT] Migrated to use new methods in the Lintian::Collect
       interfaces rather than accessing the Lab directly.
+    + [NT] Removed "fields" from Needs-Info.
   * checks/{debconf,conffiles}.desc:
     + [NT] Added missing bin-pkg-control Needs-Info.
   * checks/{cruft,fields}{,.desc}:
@@ -156,6 +157,10 @@ lintian (2.5.2) UNRELEASED; urgency=low
     + [NT] Symlink checking extended to relative paths as well.
       (Closes: #217023)
 
+  * collection/*:
+    + [NT] Removed all Needs-Info on "fields" and all checks that
+      used the "fields" dir (or files therein) to determine if the
+      scripts had been called in the wrong dir.
   * collection/diffstat:
     + [NT] No longer unconditionally creates a diffstat file,
       since the Lintian::Collect interface will fall back to
@@ -164,6 +169,9 @@ lintian (2.5.2) UNRELEASED; urgency=low
     + [NT] Removed creation of cross package symlinks.  They have
       been replaced by the group information that checks are
       passed.
+    + [NT] Deprecated it in favour of a smarter Lintian::Collect.
+      It will be removed in a later release; for now it will just
+      remove the "fields" directory in the lab.
   * collection/file-info:
     + [NT] Double check the output of file(1) when it says a ".gz"
       file is not gzip compressed.  This should reduce the number
diff --git a/lib/Lintian/Collect.pm b/lib/Lintian/Collect.pm
index faed3d3..9c994fd 100644
--- a/lib/Lintian/Collect.pm
+++ b/lib/Lintian/Collect.pm
@@ -20,7 +20,8 @@ package Lintian::Collect;
 use strict;
 use warnings;
 
-use Util qw(fail);
+use Util qw(get_dsc_info get_deb_info);
+use Carp qw(croak);
 
 # Take the package name and type, initialize an appropriate collect object
 # based on the package type, and return it.  fail with unknown types,
@@ -38,7 +39,7 @@ sub new {
 	require Lintian::Collect::Changes;
 	$object = Lintian::Collect::Changes->new ($pkg);
     } else {
-        fail("Undefined type: $type");
+        croak("Undefined type: $type");
     }
     $object->{name} = $pkg;
     $object->{type} = $type;
@@ -72,21 +73,45 @@ sub base_dir {
 # packages, this is the *.dsc file; for binary packages, this is the control
 # file in the control section of the package.  For .changes files, the 
 # information will be retrieved from the file itself.
-# sub field Needs-Info fields
+# sub field Needs-Info <>
 sub field {
     my ($self, $field) = @_;
-    return $self->{field}{$field} if exists $self->{field}{$field};
-    my $base_dir = $self->base_dir();
-    if (open(FIELD, '<', "$base_dir/fields/$field")) {
-        local $/;
-        my $value = <FIELD>;
-        close FIELD;
-        $value =~ s/\n\z//;
-        $self->{field}{$field} = $value;
+    return $self->_get_field($field);
+}
+
+# $self->_get_field([$name])
+#
+# Method getting the fields; this is the backing method of $self->field
+#
+# It must return either a field (if $name is given) or a hash, where the keys are
+# the name of the fields.
+#
+# It must cache the result if possible, since field and fields are called often.
+# sub _get_field Needs-Info <>
+sub _get_field {
+    my ($self, $field) = @_;
+    my $fields;
+    unless (exists $self->{field}) {
+        my $base_dir = $self->base_dir();
+        my $type = $self->{type};
+        if ($type eq 'changes' or $type eq 'source'){
+            my $file = 'changes';
+            $file = 'dsc' if $type eq 'source';
+            $fields = get_dsc_info("$base_dir/$file");
+        } elsif ($type eq 'binary' or $type eq 'udeb'){
+            # (ab)use the unpacked control dir if it is present
+            if ( -f "$base_dir/control/control" && -s "$base_dir/control/control") {
+                $fields = get_dsc_info("$base_dir/control/control");
+            } else {
+                $fields = (get_deb_info("$base_dir/deb"));
+            }
+        }
+        $self->{field} = $fields;
     } else {
-        $self->{field}{$field} = undef;
+        $fields = $self->{field};
     }
-    return $self->{field}{$field};
+    return $fields->{$field} if $field;
+    return $fields;
 }
 
 =head1 NAME
@@ -137,15 +162,15 @@ binary / udeb packages and .changes files.
 
 =over 4
 
-=item field(FIELD)
+=item field([FIELD])
+
+If FIELD is given, this method returns the value of the control field
+FIELD in the control file for the package.  For a source package, this
+is the *.dsc file; for a binary package, this is the control file in
+the control section of the package.
 
-Returns the value of the control field FIELD in the control file for the
-package.  For a source package, this is the *.dsc file; for a binary
-package, this is the control file in the control section of the package.
-The value will be read from the F<fields/> subdirectory of the current
-directory if it hasn't previously been requested and cached in memory so
-that subsequent requests for the same field can be answered without file
-accesses.
+Otherwise this will return a hash of fields, where the key is the field
+name (in all lowercase).
 
 =item name()
 

-- 
Debian package checker


Reply to: