#!/bin/sh set -eu base="${TMPDIR-/tmp}/mcpu-cpp-no-config-defaults-$$" mkdir -p "$base/home/.mcpu/etc" "$base/I" "$base/isystem" "$base/after" trap 'rm -rf "$base"' EXIT HUP INT TERM runtime_root=$(cd "$(dirname "$MCPU_CPP")/.." && pwd -P) cat > "$base/home/.mcpu/etc/mcpu-cpp.conf" < "$base/search.out" grep "^search: $runtime_root/include/diff$" "$base/search.out" >/dev/null grep "^search: $runtime_root/include/dift$" "$base/search.out" >/dev/null grep "^search: $runtime_root/include/alg$" "$base/search.out" >/dev/null grep "^search: $runtime_root/include/as$" "$base/search.out" >/dev/null grep "^search: $runtime_root/include/avm$" "$base/search.out" >/dev/null grep "^search: $runtime_root/include/acs$" "$base/search.out" >/dev/null grep "^search: $runtime_root/include$" "$base/search.out" >/dev/null if grep "$base/forbidden" "$base/search.out" >/dev/null; then echo '--no-config read the user configuration file' >&2 exit 1 fi # The same runtime-derived value is visible through -dconfig and -v. HOME="$base/home" "$MCPU_CPP" --no-config -dconfig > "$base/config.out" grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $runtime_root/include;$" "$base/config.out" >/dev/null if grep "$base/forbidden" "$base/config.out" >/dev/null; then echo '--no-config leaked user configuration into -dconfig' >&2 exit 1 fi HOME="$base/home" "$MCPU_CPP" --no-config -v -dsearch-dirs \ > "$base/verbose-search.out" 2> "$base/verbose.out" grep "^config: MCPU_CPP_SYSTEM_INCLUDE_PATH=$runtime_root/include$" "$base/verbose.out" >/dev/null if grep "$base/forbidden" "$base/verbose.out" >/dev/null; then echo '--no-config leaked user configuration into -v' >&2 exit 1 fi # Explicit command-line classes retain their normative priority around the # runtime-derived system root. HOME="$base/home" "$MCPU_CPP" --no-config \ -I "$base/I" -isystem "$base/isystem" -idirafter "$base/after" \ -dsearch-dirs > "$base/ordered.out" first=$(sed -n '1p' "$base/ordered.out") second=$(sed -n '2p' "$base/ordered.out") last=$(tail -n 1 "$base/ordered.out") test "$first" = "search: $base/I" test "$second" = "search: $base/isystem" test "$last" = "search: $base/after" grep "^search: $runtime_root/include$" "$base/ordered.out" >/dev/null # -nostdinc, not --no-config, is the switch that suppresses the runtime-derived # standard-system include tree. Explicit classes remain visible. HOME="$base/home" "$MCPU_CPP" --no-config -nostdinc \ -I "$base/I" -isystem "$base/isystem" -idirafter "$base/after" \ -dsearch-dirs > "$base/nostdinc.out" cat > "$base/nostdinc.expected" < "$base/empty.out" test ! -s "$base/empty.out"