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:           Sat Aug 13 12:22:20 UTC 2022

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

Log Message:
lintpkgsrc: fix expansion of the ':U' modifier

In Perl, 0 is falsy, but in bmake, the modifier ':U' only cares about
undefined vs. defined.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl
cvs rdiff -u -r1.7 -r1.8 pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t
cvs rdiff -u -r1.14 -r1.15 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t
cvs rdiff -u -r1.11 -r1.12 \
    pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t \
    pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.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.87 pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.88
--- pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl:1.87 Sat Aug 13 11:34:39 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/lintpkgsrc.pl      Sat Aug 13 12:22:20 2022
@@ -1,6 +1,6 @@
 #!@PERL5@
 
-# $NetBSD: lintpkgsrc.pl,v 1.87 2022/08/13 11:34:39 rillig Exp $
+# $NetBSD: lintpkgsrc.pl,v 1.88 2022/08/13 12:22:20 rillig Exp $
 
 # Written by David Brownlee <abs%netbsd.org@localhost>.
 #
@@ -59,9 +59,8 @@ sub vars($self) {
        keys $self->{vars}->%*;
 }
 
-# Pkgs collects all versions of a given PKGBASE, e.g. apache-1.3.27 and
-# apache-2.0.46.
-#
+# All versions of a given PKGBASE, e.g. apache-1.3.27 and apache-2.0.46.
+# Multi-prefix packages like py39-* are stored as simply py-*.
 package Pkgs;
 
 sub new($class, $pkgbase) {
@@ -77,8 +76,7 @@ sub pkgbase($self) {
        $self->{pkgbase};
 }
 
-# Returns all available versions of the package, in decreasing
-# alphabetical(!) order.
+# All available versions of the package, in decreasing alphabetical(!) order.
 sub versions($self) {
        reverse sort keys $self->{pkgvers}->%*;
 }
@@ -314,7 +312,7 @@ sub eval_mk_cond($line, $vars) {
 
        # XXX This is _so_ wrong - need to parse this correctly
        $test =~ s/""/\r/g;
-       $test =~ s/"//g; # "
+       $test =~ s/"//g;
        $test =~ s/\r/""/g;
 
        debug("conditional: $test\n");
@@ -333,7 +331,6 @@ sub eval_mk_cond($line, $vars) {
 
        if ($test =~ /^[ <> \d () \s & | . ! ]+$/xx) {
                debug("eval test $test\n");
-               $! = undef;
                my $result = eval "($test) ? 1 : 0";
                defined $result or fail("Eval '$test' failed in '$line': $@");
                debug("conditional: evaluated to " . ($result ? 'true' : 'false') . "\n");
@@ -433,7 +430,8 @@ sub parse_makefile_line_var($varname, $o
 
 sub expand_modifiers($file, $varname, $left, $subvar, $mods, $right, $vars) {
        my @mods = split(':', $mods);
-       my $result = $vars->{$subvar} || '';
+       my $result = $vars->{$subvar};
+       $result = '' unless defined $result;
 
        # If the value of $subvar contains a '$', skip it on this pass.
        # Hopefully it will get substituted and we can catch it
@@ -442,8 +440,11 @@ sub expand_modifiers($file, $varname, $l
 
        debug("$file: substitutelist $varname ($result) $subvar (@mods)\n");
        foreach (@mods) {
+               debug("expanding modifier '$_'\n");
+
                if (m#^ (U) (.*) #x) {
-                       $result ||= "fallback:$2";
+                       $result = $2 unless defined $vars->{$subvar};
+
                } elsif (m#^ ([CS]) (.) ([^/\@]+) \2 ([^/\@]*) \2 ([1g]*) #x) {
                        # TODO: Use non-greedy repetitions above.
                        # TODO: Properly handle separators other than '/' and '@'.
@@ -471,12 +472,13 @@ sub expand_modifiers($file, $varname, $l
                        if (defined $notfirst) {
                                $result .= " $notfirst";
                        }
+
                } else {
                        debug("$file: variable '$varname' has unknown modifier '$_'\n");
-                       next;
                }
        }
 
+       $result = '' if !defined $result;
        $vars->{$varname} = "$left$result$right";
        return 1;
 }

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.7 pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.8
--- pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t:1.7       Wed Aug 10 21:48:47 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/glob.t   Sat Aug 13 12:22:20 2022
@@ -1,4 +1,6 @@
-# $NetBSD: glob.t,v 1.7 2022/08/10 21:48:47 rillig Exp $
+# $NetBSD: glob.t,v 1.8 2022/08/13 12:22:20 rillig Exp $
+#
+# Tests for file globbing and matching.
 
 use strict;
 use warnings;

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.14 pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.15
--- pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t:1.14  Sat Aug 13 10:51:28 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/packages.t       Sat Aug 13 12:22:20 2022
@@ -1,4 +1,7 @@
-# $NetBSD: packages.t,v 1.14 2022/08/13 10:51:28 rillig Exp $
+# $NetBSD: packages.t,v 1.15 2022/08/13 12:22:20 rillig Exp $
+#
+# Tests for the internal package database, which stores the packages and their
+# versions, and a few variables like DEPENDS and BROKEN.
 
 use strict;
 use warnings;

Index: pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t:1.11 pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t:1.12
--- pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t:1.11    Sat Aug 13 10:23:40 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/parse_makefile.t Sat Aug 13 12:22:20 2022
@@ -1,4 +1,7 @@
-# $NetBSD: parse_makefile.t,v 1.11 2022/08/13 10:23:40 rillig Exp $
+# $NetBSD: parse_makefile.t,v 1.12 2022/08/13 12:22:20 rillig Exp $
+#
+# Tests for parsing and interpreting package makefiles, in order to avoid
+# running bmake on the packages, as that is generally slow.
 
 use strict;
 use warnings;
@@ -94,9 +97,26 @@ sub test_parse_makefile_vars_cond() {
        ok($vars->{BRANCH}, 'else');
 }
 
+sub test_parse_makefile_vars_default() {
+       my $dir = File::Temp->newdir();
+       my $file = "$dir/filename.mk";
+
+       write_file($file, map { "$_\n" } (
+           'DEFAULT?= 0',
+           'DEFAULT?= 1',
+           'DEFAULT?= 2',
+       ));
+
+       my $vars;
+       $vars = parse_makefile_vars($file, undef);
+       ok($vars->{DEFAULT}, '0');
+}
+
 sub test_expand_modifiers() {
        my $vars = {
-           REF => 'VALUE',
+           REF   => 'VALUE',
+           ZERO  => '0',
+           EMPTY => '',
        };
 
        expand_modifiers('file.mk', 'VAR', '<', 'REF', 'S,U,X,', '>', $vars);
@@ -109,6 +129,18 @@ sub test_expand_modifiers() {
        expand_modifiers('file.mk', 'VAR', '<', 'REF', 'S,VAL,H,', '>', $vars);
 
        ok($vars->{VAR}, '<HUE>');
+
+       expand_modifiers('file.mk', 'VAR', 'undef <', 'UNDEF', 'Ufallback', '>', $vars);
+
+       ok($vars->{VAR}, 'undef <fallback>');
+
+       expand_modifiers('file.mk', 'VAR', 'empty <', 'EMPTY', 'Ufallback', '>', $vars);
+
+       ok($vars->{VAR}, 'empty <>');
+
+       expand_modifiers('file.mk', 'VAR', 'zero <', 'ZERO', 'Ufallback', '>', $vars);
+
+       ok($vars->{VAR}, 'zero <0>');
 }
 
 sub test_eval_mk_cond_func() {
@@ -177,6 +209,7 @@ sub test_eval_mk_cond() {
 test_expand_exprs();
 test_parse_makefile_vars();
 test_parse_makefile_vars_cond();
+test_parse_makefile_vars_default();
 test_expand_modifiers();
 test_eval_mk_cond_func();
 test_eval_mk_cond();
Index: pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t
diff -u pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.11 pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.12
--- pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t:1.11        Fri Aug 12 22:18:35 2022
+++ pkgsrc/pkgtools/lintpkgsrc/files/t/pkgversion.t     Sat Aug 13 12:22:20 2022
@@ -1,4 +1,6 @@
-# $NetBSD: pkgversion.t,v 1.11 2022/08/12 22:18:35 rillig Exp $
+# $NetBSD: pkgversion.t,v 1.12 2022/08/13 12:22:20 rillig Exp $
+#
+# Tests for parsing and comparing package versions, such as 1.0nb4.
 
 use strict;
 use warnings;



Home | Main Index | Thread Index | Old Index