From 6526baba14fb233122d8d9ebd798bd92889d2976 Mon Sep 17 00:00:00 2001 From: mharo Date: Sun, 16 Apr 2000 20:24:40 +0000 Subject: Update portlint so it supports PORTNAME/PORTVERSION. This version isn't 100% ready for prime time, but it works well enough that it should be fine to use for most things. I'm not sure if I'll have time to fix the few minor bugs that I know of and give it a good testing today. Parts of the PORTNAME/PORTVERSION changes were submitted by knu. Other changes in this version: * add "-V", version flag * use getopts instead of parsing @ARGV - this fixes a bug where you could only specify one flag after the dash (ie. -c -N would work and -cN wouldn't) * change some warnings to fatals * ignore dot directives in Makefile - this usually reduces the number of warnings displayed when a Makefile contains .include or .if foo * don't blame just emacs for leaving around temporary editor files * don't warn about installing files into /compat * correct counting of number of chars in pkg/COMMENT * understand multiple rcsid tags in the comments section - this allows us to have both $FreeBSD$ and $NetBSD$, for example without getting funky warning messages * scope variables with my instead of local so we can use strict to help us find bugs in portlint --- devel/portlint/src/portlint.pl | 541 ++++++++++++++++++++++++----------------- 1 file changed, 318 insertions(+), 223 deletions(-) (limited to 'devel/portlint/src') diff --git a/devel/portlint/src/portlint.pl b/devel/portlint/src/portlint.pl index 505e5552f45..429e4de129f 100644 --- a/devel/portlint/src/portlint.pl +++ b/devel/portlint/src/portlint.pl @@ -10,42 +10,67 @@ # All rights reserved. # Freely redistributable. Absolutely no warranty. # -# Please note that this perl code MUST be able to handle (Open|Net|Free)BSD +# Please note that this perl code used to be able to handle (Open|Net|Free)BSD # bsd.port.mk. There are significant differences in those so you'll have # hard time upgrading this... +# This code now mainly supports FreeBSD, but patches to update support for +# OpenBSD and NetBSD will be accepted. # # $FreeBSD$ -# $Id: portlint.pl,v 1.4 2000/03/28 05:36:07 mharo Exp $ +# $Id: portlint.pl,v 1.14 2000/04/16 19:58:15 mharo Exp $ # +use vars qw/ $opt_a $opt_b $opt_c $opt_h $opt_v $opt_N $opt_B $opt_V /; +use Getopt::Std; +#use strict; + +my ($err, $warn); +my ($extrafile, $parenwarn, $committer, $verbose, $newport); +my $contblank; +my $portdir; + $err = $warn = 0; $extrafile = $parenwarn = $committer = $verbose = $newport = 0; $contblank = 1; $portdir = '.'; -$l = '[{(]'; -$r = '[)}]'; -$s = '[ \t]'; +# version variables +my $major = 2; +my $minor = 2; + +sub l { '[{(]'; } +sub r { '[)}]'; } +sub s { '[ \t]'; } + +my $l = &l; +my $r = &r; +my $s = &s; + # default setting - for FreeBSD -$portsdir = '/usr/ports'; -$rcsidstr = 'FreeBSD'; -$multiplist = 0; -$ldconfigwithtrue = 0; -$rcsidinplist = 0; -$mancompress = 1; -$manstrict = 0; -$newxdef = 1; -$automan = 1; -$manchapters = '123456789ln'; -$localbase = '/usr/local'; - -#select(STDERR); -while (@ARGV > 0) { - $_ = shift; - /^-h/ && do { - ($prog) = ($0 =~ /([^\/]+)$/); - print STDERR < 0 && /^-B$/ && do { - $contblank = shift; - if ($contblank !~ /^\d+$/) { - print STDERR "FATAL: -B must come with number.\n"; - exit 1; - } - next; - }; - $portdir = $_; } +sub version { + print "$prog version $major.$minor\n"; + exit $major; +} + + +getopts('abchvNB:V'); + +&usage if $opt_h; +&version if $opt_V; +$extrafile = 1 if $opt_a; +$parenwarn = 1 if $opt_b; +$committer = 1 if $opt_c; +$verbose = 1 if $opt_v; +$newport = 1 if $opt_N; +$contblank = $opt_B if $opt_B; + +$portdir = $ARGV[0] ? $ARGV[0] : '.'; + # OS dependent configs # os portsdir rcsid mplist ldcfg plist-rcsid mancompresss strict localbase newxdef automan -@osdep = split(/\n/, <, <$portdir/pkg/*>)) { + foreach my $i ((<$portdir/scripts/*>, <$portdir/pkg/*>)) { next if (! -T $i); $i =~ s/^$portdir\///; next if (defined $checker{$i}); @@ -222,19 +250,19 @@ if ($extrafile) { } } } -foreach $i (<$portdir/patches/patch-??>) { +foreach my $i (<$portdir/patches/patch-??>) { next if (! -T $i); $i =~ s/^$portdir\///; next if (defined $checker{$i}); push(@checker, $i); $checker{$i} = 'checkpatch'; } -foreach $i (@checker) { +foreach my $i (@checker) { print "OK: checking $i.\n"; if (! -f "$portdir/$i") { &perror("FATAL: no $i in \"$portdir\"."); } else { - $proc = $checker{$i}; + my $proc = $checker{$i}; &$proc($i) || &perror("Cannot open the file $i\n"); if ($i !~ /^patches\//) { &checklastline($i) @@ -244,16 +272,16 @@ foreach $i (@checker) { } if ($committer) { if (scalar(@_ = <$portdir/work/*>) || -d "$portdir/work") { - &perror("WARN: be sure to cleanup $portdir/work ". + &perror("FATAL: be sure to cleanup $portdir/work ". "before committing the port."); } if (scalar(@_ = <$portdir/*/*~>) || scalar(@_ = <$portdir/*~>)) { - &perror("WARN: for safety, be sure to cleanup ". - "emacs backup files before committing the port."); + &perror("FATAL: for safety, be sure to cleanup ". + "editor backup files before committing the port."); } if (scalar(@_ = <$portdir/*/*.orig>) || scalar(@_ = <$portdir/*.orig>) || scalar(@_ = <$portdir/*/*.rej>) || scalar(@_ = <$portdir/*.rej>)) { - &perror("WARN: for safety, be sure to cleanup ". + &perror("FATAL: for safety, be sure to cleanup ". "patch backup files before committing the port."); } } @@ -268,18 +296,18 @@ exit $err; # pkg/COMMENT, pkg/DESCR # sub checkdescr { - local($file) = @_; - local(%maxchars) = ('pkg/COMMENT', 70, 'pkg/DESCR', 80); - local(%maxlines) = ('pkg/COMMENT', 1, 'pkg/DESCR', 24); - local(%errmsg) = ('pkg/COMMENT', "must be one-liner.", + my($file) = @_; + my(%maxchars) = ('pkg/COMMENT', 70, 'pkg/DESCR', 80); + my(%maxlines) = ('pkg/COMMENT', 1, 'pkg/DESCR', 24); + my(%errmsg) = ('pkg/COMMENT', "must be one-liner.", 'pkg/DESCR', "exceeds $maxlines{'pkg/DESCR'} ". "lines, make it shorter if possible."); - local($longlines, $linecnt, $tmp) = (0, 0, ""); + my($longlines, $linecnt, $tmp) = (0, 0, ""); open(IN, "< $portdir/$file") || return 0; while () { $linecnt++; - $longlines++ if ($maxchars{$file} < length($_)); + $longlines++ if ($maxchars{$file} < length(chomp($_))); $tmp .= $_; } if ($linecnt > $maxlines{$file}) { @@ -289,7 +317,7 @@ sub checkdescr { print "OK: $file has $linecnt lines.\n" if ($verbose); } if ($longlines > 0) { - &perror("WARN: $i includes lines that exceed $maxchars{$file} ". + &perror("WARN: $file includes lines that exceed $maxchars{$file} ". "characters."); } if ($tmp =~ /[\033\200-\377]/) { @@ -309,16 +337,16 @@ sub checkdescr { # pkg/PLIST # sub checkplist { - local($file) = @_; - local($curdir) = ($localbase); - local($inforemoveseen, $infoinstallseen, $infoseen) = (0, 0, 0); - local($infobeforeremove, $infoafterinstall) = (0, 0); - local($infooverwrite) = (0); - local($rcsidseen) = (0); + my($file) = @_; + my($curdir) = ($localbase); + my($inforemoveseen, $infoinstallseen, $infoseen) = (0, 0, 0); + my($infobeforeremove, $infoafterinstall) = (0, 0); + my($infooverwrite) = (0); + my($rcsidseen) = (0); - local(@exec_info) = (); - local(@unexec_info) = (); - local(@infofile) = (); + my(@exec_info) = (); + my(@unexec_info) = (); + my(@infofile) = (); open(IN, "< $portdir/$file") || return 0; while () { @@ -432,12 +460,14 @@ sub checkplist { } # check that every infofile has an exec install-info and unexec install-info - $exec_install = join(/ /, @exec_info); - $exec_install .= ' '; - $unexec_install = join(/ /, @unexec_info); - $unexec_install .= ' '; - foreach $if (@infofile) { - if ($exec_install !~ m/\%D\/$if/) { + my $exec_install = join(/ /, @exec_info); + my $exec_install .= ' '; + my $unexec_install = join(/ /, @unexec_info); + my $unexec_install .= ' '; + + foreach my $if (@infofile) { + next if ($if =~ m/info-/); + if ($exec_install !~ m/\%D\/\Q$if\E/) { &perror("FATAL: you need an '\@exec install-info \%D/$if \%D/info/dir' line in your PLIST"); } if ($unexec_install !~ m/\%D\/$if/) { @@ -482,8 +512,8 @@ sub checkplist { # misc files # sub checkpathname { - local($file) = @_; - local($whole); + my($file) = @_; + my($whole); open(IN, "< $portdir/$file") || return 0; $whole = ''; @@ -495,8 +525,8 @@ sub checkpathname { } sub checklastline { - local($file) = @_; - local($whole); + my($file) = @_; + my($whole); open(IN, "< $portdir/$file") || return 0; $whole = ''; @@ -516,8 +546,8 @@ sub checklastline { } sub checkpatch { - local($file) = @_; - local($whole); + my($file) = @_; + my($whole); if (-z "$portdir/$file") { &perror("FATAL: $file has no content. should be removed ". @@ -542,15 +572,17 @@ sub checkpatch { # Makefile # sub checkmakefile { - local($file) = @_; - local($rawwhole, $whole, $idx, @sections); - local($tmp); - local($i, $j, $k, $l); - local(@varnames) = (); - local($distfiles, $pkgname, $distname, $extractsufx) = ('', '', '', ''); - local($bogusdistfiles) = (0); - local($realwrksrc, $wrksrc, $nowrksubdir) = ('', '', ''); - local(@mman, @pman); + my($file) = @_; + my($rawwhole, $whole, $idx, @sections); + my($i, $j, $k, $l); + my @cat = (); + my $has_lang_cat = 0; + my $tmp; + my $bogusdistfiles = 0; + my @varnames = (); + my($portname, $portversion, $distfiles, $distname, $extractsufx) = ('', '', '', '', ''); + my($realwrksrc, $wrksrc, $nowrksubdir) = ('', '', ''); + my(@mman, @pman); open(IN, "< $portdir/$file") || return 0; $rawwhole = ''; @@ -621,10 +653,29 @@ sub checkmakefile { } # - # whole file: IS_INTERACTIVE/NOPORTDOCS + # whole file: NO_CHECKSUM # $whole =~ s/\n#[^\n]*/\n/g; $whole =~ s/\n\n+/\n/g; + print "OK: checking NO_CHECKSUM.\n" if ($verbose); + if ($whole =~ /\nNO_CHECKSUM/) { + &perror("FATAL: use of NO_CHECKSUM discouraged. ". + "it is intended to be a user variable."); + } + + # + # whole file: PKGNAME + # + print "OK: checking PKGNAME.\n" if ($verbose); + if ($whole =~ /\nPKGNAME/) { + &perror("FATAL: PKGNAME is obsoleted by PORTNAME, ". + "PORTVERSION, PKGNAMEPREFIX and PKGNAMESUFFIX."); + } + + + # + # whole file: IS_INTERACTIVE/NOPORTDOCS + # print "OK: checking IS_INTERACTIVE.\n" if ($verbose); if ($whole =~ /\nIS_INTERACTIVE/) { if ($whole !~ /defined\((BATCH|FOR_CDROM)\)/) { @@ -643,8 +694,9 @@ sub checkmakefile { # # whole file: direct use of command names # + my %cmdnames = (); print "OK: checking direct use of command names.\n" if ($verbose); - foreach $i (split(/\s+/, <