pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/mk Moved the portability checks from the configure/ di...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0319f9b7ec2e
branches:  trunk
changeset: 521300:0319f9b7ec2e
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Nov 09 02:53:15 2006 +0000

description:
Moved the portability checks from the configure/ directory to checks/,
since according to the comment in check/bsd.check.mk, they belong there.

Added a new check for all C and C++ header files to make sure they don't
contain strings like ${prefix} or ${exec_prefix}, which is currently a
problem with sysutils/dbus and has been noticed in PR 35019. This check
is disabled by default since I don't know anything about possible false
positives, but I plan to enable it for PKG_DEVELOPERs after some
testing.

Added two names for hooks that are placed in the configure and in the
build phase. Now the checks look more like becoming something one could
call a framework, sharing a common structure and a documented interface.

diffstat:

 mk/build/build.mk                 |    3 +-
 mk/check/bsd.check.mk             |   24 +++++++-
 mk/check/check-headers.mk         |   37 ++++++++++++
 mk/check/check-headers.sh         |   48 +++++++++++++++
 mk/check/check-portability.mk     |   50 ++++++++++++++++
 mk/check/check-portability.sh     |   78 +++++++++++++++++++++++++
 mk/check/check-subr.sh            |   85 ++++++++++++++++++++++++++++
 mk/configure/check-portability.mk |   48 ---------------
 mk/configure/check-portability.sh |  115 --------------------------------------
 mk/configure/configure.mk         |    8 +-
 10 files changed, 329 insertions(+), 167 deletions(-)

diffs (truncated from 581 to 300 lines):

diff -r b0cb47780a61 -r 0319f9b7ec2e mk/build/build.mk
--- a/mk/build/build.mk Thu Nov 09 02:19:59 2006 +0000
+++ b/mk/build/build.mk Thu Nov 09 02:53:15 2006 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: build.mk,v 1.8 2006/10/26 21:12:47 rillig Exp $
+# $NetBSD: build.mk,v 1.9 2006/11/09 02:53:15 rillig Exp $
 #
 # This file defines what happens in the build phase, excluding the
 # self-test, which is defined in test.mk.
@@ -81,6 +81,7 @@
 _REAL_BUILD_TARGETS+=  build-check-interactive
 _REAL_BUILD_TARGETS+=  build-message
 _REAL_BUILD_TARGETS+=  build-vars
+_REAL_BUILD_TARGETS+=  pre-build-checks-hook
 _REAL_BUILD_TARGETS+=  pre-build
 _REAL_BUILD_TARGETS+=  do-build
 _REAL_BUILD_TARGETS+=  post-build
diff -r b0cb47780a61 -r 0319f9b7ec2e mk/check/bsd.check.mk
--- a/mk/check/bsd.check.mk     Thu Nov 09 02:19:59 2006 +0000
+++ b/mk/check/bsd.check.mk     Thu Nov 09 02:53:15 2006 +0000
@@ -1,8 +1,24 @@
-# $NetBSD: bsd.check.mk,v 1.3 2006/10/13 06:32:15 rillig Exp $
+# $NetBSD: bsd.check.mk,v 1.4 2006/11/09 02:53:15 rillig Exp $
 #
 # This Makefile fragment is included by bsd.pkg.mk and provides all
 # variables and targets related to build and install checks.
 #
+# There are some predefined hooks where checks can be added:
+#
+# pre-configure-checks-hook
+#      Is run before configuring the package.
+#
+# pre-build-checks-hook
+#      Is run before building the package.
+#
+# #notyet post-install-privileged-checks-hook
+#      Is run after the installation, as the user who installed
+#      the package.
+#
+# #notyet post-install-checks-hook
+#      Is run after the installation, as the user who built
+#      the package.
+#
 # The following are the "public" targets provided this module:
 #
 #    check-files-pre, check-files-post, check-files
