Bug#493903: lintian: please provide a way of limiting the checks run by lintian based on tags
Hi,
On Tue, 2008-08-05 at 21:40 +0200, Joerg Jaspert wrote:
> please provide a way to limit the checks that get run by providing an
> input file listing tags, one per line.
I've attached a first-pass patch implementing a "--tags-file" option. It
only runs those checks which are necessary to test the tags specified in
the file; all of the tags in the relevant checks will still be run, as
not doing so is a rather larger change to lintian's internals. :-)
The patch is lacking in documentation, commenting, etc., but it is
functional and I wanted to give people an opportunity to yell if there
was anything they didn't like in the approach.
By way of an example:
$ cat testtags
copyright-without-copyright-notice
doc-base-file-unknown-field
svk-commit-file-in-package
$ frontend/lintian libwsdl4j-java_1.6.2-1_all.deb
E: libwsdl4j-java: doc-base-file-unknown-field libwsdl4j-java-doc:3 authors
E: libwsdl4j-java: doc-base-file-references-missing-file libwsdl4j-java-doc:8 /usr/share/doc/libwsdl4j-java-doc/api/index.html
E: libwsdl4j-java: doc-base-file-references-missing-file libwsdl4j-java-doc:9 /usr/share/doc/libwsdl4j-java-doc/api/*.html
W: libwsdl4j-java: copyright-without-copyright-notice
W: libwsdl4j-java: bad-homepage wsdl4j.sourceforge.net
$ frontend/lintian --tags-file testtags libwsdl4j-java_1.6.2-1_all.deb
W: libwsdl4j-java: copyright-without-copyright-notice
E: libwsdl4j-java: doc-base-file-unknown-field libwsdl4j-java-doc:3 authors
Regards,
Adam
diff --git a/frontend/lintian b/frontend/lintian
index 1be2e9b..285df99 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -55,6 +55,8 @@ my $unpack_level = undef; #flag for -l|--unpack-level switch
our $no_override = 0; #flag for -o|--no-override switch
our $show_overrides = 0; #flag for --show-overrides switch
our $color = 'never'; #flag for --color switch
+our %only_tags; #
+my $tags_file = ''; #
my $check_checksums = 0; #flag for -m|--md5sums|--checksums switch
my $allow_root = 0; #flag for --allow-root switch
my $fail_on_warnings = 0; #flag for --fail-on-warnings switch
@@ -270,6 +272,7 @@ my %opthash = ( # ------------------ actions
"allow-root" => \$allow_root,
"fail-on-warnings" => \$fail_on_warnings,
"keep-lab" => \$keep_lab,
+ "tags-file=s" => \$tags_file,
# Note: Ubuntu has (and other derivatives might gain) a
# -D/--debian option to make lintian behave like in Debian, that
# is, to revert distribution-specific changes
@@ -349,6 +352,22 @@ if ($action =~ /^(check|unpack|remove)$/ and $#ARGV == -1 and not $check_everyth
syntax();
}
+# read a list of tags from the file specified
+if ($tags_file) {
+ if (open(TAGS, '<', $tags_file)) {
+ while (<TAGS>) {
+ if (m,^([a-z0-9-]+)\s*$,) {
+ $only_tags{$1} = 1;
+ } else {
+ print STDERR "warning: unable to parse tags file entry $tags_file:$.\n";
+ }
+ }
+ close TAGS;
+ } else {
+ die "unable to open tags file '" . $tags_file . "': $!\n";
+ }
+}
+
# }}}
# {{{ Setup Configuration
@@ -987,6 +1006,7 @@ $Tags::show_info = $display_infotags;
$Tags::show_experimental = $display_experimentaltags;
$Tags::show_overrides = $show_overrides;
$Tags::color = $color;
+%Tags::only_tags = %only_tags;
use warnings;
# load information about checker scripts
@@ -999,6 +1019,12 @@ for my $f (readdir CHECKDIR) {
print "N: Reading checker description file $f ...\n" if $debug >= 2;
my @secs = read_dpkg_control("$LINTIAN_ROOT/checks/$f");
+ my @check_secs = @secs;
+ shift @check_secs;
+
+ next if keys %only_tags && (0 == scalar grep
+ {exists $only_tags{$_}} map {$_->{'tag'}} @check_secs);
+
my $script;
($script = $secs[0]->{'check-script'})
or fail("error in description file $f: `Check-Script:' not defined");
diff --git a/lib/Tags.pm b/lib/Tags.pm
index b34ab8b..d71ed1e 100644
--- a/lib/Tags.pm
+++ b/lib/Tags.pm
@@ -47,6 +47,7 @@ our $max_severity = 99;
our $min_significance = 1;
our $max_significance = 99;
our $color = 'never';
+our %only_tags;
# The master hash with all tag info. Key is the tag name, value another hash
# with the following keys:
@@ -332,6 +333,9 @@ sub tag {
return 0;
}
+ return 0 unless
+ ! keys %only_tags or exists $only_tags{$tag};
+
# Newlines in @information would cause problems, so replace them with \n.
@information = map { s,\n,\\n,; $_ } @information;
Reply to: