diff options
| author | rillig <rillig@pkgsrc.org> | 2022-08-13 12:22:20 +0000 |
|---|---|---|
| committer | rillig <rillig@pkgsrc.org> | 2022-08-13 12:22:20 +0000 |
| commit | ad139f3f97b8950d9667e7f882b09108c0c2147c (patch) | |
| tree | 60b050726f062dcbb6ccdb8c1067bedf9b53940e /pkgtools/lintpkgsrc/files | |
| parent | 6675060e3dc281fce0aedee85dde2100a8aecce4 (diff) | |
| download | pkgsrc-ad139f3f97b8950d9667e7f882b09108c0c2147c.tar.gz | |
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 (limited to 'pkgtools/lintpkgsrc/files')
| -rwxr-xr-x | pkgtools/lintpkgsrc/files/lintpkgsrc.pl | 24 | ||||
| -rw-r--r-- | pkgtools/lintpkgsrc/files/t/glob.t | 4 | ||||
| -rw-r--r-- | pkgtools/lintpkgsrc/files/t/packages.t | 5 | ||||
| -rw-r--r-- | pkgtools/lintpkgsrc/files/t/parse_makefile.t | 37 | ||||
| -rw-r--r-- | pkgtools/lintpkgsrc/files/t/pkgversion.t | 4 |
5 files changed, 58 insertions, 16 deletions
diff --git a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl index 056a951bae0..655e4d03811 100755 --- a/pkgtools/lintpkgsrc/files/lintpkgsrc.pl +++ b/pkgtools/lintpkgsrc/files/lintpkgsrc.pl @@ -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>. # @@ -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, $op, $value, $vars) { 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, $left, $subvar, $mods, $right, $vars) { 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, $left, $subvar, $mods, $right, $vars) { 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 --git a/pkgtools/lintpkgsrc/files/t/glob.t b/pkgtools/lintpkgsrc/files/t/glob.t index 721009fa0d8..4656e9b11df 100644 --- a/pkgtools/lintpkgsrc/files/t/glob.t +++ b/pkgtools/lintpkgsrc/files/t/glob.t @@ -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 --git a/pkgtools/lintpkgsrc/files/t/packages.t b/pkgtools/lintpkgsrc/files/t/packages.t index 276b9a44fa4..e4341116530 100644 --- a/pkgtools/lintpkgsrc/files/t/packages.t +++ b/pkgtools/lintpkgsrc/files/t/packages.t @@ -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 --git a/pkgtools/lintpkgsrc/files/t/parse_makefile.t b/pkgtools/lintpkgsrc/files/t/parse_makefile.t index ad5b20dd49b..480c2264633 100644 --- a/pkgtools/lintpkgsrc/files/t/parse_makefile.t +++ b/pkgtools/lintpkgsrc/files/t/parse_makefile.t @@ -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(); diff --git a/pkgtools/lintpkgsrc/files/t/pkgversion.t b/pkgtools/lintpkgsrc/files/t/pkgversion.t index 52ab9c6f7cb..3002cfd8313 100644 --- a/pkgtools/lintpkgsrc/files/t/pkgversion.t +++ b/pkgtools/lintpkgsrc/files/t/pkgversion.t @@ -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; |
