pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files - Improved checking of sed comm...
details: https://anonhg.NetBSD.org/pkgsrc/rev/70b25521e1b8
branches: trunk
changeset: 508848:70b25521e1b8
user: rillig <rillig%pkgsrc.org@localhost>
date: Sun Feb 26 17:40:44 2006 +0000
description:
- Improved checking of sed commands that are used in the SUBST
framework. Now, unescaped shell special characters are detected.
diffstat:
pkgtools/pkglint/files/makevars.map | 5 +-
pkgtools/pkglint/files/pkglint.pl | 57 +++++++++++++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 6 deletions(-)
diffs (112 lines):
diff -r 98e4cc6db307 -r 70b25521e1b8 pkgtools/pkglint/files/makevars.map
--- a/pkgtools/pkglint/files/makevars.map Sun Feb 26 17:27:22 2006 +0000
+++ b/pkgtools/pkglint/files/makevars.map Sun Feb 26 17:40:44 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: makevars.map,v 1.66 2006/02/26 04:26:52 rillig Exp $
+# $NetBSD: makevars.map,v 1.67 2006/02/26 17:40:44 rillig Exp $
#
# This file contains the guessed type of some variables, according to
@@ -326,8 +326,7 @@
SUBST_FILTER_CMD List of ShellWord
# ^^ more appropriately, a Shellcommand
SUBST_MESSAGE Message
-SUBST_SED List of ShellWord
-# ^^ This may be changed to a List+ later.
+SUBST_SED SedCommands
SUBST_STAGE Stage
SVR4_PKGNAME SVR4PkgName
TEST_DIRS List of WrksrcSubdirectory
diff -r 98e4cc6db307 -r 70b25521e1b8 pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Sun Feb 26 17:27:22 2006 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Sun Feb 26 17:40:44 2006 +0000
@@ -1,5 +1,5 @@
#! @PERL@
-# $NetBSD: pkglint.pl,v 1.534 2006/02/26 16:21:14 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.535 2006/02/26 17:40:44 rillig Exp $
#
# pkglint - static analyzer and checker for pkgsrc packages
@@ -1999,6 +1999,17 @@
return $len;
}
+sub shell_split($) {
+ my ($text) = @_;
+ my ($words);
+
+ $words = [];
+ while ($text =~ s/$regex_shellword//) {
+ push(@{$words}, $1);
+ }
+ return (($text =~ qr"^\s*$") ? $words : false);
+}
+
#
# Loading package-specific data from files.
#
@@ -2428,7 +2439,7 @@
if ($state == SWST_PLAIN && defined($mod) && $mod =~ qr":Q$") {
# Fine.
- } elsif (($state == SWST_SQUOT || $state == SWST_DQUOT) && $varname =~ qr"^(?:.*DIR|.*FILE|.*PATH|.*_VAR|PREFIX|LOCALBASE|PKGNAME)$") {
+ } elsif (($state == SWST_SQUOT || $state == SWST_DQUOT) && $varname =~ qr"^(?:.*DIR|.*FILE|.*PATH|.*_VAR|PREFIX|.*BASE|PKGNAME)$") {
# This is ok if we don't allow these
# variables to have embedded [\$\\\"\'\`].
@@ -3090,6 +3101,46 @@
$line->log_error("SVR4_PKGNAME must not be longer than 5 characters.");
}
+ } elsif ($type eq "SedCommands") {
+ my $words = shell_split($value);
+ if (!$words) {
+ $line->log_error("Invalid shell words in sed commands.");
+
+ } else {
+ my $nwords = scalar(@{$words});
+ my $ncommands = 0;
+
+ for (my $i = 0; $i < $nwords; $i++) {
+ my $word = $words->[$i];
+ checkline_mk_shellword($line, $word, true);
+
+ if ($word eq "-e") {
+ if ($i + 1 < $nwords) {
+ # Check the real sed command here.
+ $i++;
+ $ncommands++;
+ if ($ncommands > 1) {
+ $line->log_warning("Each sed command should appear in an assignment of its own.");
+ }
+ checkline_mk_shellword($line, $word, true);
+ } else {
+ $line->log_error("The -e option to sed requires an argument.");
+ }
+ } elsif ($word eq "-E") {
+ # Switch to extended regular expressions mode.
+
+ } elsif ($word eq "-n") {
+ # Don't print lines per default.
+
+ } elsif ($i == 0 && $word =~ qr"^([\"']?)\d*s(.).*\2\1g?$") {
+ $line->log_warning("Please always use \"-e\" in sed commands, even if there is only one substitution.");
+
+ } else {
+ $line->log_warning("Unknown sed command ${word}.");
+ }
+ }
+ }
+
} elsif ($type eq "ShellCommand") {
checkline_mk_shellcmd($line, $value);
@@ -3314,7 +3365,7 @@
}
} else {
- checkline_mk_vartype_basic($line, $varname, $type, $op, $value, $comment, false);
+ checkline_mk_vartype_basic($line, $varname, $type, $op, $value, $comment, ($type eq "SedCommands"));
}
}
Home |
Main Index |
Thread Index |
Old Index