diff options
author | rillig <rillig> | 2006-10-12 17:57:05 +0000 |
---|---|---|
committer | rillig <rillig> | 2006-10-12 17:57:05 +0000 |
commit | 97a1f36ed13ed4169535cb02ee18a54136bef95c (patch) | |
tree | 2b7d4017ab5d938c26bd1a3b78e8c4f731ed3d80 /mk | |
parent | 238c79dee621ff14042bb2a6d81917141af2c2be (diff) | |
download | pkgsrc-97a1f36ed13ed4169535cb02ee18a54136bef95c.tar.gz |
Portability checks, version two.
The actual check has moved into a shell file to allow for nice-looking
code. Instead of only the configure scripts, it scans all files whose
first line matches "#!*/bin/sh". Therefore the check is run no matter if
HAS_CONFIGURE is set or not.
Added a warning (not an error) for every use of $RANDOM that is not
combined with $$, the process ID. $RANDOM is only implemented by bash
and some versions of the ksh.
Diffstat (limited to 'mk')
-rw-r--r-- | mk/configure/check-portability.mk | 32 | ||||
-rw-r--r-- | mk/configure/check-portability.sh | 100 | ||||
-rw-r--r-- | mk/configure/configure.mk | 6 |
3 files changed, 107 insertions, 31 deletions
diff --git a/mk/configure/check-portability.mk b/mk/configure/check-portability.mk index cc66bc48c4f..2a240e16a5b 100644 --- a/mk/configure/check-portability.mk +++ b/mk/configure/check-portability.mk @@ -1,4 +1,4 @@ -# $NetBSD: check-portability.mk,v 1.4 2006/10/05 10:52:40 rillig Exp $ +# $NetBSD: check-portability.mk,v 1.5 2006/10/12 17:57:05 rillig Exp $ # # This file contains some checks that are applied to the configure # scripts to check for certain constructs that are known to cause @@ -33,29 +33,7 @@ do-configure-pre-hook: _configure-check-for-test .endif .PHONY: _configure-check-for-test _configure-check-for-test: - @${STEP_MSG} "Checking for \"test ... == ...\" in configure scripts" -.for d in ${CONFIGURE_DIRS} - ${_PKG_SILENT}${_PKG_DEBUG}set -e; \ - cd ${WRKSRC}; cd ${d}; \ - case `sed '1q' < ${CONFIGURE_SCRIPT}` in \ - "#!"*"/bin/sh") \ - found=no; \ - while read line; do \ - set args $$line; shift; \ - while [ $$# -ge 3 ]; do \ - if [ ":$$1" = ":test" ] && [ ":$$3" = ":==" ]; then \ - found=yes; \ - ${ERROR_MSG} "[configure.mk] $$line"; \ - elif [ ":$$1" = ":#" ]; then \ - break; \ - fi; \ - shift; \ - done; \ - if [ "$$found" = "yes" ]; then \ - ${ERROR_MSG} "[configure.mk] Found test ... == ... in configure script."; \ - exit 1; \ - fi; \ - done < ${CONFIGURE_SCRIPT}; \ - ;; \ - esac -.endfor + @${STEP_MSG} "Checking for portability problems in extracted files" + ${_PKG_SILENT}${_PKG_DEBUG} \ + cd ${WRKSRC} \ + && sh ${PKGSRCDIR}/mk/configure/check-portability.sh diff --git a/mk/configure/check-portability.sh b/mk/configure/check-portability.sh new file mode 100644 index 00000000000..0c65dbb6b99 --- /dev/null +++ b/mk/configure/check-portability.sh @@ -0,0 +1,100 @@ +# $NetBSD: check-portability.sh,v 1.1 2006/10/12 17:57:05 rillig Exp $ +# +# This program checks the extracted files for portability issues that +# are likely to result in false assumptions by the package. +# +# The most prominent example is the "==" operator of test(1), which is +# only implemented by bash and some versions of the ksh. +# +# Note: because this program is run with the tools wrapper directory in +# the PATH, it calls the utilities by their base names. It also assumes +# to be interpreted by a POSIX-conforming shell. +# + +set -eu + +exitcode=0 + +error_msg() { + echo "ERROR: [check-portability.sh] $*" 1>&2 + exitcode=1 +} + +warning_msg() { + echo "WARNING: [check-portability.sh] $*" 1>&2 +} + +last_heading="" +heading() { + + if test "$1" != "$last_heading"; then + last_heading="$1" + error_msg "=> $1" + fi +} + +# usage: check_shell <fname> +check_shell() { + # See the end of the loop for the redirection. + while read line; do + + # 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="${line%%#*}" + + # Check for $RANDOM, which is specific to ksh and bash. + case "$line" in + *"\$\$-\$RANDOM"* \ + | *"\$RANDOM-\$\$"* \ + | *"\$RANDOM"[A-Z_]*) + # When $RANDOM is prefixed by the process ID, it + # doesn't matter too much if $RANDOM is empty. + # This code is often found in GNU configure scripts. + ;; + + *\$RANDOM*) + heading "Found \$RANDOM:" + warning_msg "$fname: $line" + ;; + esac + + # + # Split the line into words and check them. + # + set args $line; shift + while [ $# -ge 3 ]; do + case "$1" in + "test" | "[") + if [ "==" = "$3" ]; then + heading "Found test ... == ...:" + error_msg "$fname: $line" + fi + ;; + esac + shift + done + + done < "$1" +} + +find * -type f -print 2>/dev/null \ +| { + while read fname; do + + case "$fname" in + *.orig) + continue;; + esac + + read firstline < "$fname" || continue + case "$firstline" in + "#!"*"/bin/sh") + check_shell "$fname" + ;; + esac + done + exit $exitcode +} diff --git a/mk/configure/configure.mk b/mk/configure/configure.mk index 40a4eb11cd8..d041b9e079d 100644 --- a/mk/configure/configure.mk +++ b/mk/configure/configure.mk @@ -1,4 +1,4 @@ -# $NetBSD: configure.mk,v 1.10 2006/10/02 15:42:47 rillig Exp $ +# $NetBSD: configure.mk,v 1.11 2006/10/12 17:57:05 rillig Exp $ # # CONFIGURE_SCRIPT is the path to the script to run in order to # configure the software for building. If the path is relative, @@ -32,9 +32,7 @@ _BUILD_DEFS+= CONFIGURE_ENV CONFIGURE_ARGS .if defined(USE_PKGLOCALEDIR) . include "${PKGSRCDIR}/mk/configure/replace-localedir.mk" .endif -.if defined(HAS_CONFIGURE) -. include "${.PARSEDIR}/check-portability.mk" -.endif +.include "${.PARSEDIR}/check-portability.mk" ###################################################################### ### configure (PUBLIC) |