diff --git a/util/run-gnu-test.sh b/util/run-gnu-test.sh index 23d78ca625a..d36f534a101 100755 --- a/util/run-gnu-test.sh +++ b/util/run-gnu-test.sh @@ -2,7 +2,7 @@ # `run-gnu-test.bash [TEST]` # run GNU test (or all tests if TEST is missing/null) -# spell-checker:ignore (env/vars) GNULIB SRCDIR SUBDIRS OSTYPE MAKEFLAGS; (utils) shellcheck greadlink +# spell-checker:ignore (env/vars) GNULIB SRCDIR SUBDIRS OSTYPE MAKEFLAGS; (utils) shellcheck greadlink ginstall # ref: [How the GNU coreutils are tested](https://www.pixelbeat.org/docs/coreutils-testing.html) @@ # * note: to run a single test => `make check TESTS=PATH/TO/TEST/SCRIPT SUBDIRS=. VERBOSE=yes` @@ -35,6 +35,39 @@ export MAKEFLAGS cd "${path_GNU}" && echo "[ pwd:'${PWD}' ]" +# --- Self-heal: make the shared GNU harness point at THIS checkout ---------- +# ${path_GNU} is shared between sibling uutils checkouts; whichever one last ran +# build-gnu.sh leaves its own target dir patched into the Makefile/local.mk +# PATH, so the harness can silently run a stale/other build. Re-point the PATH +# (and re-create the multicall hardlinks) here so that running this script is +# enough to test the current tree - no full rebuild just because another +# checkout stole the PATH. +: "${PROFILE:=debug}" +if [ -n "${CARGO_TARGET_DIR}" ]; then + UU_BUILD_DIR="${CARGO_TARGET_DIR}/${PROFILE}" +else + UU_BUILD_DIR="${path_UUTILS}/target/${PROFILE}" +fi +if [ ! -x "${UU_BUILD_DIR}/coreutils" ]; then + echo "error: no coreutils binary at '${UU_BUILD_DIR}'." >&2 + echo " run 'bash util/build-gnu.sh' first (PROFILE=${PROFILE})." >&2 + exit 1 +fi +echo "Re-pointing GNU harness at '${UU_BUILD_DIR}'" +for binary in $("${UU_BUILD_DIR}/coreutils" --list); do + tgt="${UU_BUILD_DIR}/${binary}" + [ "${tgt}" -ef "${UU_BUILD_DIR}/coreutils" ] || ln -f "${UU_BUILD_DIR}/coreutils" "${tgt}" +done +# The GNU tests invoke `ginstall` rather than `install`. +[ -e "${UU_BUILD_DIR}/ginstall" ] || [ ! -e "${UU_BUILD_DIR}/install" ] || ln -f "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" +uu_path_sed="s/^[[:blank:]]*PATH=.*/ PATH='${UU_BUILD_DIR//\//\\/}\$(PATH_SEPARATOR)'\"\$\$PATH\" \\\/" +for f in Makefile tests/local.mk; do + if [ -f "${f}" ]; then sed -i "${uu_path_sed}" "${f}"; fi +done +# Keep Makefile newer than Makefile.in so make won't regenerate it and undo the patch. +if [ -f Makefile ]; then touch Makefile; fi +# --------------------------------------------------------------------------- + export RUST_BACKTRACE=1 # Determine if we have SELinux tests