pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc Update pkglint to 3.83. Changes:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/cf4d6dc5bd7b
branches:  trunk
changeset: 477357:cf4d6dc5bd7b
user:      hubertf <hubertf%pkgsrc.org@localhost>
date:      Wed Jun 30 18:49:36 2004 +0000

description:
Update pkglint to 3.83. Changes:

- made the program compile with "use strict"
- completely rewrote some subs to make the code more readable
- converted the global ("local") variables into local ("my") ones ;-)
- limited the scope of variables where possible
- added file and line number to the error messages where possible

Patch contributed by Roland Illig in private mail.

diffstat:

 doc/CHANGES                       |    3 +-
 pkgtools/pkglint/Makefile         |    4 +-
 pkgtools/pkglint/files/pkglint.pl |  711 ++++++++++++++++++-------------------
 3 files changed, 357 insertions(+), 361 deletions(-)

diffs (truncated from 1141 to 300 lines):

diff -r 2ecc63b18b2e -r cf4d6dc5bd7b doc/CHANGES
--- a/doc/CHANGES       Wed Jun 30 17:48:19 2004 +0000
+++ b/doc/CHANGES       Wed Jun 30 18:49:36 2004 +0000
@@ -1,4 +1,4 @@
-$NetBSD: CHANGES,v 1.6406 2004/06/30 17:35:43 jschauma Exp $
+$NetBSD: CHANGES,v 1.6407 2004/06/30 18:49:36 hubertf Exp $
 
 Changes to the packages collection and infrastructure in 2004:
 
@@ -3191,3 +3191,4 @@
        Updated xfce4-cpugraph-plugin to 0.2.2 [martti 2004-06-30]
        Updated binutils to 2.15.0.0 [shannonjr 2004-06-30]
        Added xraidadmin-1.3 [jschauma 2004-06-30]
+       Updated pkglint to 3.83 [hubertf 2004-06-30]
diff -r 2ecc63b18b2e -r cf4d6dc5bd7b pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Wed Jun 30 17:48:19 2004 +0000
+++ b/pkgtools/pkglint/Makefile Wed Jun 30 18:49:36 2004 +0000
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.195 2004/06/28 14:33:47 hubertf Exp $
+# $NetBSD: Makefile,v 1.196 2004/06/30 18:49:36 hubertf Exp $
 #
 
-DISTNAME=      pkglint-3.82
+DISTNAME=      pkglint-3.83
 CATEGORIES=    pkgtools devel
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 2ecc63b18b2e -r cf4d6dc5bd7b pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Wed Jun 30 17:48:19 2004 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Wed Jun 30 18:49:36 2004 +0000
@@ -11,7 +11,7 @@
 # Freely redistributable.  Absolutely no warranty.
 #
 # From Id: portlint.pl,v 1.64 1998/02/28 02:34:05 itojun Exp
-# $NetBSD: pkglint.pl,v 1.109 2004/06/28 14:33:47 hubertf Exp $
+# $NetBSD: pkglint.pl,v 1.110 2004/06/30 18:49:37 hubertf Exp $
 #
 # This version contains lots of changes necessary for NetBSD packages
 # done by Hubert Feyrer <hubertf%netbsd.org@localhost>,
@@ -19,6 +19,8 @@
 # Roland Illig <roland.illig%gmx.de@localhost> and others.
 #
 
+use strict;
+
 use Getopt::Std;
 use File::Basename;
 use FileHandle;
@@ -45,11 +47,28 @@
 # Constants
 my $regex_rcsidstr     = qr"\$($conf_rcsidstr)(?::[^\$]*|)\$";
 my $regex_known_rcs_tag        = qr"\$(Author|Date|Header|Id|Locker|Log|Name|RCSfile|Revision|Source|State|$conf_rcsidstr)(?::[^\$]*?|)\$";
+my $regex_validchars   = qr"[\011\040-\176]";
 
 # Global variables that should be eliminated by the next refactoring.
 my %definesfound       = ();
 my $errors             = 0; # number of errors
 my $warnings           = 0; # number of warnings
+my $pkgdir             = ".";
+my $filesdir           = "files";
+my $patchdir           = "patches";
+my $distinfo           = "distinfo";
+my $scriptdir          = "scripts";
+my $seen_PKG_REGISTER  = undef;
+my $category           = undef;
+my %cmdnames           = ();
+my $seen_PLIST_SRC = 0;
+my $seen_NO_PKG_REGISTER = 0;
+my $seen_NO_CHECKSUM = 0;
+my $seen_USE_PKGLOCALEDIR = 0;
+my $seen_USE_BUILDLINK2 = 0;
+my %predefined;
+my $pkgname            = "(none)";
+
 
 # == Output of messages to the user ==
 # The log_* routines take the parameters ($file, $lineno, $msg).
@@ -135,18 +154,8 @@
        }
 }
 
