pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files The ">&" shell operator is reco...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/21ab6ca787ca
branches:  trunk
changeset: 514182:21ab6ca787ca
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Jun 08 15:56:00 2006 +0000

description:
The ">&" shell operator is recognized correctly. A warning is printed
for every shell command that is not known in the tools framework.

diffstat:

 pkgtools/pkglint/files/makevars.map |  12 +++++-
 pkgtools/pkglint/files/pkglint.pl   |  71 +++++++++++++++++++++++++++++++++---
 2 files changed, 75 insertions(+), 8 deletions(-)

diffs (182 lines):

diff -r a54a15a1a25f -r 21ab6ca787ca pkgtools/pkglint/files/makevars.map
--- a/pkgtools/pkglint/files/makevars.map       Thu Jun 08 15:54:55 2006 +0000
+++ b/pkgtools/pkglint/files/makevars.map       Thu Jun 08 15:56:00 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: makevars.map,v 1.110 2006/06/08 15:50:54 rillig Exp $
+# $NetBSD: makevars.map,v 1.111 2006/06/08 15:56:00 rillig Exp $
 #
 
 # This file contains the guessed type of some variables, according to
@@ -239,6 +239,10 @@
 DLOPEN_REQUIRE_PTHREADS        YesNo
 DL_AUTO_VARS           Yes [m:s,c:s,o:s]
 DL_LIBS                        List of LdFlag
+DO_NADA                        ShellCommand [$system]
+ECHO                   ShellCommand [$system]
+ECHO_MSG               ShellCommand [$system]
+ECHO_N                 ShellCommand [$system]
 EGDIR                  Pathname [m:s,c:s]
 # ^^ This variable is not defined by the system, but has been established
 # as a convention.
@@ -256,6 +260,8 @@
 EMACS_VERSION_MAJOR    Integer [*:u]
 EMACS_VERSION_MINOR    Integer [*:u]
 EMACS_VERSION_REQD     List of { emacs21 emacs21nox emacs20 xemacs215 xemacs214 } [m:as]
+ERROR_CAT              ShellCommand [$system]
+ERROR_MSG              ShellCommand [$system]
 EVAL_PREFIX            InternalList of ShellWord [m:a,c:a]
 # ^^ FIXME: Looks like a type mismatch.
 EXTRACT_CMD            ShellCommand [m:s]
@@ -427,6 +433,7 @@
 PERL5_PACKLIST_DIR     Pathname []
 PGSQL_VERSIONS_ACCEPTED        List of { 73 74 80 }
 PGSQL_VERSION_DEFAULT  Version [$user]
+PHASE_MSG              ShellCommand [$system]
 PKGBASE                        Identifier []
 PKGCONFIG_OVERRIDE     List of Pathmask [m:as,c:a]
 PKGDIR                 RelativePkgDir
@@ -528,6 +535,7 @@
 SHLIBTOOL_OVERRIDE     List of Pathmask [m:as,c:a]
 SITES.*                        List of URL [m:as,c:as,o:as]
 SPECIAL_PERMS          List of ShellWord [$list]
+STEP_MSG               ShellCommand [$system]
 SUBST_CLASSES          List of Identifier [m:a,c:a,h:a,Makefile.*:a]
 SUBST_FILES.*          List of Pathmask [m:as,c:as,h:as,o:as,Makefile.*:as]
 SUBST_FILTER_CMD.*     ShellCommand [m:s,c:s,h:s,o:s,Makefile.*:as]
@@ -578,6 +586,8 @@
 USE_TOOLS              List of Tool [m:a,c:a,o:a]
 USE_X11                        Yes [m:s,c:s]
 USE_X11BASE            Yes [m:s,c:s]
+WARNING_MSG            ShellCommand [$system]
+WARNING_CAT            ShellCommand [$system]
 WRAPPER_REORDER_CMDS   List of WrapperReorder [b:a,c:a,m:a]
 WRAPPER_TRANSFORM_CMDS List of WrapperTransform [b:a,c:a,m:a]
 WRKSRC                 WrkdirSubdirectory [m:s,c:ds,Makefile.*:ds]
diff -r a54a15a1a25f -r 21ab6ca787ca pkgtools/pkglint/files/pkglint.pl
--- a/pkgtools/pkglint/files/pkglint.pl Thu Jun 08 15:54:55 2006 +0000
+++ b/pkgtools/pkglint/files/pkglint.pl Thu Jun 08 15:56:00 2006 +0000
@@ -1,5 +1,5 @@
 #! @PERL@
-# $NetBSD: pkglint.pl,v 1.611 2006/06/08 07:15:27 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.612 2006/06/08 15:56:00 rillig Exp $
 #
 
 # pkglint - static analyzer and checker for pkgsrc packages
@@ -1564,7 +1564,7 @@
        |       \$\$\(                  # POSIX-style backticks replacement
        |       [^\(\)'\"\\\s;&\|<>\#\`\$] # non-special character
        |       \$\{[^\s\"'`]+          # HACK: nested make(1) variables
-       )+ | ;;? | &&? | \|\|? | \( | \) | <<? | >>? | \#.*)"sx;
+       )+ | ;;? | &&? | \|\|? | \( | \) | >& | <<? | >>? | \#.*)"sx;
 my $regex_varname              = qr"[-*+.0-9A-Z_a-z{}\[]+";
 
 #
@@ -3378,7 +3378,7 @@
                ${DO_NADA}
                ${ECHO} ${ECHO_MSG} ${ECHO_N} ${ERROR_CAT} ${ERROR_MSG}
                ${PHASE_MSG}
-               ${STEP_MSG}
+               ${SHCOMMENT} ${STEP_MSG}
                ${WARNING_CAT} ${WARNING_MSG}
        ));
 
