pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files Completely rewrote plist-clash....



details:   https://anonhg.NetBSD.org/pkgsrc/rev/9617afa66abd
branches:  trunk
changeset: 501620:9617afa66abd
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Mon Oct 24 20:56:53 2005 +0000

description:
Completely rewrote plist-clash.pl. It has been unmodified for 7 years,
while pkgsrc has changed dramatically. Now it is usable again, although
far from perfect.

diffstat:

 pkgtools/pkglint/files/plist-clash.pl |  139 ++++++++++++---------------------
 1 files changed, 52 insertions(+), 87 deletions(-)

diffs (153 lines):

diff -r 81474329b6da -r 9617afa66abd pkgtools/pkglint/files/plist-clash.pl
--- a/pkgtools/pkglint/files/plist-clash.pl     Mon Oct 24 20:45:28 2005 +0000
+++ b/pkgtools/pkglint/files/plist-clash.pl     Mon Oct 24 20:56:53 2005 +0000
@@ -1,97 +1,62 @@
-#!@PERL@
+#! @PERL@
+# $NetBSD: plist-clash.pl,v 1.4 2005/10/24 20:56:53 rillig Exp $
 #
-# $NetBSD: plist-clash.pl,v 1.3 2005/02/14 22:14:48 cube Exp $
-#
-# Scan all ports and look for filenames used by more than one port.
+# Scan all PLIST files given on the command line and report all lines
+# that appear more than once.
+
+my $conf_rootdir = '@PKGSRCDIR@';
+
+my %files = ();
+
+sub read_PLIST($) {
+       my ($fname) = @_;
+
+       if (!open(F, "<", $fname)) {
+               warn "$!\n";
+               return undef;
+       }
 
-if(`uname -s` eq "FreeBSD"){
-    $OS="FreeBSD";
-    $PORTSDIR="/usr/ports";
-}else{
-    $OS="NetBSD";
-    $PORTSDIR="@PORTSDIR@";
+       my $lineno = 0;
+       foreach my $line (<F>) {
+               chomp($line);
+               $lineno++;
+
+               # Ignore comments and commands
+               next if ($line =~ qr"^@");
+
+               # Ignore filenames with embedded variables
+               next if ($line =~ qr"\$");
+               
+               if ($line =~ qr"^[A-Za-z0-9].*") {
+                       if (!exists($files{$line})) {
+                               $files{$line} = [];
+                       }
+                       push(@{$files{$line}}, "$fname:$lineno");
+
+               } else {
+                       warn("ERROR: $fname:$lineno: Unknown line type\n");
+               }
+       }
+       close(F);
 }
 
-###########################################################################
-sub read_plist
-{
-    local($pkg)=@_;
-    local($base);
+sub main() {
+       if (@ARGV == 0) {
+               die("usage: $0 <plist>...\n");
+       }
 
-    $prefix="\$LOCALBASE";
-    
-    if(! -d $pkg){
-       print "$pkg: no such dir\n";
-       return;
-    }
-
-    open(M,"$pkg/Makefile") || die "Can't read $pkg/Makefile: $!\n";
-    while(<M>){
-       $prefix="\$X11BASE" if /USE_X11/;
-       $prefix="\$X11BASE" if /USE_IMAKE/;
-       $prefix=$1 if /^PREFIX\??=\s*(\S+)/;
-    }
-    close(M);
-
-    # printf "%-40s prefix=%s\n","$pkg:",$prefix;
+       foreach my $plist (@ARGV) {
+               read_PLIST($plist);
+       }
 
-    # NetBSD may have more than one PLIST file
-    opendir(D,"$pkg/pkg/.") || die "Can't readdir($pkg/pkg/.): $!\n";
-    while($f=readdir(D)){
-       if($f =~ /^PLIST/){
-           next if $f=~/.orig$/;
-           
-           # printf("%-40s PLIST=$f\n","",$f);
-
-           open(P,"$pkg/pkg/$f") or die "Can't read $pkg/pkg/$f: $!\n";
-           while(<P>){
-               next if /^@/;
-               chomp;
-
-               # strip .gz off manpages - handled via MANZ
-               s/.gz$// if /^man/;
-
-               ($p) = $pkg =~ m@$PORTSDIR/(.+)@;
-               if(0 and $F{"$prefix/$_"}){
-                   print "$prefix/$_ already used by ",$F{"$prefix/$_"},"\n";
+       foreach my $file (sort keys %files) {
+               my $srcs = $files{$file};
+               if (@{$srcs} != 1) {
+                       foreach my $src (@{$srcs}) {
+                               print "$src: $file\n";
+                       }
                }
-               $F{"$prefix/$_"} .= " $p";
-           }
-           close(P);
        }
-    }
-    closedir(D);
 }
 
-
-###########################################################################
-# M A I N
-###########################################################################
-
-if($#ARGV < 0){
-    die "Usage: $0 portsdir1 ...\n";
-}
-
-# loop to parse all PLIST files
-foreach $pkg (@ARGV){
-    print "===> $pkg\n";
-    &read_plist($pkg);
-}
-
-# Output diplicates
-foreach $file (sort keys %F){
-    $pkgs=$F{$file};
-    $pkgs=~s/^\s+//g;
-
-    # clean up duplicates (e.g. via PLIST-*)
-    undef %pF;
-    foreach $p (split(/ /,$pkgs)){
-       $pF{$p}=1;
-    }
-    @pkgs=sort keys %pF;
-
-    $n=$#pkgs+1;
-    if($n>1){
-       print "$n for $file: ",join(", ",@pkgs),"\n";
-    }
-}
+main();



Home | Main Index | Thread Index | Old Index