-#
-# variables for global checks.
-#
-$sharedocused = 0;
-$seen_PLIST_SRC = 0;
-$seen_NO_PKG_REGISTER = 0;
-$seen_NO_CHECKSUM = 0;
-$seen_USE_PKGLOCALEDIR = 0;
-$seen_USE_BUILDLINK2 = 0;
-
 %predefined = ();
-foreach $i (split("\n", <<EOF)) {
+foreach my $i (split("\n", <<EOF)) {
 XCONTRIB       ftp://crl.dec.com/pub/X11/contrib/
 XCONTRIB       ftp://ftp.sunsite.auc.dk/pub/X/X.org/contrib/
 XCONTRIB       ftp://ftp.uni-paderborn.de/pub/X11/contrib/
@@ -172,7 +181,7 @@
 SOURCEFORGE    ftp://download.sourceforge.net/
 SOURCEFORGE    http://download.sourceforge.net/
 EOF
-       ($j, $k) = split(/\t+/, $i);
+       my ($j, $k) = split(/\t+/, $i);
        $predefined{$k} = $j;
 }
 
@@ -181,18 +190,18 @@
 if (! -f "$opt_packagedir/Makefile") {
        log_error(NO_FILE, NO_LINE_NUMBER, "no Makefile in \"$opt_packagedir\".");
 } else {
-       checkfile_Makefile("Makefile") || log_error(NO_FILE, NO_LINE_NUMBER, "Cannot open the file $i\n");
+       checkfile_Makefile("Makefile") || log_error("$opt_packagedir/Makefile", NO_LINE_NUMBER, "error while reading.");
 }
 
 
 #
 # check for files.
 #
-@checker = ("$pkgdir/DESCR");
-%checker = ("$pkgdir/DESCR", \&checkfile_DESCR);
+my @checker = ("$pkgdir/DESCR");
+my %checker = ("$pkgdir/DESCR", \&checkfile_DESCR);
 
 if ($opt_extrafile) {
-       foreach $i ((<$opt_packagedir/$filesdir/*>, <$opt_packagedir/$pkgdir/*>)) {
+       foreach my $i ((<$opt_packagedir/$filesdir/*>, <$opt_packagedir/$pkgdir/*>)) {
                next if (! -T $i);
                next if ($i =~ /distinfo$/);
                next if ($i =~ /Makefile$/);
@@ -210,7 +219,7 @@
                }
        }
 }
-foreach $i (<$opt_packagedir/$patchdir/patch-*>) {
+foreach my $i (<$opt_packagedir/$patchdir/patch-*>) {
        next if (! -T $i);
        $i =~ s/^\Q$opt_packagedir\E\///;
        next if (defined $checker{$i});
@@ -218,16 +227,16 @@
        $checker{$i} = \&checkfile_patches_patch;
 }
 if (-e <$opt_packagedir/$distinfo>) {
-       $i = "$distinfo";
+       my $i = "$distinfo";
        next if (defined $checker{$i});
        push(@checker, $i);
        $checker{$i} = \&checkfile_distinfo;
 }
 {
        # Make sure there's a distinfo if there are patches
-       $patches=0;
+       my $patches=0;
        patch:
-           foreach $i (<$opt_packagedir/$patchdir/patch-*>) {
+           foreach my $i (<$opt_packagedir/$patchdir/patch-*>) {
                if ( -T "$i" ) { 
                        $patches=1;
                        last patch;
@@ -237,7 +246,7 @@
                log_warning(NO_FILE, NO_LINE_NUMBER, "no $opt_packagedir/$distinfo file. Please run '$conf_make makepatchsum'.");
        }
 }
-foreach $i (@checker) {
+foreach my $i (@checker) {
        log_info(NO_FILE, NO_LINE_NUMBER, "checking $i.");
        if (! -f "$opt_packagedir/$i") {
                log_error(NO_FILE, NO_LINE_NUMBER, "no $i in \"$opt_packagedir\".");
@@ -322,272 +331,251 @@
        return $result;
 }
 
-sub checkfile_DESCR($) {
-       local($file) = @_;
-       local(%maxchars) = ('DESCR', 80);
-       local(%maxlines) = ('DESCR', 24);
-       local(%errmsg) = ('DESCR', "exceeds $maxlines{'DESCR'} ".
-                                  "lines, make it shorter if possible");
-       local($longlines, $linecnt, $tmp) = (0, 0, "");
-       my ($line);
+sub checkline_length($$) {
+       my ($line, $maxlength) = @_;
 
-       &checkperms("$opt_packagedir/$file");
-
-       $shortname = basename($file);
-       open(IN, "< $opt_packagedir/$file") || return 0;
+       if (length($line->[2]) > $maxlength) {
+               log_warning($line->[0], $line->[1], "Line too long (should be no more than $maxlength characters).");
+       }
+       return 1;
+}
 
-       while (defined($line = <IN>)) {
-               $linecnt++;
-               $longlines++ if ($maxchars{$shortname} < length($line));
-               $tmp .= $line;
-       }
-       close(IN);
+sub checkline_valid_characters($$) {
+       my ($line, $re_validchars) = @_;
+       my ($rest);
 
-       if ($linecnt > $maxlines{$shortname}) {
-               log_warning(NO_FILE, NO_LINE_NUMBER, "$file $errmsg{$shortname} ".
-                       "(currently $linecnt lines).");
-       } else {
-               log_info(NO_FILE, NO_LINE_NUMBER, "$file has $linecnt lines.");
-       }
-       if ($longlines > 0) {
-               log_warning(NO_FILE, NO_LINE_NUMBER, "$file includes lines that exceed ".
-                       "$maxchars{$shortname} characters.");
-       }
-       if ($tmp =~ /[\033\200-\377]/) {
-               log_warning(NO_FILE, NO_LINE_NUMBER, "$file includes iso-8859-1, or ".
-                       "other local characters.  $file should be ".
-                       "plain ascii file.");
+       ($rest = $line->[2]) =~ s/$re_validchars//g;
+       if ($rest ne "") {
+               my @chars = map { $_ = sprintf("0x%02x", ord($_)); } split(//, $rest);
+               log_warning($line->[0], $line->[1],
+                       sprintf("Line contains invalid characters (%s).", join(", ", @chars)));
        }
        return 1;
 }
 
-sub checkfile_distinfo($) {
-       local($file) = @_;      # distinfo
-       local(%indistinfofile);
-       my $line;
-
-       checkperms("$opt_packagedir/$file");
+sub checkline_trailing_whitespace($) {
+       my ($line) = @_;
+       if ($line =~ /\s+$/) {
+               log_warning($line->[0], $line->[1], "Trailing white space.");
+       }
+       return 1;
+}
 
-       open(SUM,"<$opt_packagedir/$file") || return 0;
-       $line = <SUM>;
-       if ($line !~ /^\$NetBSD(:.*|)\$$/) {
-           log_error(NO_FILE, NO_LINE_NUMBER, "missing RCS Id in distinfo file: $_");
-       }
-       while(defined($line = <SUM>)) {
-               next unless $line =~ /^(MD5|SHA1|RMD160) \(([^)]+)\) = (.*)$/;
-               $alg=$1;
-               $patch=$2;
-               $sum=$3;
-
-               # bitch about *~
-               if ($patch =~ /~$/) {
-                       log_warning(NO_FILE, NO_LINE_NUMBER, "possible backup file '$patch' in $opt_packagedir/$file?");
-               }
+#
+# Specific subroutines
+#
 
-               if (-T "$opt_packagedir/$patchdir/$patch") {
-                       $calcsum=`sed -e '/\$NetBSD.*/d' $opt_packagedir/$patchdir/$patch | digest $alg`;
-                       chomp($calcsum);
-                       if ( "$sum" ne "$calcsum" ) {
-                               log_error(NO_FILE, NO_LINE_NUMBER, "checksum of $patch differs between $opt_packagedir/$file and\n"
-                                      ."       $opt_packagedir/$patchdir/$patch. Rerun '$conf_make makepatchsum'.");
-                       }
-               } elsif ($patch =~ /^patch-[a-z0-9]+$/)  {
-                       log_error(NO_FILE, NO_LINE_NUMBER, "patchfile '$patch' is in $file\n"
-                              ."       but not in $opt_packagedir/$patchdir/$patch. Rerun '$conf_make makepatchsum'.");
-               }
+sub checkfile_DESCR($) {
+       my ($file) = @_;
+       my ($maxchars, $maxlines, $fname) = (80, 24, "$opt_packagedir/$file");
+       my ($descr);
 
-               $indistinfofile{$patch} = 1;
+       checkperms($fname);
+       if (!defined($descr = load_file($fname))) {
+               log_error($fname, NO_LINE_NUMBER, "Error while reading.");
+               return 0;
        }
-       close(SUM);
 
-       foreach $patch ( <$opt_packagedir/$patchdir/patch-*> ) {
-               $patch =~ /\/([^\/]+)$/;
-               if (! $indistinfofile{$1}) {
-                       log_error(NO_FILE, NO_LINE_NUMBER, "patchsum of '$1' is in $opt_packagedir/$patchdir/$1 but not in\n"
-                              ."       $file. Rerun '$conf_make makepatchsum'.");
-               }
+       foreach my $line (@$descr) {
+               checkline_length($line, $maxchars);
+               checkline_trailing_whitespace($line);
+               checkline_valid_characters($line, $regex_validchars);
+       }
+
+       if (scalar(@$descr) > $maxlines) {
+               log_warning($fname, NO_LINE_NUMBER, "File too long (should be no more than $maxlines lines).");
        }
 
        return 1;
 }



Home | Main Index | Thread Index | Old Index