tools/check-buildtools.sh: a build tool built for the target instead of the host is reported (t0197)
Reads noinst_PROGRAMS from the generated Makefiles of a finished build's work directory and looks at each program (and its libtool .libs/ twin) with file(1): 'for NetBSD' on a cross host is a finding. Reading the Makefiles, not the files on disk, keeps an old binary that no Makefile names any more from counting (first version compared names with the PLIST and missed doc_utils, whose programs share their names with installed ones). Measured on the work directories of the green build (userland-2026-11-14s.log): wm/mcde 8 host tools, restore and testcgm for the target; x11/mcde-motif 4 host tools. Synthetic tree: target tool, .libs twin, stale EXTRA_PROGRAMS binary, missing program, continuation lines, an unresolved $(am__EXEEXT_1) -- all as expected. Two doc_utils programs are listed as known (docs are off, pkgsrc-cross.mk.conf:238); not wired into userland.sh until a run can test it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3d4c38bb8b
commit
5c772036d6
1 file changed
+158
Executable
+158
@@ -0,0 +1,158 @@
|
||||
#!/bin/sh
|
||||
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
||||
#
|
||||
# check-buildtools.sh -- the programs a package builds for its own build must
|
||||
# be binaries of the build host
|
||||
#
|
||||
# usage: tools/check-buildtools.sh [PKGPATH ...]
|
||||
# no arguments: the forks of ext/ (wm/mcde, x11/mcde-motif)
|
||||
#
|
||||
# MCDE and its Motif run programs while they are built (tradcpp, makestrs, wml,
|
||||
# mkdbd, mkcatdefs ...). Compiled for the target, such a program stops the
|
||||
# cross build with "not found" or "Exec format error", far from the cause
|
||||
# (tasksd t0197, build/logs/userland-2026-11-14j.log:7715ff). A program that is
|
||||
# built and not installed is automake's noinst_PROGRAMS, so this reads that
|
||||
# variable from the generated Makefiles of a finished build's work directory
|
||||
# and looks at each program (and its libtool .libs/ twin) with file(1): one
|
||||
# "for NetBSD" is a finding. The Makefiles, not the files on disk, say what
|
||||
# counts: an old binary that no Makefile names any more (EXTRA_PROGRAMS, a
|
||||
# removed tool) is left alone. A program nothing runs should not be built at
|
||||
# all: EXTRA_PROGRAMS in its Makefile.am.
|
||||
#
|
||||
# A native build on NetBSD has no host/target difference: nothing to check.
|
||||
# A package whose work directory is not there (not built, or cleaned) is
|
||||
# reported as skipped, never as good.
|
||||
#
|
||||
# Measured 2026-11-14 on the work directories of the green build
|
||||
# (build/logs/userland-2026-11-14s.log): wm/mcde had 8 host tools (tradcpp,
|
||||
# lineToData, mk_fonts_alias, mkdbd, mkcatdefs, merge, dfiles, pmaker) and
|
||||
# restore and testcgm built for the target, run by nothing; x11/mcde-motif 4
|
||||
# host tools (wml, wmldbcreate, wmluiltok, makestrs).
|
||||
#
|
||||
# Known, and only these: programs/dtdocbook/doc_utils builds dtdocbook2infolib
|
||||
# and validator for the target. They are the in-tree copies of the docbook
|
||||
# tools that doc/ would run to build man pages and help volumes; the
|
||||
# documentation is off (tools/pkgsrc-cross.mk.conf:238 PKG_OPTIONS.cde=
|
||||
# -docs), so nothing runs them. With +docs the cross build needs them (and
|
||||
# the whole docbook chain behind them) as host binaries: take the two names
|
||||
# out of known_target() then, and make them so (tasksd t0197).
|
||||
#
|
||||
# WORKROOT (default build/pkgsrc-work) is where the work directories are.
|
||||
# Exit status 0: nothing wrong; 1: a build tool for the target; 2: usage.
|
||||
|
||||
set -u
|
||||
|
||||
TOP=$(cd "$(dirname "$0")/.." && pwd)
|
||||
WORKROOT=${WORKROOT:-$TOP/build/pkgsrc-work}
|
||||
|
||||
[ $# -gt 0 ] || set -- wm/mcde x11/mcde-motif
|
||||
|
||||
if [ "$(uname -s)" = NetBSD ]; then
|
||||
echo "check-buildtools: native build, every binary is a host binary: nothing to check"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
tmp=$(mktemp -d "${TMPDIR:-/tmp}/buildtools.XXXXXX") || exit 2
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
|
||||
# the names in noinst_PROGRAMS of one Makefile, one a line, without $(EXEEXT);
|
||||
# a name that is still a make variable ($(am__EXEEXT_1) of a conditional) is
|
||||
# printed as "?" so that it is counted and not guessed
|
||||
noinst_programs()
|
||||
{
|
||||
awk '
|
||||
/^noinst_PROGRAMS[ \t]*=/ {
|
||||
s = $0
|
||||
while (s ~ /\\$/) {
|
||||
sub(/\\$/, "", s)
|
||||
if ((getline l) <= 0)
|
||||
break
|
||||
s = s " " l
|
||||
}
|
||||
sub(/^noinst_PROGRAMS[ \t]*=/, "", s)
|
||||
n = split(s, a, /[ \t]+/)
|
||||
for (i = 1; i <= n; i++) {
|
||||
if (a[i] == "")
|
||||
continue
|
||||
sub(/\$\(EXEEXT\)$/, "", a[i])
|
||||
print (a[i] ~ /\$/) ? "?" : a[i]
|
||||
}
|
||||
}' "$1"
|
||||
}
|
||||
|
||||
# a program built for the target that nothing runs, with the reason in the
|
||||
# header above; the argument is the path relative to the work directory
|
||||
known_target()
|
||||
{
|
||||
case $1 in
|
||||
*/programs/dtdocbook/doc_utils/.libs/dtdocbook2infolib | \
|
||||
*/programs/dtdocbook/doc_utils/.libs/validator)
|
||||
return 0 ;;
|
||||
esac
|
||||
return 1
|
||||
}
|
||||
|
||||
bad=0
|
||||
checked=0
|
||||
for pkg in "$@"; do
|
||||
work=$(ls -d "$WORKROOT/$pkg"/work.* 2> /dev/null | head -1)
|
||||
if [ -z "$work" ]; then
|
||||
echo "check-buildtools: $pkg: skipped, no work directory under $WORKROOT/$pkg"
|
||||
continue
|
||||
fi
|
||||
|
||||
# the Makefiles of the package's own tree, not pkgsrc's staging
|
||||
find "$work" \
|
||||
\( -name .buildlink -o -name .cwrapper -o -name .tools \
|
||||
-o -name .wrapper -o -name .destdir \) -prune -o \
|
||||
-type f -name Makefile -print > "$tmp/makefiles"
|
||||
if [ ! -s "$tmp/makefiles" ]; then
|
||||
echo "check-buildtools: $pkg: skipped, no Makefile in $work (not configured)"
|
||||
continue
|
||||
fi
|
||||
|
||||
host=0
|
||||
target=0
|
||||
known=0
|
||||
unparsed=0
|
||||
while IFS= read -r mf; do
|
||||
dir=${mf%/*}
|
||||
for name in $(noinst_programs "$mf"); do
|
||||
if [ "$name" = "?" ]; then
|
||||
unparsed=$((unparsed + 1))
|
||||
continue
|
||||
fi
|
||||
# a libtool program is a wrapper script with the binary in .libs/
|
||||
for cand in "$dir/$name" "$dir/.libs/$name"; do
|
||||
[ -f "$cand" ] || continue
|
||||
desc=$(file "$cand" 2> /dev/null)
|
||||
case $desc in
|
||||
*' ELF '*'for NetBSD'*)
|
||||
if known_target "${cand#"$work"/}"; then
|
||||
known=$((known + 1))
|
||||
continue
|
||||
fi
|
||||
echo "check-buildtools: $pkg: built for NetBSD, run by the build?: ${cand#"$work"/}"
|
||||
target=$((target + 1)) ;;
|
||||
*' ELF '*)
|
||||
host=$((host + 1)) ;;
|
||||
esac
|
||||
done
|
||||
done
|
||||
done < "$tmp/makefiles"
|
||||
|
||||
echo "check-buildtools: $pkg: $host host build tool(s), $target for the target, $known known for the target, $unparsed name(s) not resolved"
|
||||
bad=$((bad + target))
|
||||
checked=$((checked + 1))
|
||||
done
|
||||
|
||||
if [ "$bad" -ne 0 ]; then
|
||||
echo "check-buildtools: $bad build tool(s) built for the target instead of the host"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$checked" -eq 0 ]; then
|
||||
echo "check-buildtools: nothing checked (no package was built)"
|
||||
exit 0
|
||||
fi
|
||||
echo "check-buildtools: ok, $checked package(s) checked"
|
||||
exit 0
|
||||
Reference in new issue
Block a user