pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/pkgtools/lintpkgsrc lintpkgsrc: cleanup: merge 'store'...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/3f41f8b8b2c4
branches:  trunk
changeset: 382774:3f41f8b8b2c4
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Aug 04 21:55:57 2022 +0000

description:
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.

diffstat:

 pkgtools/lintpkgsrc/Makefile            |   3 +-
 pkgtools/lintpkgsrc/files/lintpkgsrc.pl |  65 +++++++++++---------------------
 pkgtools/lintpkgsrc/files/t/packages.t  |  20 +++++----
 3 files changed, 35 insertions(+), 53 deletions(-)

diffs (174 lines):

diff -r 16059903dff5 -r 3f41f8b8b2c4 pkgtools/lintpkgsrc/Makefile
--- a/pkgtools/lintpkgsrc/Makefile      Thu Aug 04 21:44:45 2022 +0000
+++ b/pkgtools/lintpkgsrc/Makefile      Thu Aug 04 21:55:57 2022 +0000
@@ -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 @@
 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
diff -r 16059903dff5 -r 3f41f8b8b2c4 pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Thu Aug 04 21:44:45 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Thu Aug 04 21:55:57 2022 +0000
@@ -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 @@
        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 @@
        ($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 store($) {
-       my ($self) = @_;
-
-       foreach my $pkgs ($self->pkgs) {
-               $pkgs->store();
-       }
-}
-
 package main;
 
 # Buildtime configuration
@@ -1374,14 +1339,30 @@
        (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 @@
 
        if ($opt{E}) {
                scan_pkgsrc_makefiles($pkgsrcdir);
-               store_pkgsrc_makefiles($opt{E});
+               store_pkgsrc_makefiles($pkgdb, $opt{E});
        }
 }
 
diff -r 16059903dff5 -r 3f41f8b8b2c4 pkgtools/lintpkgsrc/files/t/packages.t
--- a/pkgtools/lintpkgsrc/files/t/packages.t    Thu Aug 04 21:44:45 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/packages.t    Thu Aug 04 21:55:57 2022 +0000
@@ -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 @@
 
        $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