Received: by mail.netbsd.org (Postfix, from userid 605) id DDAE784E62; Fri, 13 Mar 2020 08:11:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.netbsd.org (Postfix) with ESMTP id 623DA84E31 for ; Fri, 13 Mar 2020 08:11:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at netbsd.org Received: from mail.netbsd.org ([IPv6:::1]) by localhost (mail.netbsd.org [IPv6:::1]) (amavisd-new, port 10025) with ESMTP id 0eM1lF33yO_W for ; Fri, 13 Mar 2020 08:11:36 +0000 (UTC) Received: from cvs.NetBSD.org (ivanova.netbsd.org [199.233.217.197]) by mail.netbsd.org (Postfix) with ESMTP id 9B97684DA0 for ; Fri, 13 Mar 2020 08:11:36 +0000 (UTC) Received: by cvs.NetBSD.org (Postfix, from userid 500) id 9042AFB27; Fri, 13 Mar 2020 08:11:36 +0000 (UTC) Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_1584087096169070" MIME-Version: 1.0 Date: Fri, 13 Mar 2020 08:11:36 +0000 From: "Roland Illig" Subject: CVS commit: pkgsrc/mk/check To: pkgsrc-changes@NetBSD.org Reply-To: rillig@netbsd.org X-Mailer: log_accum Message-Id: <20200313081136.9042AFB27@cvs.NetBSD.org> Sender: pkgsrc-changes-owner@NetBSD.org List-Id: pkgsrc-changes.NetBSD.org Precedence: bulk List-Unsubscribe: This is a multi-part message in MIME format. --_----------=_1584087096169070 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Module Name: pkgsrc Committed By: rillig Date: Fri Mar 13 08:11:36 UTC 2020 Modified Files: pkgsrc/mk/check: check-portability.mk check-portability.sh Added Files: pkgsrc/mk/check: check-portability.awk Log Message: mk/check: revert collateral damage from previous commit Killing the editor does not stop cvs from committing; to achieve that, it is necessary to remove the file containing the commit message being edited. To generate a diff of this commit: cvs rdiff -u -r0 -r1.11 pkgsrc/mk/check/check-portability.awk cvs rdiff -u -r1.13 -r1.14 pkgsrc/mk/check/check-portability.mk cvs rdiff -u -r1.18 -r1.19 pkgsrc/mk/check/check-portability.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. --_----------=_1584087096169070 Content-Disposition: inline Content-Length: 6025 Content-Transfer-Encoding: binary Content-Type: text/x-diff; charset=us-ascii Modified files: Index: pkgsrc/mk/check/check-portability.mk diff -u pkgsrc/mk/check/check-portability.mk:1.13 pkgsrc/mk/check/check-portability.mk:1.14 --- pkgsrc/mk/check/check-portability.mk:1.13 Fri Mar 13 08:04:08 2020 +++ pkgsrc/mk/check/check-portability.mk Fri Mar 13 08:11:36 2020 @@ -1,39 +1,40 @@ -# $NetBSD: check-portability.mk,v 1.13 2020/03/13 08:04:08 rillig Exp $ +# $NetBSD: check-portability.mk,v 1.14 2020/03/13 08:11:36 rillig Exp $ # -# This file checks that the extracted shell programs don't contain -# bashisms and other constructs that only work on some platforms. +# This file contains some checks that are applied to the configure +# scripts to check for certain constructs that are known to cause +# problems on some platforms. The detailed checks are in +# check-portability.sh. # # User-settable variables: # # CHECK_PORTABILITY -# Whether to enable the portability checks. +# Whether to enable some portability checks for the configure +# scripts before they are run. # # Default value: yes for PKG_DEVELOPERs, no otherwise. # # Package-settable variables: # # CHECK_PORTABILITY_SKIP -# The shell patterns that should not be checked. -# Note that a * in a pattern also matches a slash in a pathname. +# The list of files that should be skipped in the portability +# check. # # Default value: ${REPLACE_BASH} -# Examples: debian/* test/* *.bash +# Example: debian/* _VARGROUPS+= check-portability _USER_VARS.check-portability= CHECK_PORTABILITY _PKG_VARS.check-portability= CHECK_PORTABILITY_SKIP -.if ${PKG_DEVELOPER:Uno} != no +.if ${PKG_DEVELOPER:Uno} != "no" CHECK_PORTABILITY?= yes .endif CHECK_PORTABILITY?= no CHECK_PORTABILITY_SKIP?= ${REPLACE_BASH} .if ${CHECK_PORTABILITY:tl} == yes && ${CHECK_PORTABILITY_SKIP} != "*" -TOOL_DEPENDS+= check-portability>=19.4.1:../../pkgtools/check-portability pre-configure-checks-hook: _check-portability .endif - .PHONY: _check-portability _check-portability: @${STEP_MSG} "Checking for portability problems in extracted files" Index: pkgsrc/mk/check/check-portability.sh diff -u pkgsrc/mk/check/check-portability.sh:1.18 pkgsrc/mk/check/check-portability.sh:1.19 --- pkgsrc/mk/check/check-portability.sh:1.18 Fri Mar 13 08:04:08 2020 +++ pkgsrc/mk/check/check-portability.sh Fri Mar 13 08:11:36 2020 @@ -1,4 +1,4 @@ -# $NetBSD: check-portability.sh,v 1.18 2020/03/13 08:04:08 rillig Exp $ +# $NetBSD: check-portability.sh,v 1.19 2020/03/13 08:11:36 rillig Exp $ # # This program checks all files in the current directory and any # subdirectories for portability issues that are likely to result in @@ -20,8 +20,18 @@ cs_setprogname "$0" # usage: check_shell check_shell() { - ${PREFIX}/bin/check-portability "$1" 1>&2 \ + env \ + CK_FNAME="$1" \ + CK_PROGNAME="check-portability.awk" \ + awk -f "$checkdir/check-subr.awk" \ + -f "$checkdir/check-portability.awk" \ + < "$1" 1>&2 \ || cs_exitcode=1 + + if test -f "${PREFIX}/bin/check-portability"; then + ${PREFIX}/bin/check-portability "$1" 1>&2 \ + || cs_exitcode=1 + fi } find ./* -type f -print 2>/dev/null \ Added files: Index: pkgsrc/mk/check/check-portability.awk diff -u /dev/null pkgsrc/mk/check/check-portability.awk:1.11 --- /dev/null Fri Mar 13 08:11:36 2020 +++ pkgsrc/mk/check/check-portability.awk Fri Mar 13 08:11:36 2020 @@ -0,0 +1,89 @@ +# $NetBSD: check-portability.awk,v 1.11 2020/03/13 08:11:36 rillig Exp $ +# +# Checks a shell file for possible portability problems. +# +# ENVIRONMENT +# (See check-subr.awk) +# + +BEGIN { + found_random = no; + found_test_eqeq = no; +} + +# Check for $RANDOM, which is specific to ksh and bash. +function check_random(line) { + + # $RANDOM together with the PID is often found in GNU-style + # configure scripts and is considered acceptable. + if (line ~ /\$\$-\$RANDOM/ || line ~ /\$RANDOM-\$\$/) { + # Assume that this is ok. + + } else if (line ~ /\$RANDOM[A-Z_]+/) { + # That's ok, too. + + } else if (line ~ /\$RANDOM/) { + found_random = yes; + cs_warning_heading("Found $RANDOM:"); + cs_warning_msg(cs_fname ": " $0); + } +} + +function check_test_eqeq(line, n, word, i) { + + if (length(line) == 0) + return; + n = split(line, word); + for (i = 3; i < n; i++) { + if (word[i] == "==") { + if (word[i-2] == "test" || word[i-2] == "[") { + found_test_eqeq = yes; + cs_error_heading("Found test ... == ...:"); + cs_error_msg(cs_fname ": " $0); + } + } + } +} + +/./ { + # Note: This code does not find _all_ instances of + # unportable code. If a single line contains an unsafe and + # a safe usage of $RANDOM, it will pass the test. + + # Strip comments + line = $0; + gsub(/^#.*/, "", line); + gsub(/[[:space:]]#.*/, "", line); + + check_random(line); + check_test_eqeq(line); +} + +END { + if (found_random) { + h = "The variable $RANDOM is not required for a POSIX-conforming shell, and\n"; + h = h "many implementations of /bin/sh do not support it. It should therefore\n"; + h = h "not be used in shell programs that are meant to be portable across a\n"; + h = h "large number of POSIX-like systems.\n" + cs_explain(h); + } + + if (found_test_eqeq) { + h = "The \"test\" command, as well as the \"[\" command, are not required to know\n"; + h = h "the \"==\" operator. Only a few implementations like bash and some\n"; + h = h "versions of ksh support it.\n"; + h = h "\n"; + h = h "When you run \"test foo == foo\" on a platform that does not support the\n"; + h = h "\"==\" operator, the result will be \"false\" instead of \"true\". This can\n"; + h = h "lead to unexpected behavior.\n"; + h = h "\n"; + h = h "There are two ways to fix this error message. If the file that contains\n"; + h = h "the \"test ==\" is needed for building the package, you should create a\n"; + h = h "patch for it, replacing the \"==\" operator with \"=\". If the file is not\n"; + h = h "needed, add its name to the CHECK_PORTABILITY_SKIP variable in the\n"; + h = h "package Makefile.\n"; + cs_explain(h); + } + + cs_exit(); +} --_----------=_1584087096169070--