Fri Mar 13 08:11:36 2020 UTC ()
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.


(rillig)
diff -r0 -r1.11 pkgsrc/mk/check/check-portability.awk
diff -r1.13 -r1.14 pkgsrc/mk/check/check-portability.mk
diff -r1.18 -r1.19 pkgsrc/mk/check/check-portability.sh

File Added: pkgsrc/mk/check/check-portability.awk
# $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();
}

cvs diff -r1.13 -r1.14 pkgsrc/mk/check/check-portability.mk (expand / switch to unified diff)

--- pkgsrc/mk/check/check-portability.mk 2020/03/13 08:04:08 1.13
+++ pkgsrc/mk/check/check-portability.mk 2020/03/13 08:11:36 1.14
@@ -1,45 +1,46 @@ @@ -1,45 +1,46 @@
1# $NetBSD: check-portability.mk,v 1.13 2020/03/13 08:04:08 rillig Exp $ 1# $NetBSD: check-portability.mk,v 1.14 2020/03/13 08:11:36 rillig Exp $
2# 2#
3# This file checks that the extracted shell programs don't contain 3# This file contains some checks that are applied to the configure
4# bashisms and other constructs that only work on some platforms. 4# scripts to check for certain constructs that are known to cause
 5# problems on some platforms. The detailed checks are in
 6# check-portability.sh.
5# 7#
6# User-settable variables: 8# User-settable variables:
7# 9#
8# CHECK_PORTABILITY 10# CHECK_PORTABILITY
9# Whether to enable the portability checks. 11# Whether to enable some portability checks for the configure
 12# scripts before they are run.
10# 13#
11# Default value: yes for PKG_DEVELOPERs, no otherwise. 14# Default value: yes for PKG_DEVELOPERs, no otherwise.
12# 15#
13# Package-settable variables: 16# Package-settable variables:
14# 17#
15# CHECK_PORTABILITY_SKIP 18# CHECK_PORTABILITY_SKIP
16# The shell patterns that should not be checked. 19# The list of files that should be skipped in the portability
17# Note that a * in a pattern also matches a slash in a pathname. 20# check.
18# 21#
19# Default value: ${REPLACE_BASH} 22# Default value: ${REPLACE_BASH}
20# Examples: debian/* test/* *.bash 23# Example: debian/*
21 24
22_VARGROUPS+= check-portability 25_VARGROUPS+= check-portability
23_USER_VARS.check-portability= CHECK_PORTABILITY 26_USER_VARS.check-portability= CHECK_PORTABILITY
24_PKG_VARS.check-portability= CHECK_PORTABILITY_SKIP 27_PKG_VARS.check-portability= CHECK_PORTABILITY_SKIP
25 28
26.if ${PKG_DEVELOPER:Uno} != no 29.if ${PKG_DEVELOPER:Uno} != "no"
27CHECK_PORTABILITY?= yes 30CHECK_PORTABILITY?= yes
28.endif 31.endif
29CHECK_PORTABILITY?= no 32CHECK_PORTABILITY?= no
30CHECK_PORTABILITY_SKIP?= ${REPLACE_BASH} 33CHECK_PORTABILITY_SKIP?= ${REPLACE_BASH}
31 34
32.if ${CHECK_PORTABILITY:tl} == yes && ${CHECK_PORTABILITY_SKIP} != "*" 35.if ${CHECK_PORTABILITY:tl} == yes && ${CHECK_PORTABILITY_SKIP} != "*"
33TOOL_DEPENDS+= check-portability>=19.4.1:../../pkgtools/check-portability 
34pre-configure-checks-hook: _check-portability 36pre-configure-checks-hook: _check-portability
35.endif 37.endif
36 
37.PHONY: _check-portability 38.PHONY: _check-portability
38_check-portability: 39_check-portability:
39 @${STEP_MSG} "Checking for portability problems in extracted files" 40 @${STEP_MSG} "Checking for portability problems in extracted files"
40 ${RUN} \ 41 ${RUN} \
41 [ -d ${WRKSRC}/. ] || exit 0; \ 42 [ -d ${WRKSRC}/. ] || exit 0; \
42 cd ${WRKSRC}; \ 43 cd ${WRKSRC}; \
43 env SKIP_FILTER=${CHECK_PORTABILITY_SKIP:@p@${p}) skip=yes;;@:Q} \ 44 env SKIP_FILTER=${CHECK_PORTABILITY_SKIP:@p@${p}) skip=yes;;@:Q} \
44 PREFIX=${PREFIX} \ 45 PREFIX=${PREFIX} \
45 sh ${PKGSRCDIR}/mk/check/check-portability.sh 46 sh ${PKGSRCDIR}/mk/check/check-portability.sh

