pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc/files lintpkgsrc: cleanup: sort su...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3da941d1e0d4
branches:  trunk
changeset: 382509:3da941d1e0d4
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Jul 30 08:18:31 2022 +0000

description:
lintpkgsrc: cleanup: sort subs from small to big

This way, perl properly checks the sub prototypes.

No functional change.

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl |  1454 +++++++++++++++---------------
 1 files changed, 725 insertions(+), 729 deletions(-)

diffs (truncated from 1553 to 300 lines):

diff -r 49ea63ae0a4b -r 3da941d1e0d4 pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Sat Jul 30 07:37:03 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Sat Jul 30 08:18:31 2022 +0000
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.27 2022/07/30 07:37:03 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.28 2022/07/30 08:18:31 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -22,6 +22,207 @@
 use IPC::Open3;
 use Cwd 'realpath', 'getcwd';
 
+# PkgList is the master list of all packages in pkgsrc.
+#
+package PkgList;
+
+sub add($@) {
+       my $self = shift;
+
+       if (!$self->pkgs($_[0])) {
+               $self->{_pkgs}{ $_[0] } = new Pkgs $_[0];
+       }
+       $self->pkgs($_[0])->add(@_);
+}
+
+sub new($) {
+       my $class = shift;
+       my $self = {};
+       bless $self, $class;
+       return $self;
+}
+
+sub numpkgver($) {
+       my $self = shift;
+       scalar($self->pkgver);
+}
+
+sub pkgver($@) {
+       my $self = shift;
+
+       if (@_ == 0) {
+               my (@list);
+               foreach my $pkg ($self->pkgs) {
+                       push(@list, $pkg->pkgver);
+               }
+               return (@list);
+       }
+
+       if (defined $self->{_pkgs}{$_[0]}) {
+               return (@_ > 1)
+                   ? $self->{_pkgs}{$_[0]}->pkgver($_[1])
+                   : $self->{_pkgs}{$_[0]}->pkgver();
+       }
+       return;
+}
+
+sub pkgs($@) {
+       my $self = shift;
+
+       if (@_) {
+               return $self->{_pkgs}{$_[0]};
+       } else {
+               return (sort { $a->pkg cmp $b->pkg } values %{$self->{_pkgs}});
+       }
+}
+
+sub store($) {
+       my $self = shift;
+       my @pkgs = keys %{$self->{_pkgs}};
+       my ($cnt, $subcnt) = $self->count;
+
+       print("\$pkgcnt = $cnt;\n");
+       print("\$subpkgcnt = $subcnt;\n");
+       map($self->{_pkgs}{$_}->store, keys %{$self->{_pkgs}});
+}
+
+sub count($) {
+       my $self = shift;
+       my ($pkgcnt, $pkgsubcnt);
+
+       map {
+               $pkgcnt++;
+               $pkgsubcnt += $self->{_pkgs}{$_}->count;
+       } keys %{$self->{_pkgs}};
+       wantarray ? ($pkgcnt, $pkgsubcnt) : $pkgcnt;
+}
+
+# Pkgs is all versions of a given package (eg: apache-1.x and apache-2.x)
+#
+package Pkgs;
+
+sub add($@) {
+       my $self = shift;
+
+       $self->{_pkgver}{$_[1]} = new PkgVer @_;
+}
+
+sub new($@) {
+       my $class = shift;
+       my $self = {};
+
+       bless $self, $class;
+       $self->{_pkg} = $_[0];
+       return $self;
+}
+
+sub versions($) {
+       my $self = shift;
+
+       return sort { $b cmp $a } keys %{$self->{_pkgver}};
+}
+
+sub pkg($) {
+       my $self = shift;
+       $self->{_pkg};
+}
+
+sub pkgver($@) {
+       my $self = shift;
+
+       if (@_) {
+               if ($self->{_pkgver}{$_[0]}) {
+                       return ($self->{_pkgver}{$_[0]});
+               }
+               return;
+       }
+       return sort { $b->ver() cmp $a->ver() } values %{$self->{_pkgver}};
+}
+
+sub latestver($) {
+       my $self = shift;
+
+       ($self->pkgver())[0];
+}
+
+sub store($) {
+       my $self = shift;
+
+       print("\$pkgnum++;\n");
+       map($self->{_pkgver}{$_}->store, keys %{$self->{_pkgver}});
+}
+
+sub count($) {
+       my $self = shift;
+
+       scalar(keys %{$self->{_pkgver}});
+}
+
+# PkgVer is a unique package+version
+#
+package PkgVer;
+
+sub new($$$) {
+       my $class = shift;
+       my $self = {};
+
+       bless $self, $class;
+       $self->{_pkg} = $_[0];
+       $self->{_ver} = $_[1];
+       return $self;
+}
+
+sub pkgname($) {
+       my $self = shift;
+
+       $self->pkg . '-' . $self->ver;
+}
+
+sub pkg($) {
+       my $self = shift;
+
+       $self->{_pkg};
+}
+
+sub var($$$) {
+       my $self = shift;
+       my ($key, $val) = @_;
+
+       (defined $val)
+           ? ($self->{$key} = $val)
+           : $self->{$key};
+}
+
+sub ver($) {
+       my $self = shift;
+
+       $self->{_ver};
+}
+
+sub vars($) {
+       my $self = shift;
+
+       grep(!/^_(pkg|ver)$/, keys %{$self});
+}
+
+sub store($) {
+       my $self = shift;
+       my $data;
+
+       ($data = $self->{_pkg}) =~ s/([\\\$\@\%\"])/\\$1/g;
+       print("\$pkgver = \$pkglist->add(\"$data\", \"");
+
+       ($data = $self->{_ver}) =~ s/([\\\$\@\%\"])/\\$1/g;
+       print("$data\"); __pkgcount(1);\n");
+
+       foreach ($self->vars) {
+               ($data = $self->{$_}) =~ s/([\\\$\@\%\"])/\\$1/g;
+               print("\$pkgver->var(\"$_\", \"$data\");\n");
+       }
+}
+
+package main;
+
 # Buildtime configuration
 my $conf_make = '@MAKE@';
 my $conf_pkgsrcdir = '@PKGSRCDIR@';
@@ -38,16 +239,59 @@
     %prebuilt_pkgdir_cache,    # To avoid symlink loops in prebuilt_pkgdirs
 );
 
-sub usage_and_exit();
-sub listdir($$);
-sub get_default_makefile_vars();
-sub fail($);
-sub parse_makefile_pkgsrc($);
-
 # Horrible kludge to ensure we have a value for testing in conditionals, but
 # gets removed in the final evaluation
 my $magic_undefined = 'M_a_G_i_C_uNdEfInEd';
 
+sub debug(@) {
+
+       ($opt{D}) && print STDERR 'DEBUG: ', @_;
+}
+
+sub verbose(@) {
+
+       if (-t STDERR) {
+               print STDERR @_;
+       }
+}
+
+sub fail($) {
+
+       print STDERR shift(), "\n";
+       exit(3);
+}
+
+# List (recursive) non directory contents of specified directory
+#
+#TODO this entire sub should be replaced with direct calls to
+#     File::Find
+sub listdir($$);
+sub listdir($$) {
+       my ($base, $dir) = @_;
+       my ($thisdir);
+       my (@list, @thislist);
+
+       $thisdir = $base;
+       if (defined($dir)) {
+               $thisdir .= "/$dir";
+               $dir .= '/';
+       } else {
+               $dir = '';
+       }
+
+       opendir(DIR, $thisdir) || fail("Unable to opendir($thisdir): $!");
+       @thislist = grep(substr($_, 0, 1) ne '.' && $_ ne 'CVS', readdir(DIR));
+       closedir(DIR);
+       foreach my $entry (@thislist) {
+               if (-d "$thisdir/$entry") {
+                       push(@list, listdir($base, "$dir$entry"));
+               } else {
+                       push(@list, "$dir$entry");
+               }
+       }
+       @list;
+}
+
 sub canonicalize_pkgname($) {
        my ($pkgname) = @_;
 
@@ -57,95 +301,6 @@
        return $pkgname;
 }
 
-# Could speed up by building a cache of package names to paths, then processing
-# each package name once against the tests.
-sub check_prebuilt_packages() {
-
-       if ($_ eq 'distfiles' || $_ eq 'pkgsrc') {
-               # Skip these subdirs if present
-               $File::Find::prune = 1;
-
-       } elsif (/(.+)-(\d.*)\.t[bg]z$/) {
-               my ($pkg, $ver) = ($1, $2);
-



Home | Main Index | Thread Index | Old Index