@@ -3398,6 +3398,14 @@
                                $line->log_warning("The shell command \"${cmd}\" should not be hidden.");
                        }
                }
+
+               if ($hidden =~ qr"-") {
+                       $line->log_warning("The use of a leading \"-\" to suppress errors is deprecated.");
+                       $line->explain_warning(
+                               "If you really want to ignore any errors from this command (including",
+                               "all errors you never thought of), append \"|| \${TRUE}\" to the",
+                               "command.");
+               }
        }
 
        $state = SCST_START;
@@ -3421,7 +3429,7 @@
                if ($state == SCST_START && exists($vartools->{$shellword})) {
                        my $addition = "";
 
-                       if (!exists(get_predefined_vartool_names->{$shellword})) {
+                       if (!exists(get_predefined_vartool_names()->{$shellword})) {
                                my $toolvarname = get_vartool_names->{$shellword};
                                my $toolname = get_varname_to_toolname->{$toolvarname};
                                $addition = " and add USE_TOOLS+=${toolname} before this line";
@@ -3429,8 +3437,56 @@
                        $line->log_warning("Direct use of tool \"${shellword}\". Please use \$\{$vartools->{$shellword}\} instead${addition}.");
                }
 
-               if ($state == SCST_START && exists(forbidden_commands->{$shellword})) {
-                       $line->log_error("${shellword} is forbidden and must not be used.");
+               if ($state == SCST_START) {
+                       if (exists(forbidden_commands->{$shellword})) {
+                               $line->log_error("${shellword} is forbidden and must not be used.");
+
+                       } elsif (exists(get_tool_names()->{$shellword})) {
+                               # Fine.
+
+                       } elsif ($shellword =~ qr"^\$\{([\w_]+)\}$" && (exists($vartools->{$1}) || defined(get_variable_type($line, $1)))) {
+                               # Fine.
+
+                       } elsif ($shellword =~ qr"^(?:\(|\)|:|;|;;|&&|\|\||\{|\}|break|case|cd|continue|do|done|elif|else|esac|eval|exit|export|fi|for|if|set|shift|then|unset|while)$") {
+                               # Shell builtins are fine.
+
+                       } elsif ($shellword =~ qr"^[\w_]+=.*$") {
+                               # Variable assignment.
+
+                       } elsif ($shellword =~ qr"^\./.*$") {
+                               # All commands from the current directory are fine.
+
+                       } elsif ($shellword =~ qr"^#") {
+                               my $semicolon = ($shellword =~ qr";");
+                               my $multiline = ($line->lines =~ qr"--");
+
+                               if ($semicolon) {
+                                       $line->log_warning("A shell comment should not contain semicolons.");
+                               }
+                               if ($multiline) {
+                                       $line->log_warning("A shell comment does not stop at the end of line.");
+                               }
+
+                               if ($semicolon || $multiline) {
+                                       $line->explain_warning(
+                                               "When you split a shell command into multiple lines that are continues",
+                                               "with a backslash, they will nevertheless be converted to a single line",
+                                               "before the shell sees them. That means that even if it _looks_ like that",
+                                               "the comment only spans one line in the Makefile, in fact it spans until",
+                                               "the end of the whole shell command. To insert a comment into shell code,",
+                                               "you can pass it as an argument to the \${SHCOMMENT} macro, which expands",
+                                               "to a command doing nothing. Note that any special characters are",
+                                               "nevertheless interpreted by the shell.");
+                               }
+
+                       } else {
+                               $line->log_warning("Unknown shell command \"${shellword}\".");
+                               $line->explain_warning(
+                                       "If you want your package to be portable to all platforms that pkgsrc",
+                                       "supports, you should only use shell commands that are covered by the",
+                                       "tools framework.");
+
+                       }
                }
 
                if ($state == SCST_COND && $shellword eq "cd") {
@@ -3494,6 +3550,8 @@
                }
 
                $state =  ($shellword eq ";;") ? SCST_CASE_LABEL
+                       # Note: The order of the following two lines is important.
+                       : ($state == SCST_CASE_LABEL_CONT && $shellword eq "|") ? SCST_CASE_LABEL
                        : ($shellword =~ qr"^[;&\|]+$") ? SCST_START
                        : ($state == SCST_START) ? (
                                  ($shellword eq "\${INSTALL}") ? SCST_INSTALL
@@ -3529,7 +3587,6 @@
                        : ($state == SCST_CASE_IN && $shellword eq "in") ? SCST_CASE_LABEL
                        : ($state == SCST_CASE_LABEL && $shellword eq "esac") ? SCST_CONT
                        : ($state == SCST_CASE_LABEL) ? SCST_CASE_LABEL_CONT
-                       : ($state == SCST_CASE_LABEL_CONT && $shellword eq "|") ? SCST_CASE_LABEL
                        : ($state == SCST_CASE_LABEL_CONT && $shellword eq ")") ? SCST_START
                        : ($state == SCST_CONT) ? SCST_CONT
                        : ($state == SCST_COND) ? SCST_COND_CONT



Home | Main Index | Thread Index | Old Index