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 the heuristics for s...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/70d92215bf7f
branches:  trunk
changeset: 504190:70d92215bf7f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Dec 06 17:32:12 2005 +0000

description:
- Improved the heuristics for shell words by allowing pkgsrc variables with
  a "$" in the modifier part, as long as they don't contain references to
  other variables.
- Removed checkline_mk_direct_tool_use().
- Renamed checkline_mk_shellcmd() to checkline_mk_shelltext(). This sub-
  routine is also used for checking the right hand side of variable assign-
  ments.
- Renamed direct_tools_ok_vars to non_shellcode_vars, which is more
  appropriate. Added some variables to it that produced false positive
  warnings.

diffstat:

 pkgtools/pkglint/files/pkglint.pl |  61 +++++++++++++++-----------------------
 1 files changed, 25 insertions(+), 36 deletions(-)

diffs (133 lines):

diff -r 05458249eefe -r 70d92215bf7f pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Tue Dec 06 17:22:52 2005 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Tue Dec 06 17:32:12 2005 +0000
@@ -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.425 2005/12/06 16:13:28 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.426 2005/12/06 17:32:12 rillig Exp $
 #
 # This version contains lots of changes necessary for NetBSD packages
 # done by:
@@ -765,7 +765,7 @@
        |       \"(?:\\.|[^\"\\])*\"
        |       \`[^\`]*\`
        |       \\.
-       |       \$\{[^\$}]+\}
+       |       \$\{[^{}]+\}
        |       [^'\"\\\s;&\|<>\#]
        )+ | ;;? | &&? | \|\|? | <<? | >>? | \#.*)"sx;
 
@@ -1520,27 +1520,9 @@
        }
 }
 
-sub checkline_mk_direct_tool_use($$$) {
-       my ($line, $text, $where) = @_;
-       my ($rest, $vartools);
-
-       return unless $opt_warn_directcmd;
-
-       $vartools = get_vartool_names();
-
-       $rest = $text;
-       while ($rest =~ s/^$regex_shellword//) {
-               my ($word) = ($1);
-
-               if (exists($vartools->{$word})) {
-                       $line->log_warning("Possible direct use of tool \"${word}\" ${where}. Please use \$\{$vartools->{$word}\} instead.");
-               }
-       }
-}
-
 sub checkline_mk_text($$) {
        my ($line, $text) = @_;
-       my ($rest);
+       my ($rest, $state, $vartools);
 
        if ($text =~ qr"^(?:[^#]*[^\$])?\$(\w+)") {
                my ($varname) = ($1);
@@ -1565,11 +1547,12 @@
                        $line->log_warning("Use of ${varname} is deprecated. ".get_deprecated_map()->{$varname});
                }
        }
+
 }
 
-sub checkline_mk_shellcmd($$) {
-       my ($line, $shellcmd) = @_;
-       my ($rest, $state, $vartools);
+sub checkline_mk_shelltext($$) {
+       my ($line, $text) = @_;
+       my ($vartools, $state, $rest);
 
        use constant SCST_START         =>  0;
        use constant SCST_CONT          =>  1;
@@ -1581,16 +1564,14 @@
        use constant SCST_SED           => 40;
        use constant SCST_SED_E         => 41;
 
-       checkline_mk_text($line, $shellcmd);
-
-       if ($shellcmd =~ qr"^\@*-(.*(MKDIR|INSTALL.*-d|INSTALL_.*_DIR).*)") {
+       if ($text =~ qr"^\@*-(.*(MKDIR|INSTALL.*-d|INSTALL_.*_DIR).*)") {
                my ($mkdir_cmd) = ($1);
 
                $line->log_note("You don't need to use \"-\" before ${mkdir_cmd}.");
        }
 
        $vartools = get_vartool_names();
-       $rest = $shellcmd;
+       $rest = $text;
        $state = SCST_START;
        while ($rest =~ s/^$regex_shellword//) {
                my ($shellword) = ($1);
@@ -1662,31 +1643,39 @@
        }
 
        if ($rest !~ qr"^\s*$") {
-               $line->log_warning("Invalid shell word \"${shellcmd}\".");
+               $line->log_warning("Invalid shell word \"${text}\".");
        }
 }
 
+sub checkline_mk_shellcmd($$) {
+       my ($line, $shellcmd) = @_;
+
+       checkline_mk_text($line, $shellcmd);
+       checkline_mk_shelltext($line, $shellcmd);
+}
+
 sub checkline_mk_varassign($$$$$) {
        my ($line, $varname, $op, $value, $comment) = @_;
        my $varbase = ($varname =~ qr"(.+?)\..*") ? $1 : $varname;
 
-       use constant direct_tools_ok_vars => array_to_hash(qw(
+       use constant non_shellcode_vars => array_to_hash(qw(
                BUILDLINK_TRANSFORM BUILD_DEPENDS BUILD_TARGET
-               CFLAGS CPPFLAGS COMMENT CONFLICTS
+               CATEGORIES CFLAGS CPPFLAGS COMMENT CONFLICTS
                DEPENDS DISTNAME
                EXTRACT_SUFX EXTRACT_USING
                INSTALL_TARGET INTERACTIVE_STAGE
                MANSOURCEPATH MASTER_SITES
-               PKGNAME PKGSRC_USE_TOOLS PKG_FAIL_REASON
-               SUBST_CLASSES
+               PKGNAME PKGSRC_USE_TOOLS PKG_FAIL_REASON PKG_SUGGESTED_OPTIONS PKG_SUPPORTED_OPTIONS PRINT_PLIST_AWK
+               REPLACE_INTERPRETER RESTRICTED
+               SUBST_CLASSES SUBST_MESSAGE
                TEST_TARGET
                USE_TOOLS
        ));
 
-       if (!exists(direct_tools_ok_vars->{$varbase}) && !exists(direct_tools_ok_vars->{$varname})) {
-               checkline_mk_direct_tool_use($line, $value, "in variable ${varname}");
+       checkline_mk_text($line, $value);
+       if (!exists(non_shellcode_vars->{$varbase}) && !exists(non_shellcode_vars->{$varname})) {
+               checkline_mk_shelltext($line, $value);
        }
-       checkline_mk_text($line, $value);
        checkline_mk_vartype($line, $varname, $op, $value, $comment);
 
                        



Home | Main Index | Thread Index | Old Index