diff options
author | rillig <rillig> | 2009-07-17 20:06:22 +0000 |
---|---|---|
committer | rillig <rillig> | 2009-07-17 20:06:22 +0000 |
commit | d1eef07db06201347d9ea5f289768bb86dedfc8c (patch) | |
tree | b4b2a95b64ccd6f147ed9137374d9b62d2756bbf /pkgtools/pkglint/files/pkglint.pl | |
parent | 053a136b9ae5ba3ac9a504fed05f0044bd7757f4 (diff) | |
download | pkgsrc-d1eef07db06201347d9ea5f289768bb86dedfc8c.tar.gz |
Added the ability to resolve simple variable references of the form
${VARNAME} into their values.
This was intended to fix the false positive warnings about missing
distinfo files, but it cannot handle database/ruby-gdbm for example,
because _RUBY_VER_MAJOR uses pattern substitution. Run pkglint with
-Dtrace,misc and look for resolve_var to see what happens up to now.
Diffstat (limited to 'pkgtools/pkglint/files/pkglint.pl')
-rw-r--r-- | pkgtools/pkglint/files/pkglint.pl | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl index 52b78cabc4a..032c79a5cc2 100644 --- a/pkgtools/pkglint/files/pkglint.pl +++ b/pkgtools/pkglint/files/pkglint.pl @@ -1,5 +1,5 @@ #! @PERL@ -# $NetBSD: pkglint.pl,v 1.814 2009/07/17 04:39:33 rillig Exp $ +# $NetBSD: pkglint.pl,v 1.815 2009/07/17 20:06:22 rillig Exp $ # # pkglint - static analyzer and checker for pkgsrc packages @@ -2562,6 +2562,34 @@ sub relative_path($$) { } } +sub resolve_variable_rec1($$); +sub resolve_variable_rec2($$); + +sub resolve_variable_rec1($$) { + my ($varname, $visited) = @_; + $opt_debug_trace and log_debug(NO_FILE, NO_LINES, "resolve_variable_rec1($varname)"); + + if (!exists($visited->{$varname})) { + $visited->{$varname} = true; + if (defined($pkgctx_vardef) && exists($pkgctx_vardef->{$varname})) { + return resolve_variable_rec2($pkgctx_vardef->{$varname}->get("value"), $visited); + } + if (defined($mkctx_vardef) && exists($mkctx_vardef->{$varname})) { + return resolve_variable_rec2($mkctx_vardef->{$varname}->get("value"), $visited); + } + } + return "\${$varname}"; +} + +sub resolve_variable_rec2($$) { + my ($string, $visited) = @_; + $opt_debug_trace and log_debug(NO_FILE, NO_LINES, "resolve_variable_rec2(\"$string\")"); + + my $expanded = $string; + $expanded =~ s/\$\{(\w+)\}/resolve_variable_rec1($1, $visited)/eg; + return $expanded; +} + sub expand_variable($) { my ($varname) = @_; @@ -2571,7 +2599,11 @@ sub expand_variable($) { $value = resolve_relative_path($value, true); if ($value =~ regex_unresolved) { - $opt_debug_misc and log_debug(NO_FILE, NO_LINES, "[expand_variable] The variable ${varname} could not be resolved completely. Its value is \"${value}\"."); + $opt_debug_misc and log_debug(NO_FILE, NO_LINES, "[expand_variable] Trying harder to resolve variable references in ${varname}=\"${value}\"."); + $value = resolve_variable_rec2($value, {}); + if ($value =~ regex_unresolved) { + $opt_debug_misc and log_debug(NO_FILE, NO_LINES, "[expand_variable] Failed to resolve ${varname}=\"${value}\"."); + } } return $value; } |