pkgsrc-Changes archive

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

CVS commit: pkgsrc/pkgtools/lintpkgsrc/files



Module Name:    pkgsrc
Committed By:   rillig
Date:           Wed Aug 17 17:26:36 UTC 2022

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

Log Message:
lintpkgsrc: cleanup: move loading and storing of package data together


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.16 -r1.17 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/files/lintpkgsrc.pl
diff -u pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.107 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.108
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.107        Tue Aug 16 20:54:35 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Wed Aug 17 17:26:35 2022
@@ -1,5 +1,5 @@
 #!@PERL5@
-# $NetBSD: lintpkgsrc.pl,v 1.107 2022/08/16 20:54:35 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.108 2022/08/17 17:26:35 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -135,6 +135,51 @@ sub pkgs($self, $pkgbase = undef) {
            : sort { $a->pkgbase cmp $b->pkgbase } values %$self;
 }
 
+sub load($class, $fname) {
+       open(STORE, '<', $fname)
+           or die("Cannot read package data from $fname: $!\n");
+       my ($pkgver);
+       my $self = $class->new();
+       while (defined(my $line = <STORE>)) {
+               chomp($line);
+               if ($line =~ m"^ package \t ([^\t]+) \t ([^\t]+) $"x) {
+                       $pkgver = $self->add($1, $2);
+               } elsif ($line =~ m"^ var \t ([^\t]+) \t (.*) $"x) {
+                       $pkgver->var($1, $2);
+               } elsif ($line =~ m"^ sub ") {
+                       die "Outdated cache format in '$fname'\n";
+               } else {
+                       die "Invalid line '$line' in cache '$fname'\n";
+               }
+       }
+       close(STORE) or die;
+}
+
+sub store($self, $fname) {
+       open(STORE, '>', $fname)
+           or die("Cannot save package data to $fname: $!\n");
+       foreach my $pkgver ($self->pkgvers_all) {
+               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 package data to $fname: $!\n");
+}
+
 package main;
 
 # Buildtime configuration
@@ -1010,26 +1055,6 @@ sub chdir_or_fail($dir) {
        return $prev_dir;
 }
 
-sub load_pkgdata_from_cache($fname) {
-       open(STORE, '<', $fname)
-           or die("Cannot read pkgsrc store from $fname: $!\n");
-       my ($pkgver);
-       $pkgdata = PkgData->new();
-       while (defined(my $line = <STORE>)) {
-               chomp($line);
-               if ($line =~ m"^ package \t ([^\t]+) \t ([^\t]+) $"x) {
-                       $pkgver = $pkgdata->add($1, $2);
-               } elsif ($line =~ m"^ var \t ([^\t]+) \t (.*) $"x) {
-                       $pkgver->var($1, $2);
-               } elsif ($line =~ m"^ sub ") {
-                       die "Outdated cache format in '$fname'\n";
-               } else {
-                       die "Invalid line '$line' in cache '$fname'\n";
-               }
-       }
-       close(STORE);
-}
-
 # Generate pkgname->category/pkg mapping, optionally check DEPENDS
 #
 sub scan_pkgsrc_makefiles($pkgsrcdir) {
@@ -1037,7 +1062,7 @@ sub scan_pkgsrc_makefiles($pkgsrcdir) {
        return if defined $pkgdata; # Already done.
 
        if ($opt{I}) {
-               load_pkgdata_from_cache($opt{I});
+               $pkgdata = PkgData->load($opt{I});
                return;
        }
 
@@ -1234,32 +1259,6 @@ sub check_pkgsrc_distfiles_vs_distinfo($
        sort keys %unref_distfiles;
 }
 
-sub store_pkgdata_in_cache($db, $fname) {
-       open(STORE, '>', $fname)
-           or die("Cannot save package data to $fname: $!\n");
-       foreach my $pkgver ($db->pkgvers_all) {
-               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 package data to $fname: $!\n");
-}
-
 # Remember to update manual page when modifying option list
 #
 sub usage_and_exit($status) {
@@ -1651,7 +1650,7 @@ sub main() {
 
        if ($opt{E}) {
                scan_pkgsrc_makefiles($pkgsrcdir);
-               store_pkgdata_in_cache($pkgdata, $opt{E});
+               $pkgdata->store($opt{E});
        }
 }
 

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.16 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.17
--- pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.16  Tue Aug 16 20:54:35 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t       Wed Aug 17 17:26:36 2022
@@ -1,4 +1,4 @@
-# $NetBSD: packages.t,v 1.16 2022/08/16 20:54:35 rillig Exp $
+# $NetBSD: packages.t,v 1.17 2022/08/17 17:26:36 rillig Exp $
 #
 # Tests for the internal package database, which stores the packages and their
 # versions, and a few variables like DEPENDS and BROKEN.
@@ -104,7 +104,7 @@ sub test_package_variables() {
 }
 
 # Demonstrate how the package data is stored in the cache file.
-sub test_store_order() {
+sub test_pkgdata_store() {
        my $pkgdata = PkgData->new();
 
        my $pkgbase_1_0 = $pkgdata->add('pkgbase', '1.0');
@@ -120,7 +120,7 @@ sub test_store_order() {
        $pkgbase_1_15->var('COMMENT', 'Version 1.15');
 
        my $tmpfile = File::Temp->new();
-       store_pkgdata_in_cache($pkgdata, $tmpfile->filename);
+       $pkgdata->store($tmpfile->filename);
        my $stored = read_file($tmpfile->filename);
 
        # XXX: 1.3nb4 should be sorted before 1.15.
@@ -141,4 +141,4 @@ test_pkgver();
 test_pkgs();
 test_pkgdata();
 test_package_variables();
-test_store_order();
+test_pkgdata_store();



Home | Main Index | Thread Index | Old Index