diff options
author | rillig <rillig@pkgsrc.org> | 2006-11-09 02:53:15 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-11-09 02:53:15 +0000 |
commit | 3911155e2f241c276d7b5c75b32ccfd68c6a6627 (patch) | |
tree | f288e89bbcdc9a6720db069493d3c910a194766b /mk | |
parent | 335ef695eec1f9425771ef90afa1a8605420843c (diff) | |
download | pkgsrc-3911155e2f241c276d7b5c75b32ccfd68c6a6627.tar.gz |
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 (limited to 'mk')
-rw-r--r-- | mk/build/build.mk | 3 | ||||
-rw-r--r-- | mk/check/bsd.check.mk | 24 | ||||
-rw-r--r-- | mk/check/check-headers.mk | 37 | ||||
-rw-r--r-- | mk/check/check-headers.sh | 48 | ||||
-rw-r--r-- | mk/check/check-portability.mk (renamed from mk/configure/check-portability.mk) | 18 | ||||
-rw-r--r-- | mk/check/check-portability.sh (renamed from mk/configure/check-portability.sh) | 53 | ||||
-rw-r--r-- | mk/check/check-subr.sh | 85 | ||||
-rw-r--r-- | mk/configure/configure.mk | 8 |
8 files changed, 219 insertions, 57 deletions
diff --git a/mk/build/build.mk b/mk/build/build.mk index bcc3225d704..79e9e6f96b2 100644 --- a/mk/build/build.mk +++ b/mk/build/build.mk @@ -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 @@ ${_COOKIE.build}: real-build _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 --git a/mk/check/bsd.check.mk b/mk/check/bsd.check.mk index 0290ac2db4b..5fd94d5f82b 100644 --- a/mk/check/bsd.check.mk +++ b/mk/check/bsd.check.mk @@ -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 --git a/mk/check/check-headers.mk b/mk/check/check-headers.mk new file mode 100644 index 00000000000..1fcd04a6e57 --- /dev/null +++ b/mk/check/check-headers.mk @@ -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 --git a/mk/check/check-headers.sh b/mk/check/check-headers.sh new file mode 100644 index 00000000000..c965025d524 --- /dev/null +++ b/mk/check/check-headers.sh @@ -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 --git a/mk/configure/check-portability.mk b/mk/check/check-portability.mk index 741ebc1b6ac..61676d0a8b2 100644 --- a/mk/configure/check-portability.mk +++ b/mk/check/check-portability.mk @@ -1,4 +1,4 @@ -# $NetBSD: check-portability.mk,v 1.8 2006/10/26 14:42:53 tv Exp $ +# $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 @@ -19,6 +19,7 @@ # 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 @@ -36,13 +37,14 @@ CHECK_PORTABILITY_SKIP?= # none .if ${CHECK_PORTABILITY:M[Yy][Ee][Ss]} != "" && \ ${SKIP_PORTABILITY_CHECK:M[Yy][Ee][Ss]} == "" -do-configure-pre-hook: _configure-check-for-test +pre-configure-checks-hook: _check-portability .endif -.PHONY: _configure-check-for-test -_configure-check-for-test: +.PHONY: _check-portability +_check-portability: @${STEP_MSG} "Checking for portability problems in extracted files" - ${_PKG_SILENT}${_PKG_DEBUG} \ + ${RUN} \ [ -d ${WRKSRC}/. ] || exit 0; \ - cd ${WRKSRC} \ - && env SKIP_FILTER=${CHECK_PORTABILITY_SKIP:@p@${p}) continue;;@:Q} \ - sh ${PKGSRCDIR}/mk/configure/check-portability.sh + cd ${WRKSRC}; \ + env PKGSRCDIR=${PKGSRCDIR:Q} \ + SKIP_FILTER=${CHECK_PORTABILITY_SKIP:@p@${p}) continue;;@:Q} \ + sh ${PKGSRCDIR}/mk/check/check-portability.sh diff --git a/mk/configure/check-portability.sh b/mk/check/check-portability.sh index 079571017f9..c3bb798f098 100644 --- a/mk/configure/check-portability.sh +++ b/mk/check/check-portability.sh @@ -1,4 +1,4 @@ -# $NetBSD: check-portability.sh,v 1.5 2006/10/29 20:12:49 rillig Exp $ +# $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. @@ -6,48 +6,11 @@ # 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. -# -# ENVIRONMENT VARIABLES -# -# SKIP_FILTER: A shell command that excludes some patterns. -# -# See also: -# mk/configure/check-portability.mk -# set -eu -: ${SKIP:=""} - -exitcode=0 - -last_heading="" - -error_msg() { - echo "ERROR: [check-portability.sh] $*" 1>&2 - exitcode=1 -} - -warning_msg() { - echo "WARNING: [check-portability.sh] $*" 1>&2 -} - -error_heading() { - if test "$1" != "$last_heading"; then - last_heading="$1" - error_msg "=> $1" - fi -} - -warning_heading() { - if test "$1" != "$last_heading"; then - last_heading="$1" - warning_msg "=> $1" - fi -} +. "${PKGSRCDIR}/mk/check/check-subr.sh" +cs_setprogname "$0" # usage: check_shell <fname> check_shell() { @@ -74,8 +37,8 @@ check_shell() { ;; *\$RANDOM*) - warning_heading "Found \$RANDOM:" - warning_msg "$fname: $line" + cs_warning_heading "Found \$RANDOM:" + cs_warning_msg "$fname: $line" ;; esac @@ -87,8 +50,8 @@ check_shell() { case "$1" in "test" | "[") if [ "==" = "$3" ]; then - error_heading "Found test ... == ...:" - error_msg "$fname: $line" + cs_error_heading "Found test ... == ...:" + cs_error_msg "$fname: $line" fi ;; esac @@ -111,5 +74,5 @@ find * -type f -print 2>/dev/null \ ;; esac done - exit $exitcode + cs_exit } diff --git a/mk/check/check-subr.sh b/mk/check/check-subr.sh new file mode 100644 index 00000000000..6e9a7364584 --- /dev/null +++ b/mk/check/check-subr.sh @@ -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. +# +# SKIP_FILTER +# A shell expression of the form +# +# */pattern.*) continue;; *.txt) continue;; +# +# that can be passed to eval(1) in order to skip the files +# that are chosen by the respective *_SKIP variable in +# make(1). +# + +# Implementation notes: +# +# 1. The SKIP_FILTER variable can be used in the following pattern, +# usually inside a "for" or "while" loop. +# +# eval "case \"\$fname\" in $SKIP_FILTER *.orig) continue;; esac" +# +# 2. The programs using this file are run with the tools wrapper +# directory in the PATH, so they call the utilities by their base names. +# They may also assume to be interpreted by a POSIX-conforming shell, in +# particular _not_ by the Solaris /bin/sh. +# + +# All programs that check something are very strict. +set -eu + +cs_exitcode=0 + +# usage: cs_setprogname "progname" +# +# This function sets the variable that will later be used in diagnostic +# messages to identify the program that generated the message. +cs_setprogname() { + cs_progname="${1##*/}" +} + +# Each diagnostic message can be preceded by a heading to better identify +# messages that belong together. The heading will only be printed if it +# differs from the last one. +cs_last_heading="" + +# usage: cs_error_heading "new heading" +cs_error_heading() { + if [ x"$1" != x"$cs_last_heading" ]; then + cs_last_heading="$1" + cs_error_msg "=> $1" + fi +} + +# usage: cs_warning_heading "new heading" +cs_warning_heading() { + if [ x"$1" != x"$cs_last_heading" ]; then + cs_last_heading="$1" + cs_warning_msg "=> $1" + fi +} + +# usage: cs_error_msg "error message" +cs_error_msg() { + echo "ERROR: [$cs_progname] $*" 1>&2 + cs_exitcode=1 +} + +# usage: cs_warning_msg "warning message" +cs_warning_msg() { + echo "WARNING: [$cs_progname] $*" 1>&2 +} + +# usage: cs_exit +# +# At the end of the program, cs_exit should be called to return the +# appropriate exit status to the calling process. It is non-zero when +# any error messages have been printed and zero otherwise. +cs_exit() { + exit "$cs_exitcode" +} diff --git a/mk/configure/configure.mk b/mk/configure/configure.mk index d041b9e079d..ed202251d42 100644 --- a/mk/configure/configure.mk +++ b/mk/configure/configure.mk @@ -1,4 +1,4 @@ -# $NetBSD: configure.mk,v 1.11 2006/10/12 17:57:05 rillig Exp $ +# $NetBSD: configure.mk,v 1.12 2006/11/09 02:53:15 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,7 +32,6 @@ _BUILD_DEFS+= CONFIGURE_ENV CONFIGURE_ARGS .if defined(USE_PKGLOCALEDIR) . include "${PKGSRCDIR}/mk/configure/replace-localedir.mk" .endif -.include "${.PARSEDIR}/check-portability.mk" ###################################################################### ### configure (PUBLIC) @@ -74,10 +73,15 @@ ${_COOKIE.configure}: real-configure ### real-configure is a helper target onto which one can hook all of the ### targets that do the actual configuration of the sources. ### +# +# Note: pre-configure-checks-hook comes after pre-configure to allow +# packages for fixing bad files with SUBST_STAGE.* = pre-configure. +# _REAL_CONFIGURE_TARGETS+= configure-check-interactive _REAL_CONFIGURE_TARGETS+= configure-message _REAL_CONFIGURE_TARGETS+= configure-vars _REAL_CONFIGURE_TARGETS+= pre-configure +_REAL_CONFIGURE_TARGETS+= pre-configure-checks-hook _REAL_CONFIGURE_TARGETS+= do-configure-pre-hook _REAL_CONFIGURE_TARGETS+= do-configure _REAL_CONFIGURE_TARGETS+= do-configure-post-hook |