pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/lintpkgsrc



Module Name:    pkgsrc
Committed By:   rillig
Date:           Thu Aug  4 21:55:58 UTC 2022

Modified Files:
        pkgsrc/pkgtools/lintpkgsrc: Makefile
        pkgsrc/pkgtools/lintpkgsrc/files: lintpkgsrc.pl
        pkgsrc/pkgtools/lintpkgsrc/files/t: packages.t

Log Message:
lintpkgsrc: cleanup: merge 'store' subroutines

With small changes, the subroutine for storing the cache can be
restricted to the public API of the types PkgDb, Pkgs and PkgVer. This
way, the 'store' subroutines no longer need to be part of the classes.
Implementing the code in a single external subroutine saves a few lines
of code.

The order of the PkgVer entries in the cache file changes, everything
else is as before.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 pkgsrc/pkgtools/lintpkgsrc/Makefile
cvs rdiff -u -r1.55 -r1.56 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.9 -r1.10 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/pkgtools/lintpkgsrc/Makefile
diff -u pkgsrc/pkgtools/lintpkgsrc/Makefile:1.45 pkgsrc/pkgtools/lintpkgsrc/Makefile:1.46
--- pkgsrc/pkgtools/lintpkgsrc/Makefile:1.45    Wed Aug  3 22:03:43 2022
+++ pkgsrc/pkgtools/lintpkgsrc/Makefile Thu Aug  4 21:55:57 2022
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.45 2022/08/03 22:03:43 rillig Exp $
+# $NetBSD: Makefile,v 1.46 2022/08/04 21:55:57 rillig Exp $
 
 PKGNAME=       lintpkgsrc-4.99
 CATEGORIES=    pkgtools
@@ -8,7 +8,6 @@ HOMEPAGE=       https://www.NetBSD.org/docs/pk
 COMMENT=       Sanity checks on the complete pkgsrc tree
 
 DEPENDS+=      digest>=20010101:../../pkgtools/digest
-TEST_DEPENDS+= p5-Capture-Tiny>=0:../../devel/p5-Capture-Tiny
 TEST_DEPENDS+= p5-File-Slurp>=0:../../devel/p5-File-Slurp
 TEST_DEPENDS+= p5-IO-Null>=0:../../devel/p5-IO-Null
 CONFLICTS+=    pkglint<4.82

Index: pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.55 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.56
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.55 Thu Aug  4 07:00:51 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Thu Aug  4 21:55:58 2022
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.55 2022/08/04 07:00:51 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.56 2022/08/04 21:55:58 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -70,24 +70,6 @@ sub vars($) {
        keys %{$self->{vars}};
 }
 
-sub store($) {
-       my ($self) = @_;
-
-       my $name = $self->pkgbase;
-       my $ver = $self->pkgversion;
-
-       $name =~ /\s/ and die "cannot store package name '$name'\n";
-       $ver =~ /\s/ and die "cannot store package version '$ver'\n";
-       printf("package\t%s\t%s\n", $name, $ver);
-
-       foreach my $varname (sort $self->vars) {
-               my $value = $self->var($varname);
-               $varname =~ /\s/ and die "cannot store variable name '$varname'\n";
-               $value =~ /\n/ and die "cannot store variable value '$value'\n";
-               printf("var\t%s\t%s\n", $varname, $value);
-       }
-}
-
 # Pkgs collects all versions of a given PKGBASE, e.g. apache-1.3.27 and
 # apache-2.0.46.
 #
@@ -145,15 +127,6 @@ sub latestver($) {
        ($self->pkgver)[0];
 }
 
-sub store($) {
-       my ($self) = @_;
-
-       my $pkgvers = $self->{pkgvers};
-       foreach my $pkgver (sort keys %$pkgvers) {
-               $pkgvers->{$pkgver}->store();
-       }
-}
-
 # PkgDb is a small database of all packages in pkgsrc.
 package PkgDb;
 
@@ -220,14 +193,6 @@ sub pkgs($$) {
        }
 }
 
