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: fix expansion of...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/fca12772044e
branches:  trunk
changeset: 383158:fca12772044e
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Aug 13 12:22:20 2022 +0000

description:
lintpkgsrc: fix expansion of the ':U' modifier

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

diffstat:

 pkgtools/lintpkgsrc/files/lintpkgsrc.pl      |  24 +++++++++--------
 pkgtools/lintpkgsrc/files/t/glob.t           |   4 ++-
 pkgtools/lintpkgsrc/files/t/packages.t       |   5 +++-
 pkgtools/lintpkgsrc/files/t/parse_makefile.t |  37 ++++++++++++++++++++++++++-
 pkgtools/lintpkgsrc/files/t/pkgversion.t     |   4 ++-
 5 files changed, 58 insertions(+), 16 deletions(-)

diffs (189 lines):

diff -r 2f8e071266cc -r fca12772044e pkgtools/lintpkgsrc/files/lintpkgsrc.pl
--- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Sat Aug 13 11:34:39 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl   Sat Aug 13 12:22:20 2022 +0000
@@ -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 @@
        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 @@
        $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 @@
 
        # 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 @@
 
        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 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 @@
 
        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 @@
                        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;
 }
diff -r 2f8e071266cc -r fca12772044e pkgtools/lintpkgsrc/files/t/glob.t
--- a/pkgtools/lintpkgsrc/files/t/glob.t        Sat Aug 13 11:34:39 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/glob.t        Sat Aug 13 12:22:20 2022 +0000
@@ -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;
diff -r 2f8e071266cc -r fca12772044e pkgtools/lintpkgsrc/files/t/packages.t
--- a/pkgtools/lintpkgsrc/files/t/packages.t    Sat Aug 13 11:34:39 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/packages.t    Sat Aug 13 12:22:20 2022 +0000
@@ -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;
diff -r 2f8e071266cc -r fca12772044e pkgtools/lintpkgsrc/files/t/parse_makefile.t
--- a/pkgtools/lintpkgsrc/files/t/parse_makefile.t      Sat Aug 13 11:34:39 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/parse_makefile.t      Sat Aug 13 12:22:20 2022 +0000
@@ -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 @@
        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 @@
        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 @@
 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();
diff -r 2f8e071266cc -r fca12772044e pkgtools/lintpkgsrc/files/t/pkgversion.t
--- a/pkgtools/lintpkgsrc/files/t/pkgversion.t  Sat Aug 13 11:34:39 2022 +0000
+++ b/pkgtools/lintpkgsrc/files/t/pkgversion.t  Sat Aug 13 12:22:20 2022 +0000
@@ -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