diff options
author | rillig <rillig@pkgsrc.org> | 2006-06-08 15:56:00 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-06-08 15:56:00 +0000 |
commit | 5a8c02e2ea68a72ef07c2bd074ae919ab8a54e89 (patch) | |
tree | c471cfbf66d77b44220c302574576f3fb0fcca14 /pkgtools/pkglint | |
parent | f2202d92995b0c4e64b8253e8a24f930d42958b0 (diff) | |
download | pkgsrc-5a8c02e2ea68a72ef07c2bd074ae919ab8a54e89.tar.gz |
The ">&" shell operator is recognized correctly. A warning is printed
for every shell command that is not known in the tools framework.
Diffstat (limited to 'pkgtools/pkglint')
-rw-r--r-- | pkgtools/pkglint/files/makevars.map | 12 | ||||
-rw-r--r-- | pkgtools/pkglint/files/pkglint.pl | 71 |
2 files changed, 75 insertions, 8 deletions
diff --git a/pkgtools/pkglint/files/makevars.map b/pkgtools/pkglint/files/makevars.map index 40c1c1379a1..9e623b3fdef 100644 --- a/pkgtools/pkglint/files/makevars.map +++ b/pkgtools/pkglint/files/makevars.map @@ -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 @@ DJB_SLASHPACKAGE YesNo 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_VERSIONS_ACCEPTED List of { emacs21 emacs21nox emacs20 xemacs215 xemacs214 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 List of Perl5Packlist [m:s,o:sa] 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 ShellCommand [] 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_PKGSRC_GCC Yes [$user] 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 --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl index 26232a00041..07b3dc455b6 100644 --- a/pkgtools/pkglint/files/pkglint.pl +++ b/pkgtools/pkglint/files/pkglint.pl @@ -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 @@ my $regex_shellword = qr"\s*( | \$\$\( # 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 @@ sub checkline_mk_shelltext($$) { ${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 @@ sub checkline_mk_shelltext($$) { $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 @@ sub checkline_mk_shelltext($$) { 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 @@ sub checkline_mk_shelltext($$) { $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 @@ sub checkline_mk_shelltext($$) { } $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 @@ sub checkline_mk_shelltext($$) { : ($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 |