cvs diff -r1.18 -r1.19 pkgsrc/mk/check/check-portability.sh (expand / switch to unified diff)

--- pkgsrc/mk/check/check-portability.sh 2020/03/13 08:04:08 1.18
+++ pkgsrc/mk/check/check-portability.sh 2020/03/13 08:11:36 1.19
@@ -1,37 +1,47 @@ @@ -1,37 +1,47 @@
1# $NetBSD: check-portability.sh,v 1.18 2020/03/13 08:04:08 rillig Exp $ 1# $NetBSD: check-portability.sh,v 1.19 2020/03/13 08:11:36 rillig Exp $
2# 2#
3# This program checks all files in the current directory and any 3# This program checks all files in the current directory and any
4# subdirectories for portability issues that are likely to result in 4# subdirectories for portability issues that are likely to result in
5# false assumptions by the package. 5# false assumptions by the package.
6# 6#
7# The most prominent example is the "==" operator of test(1), which is 7# The most prominent example is the "==" operator of test(1), which is
8# only implemented by bash and some versions of the ksh. 8# only implemented by bash and some versions of the ksh.
9# 9#
10# usage: cd $WRKSRC && [SKIP_FILTER=...] check-portability.sh 10# usage: cd $WRKSRC && [SKIP_FILTER=...] check-portability.sh
11# 11#
12 12
13set -eu 13set -eu
14 14
15checkdir=`dirname "$0"` 15checkdir=`dirname "$0"`
16. "$checkdir/check-subr.sh" 16. "$checkdir/check-subr.sh"
17cs_setprogname "$0" 17cs_setprogname "$0"
18 18
19: ${SKIP_FILTER:=""} 19: ${SKIP_FILTER:=""}
20 20
21# usage: check_shell <fname> 21# usage: check_shell <fname>
22check_shell() { 22check_shell() {
23 ${PREFIX}/bin/check-portability "$1" 1>&2 \ 23 env \
 24 CK_FNAME="$1" \
 25 CK_PROGNAME="check-portability.awk" \
 26 awk -f "$checkdir/check-subr.awk" \
 27 -f "$checkdir/check-portability.awk" \
 28 < "$1" 1>&2 \
24 || cs_exitcode=1 29 || cs_exitcode=1
 30
 31 if test -f "${PREFIX}/bin/check-portability"; then
 32 ${PREFIX}/bin/check-portability "$1" 1>&2 \
 33 || cs_exitcode=1
 34 fi
25} 35}
26 36
27find ./* -type f -print 2>/dev/null \ 37find ./* -type f -print 2>/dev/null \
28| sed 's,$,_,' \ 38| sed 's,$,_,' \
29| { 39| {
30 opsys=`uname -s`-`uname -r` 40 opsys=`uname -s`-`uname -r`
31 while read fname; do 41 while read fname; do
32 fname="${fname#./}" 42 fname="${fname#./}"
33 fname="${fname%_}" 43 fname="${fname%_}"
34 44
35 skip=no 45 skip=no
36 eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac" 46 eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac"
37 [ $skip = no ] || continue 47 [ $skip = no ] || continue