aboutsummaryrefslogtreecommitdiffstats
path: root/Mk/Scripts
diff options
context:
space:
mode:
authormandree <mandree@FreeBSD.org>2013-11-01 03:07:38 +0800
committermandree <mandree@FreeBSD.org>2013-11-01 03:07:38 +0800
commitedafa1876d05d2c6642ec462b7fbf55652f3ba79 (patch)
treec17d6b9d2abf5fa7ceb6a5b58e1de85e4e6daac8 /Mk/Scripts
parent30a71b852b77a1c426c40c2c71a2164d3ee39b42 (diff)
downloadfreebsd-ports-gnome-edafa1876d05d2c6642ec462b7fbf55652f3ba79.tar.gz
freebsd-ports-gnome-edafa1876d05d2c6642ec462b7fbf55652f3ba79.tar.zst
freebsd-ports-gnome-edafa1876d05d2c6642ec462b7fbf55652f3ba79.zip
bsd.stage.mk: Fewer false positives, much faster, easier maintenance.
Bugfixes: * @cmd in pkg-plist is now properly handled. - It was previously treated the same as though there was a directory following it, missing the prefix. (ordering matters in case...esac) - Due to the cwd=${PREFIX} inside the while read line loop, state tracking was broken and every new line assumed that cwd were the prefix. * stage-qa no longer complains about unstripped binaries if debugging is active (WITH_DEBUG set && WITHOUT_DEBUG unset). * The compress-man target uses ECHO_MSG, not ECHO_CMD, to print its build step. Additions: * The plist parser now understands @unexec rmdir ... || ... lines, including those with redirections, so that there are no false positives for directories stripped with @unexec rmdir (usually happens on stuff installed outside $PREFIX, as in /var). * The system's root and var mtrees are now also expanded to avoid false @dirrm positives if a port installs directories under /var and has to create parents in the stagedir that are present in a fully installed system (i. e. in the real $PREFIX). * Given that pkg_create is deemed beyond repair with respect to deleting files outside prefix, generate @unexec rmdir statements for such directories, rather than @dirrmtry, to sidestep the problem. Speedups: * the orphan check now generates sorted lists of staged files, and plisted/mtree files, and compares them with comm(1). This saves us the overhead of running one grep process per file and up to two per directory, and defers the actual list processing to a shell utility. Complexity has not changed, but overhead per item has. * the orphan check now uses one file for directories and one file for files mentioned in pkg-plist, so we need not decorate them with "dir " and parse them out any longer. * qa.sh's shebang scanner only looks at the first line of a file, sed is told to exit from the 2nd line. Other Changes: * Split the makeplist/check-orphans logic out of bsd.stage.mk, it is too unwieldy to maintain in make-escaped shell syntax, and permits shell tracing with "SH=sh -x" (including quotes!) * Unify the functions "makeplist" and "check-orphans" in one script. The only difference is that makeplist assumes an empty pkg-plist, whereas check-orphans parses it. * overhaul the mtree extractor, avoiding awk. Reviewed by: bapt Approved by: portmgr (bapt)
Diffstat (limited to 'Mk/Scripts')
-rw-r--r--Mk/Scripts/check-stagedir.sh113
-rw-r--r--Mk/Scripts/qa.sh5
2 files changed, 116 insertions, 2 deletions
diff --git a/Mk/Scripts/check-stagedir.sh b/Mk/Scripts/check-stagedir.sh
new file mode 100644
index 000000000000..cb07479c2329
--- /dev/null
+++ b/Mk/Scripts/check-stagedir.sh
@@ -0,0 +1,113 @@
+#!/bin/sh
+# ports/Mk/Scripts/check-stagedir.sh - called from ports/Mk/bsd.stage.mk
+
+set -e
+export LC_ALL=C
+
+# lists an mtree file's contents, prefixed to dir.
+listmtree() { # mtreefile prefix
+ {
+ echo '#mtree'
+ sed 's/nochange$//;' $1
+ } | tar -tf- | sed "s,^,$2/,;s,^$2/\.$,$2,;s,^$,/,"
+}
+
+# obtain operating mode from command line
+makeplist=0
+case "$1" in
+ orphans) ;;
+ makeplist) makeplist=1 ;;
+ *) echo >&2 "Usage: $0 {orphans|makelist}" ; exit 1 ;;
+esac
+
+# validate environment
+envfault=0
+for i in STAGEDIR PREFIX LOCALBASE WRKDIR WRKSRC MTREE_FILE \
+ TMPPLIST DATADIR DOCSDIR EXAMPLESDIR
+do
+ if eval test -z "\$$i" ; then
+ echo >&2 "Environment variable $i undefined. Aborting."
+ envfault=1
+ fi
+done
+if [ $envfault -ne 0 ] ; then
+ exit 1
+fi
+
+set -u
+
+#### EXPAND TMPPLIST TO ABSOLUTE PATHS, SPLITTING FILES AND DIRS TO
+# Use file descriptors 1 and 3 so that the while loop can write
+# files to the pipe and dirs to a separate file.
+if [ $makeplist = 0 ] ; then
+ # check for orphans
+ cwd=${PREFIX}
+ while read line; do
+ case $line in
+ @dirrm*|'@unexec rmdir'*)
+ line="$(printf %s "$line" \
+ | sed -Ee 's/\|\|.*//;s|[0-9]*[[:space:]]*>[&]?[[:space:]]*[^[:space:]]+||g' \
+ -e "/^@unexec[[:space:]]+rmdir/s|([^%])%D([^%])|\1${PREFIX}\2|g" \
+ -e '/^@unexec[[:space:]]+rmdir/s|"(.*)"[[:space:]]+|\1|g' \
+ -e 's/@unexec[[:space:]]+rmdir[[:space:]]+//' \
+ -e 's/@dirrm(try)?[[:space:]]+//' \
+ -e 's/[[:space:]]+$//')"
+ case "$line" in
+ /*) echo >&3 "$line" ;;
+ *) echo >&3 "$cwd/$line" ;;
+ esac
+ ;;
+ # order matters here - we must check @cwd first because
+ # otherwise the @cwd* would also match it first, shadowing the
+ # @cwd) line.
+ @cwd|@cd) cwd=${PREFIX} ;;
+ @cwd*|@cd*) set -- $line ; cwd=$2 ;;
+ @*) ;;
+ /*) echo "$line" ;;
+ *) echo "$cwd/$line" ;;
+ esac
+ done < ${TMPPLIST} 3>${WRKDIR}/.plist-dirs-unsorted | sort >${WRKDIR}/.plist-files
+else
+ # generate plist - pretend the plist had been empty
+ : >${WRKDIR}/.plist-dirs-unsorted
+ : >${WRKDIR}/.plist-files
+fi
+
+### PRODUCE MTREE FILE
+{
+ listmtree /etc/mtree/BSD.root.dist ""
+ #listmtree /etc/mtree/BSD.usr.dist /usr
+ listmtree /etc/mtree/BSD.var.dist /var
+
+ if [ -n "${MTREE_FILE}" ]; then
+ listmtree "${MTREE_FILE}" "${PREFIX}"
+ fi
+
+ a=${PREFIX}
+ while :; do
+ a=${a%/*}
+ [ -z "${a}" ] && break
+ echo ${a}
+ done
+} > ${WRKDIR}/.mtree
+
+### HANDLE FILES
+find ${STAGEDIR} -type f -o -type l | sort | sed -e "s,${STAGEDIR},," >${WRKDIR}/.staged-files
+comm -13 ${WRKDIR}/.plist-files ${WRKDIR}/.staged-files \
+ | sed \
+ -e "s,${DOCSDIR},%%PORTDOCS%%%%DOCSDIR%%,g" \
+ -e "s,${EXAMPLESDIR},%%PORTEXAMPLES%%%%EXAMPLESDIR%%,g" \
+ -e "s,${DATADIR},%%DATADIR%%,g" \
+ -e "s,${PREFIX}/,,g" | grep -v "^share/licenses" || [ $? = 1 ]
+
+### HANDLE DIRS
+cat ${WRKDIR}/.plist-dirs-unsorted ${WRKDIR}/.mtree | sort -u >${WRKDIR}/.traced-dirs
+find ${STAGEDIR} -type d | sed -e "s,^${STAGEDIR},,;/^$/d" | sort >${WRKDIR}/.staged-dirs
+comm -13 ${WRKDIR}/.traced-dirs ${WRKDIR}/.staged-dirs \
+ | sort -r | sed \
+ -e "s,\(.*\)${DOCSDIR},%%PORTDOCS%%\1%%DOCSDIR%%,g" \
+ -e "s,\(.*\)${EXAMPLESDIR},%%PORTEXAMPLES%%\1%%EXAMPLESDIR%%,g" \
+ -e "s,${DATADIR},%%DATADIR%%,g" \
+ -e "s,${PREFIX}/,,g" \
+ -e 's,^,@dirrmtry ,' \
+ -e 's,@dirrmtry \(/.*\),@unexec rmdir >/dev/null 2>\&1 \1 || :,' | grep -v "^@dirrmtry share/licenses" || [ $? = 1 ]
diff --git a/Mk/Scripts/qa.sh b/Mk/Scripts/qa.sh
index b3e022fdc654..e2f49a40d73f 100644
--- a/Mk/Scripts/qa.sh
+++ b/Mk/Scripts/qa.sh
@@ -18,7 +18,7 @@ err() {
shebang() {
rc=0
for f in `find ${STAGEDIR} -type f`; do
- interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p' $f)
+ interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p;2q' $f)
case "$interp" in
"") ;;
/usr/bin/env) ;;
@@ -62,7 +62,8 @@ paths() {
# For now do not raise an error, just warnings
stripped() {
- [ -x /usr/bin/file ] || return
+ [ -x /usr/bin/file ] || return # this is fatal
+ [ -n "${STRIP}" ] || return 0
for f in `find ${STAGEDIR} -type f`; do
output=`/usr/bin/file ${f}`
case "${output}" in