hi,

i just wondered how am i supposed to add my own checks to lintian.  It
seems the only way to do this (without beeing root) is to copy the stuff
from /usr/share/lintian to $HOME and use the --root switch to change
$LINTIAN_ROOT.  

I think it would be very nice if lintian could check ~/.lintian/checks
for checks and load them, just like linda does. Attached is a (i guess
pretty hackish patch) against trunk which does this.

 :~$ perl lintian --root /home/abi/lintian/trunk/ /home/abi/strnew/*.deb
 E: streamripper: my-custom-check

 :~$ ls -1 ~/.lintian/checks
 my-custom-check
 my-custom-check.desc

bye,
    - michael
Index: frontend/lintian
===================================================================
--- frontend/lintian    (revision 585)
+++ frontend/lintian    (working copy)
@@ -892,76 +892,86 @@
 $Tags::show_overrides = $show_overrides;
 use warnings;
 
-# load information about checker scripts
-opendir(CHECKDIR, "$LINTIAN_ROOT/checks")
-    or fail("cannot read directory $LINTIAN_ROOT/checks");
+my @checkdirs = ( $LINTIAN_ROOT );
+if ( -d $ENV{HOME}."/.lintian/checks/" ) {
+       push @checkdirs, $ENV{HOME}."/.lintian/"
+}
 
-for my $f (readdir CHECKDIR) {
-    next unless $f =~ /\.desc$/;
-    print "N: Reading checker description file $f ...\n" if $debug >= 2;
+foreach my $DIR (@checkdirs) {
+    
+    # load information about checker scripts
+    opendir(CHECKDIR, "$DIR/checks")
+       or fail("cannot read directory $DIR/checks: $!");
 
-    my @secs = read_dpkg_control("$LINTIAN_ROOT/checks/$f");
-    my $script;
-    ($script = $secs[0]->{'check-script'})
-       or fail("error in description file $f: `Check-Script:' not defined");
+    for my $f (readdir CHECKDIR) {
+       next unless $f =~ /\.desc$/;
+       print "N: Reading checker description file $f ...\n" if $debug >= 2;
 
-    # ignore check `lintian' (this check is a special case and contains the
-    # tag info for the lintian frontend--this script here)
-    if ($secs[0]->{'check-script'} ne 'lintian') {
+       my @secs = read_dpkg_control("$DIR/checks/$f");
+       my $script;
+       ($script = $secs[0]->{'check-script'})
+           or fail("error in description file $f: `Check-Script:' not 
defined");
 
-       delete $secs[0]->{'check-script'};
-       $check_info{$script}->{'script'} = $script;
-       my $p = $check_info{$script};
+       # ignore check `lintian' (this check is a special case and contains the
+       # tag info for the lintian frontend--this script here)
+       if ($secs[0]->{'check-script'} ne 'lintian') {
 
-       set_value($f,$p,'type',$secs[0],1);
-       # convert Type:
-       my ($b,$s,$u) = ( "", "", "" );
-       for (split(/\s*,\s*/o,$p->{'type'})) {
-           if ($_ eq 'binary') {
-               $b = 'b';
-           } elsif ($_ eq 'source') {
-               $s = 's';
-           } elsif ($_ eq 'udeb') {
-               $u = 'u';
-           } else {
-               fail("unknown type $_ specified in description file $f");
+           delete $secs[0]->{'check-script'};
+           $check_info{$script}->{'script'} = $DIR."/checks/".$script;
+           my $p = $check_info{$script};
+
+           set_value($f,$p,'type',$secs[0],1);
+           # convert Type:
+           my ($b,$s,$u) = ( "", "", "" );
+           for (split(/\s*,\s*/o,$p->{'type'})) {
+               if ($_ eq 'binary') {
+                   $b = 'b';
+               } elsif ($_ eq 'source') {
+                   $s = 's';
+               } elsif ($_ eq 'udeb') {
+                   $u = 'u';
+               } else {
+                   fail("unknown type $_ specified in description file $f");
+               }
            }
-       }
-       $p->{'type'} = "$s$b$u";
+           $p->{'type'} = "$s$b$u";
 
-       set_value($f,$p,'unpack-level',$secs[0],1);
-       set_value($f,$p,'abbrev',$secs[0],1);
+           set_value($f,$p,'unpack-level',$secs[0],1);
+           set_value($f,$p,'abbrev',$secs[0],1);
 
-       if (exists $secs[0]->{'needs-info'} && defined 
$secs[0]->{'needs-info'}) {
-           for (split(/\s*,\s*/o,$secs[0]->{'needs-info'})) {
-               $p->{$_} = 1;
-           }
-           delete $secs[0]->{'needs-info'};
-       }
+           if (exists $secs[0]->{'needs-info'} && defined 
$secs[0]->{'needs-info'}) {
+               for (split(/\s*,\s*/o,$secs[0]->{'needs-info'})) {
+                   $p->{$_} = 1;
+               }
+               delete $secs[0]->{'needs-info'};
+           }   
 
-       # ignore Info: and other fields for now...
-       delete $secs[0]->{'info'};
-       delete $secs[0]->{'standards-version'};
-       delete $secs[0]->{'author'};
+           # ignore Info: and other fields for now...
+           delete $secs[0]->{'info'};
+           delete $secs[0]->{'standards-version'};
+           delete $secs[0]->{'author'};
 
-       for (keys %{$secs[0]}) {
-           print STDERR "warning: unused tag $_ in description file $f\n";
-       }
+           for (keys %{$secs[0]}) {
+               print STDERR "warning: unused tag $_ in description file $f\n";
+           }
 
-       if ($debug >= 2) {
-           for (sort keys %$p) {
-               print "N:  $_: $p->{$_}\n";
+           if ($debug >= 2) {
+               for (sort keys %$p) {
+                   print "N:  $_: $p->{$_}\n";
+               }
            }
-       }
 
-       shift(@secs);
-       map Tags::add_tag($_), @secs;
-    } # end: if ne lintian
+           shift(@secs);
+           map Tags::add_tag($_), @secs;
+       } # end: if ne lintian
 
-}
+    }
 
 closedir(CHECKDIR);
 
+}
+
+
 # }}}
 
 # {{{ Again some lone code the author just dumped where his cursor just 
happened to be
@@ -1283,7 +1293,7 @@
                next PACKAGE;
            }
 
-           my $returnvalue = Checker::runcheck($pkg, $long_type, $check);
+           my $returnvalue = Checker::runcheck($pkg, $long_type, $check, 
$ci->{script});
            # Set exit_code correctly if there was not yet an exit code
            $exit_code = $returnvalue unless $exit_code;
 
Index: lib/Checker.pm
===================================================================
--- lib/Checker.pm      (revision 585)
+++ lib/Checker.pm      (working copy)
@@ -51,6 +51,7 @@
        my $pkg = shift;
        my $type = shift;
        my $name = shift;
+       my $script = shift;
 
        # Will be set to 2 if error is encountered
        my $return = 0;
@@ -60,7 +61,7 @@
        my $check = $checks{$name};
 
        # require has a anti-require-twice cache
-       require "$LINTIAN_ROOT/checks/$name";
+       require "$script";
 
        #print STDERR "Now running $name...\n";
        $name =~ s/[-.]/_/g;

Reply via email to