pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/mk/configure Portability checks, version two.



details:   https://anonhg.NetBSD.org/pkgsrc/rev/857dbfc4f56a
branches:  trunk
changeset: 519949:857dbfc4f56a
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Oct 12 17:57:05 2006 +0000

description:
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:

 mk/configure/check-portability.mk |   32 +----------
 mk/configure/check-portability.sh |  100 ++++++++++++++++++++++++++++++++++++++
 mk/configure/configure.mk         |    6 +-
 3 files changed, 107 insertions(+), 31 deletions(-)

diffs (167 lines):

diff -r 1cd44cbb2b9e -r 857dbfc4f56a mk/configure/check-portability.mk
--- a/mk/configure/check-portability.mk Thu Oct 12 17:28:16 2006 +0000
+++ b/mk/configure/check-portability.mk Thu Oct 12 17:57:05 2006 +0000
@@ -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 @@
 .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 -r 1cd44cbb2b9e -r 857dbfc4f56a mk/configure/check-portability.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/configure/check-portability.sh Thu Oct 12 17:57:05 2006 +0000
@@ -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 -r 1cd44cbb2b9e -r 857dbfc4f56a mk/configure/configure.mk
--- a/mk/configure/configure.mk Thu Oct 12 17:28:16 2006 +0000
+++ b/mk/configure/configure.mk Thu Oct 12 17:57:05 2006 +0000
@@ -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 @@
 .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)



Home | Main Index | Thread Index | Old Index