-sub store($) {
-       my ($self) = @_;
-
-       foreach my $pkgs ($self->pkgs) {
-               $pkgs->store();
-       }
-}
-
 package main;
 
 # Buildtime configuration
@@ -1374,14 +1339,30 @@ sub scan_pkgsrc_distfiles_vs_distinfo($$
        (sort keys %bad_distfiles);
 }
 
-sub store_pkgsrc_makefiles($) {
-       my ($fname) = @_;
+sub store_pkgsrc_makefiles($$) {
+       my ($db, $fname) = @_;
 
        open(STORE, '>', $fname)
            or die("Cannot save pkgsrc store to $fname: $!\n");
-       my $prev = select(STORE);
-       $pkgdb->store();
-       select($prev);
+       foreach my $pkgver ($db->pkgver) {
+               my $pkgbase = $pkgver->pkgbase;
+               my $pkgversion = $pkgver->pkgversion;
+
+               $pkgbase =~ /^\S+$/
+                   or die "cannot store package name '$pkgbase'\n";
+               $pkgversion =~ /^\S+$/
+                   or die "cannot store package version '$pkgversion'\n";
+               print STORE "package\t$pkgbase\t$pkgversion\n";
+
+               foreach my $varname (sort $pkgver->vars) {
+                       my $value = $pkgver->var($varname);
+                       $varname =~ /^\S+$/
+                           or die "cannot store variable name '$varname'\n";
+                       $value =~ /^.*$/
+                           or die "cannot store variable value '$value'\n";
+                       print STORE "var\t$varname\t$value\n";
+               }
+       }
        close(STORE)
            or die("Cannot save pkgsrc store to $fname: $!\n");
 }
@@ -1804,7 +1785,7 @@ sub main() {
 
        if ($opt{E}) {
                scan_pkgsrc_makefiles($pkgsrcdir);
-               store_pkgsrc_makefiles($opt{E});
+               store_pkgsrc_makefiles($pkgdb, $opt{E});
        }
 }
 

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.9 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.10
--- pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.9   Thu Aug  4 07:00:51 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t       Thu Aug  4 21:55:58 2022
@@ -1,8 +1,9 @@
-# $NetBSD: packages.t,v 1.9 2022/08/04 07:00:51 rillig Exp $
+# $NetBSD: packages.t,v 1.10 2022/08/04 21:55:58 rillig Exp $
 
 use strict;
 use warnings;
-use Capture::Tiny 'capture';
+use File::Slurp 'read_file';
+use File::Temp;
 use Test;
 
 BEGIN { plan tests => 30, onfail => sub { die } }
@@ -114,21 +115,22 @@ sub test_store_order() {
 
        $pkgbase_1_15->var('COMMENT', 'Version 1.15');
 
-       my $stdout = capture {
-               $pkgdb->store();
-       };
+       my $tmpfile = File::Temp->new();
+       store_pkgsrc_makefiles($pkgdb, $tmpfile->filename);
+       my $stored = read_file($tmpfile->filename);
 
        # XXX: 1.3nb4 should be sorted before 1.15.
        # On the other hand, this is just an internal cache file format.
-       ok($stdout, ''
+       ok($stored, ''
+           . "package\tpkgbase\t1.3nb4\n"
+           . "package\tpkgbase\t1.15\n"
+           . "var\tCOMMENT\tVersion 1.15\n"
            . "package\tpkgbase\t1.0\n"
            . "var\tCOMMENT\tVersion 1\n"
            . "var\tHOMEPAGE\thttps://example.org/pkgbase\n";
            . "var\tLICENSE\tmodified-bsd\n"
            . "var\tMAINTAINER\tpkgsrc-users\@NetBSD.org\n"
-           . "package\tpkgbase\t1.15\n"
-           . "var\tCOMMENT\tVersion 1.15\n"
-           . "package\tpkgbase\t1.3nb4\n");
+       );
 }
 
 test_pkgver();



Home | Main Index | Thread Index | Old Index