@@ -15,6 +31,12 @@
 .include "${PKGSRCDIR}/mk/check/check-shlibs.mk"
 .include "${PKGSRCDIR}/mk/check/check-vulnerable.mk"
 .include "${PKGSRCDIR}/mk/check/check-wrkref.mk"
+.include "${.PARSEDIR}/check-headers.mk"
+.include "${.PARSEDIR}/check-portability.mk"
+
+pre-configure-checks-hook \
+pre-build-checks-hook: .PHONY
+       @${DO_NADA}
 
 ######################################################################
 ### check-clean (PRIVATE)
diff -r b0cb47780a61 -r 0319f9b7ec2e mk/check/check-headers.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/check/check-headers.mk Thu Nov 09 02:53:15 2006 +0000
@@ -0,0 +1,37 @@
+# $NetBSD: check-headers.mk,v 1.1 2006/11/09 02:53:15 rillig Exp $
+#
+# This file checks the C and C++ header files for possible problems.
+#
+# User-settable variables:
+#
+# CHECK_HEADERS
+#      Whether the header files should be checked.
+#
+#      Default value: "yes" for PKG_DEVELOPERs, "no" otherwise.
+#
+# Package-settable-variables:
+#
+# CHECK_HEADERS_SKIP:
+#      A list of filename patterns that should be skipped for this test.
+#
+
+.if defined(PKG_DEVELOPER)
+# still experimental
+#CHECK_HEADERS?=               yes
+.endif
+CHECK_HEADERS?=                no
+CHECK_HEADERS_SKIP?=   # none
+
+.if !empty(CHECK_HEADERS:M[Yy][Ee][Ss])
+pre-build-checks-hook: _check-headers
+.endif
+
+.PHONY: _check-headers
+_check-headers:
+       @${STEP_MSG} "Checking for possible problems in header files"
+       ${RUN}                                                          \
+       [ -d ${WRKSRC}/. ] || exit 0;                                   \
+       cd ${WRKSRC};                                                   \
+       env     PKGSRCDIR=${PKGSRCDIR:Q}                                \
+               SKIP_FILTER=${CHECK_HEADERS_SKIP:@p@${p}) continue;;@:Q} \
+               sh ${PKGSRCDIR}/mk/check/check-headers.sh
diff -r b0cb47780a61 -r 0319f9b7ec2e mk/check/check-headers.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/check/check-headers.sh Thu Nov 09 02:53:15 2006 +0000
@@ -0,0 +1,48 @@
+# $NetBSD: check-headers.sh,v 1.1 2006/11/09 02:53:15 rillig Exp $
+#
+# This program checks the header files for possible problems.
+#
+# When a macro definition contains the characters "${", it is likely
+# that is comes from a GNU-style configure script that didn't use the
+# ${prefix} or ${exec_prefix} variable correctly.
+#
+
+set -eu
+
+. "${PKGSRCDIR}/mk/check/check-subr.sh"
+cs_setprogname "$0"
+
+# usage: check_header <fname>
+check_header() {
+       # See the end of the loop for the redirection.
+       while read line; do
+
+               # Check for "${" in macro definitions.
+               case "$line" in
+               "#define"*"\${"*)
+                       cs_error_heading "Found unresolved variable in macro:"
+                       cs_error_msg "$fname: $line"
+                       ;;
+               esac
+
+       done < "$1"
+}
+
+find * -type f -print 2>/dev/null \
+| {
+       while read fname; do
+
+               case "$fname" in
+               *.h | *.hpp | *.h++ | *.hxx)
+                       ;;
+               *)
+                       continue
+                       ;;
+               esac
+
+               eval "case \"\$fname\" in $SKIP_FILTER *.orig) continue;; esac"
+
+               check_header "$fname"
+       done
+       cs_exit
+}
diff -r b0cb47780a61 -r 0319f9b7ec2e mk/check/check-portability.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/check/check-portability.mk     Thu Nov 09 02:53:15 2006 +0000
@@ -0,0 +1,50 @@
+# $NetBSD: check-portability.mk,v 1.1 2006/11/09 02:53:15 rillig Exp $
+#
+# 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 following variables may be set by the pkgsrc user in mk.conf:
+#
+# CHECK_PORTABILITY: YesNo
+#      Whether to enable some portability checks for the configure
+#      scripts before they are run.
+#
+#      Default value: yes for PKG_DEVELOPERs, no otherwise.
+#
+# The following variables may be set by the package:
+#
+# SKIP_PORTABILITY_CHECK: YesNo
+#      Whether the above checks should be skipped for the current
+#      package.
+#
+#      Default value: no
+#      Deprecated: Use CHECK_PORTABILITY_SKIP instead.
+#
+# CHECK_PORTABILITY_SKIP: List of Pathmask
+#      The list of files that should be skipped in the portability
+#      check.
+#
+#      Default value: empty.
+#
+
+.if defined(PKG_DEVELOPER)
+CHECK_PORTABILITY?=            yes
+.endif
+CHECK_PORTABILITY?=            no
+SKIP_PORTABILITY_CHECK?=       no
+CHECK_PORTABILITY_SKIP?=       # none
+
+.if ${CHECK_PORTABILITY:M[Yy][Ee][Ss]} != "" && \
+    ${SKIP_PORTABILITY_CHECK:M[Yy][Ee][Ss]} == ""
+pre-configure-checks-hook: _check-portability
+.endif
+.PHONY: _check-portability
+_check-portability:
+       @${STEP_MSG} "Checking for portability problems in extracted files"
+       ${RUN}                                                          \
+       [ -d ${WRKSRC}/. ] || exit 0;                                   \
+       cd ${WRKSRC};                                                   \
+       env     PKGSRCDIR=${PKGSRCDIR:Q}                                \
+               SKIP_FILTER=${CHECK_PORTABILITY_SKIP:@p@${p}) continue;;@:Q} \
+               sh ${PKGSRCDIR}/mk/check/check-portability.sh
diff -r b0cb47780a61 -r 0319f9b7ec2e mk/check/check-portability.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/check/check-portability.sh     Thu Nov 09 02:53:15 2006 +0000
@@ -0,0 +1,78 @@
+# $NetBSD: check-portability.sh,v 1.1 2006/11/09 02:53:15 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.
+#
+
+set -eu
+
+. "${PKGSRCDIR}/mk/check/check-subr.sh"
+cs_setprogname "$0"
+
+# 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.
+               # Note: this has the side-effect that the # in $# is also
+               # regarded as a comment.
+               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*)
+                       cs_warning_heading "Found \$RANDOM:"
+                       cs_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
+                                       cs_error_heading "Found test ... == ...:"
+                                       cs_error_msg "$fname: $line"
+                               fi
+                               ;;
+                       esac
+                       shift
+               done
+
+       done < "$1"
+}
+
+find * -type f -print 2>/dev/null \
+| {
+       while read fname; do
+
+               eval "case \"\$fname\" in $SKIP_FILTER *.orig) continue;; esac"
+
+               read firstline < "$fname" || continue
+               case "$firstline" in
+               "#!"*"/bin/sh")
+                       check_shell "$fname"
+                       ;;
+               esac
+       done
+       cs_exit
+}
diff -r b0cb47780a61 -r 0319f9b7ec2e mk/check/check-subr.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/check/check-subr.sh    Thu Nov 09 02:53:15 2006 +0000
@@ -0,0 +1,85 @@
+# $NetBSD: check-subr.sh,v 1.1 2006/11/09 02:53:15 rillig Exp $
+#
+# This file contains shell functions that are used by the various shell
+# programs that check things in pkgsrc. All these programs must be
+# called with the following environment variables set:
+#
+# PKGSRCDIR
+#      The root directory of the pkgsrc tree.



Home | Main Index | Thread Index | Old Index