diff options
author | rillig <rillig> | 2005-12-06 01:07:20 +0000 |
---|---|---|
committer | rillig <rillig> | 2005-12-06 01:07:20 +0000 |
commit | 701859e68e67dfaa4d106a567fda6aa2ccdf69a3 (patch) | |
tree | 946eb9344e1dbaef54a89270d59f8a0f7001df24 /pkgtools | |
parent | 3dae8fea14cb07876cbc876f030a3b37361f56b8 (diff) | |
download | pkgsrc-701859e68e67dfaa4d106a567fda6aa2ccdf69a3.tar.gz |
- Improved detection of valid shell words once more.
- Rewrote the code for loading the deprecated.map file. It is only
loaded once now. The code that checks for use of deprecated variables
can handle multiple variables in a single line now.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/files/pkglint.pl | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl index 32574761be1..c231785fb32 100644 --- a/pkgtools/pkglint/files/pkglint.pl +++ b/pkgtools/pkglint/files/pkglint.pl @@ -11,7 +11,7 @@ # Freely redistributable. Absolutely no warranty. # # From Id: portlint.pl,v 1.64 1998/02/28 02:34:05 itojun Exp -# $NetBSD: pkglint.pl,v 1.417 2005/12/05 23:50:16 rillig Exp $ +# $NetBSD: pkglint.pl,v 1.418 2005/12/06 01:07:20 rillig Exp $ # # This version contains lots of changes necessary for NetBSD packages # done by: @@ -765,7 +765,7 @@ my $regex_shellword = qr"\s*( | \"(?:\\.|[^\"\\])*\" | \`[^\`]*\` | \\. - | \$\{[^}]+\} + | \$\{[^\$}]+\} | [^'\"\\\s;&\|<>\#] )+ | ;;? | &&? | \|\|? | <<? | >>? | \#.*)"sx; @@ -942,6 +942,34 @@ if (false) { return ($get_make_vars_typemap_result = $vartypes); } +my $get_deprecated_map_result = undef; +sub get_deprecated_map() { + my ($fname, $lines, $vars); + + if (defined($get_deprecated_map_result)) { + return $get_deprecated_map_result; + } + + $fname = conf_datadir."/deprecated.map"; + if (!($lines = load_file($fname))) { + log_fatal($fname, NO_LINE_NUMBER, "Cannot be read."); + } + + $vars = {}; + foreach my $line (@{$lines}) { + if ($line->text =~ qr"^#" || $line->text =~ qr"^\s*$") { + # Ignore empty and comment lines. + + } elsif ($line->text =~ qr"^(\S+)\s+(.*)$") { + $vars->{$1} = $2; + + } else { + $line->log_fatal("Unknown line format."); + } + } + return ($get_deprecated_map_result = $vars); +} + my $load_dist_sites_url2name = undef; my $load_dist_sites_names = undef; sub load_dist_sites() { @@ -2230,39 +2258,33 @@ sub checklines_Makefile_varuse($) { sub checklines_deprecated_variables($) { my ($lines) = @_; - my ($fname) = (conf_datadir."/deprecated.map"); - my ($deprecated, $varnames, $varuse_regex, %vars); + my ($vars, $varnames, $regex_varuse); - if (!($deprecated = load_file($fname))) { - log_error($fname, NO_LINE_NUMBER, "Cannot be read."); - return; - } + $vars = get_deprecated_map(); + $varnames = join("|", sort(keys(%{$vars}))); + $regex_varuse = qr"\$\{(${varnames})[:}]"; - %vars = (); - foreach my $line (@{$deprecated}) { - if ($line->text =~ qr"^#" || $line->text =~ qr"^\s*$") { - next; + foreach my $line (@{$lines}) { + my ($rest); - } elsif ($line->text =~ qr"^(\S+)\s+(.*)$") { - $vars{$1} = $2; + if ($line->text =~ regex_varassign) { + my ($varname) = ($1); + $rest = $3; + if (exists($vars->{$varname})) { + $line->log_warning("Definition of ${varname} is deprecated. $vars->{$varname}"); + } - } else { - $line->log_fatal("Unknown line format."); + } elsif ($line->text =~ regex_shellcmd) { + ($rest) = ($1); } - } - $varnames = join("|", sort(keys(%vars))); - $varuse_regex = qr"\$\{(${varnames})[:}]"; - foreach my $line (@{$lines}) { - if ($line->text =~ regex_varassign) { - my ($varname, undef, $value) = ($1, $2, $3); - if (exists($vars{$varname})) { - $line->log_warning("${varname} is deprecated. $vars{$varname}"); - } + if (defined($rest)) { + while ($rest =~ s/$regex_varuse//) { + my ($varname) = ($1); - if ($value =~ $varuse_regex) { - my ($varuse_name) = ($1); - $line->log_warning("Use of ${varuse_name} is deprecated. $vars{$varuse_name}"); + if (exists($vars->{$varname})) { + $line->log_warning("Use of ${varname} is deprecated. $vars->{$varname}"); + } } } } |