From 6ae4606464252d194b374c41998d4c3df7664ac0 Mon Sep 17 00:00:00 2001 From: jlam Date: Thu, 23 Jun 2005 08:31:20 +0000 Subject: Split out the check-files implementation and related variables into a new bsd.pkg.check.mk file. This new file will eventually collect all of the various "check" targets that are run at install-time. While here, change the implementation of check-files so that it is not so monolithic. Change the meaning of the CHECK_FILES variables so that if it's not "no", then the file checks are run. Also, allow these checks to be run if the user explicitly sets CHECK_FILES in /etc/mk.conf, even if PKG_DEVELOPER is not defined. --- mk/bsd.pkg.check.mk | 253 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mk/bsd.pkg.mk | 123 ++----------------------- 2 files changed, 262 insertions(+), 114 deletions(-) create mode 100644 mk/bsd.pkg.check.mk (limited to 'mk') diff --git a/mk/bsd.pkg.check.mk b/mk/bsd.pkg.check.mk new file mode 100644 index 00000000000..72976a4369d --- /dev/null +++ b/mk/bsd.pkg.check.mk @@ -0,0 +1,253 @@ +# $NetBSD: bsd.pkg.check.mk,v 1.1 2005/06/23 08:31:20 jlam Exp $ +# +# This Makefile fragment is included by bsd.pkg.mk and defines the +# relevant variables and targets the for various install-time "check" +# targets. +# +# The following variables may be set by the user and control which +# checks are run: +# +# CHECK_FILES causes the extra or missing file checks to be run if +# it is any value other than "no". Defaults to "no". +# +# CHECK_FILES_STRICT makes the file checks very strict on errors if +# it is any value other than "no". Defaults to "no". +# +# The following targets are defined by bsd.pkg.check.mk: +# +# check-files-pre & check-files-post generate the list of files on the +# filesystem just before and just after the package's files are +# installed. +# +# check-files compares the "pre" and "post" file lists to determine +# if there are any extra or missing files installed by the +# package. +# + +# For PKG_DEVELOPERs, cause some checks to be run automatically by default. +.if defined(PKG_DEVELOPER) +CHECK_FILES?= yes +.endif + +CHECK_FILES?= no +CHECK_FILES_STRICT?= no + +########################################################################### +# CHECK_FILES_SKIP is a list of file names that will be skipped when +# analyzing file lists in the check-files target. This is useful to +# avoid getting errors triggered by changes in directories not really +# handled by pkgsrc. +# +.if defined(INFO_DIR) +CHECK_FILES_SKIP+= ${PREFIX}/${INFO_DIR}/dir +.endif +CHECK_FILES_SKIP+= ${PREFIX}/emul/linux/proc +.for d in ${MAKE_DIRS} ${OWN_DIRS} +CHECK_FILES_SKIP+= ${d} +.endfor +.for d o g m in ${MAKE_DIRS_PERMS} ${OWN_DIRS_PERMS} +CHECK_FILES_SKIP+= ${d} +.endfor +_CHECK_FILES_SKIP_FILTER= ${GREP} -v ${CHECK_FILES_SKIP:@f@-e ${f:Q}@} + +########################################################################### +# These are the files generated and used by the check-files implementation +# used across several check-files targets. +# +# _CHECK_FILES_COOKIE.* are the cookie files that contain the error +# messages discovered during each stage of file-checking. +# +# _CHECK_FILES_PRE.* are the file lists generated before any files +# from the package are installed. +# +# _CHECK_FILES_POST.* are the file lists generated after all files +# from the package are installed. +# +# The "pre" and "post" file lists are compared against each other to +# determine if the package is installing files where it shouldn't be. +# +_CHECK_FILES_COOKIE.prefix= ${WRKDIR}/.check_files_prefix_cookie +_CHECK_FILES_PRE.prefix= ${WRKDIR}/.prefix.pre +_CHECK_FILES_POST.prefix= ${WRKDIR}/.prefix.post + +_CHECK_FILES_COOKIE.sysconfdir= ${WRKDIR}/.check_files_sysconfdir_cookie +_CHECK_FILES_PRE.sysconfdir= ${WRKDIR}/.sysconfdir.pre +_CHECK_FILES_POST.sysconfdir= ${WRKDIR}/.sysconfdir.post + +_CHECK_FILES_COOKIE.varbase= ${WRKDIR}/.check_files_varbase_cookie +_CHECK_FILES_PRE.varbase= ${WRKDIR}/.varbase.pre +_CHECK_FILES_POST.varbase= ${WRKDIR}/.varbase.post + +_CHECK_FILES_COOKIES= # empty +_CHECK_FILES_COOKIES+= ${_CHECK_FILES_COOKIE.prefix} +.if empty(CHECK_FILES_STRICT:M[nN][oO]) +_CHECK_FILES_COOKIES+= ${_CHECK_FILES_COOKIE.sysconfdir} +_CHECK_FILES_COOKIES+= ${_CHECK_FILES_COOKIE.varbase} +.endif + +########################################################################### +# _CHECK_FILES_PRE holds the list of targets that are built as part of +# building the check-files-pre target. These targets should cause the +# "pre" file lists to be generated. +# +_CHECK_FILES_PRE= check-files-pre-message +_CHECK_FILES_PRE+= ${_CHECK_FILES_PRE.prefix} +.if empty(CHECK_FILES_STRICT:M[nN][oO]) +_CHECK_FILES_PRE+= ${_CHECK_FILES_PRE.sysconfdir} +_CHECK_FILES_PRE+= ${_CHECK_FILES_PRE.varbase} +.endif + +########################################################################### +# _CHECK_FILES_POST holds the list of targets that are built as part of +# building the check-files-post target. These targets should cause the +# "post" file lists to be generated. +# +_CHECK_FILES_POST= check-files-post-message +_CHECK_FILES_POST+= ${_CHECK_FILES_POST.prefix} +.if empty(CHECK_FILES_STRICT:M[nN][oO]) +_CHECK_FILES_POST+= ${_CHECK_FILES_POST.sysconfdir} +_CHECK_FILES_POST+= ${_CHECK_FILES_POST.varbase} +.endif + +########################################################################### +# check-files-pre and check-files-post targets and subtargets +# +.ORDER: ${_CHECK_FILES_PRE} +.ORDER: ${_CHECK_FILES_POST} + +.PHONY: check-files-pre check-files-post +check-files-pre: ${_CHECK_FILES_PRE} +check-files-post: ${_CHECK_FILES_POST} + +.PHONY: check-files-pre-message check-files-post-message +check-files-pre-message: + ${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}>" \ + "Generating pre-install file lists" + +check-files-post-message: + ${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}>" \ + "Generating post-install file lists" + +${_CHECK_FILES_PRE.prefix} ${_CHECK_FILES_POST.prefix}: + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${FIND} ${PREFIX} \( -type f -or -type l \) -print 2>/dev/null \ + | ${_CHECK_FILES_SKIP_FILTER} > ${.TARGET} \ + || ${TRUE} + +${_CHECK_FILES_PRE.sysconfdir} ${_CHECK_FILES_POST.sysconfdir}: + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${FIND} ${PKG_SYSCONFDIR} -print 2>/dev/null \ + | ${_CHECK_FILES_SKIP_FILTER} > ${.TARGET} \ + || ${TRUE} + +${_CHECK_FILES_PRE.varbase} ${_CHECK_FILES_POST.varbase}: + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${FIND} ${VARBASE} -print 2>/dev/null \ + | ${_CHECK_FILES_SKIP_FILTER} > ${.TARGET} \ + || ${TRUE} + +########################################################################### +# check-files targets and subtargets +# +.PHONY: check-files-prefix check-files-sysconfdir check-files-varbase +check-files-prefix: ${_CHECK_FILES_COOKIE.prefix} +check-files-sysconfdir: ${_CHECK_FILES_COOKIE.sysconfdir} +check-files-varbase: ${_CHECK_FILES_COOKIE.varbase} + +.ORDER: ${_CHECK_FILES_COOKIES} + +# The check-files target looks at the cookie files generated by the +# check-files-* subtargets, and if they are non-empty, then they +# contain the error messages collected during the build of each +# subtarget. +# +.PHONY: check-files +check-files: ${_CHECK_FILES_COOKIES} +.for _cookie_ in ${_CHECK_FILES_COOKIES} + ${_PKG_SILENT}${_PKG_DEBUG}${CAT} ${_cookie_} +.endfor + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${CAT} ${_CHECK_FILES_COOKIES} | ${AWK} 'END { if (NR > 0) exit 1; }' + +# Check ${PREFIX} for files which are not listed in the generated ${PLIST}. +${_CHECK_FILES_COOKIE.prefix}: + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${TEST} ! -f ${_CHECK_FILES_PRE.prefix} -o \ + ! -f ${_CHECK_FILES_POST.prefix}; \ + then \ + { exit 0; }; \ + fi; \ + diff -u ${_CHECK_FILES_PRE.prefix} ${_CHECK_FILES_POST.prefix} \ + > ${WRKDIR}/.files.diff || ${TRUE}; \ + ${GREP} '^+/' ${WRKDIR}/.files.diff | ${SED} "s|^+||" | ${SORT} \ + > ${WRKDIR}/.files.added; \ + ${GREP} '^-/' ${WRKDIR}/.files.diff | ${SED} "s|^-||" | ${SORT} \ + > ${WRKDIR}/.files.deleted; \ + ${GREP} '^[A-Za-z]' ${PLIST} | ${SED} "s|^|${PREFIX}/|" | ${SORT} \ + > ${WRKDIR}/.files.expected; \ + if ${AWK} 'END { if (NR == 0) exit 1; }' ${WRKDIR}/.files.deleted; \ + then \ + { ${ECHO} "*** The following files have been deleted" \ + "from ${PREFIX}!"; \ + ${SED} "s|^| |" ${WRKDIR}/.files.deleted; \ + } > ${_CHECK_FILES_COOKIE.prefix}; \ + fi; \ + if ! ${CMP} -s ${WRKDIR}/.files.expected ${WRKDIR}/.files.added; \ + then \ + { ${ECHO} "*** The PLIST does not match installed files!"; \ + ${ECHO} " The following files were not expected" \ + "in ${PREFIX}:"; \ + diff -u ${WRKDIR}/.files.expected ${WRKDIR}/.files.added \ + | ${GREP} '^+[^+]' | ${SED} "s|^+| |"; \ + } >> ${.TARGET}; \ + fi + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${RM} -f ${WRKDIR}/.files.added ${WRKDIR}/.files.deleted \ + ${WRKDIR}/.files.diff ${WRKDIR}/.files.expected + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${.TARGET} + +# Check ${SYSCONFDIR} for files which are not in the PLIST and are also +# not copied into place by the INSTALL scripts. +# +${_CHECK_FILES_COOKIE.sysconfdir}: + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${TEST} ! -f ${_CHECK_FILES_PRE.sysconfdir} -o \ + ! -f ${_CHECK_FILES_POST.sysconfdir}; \ + then \ + { exit 0; }; \ + fi; \ + if ! ${CMP} -s ${_CHECK_FILES_PRE.sysconfdir} \ + ${_CHECK_FILES_POST.sysconfdir}; \ + then \ + { ${ECHO} "*** The package has modified ${PKG_SYSCONFDIR}" \ + "contents directly!"; \ + ${ECHO} " The offending files/directories are:"; \ + diff -u ${_CHECK_FILES_PRE.sysconfdir} \ + ${_CHECK_FILES_POST.sysconfdir} \ + | ${GREP} '^+[^+]' | ${SED} "s|^+| |"; \ + } > ${.TARGET}; \ + fi + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${.TARGET} + +# Check ${VARBASE} for files which are not in the PLIST and are also +# not created by the INSTALL scripts. +# +${_CHECK_FILES_COOKIE.varbase}: + ${_PKG_SILENT}${_PKG_DEBUG} \ + if ${TEST} ! -f ${_CHECK_FILES_PRE.varbase} -o \ + ! -f ${_CHECK_FILES_POST.varbase}; \ + then \ + { exit 0; }; \ + fi; \ + if ! ${CMP} -s ${_CHECK_FILES_PRE.varbase} \ + ${_CHECK_FILES_POST.varbase}; \ + then + { ${ECHO} "*** The package has modified ${VARBASE}" \ + "contents directly!"; \ + ${ECHO} " The offending files/directories are:"; \ + diff -u ${_CHECK_FILES_PRE.varbase} \ + ${_CHECK_FILES_POST.varbase} \ + | ${GREP} '^+[^+]' | ${SED} "s|^+| |"; \ + } > ${.TARGET}; \ + fi + ${_PKG_SILENT}${_PKG_DEBUG}${TOUCH} ${TOUCH_FLAGS} ${.TARGET} diff --git a/mk/bsd.pkg.mk b/mk/bsd.pkg.mk index cb8a95da3da..15513f77058 100644 --- a/mk/bsd.pkg.mk +++ b/mk/bsd.pkg.mk @@ -1,4 +1,4 @@ -# $NetBSD: bsd.pkg.mk,v 1.1697 2005/06/23 04:15:47 jlam Exp $ +# $NetBSD: bsd.pkg.mk,v 1.1698 2005/06/23 08:31:20 jlam Exp $ # # This file is in the public domain. # @@ -58,8 +58,6 @@ build-defs-message: ${WRKDIR} # Transform package Makefile variables and set defaults ############################################################################ -CHECK_FILES?= NO # run check-files after install -CHECK_FILES_STRICT?= NO # make check-files very strict on errors CHECK_SHLIBS?= YES # run check-shlibs after install CHECK_WRKREF?= no # run check-wrkref after install CLEANDEPENDS?= NO @@ -862,6 +860,9 @@ PKGSRC_USE_TOOLS+= gzip # Patch .include "../../mk/bsd.pkg.patch.mk" +# Check +.include "../../mk/bsd.pkg.check.mk" + # Tools .include "../../mk/tools/bsd.tools.mk" @@ -2062,20 +2063,8 @@ real-su-install: ${MESSAGE} ${ECHO_MSG} "If this is not desired, set it to an appropriate value (${DEF_UMASK})"; \ ${ECHO_MSG} "and install this package again by \`\`${MAKE} deinstall reinstall''."; \ fi -.if defined(PKG_DEVELOPER) && (${CHECK_FILES} == "YES") - ${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}> Generating pre-install file lists" - ${_PKG_SILENT}${_PKG_DEBUG}${FIND} ${PREFIX} \ - \( -type f -or -type l \) -print \ - 2>/dev/null ${CHECK_FILES_SKIP_CMD} >${WRKDIR}/.prefix.pre \ - || ${TRUE} -. if ${CHECK_FILES_STRICT} == "YES" - ${_PKG_SILENT}${_PKG_DEBUG}${FIND} ${PKG_SYSCONFDIR} -print \ - 2>/dev/null ${CHECK_FILES_SKIP_CMD} >${WRKDIR}/.sysconfdir.pre \ - || ${TRUE} - ${_PKG_SILENT}${_PKG_DEBUG}${FIND} ${VARBASE} -print \ - 2>/dev/null ${CHECK_FILES_SKIP_CMD} >${WRKDIR}/.varbase.pre \ - || ${TRUE} -. endif +.if empty(CHECK_FILES:M[nN][oO]) + ${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} check-files-pre .endif .if defined(INSTALLATION_DIRS) && !empty(INSTALLATION_DIRS) ${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}> Creating installation directories" @@ -2129,20 +2118,8 @@ real-su-install: ${MESSAGE} # listed in the PLIST. \ # ${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} ${PLIST} -.if defined(PKG_DEVELOPER) && (${CHECK_FILES} == "YES") - ${_PKG_SILENT}${_PKG_DEBUG}${ECHO_MSG} "${_PKGSRC_IN}> Generating post-install file lists" - ${_PKG_SILENT}${_PKG_DEBUG}${FIND} ${PREFIX} \ - \( -type f -or -type l \) -print \ - 2>/dev/null ${CHECK_FILES_SKIP_CMD} >${WRKDIR}/.prefix.post \ - || ${TRUE} -. if ${CHECK_FILES_STRICT} == "YES" - ${_PKG_SILENT}${_PKG_DEBUG}${FIND} ${PKG_SYSCONFDIR} -print \ - 2>/dev/null ${CHECK_FILES_SKIP_CMD} >${WRKDIR}/.sysconfdir.post\ - || ${TRUE} - ${_PKG_SILENT}${_PKG_DEBUG}${FIND} ${VARBASE} -print \ - 2>/dev/null ${CHECK_FILES_SKIP_CMD} >${WRKDIR}/.varbase.post \ - || ${TRUE} -. endif +.if empty(CHECK_FILES:M[nN][oO]) + ${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} check-files-post .endif ${_PKG_SILENT}${_PKG_DEBUG}cd ${.CURDIR} && ${MAKE} ${MAKEFLAGS} post-install-script ${_PKG_SILENT}${_PKG_DEBUG}newmanpages=`${EGREP} -h \ @@ -2218,7 +2195,7 @@ real-su-install: ${MESSAGE} .if empty(CHECK_WRKREF:M[nN][oO]) ${_PKG_SILENT}${_PKG_DEBUG}${MAKE} ${MAKEFLAGS} check-wrkref .endif -.if defined(PKG_DEVELOPER) && (${CHECK_FILES} == "YES") +.if empty(CHECK_FILES:M[nN][oO]) ${_PKG_SILENT}${_PKG_DEBUG}${MAKE} ${MAKEFLAGS} check-files .endif @@ -2603,88 +2580,6 @@ check-wrkref: .endif -# CHECK_FILES_SKIP is a list of file names that will be skipped when -# analyzing file lists in the check-files target. This is useful to -# avoid getting errors triggered by changes in directories not really -# handled by pkgsrc. -# -# We have to do this here, i.e., quite late in bsd.pkg.mk parsing, so -# that the variables used in them are defined. Otherwise we may get -# problems with the 'for' expressions. -.if defined(INFO_DIR) -CHECK_FILES_SKIP+= ${PREFIX}/${INFO_DIR}/dir -.endif -CHECK_FILES_SKIP+= ${PREFIX}/emul/linux/proc - -.for e c in ${CONF_FILES} ${SUPPORT_FILES} -CHECK_FILES_SKIP+= ${c}/.pkgsrc -.endfor -.for e c o g m in ${CONF_FILES_PERMS} ${SUPPORT_FILES_PERMS} -CHECK_FILES_SKIP+= ${c}/.pkgsrc -.endfor -.for d in ${MAKE_DIRS} ${OWN_DIRS} -CHECK_FILES_SKIP+= ${d} -.endfor -.for d o g m in ${MAKE_DIRS_PERMS} ${OWN_DIRS_PERMS} -CHECK_FILES_SKIP+= ${d} -.endfor - -CHECK_FILES_SKIP_CMD= | ${GREP} -v ${CHECK_FILES_SKIP:@f@-e ${f:Q}@} - -# Check if the generated PLIST matches the list of really installed files. -# -.PHONY: check-files -check-files: -.if !defined(NO_PKG_REGISTER) - ${_PKG_SILENT}${_PKG_DEBUG} \ - errors=0; \ - diff -u ${WRKDIR}/.prefix.pre ${WRKDIR}/.prefix.post \ - >${WRKDIR}/.files.diff || ${TRUE}; \ - ${GREP} '^+/' ${WRKDIR}/.files.diff | ${SED} "s|^+||" | ${SORT} \ - >${WRKDIR}/.files.added; \ - ${GREP} '^-/' ${WRKDIR}/.files.diff | ${SED} "s|^-||" | ${SORT} \ - >${WRKDIR}/.files.deleted; \ - if ${TEST} `${WC} -l ${WRKDIR}/.files.deleted | \ - ${AWK} '{ print $$1; }'` -gt 0; \ - then \ - echo "*** The following files have been deleted from" \ - "${PREFIX}!"; \ - ${SED} "s|^| |" <${WRKDIR}/.files.deleted; \ - errors=1; \ - fi; \ - ${GREP} '^[A-Za-z]' ${PLIST} | ${SED} "s|^|${PREFIX}/|" | \ - ${SORT} >${WRKDIR}/.files.expected; \ - if ! ${CMP} -s ${WRKDIR}/.files.expected ${WRKDIR}/.files.added; then \ - echo "*** The PLIST does not match installed files!"; \ - echo " The following files were not expected in ${PREFIX}:";\ - diff -u ${WRKDIR}/.files.expected ${WRKDIR}/.files.added | \ - ${GREP} '^+[^+]' | ${SED} "s|^+| |"; \ - errors=1; \ - fi; \ - if [ ${CHECK_FILES_STRICT} = "YES" ] && \ - ! ${CMP} -s ${WRKDIR}/.sysconfdir.pre ${WRKDIR}/.sysconfdir.post; \ - then \ - echo "*** The package has modified ${PKG_SYSCONFDIR}" \ - "contents directly!"; \ - echo " The offending files/directories are:"; \ - diff -u ${WRKDIR}/.sysconfdir.pre ${WRKDIR}/.sysconfdir.post | \ - ${GREP} '^+[^+]' | ${SED} "s|^+| |"; \ - errors=1; \ - fi; \ - if [ ${CHECK_FILES_STRICT} = "YES" ] && \ - ! ${CMP} -s ${WRKDIR}/.varbase.pre ${WRKDIR}/.varbase.post; then \ - echo "*** The package has modified ${VARBASE} contents" \ - "directly!"; \ - echo " The offending files/directories are:"; \ - diff -u ${WRKDIR}/.varbase.pre ${WRKDIR}/.varbase.post |\ - ${GREP} '^+[^+]' | ${SED} "s|^+| |"; \ - errors=1; \ - fi; \ - ${RM} -f ${WRKDIR}/.files.added ${WRKDIR}/.files.deleted \ - ${WRKDIR}/.files.diff ${WRKDIR}/.files.expected; \ - ${TEST} $$errors -eq 0 -.endif - .PHONY: acquire-extract-lock acquire-patch-lock acquire-tools-lock .PHONY: acquire-wrapper-lock acquire-configure-lock acquire-build-lock .PHONY: acquire-install-lock acquire-package-lock -- cgit v1.2.3