#!/bin/sh set -eu : "${CPU_LD:?}" "${CPU_RUN:?}" TMP=${TMPDIR:-/tmp}/libmcpu-tool-inspection-$$ mkdir -p "$TMP/home/.mcpu/etc" "$TMP/root/lib" trap 'rm -rf "$TMP"' EXIT HUP INT TERM HOME="$TMP/home" export HOME # --sys-root is self-contained, suppresses config files and needs no input. "$CPU_LD" --sys-root="$TMP/root" --dump-config > "$TMP/ld-sysroot-config.txt" "$CPU_RUN" --sys-root="$TMP/root" --dump-config > "$TMP/run-sysroot-config.txt" cmp "$TMP/ld-sysroot-config.txt" "$TMP/run-sysroot-config.txt" grep '^ runtime root: '"$TMP/root"'$' "$TMP/ld-sysroot-config.txt" >/dev/null grep '^ configuration: disabled by --sys-root$' "$TMP/ld-sysroot-config.txt" >/dev/null grep '^MCPU_LD_SYSTEM_LIBRARY_PATH = '"$TMP/root"'/lib;$' "$TMP/ld-sysroot-config.txt" >/dev/null cat > "$TMP/search.expected" < "$TMP/ld-search.txt" "$CPU_RUN" --sys-root="$TMP/root" --print-search-dirs > "$TMP/run-search.txt" cmp "$TMP/search.expected" "$TMP/ld-search.txt" cmp "$TMP/search.expected" "$TMP/run-search.txt" # The effective user configuration is visible and is identical in both tools. cat > "$HOME/.mcpu/etc/mcpu-ld.conf" < "$TMP/ld-user-config.txt" "$CPU_RUN" --dump-config > "$TMP/run-user-config.txt" cmp "$TMP/ld-user-config.txt" "$TMP/run-user-config.txt" grep '^ config: '"$HOME/.mcpu/etc/mcpu-ld.conf"' \[read\]$' "$TMP/ld-user-config.txt" >/dev/null grep '^MCPU_LD_SYSTEM_LIBRARY_PATH = '"$TMP/user/lib"';$' "$TMP/ld-user-config.txt" >/dev/null cat > "$TMP/user-search.expected" < "$TMP/ld-user-search.txt" "$CPU_RUN" --print-search-dirs > "$TMP/run-user-search.txt" cmp "$TMP/user-search.expected" "$TMP/ld-user-search.txt" cmp "$TMP/user-search.expected" "$TMP/run-user-search.txt" # Empty effective system path means an empty search list; there is no fallback. printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = ;' \ > "$HOME/.mcpu/etc/mcpu-ld.conf" printf '%s\n' 'libraries:' > "$TMP/empty.expected" "$CPU_LD" --print-search-dirs > "$TMP/ld-empty.txt" "$CPU_RUN" --print-search-dirs > "$TMP/run-empty.txt" cmp "$TMP/empty.expected" "$TMP/ld-empty.txt" cmp "$TMP/empty.expected" "$TMP/run-empty.txt" # A malformed config breaks normal inspection, but explicit suppression works. printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = broken' \ > "$HOME/.mcpu/etc/mcpu-ld.conf" if "$CPU_LD" --dump-config >/dev/null 2>&1; then echo "mcpu-ld --dump-config unexpectedly accepted malformed configuration" >&2 exit 1 fi if "$CPU_RUN" --print-search-dirs >/dev/null 2>&1; then echo "mcpu-run --print-search-dirs unexpectedly accepted malformed configuration" >&2 exit 1 fi "$CPU_LD" --no-config --dump-config > "$TMP/no-config.txt" grep '^ configuration: disabled by --no-config$' "$TMP/no-config.txt" >/dev/null "$CPU_RUN" --sys-root="$TMP/root" --print-search-dirs > /dev/null # Both public help texts expose the same diagnostic actions. "$CPU_LD" --help 2>&1 | grep -q -- '--dump-config' "$CPU_LD" --help 2>&1 | grep -q -- '--print-search-dirs' "$CPU_RUN" --help 2>&1 | grep -q -- '--dump-config' "$CPU_RUN" --help 2>&1 | grep -q -- '--print-search-dirs' exit 0