blob: 595371b49e019d9633c73e82ec259c33667655c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/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" <<EOT
MCPU_CPP_INCLUDE_PATH = $base/forbidden-user;
MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/forbidden-system;
MCPU_CPP_AFTER_INCLUDE_PATH = $base/forbidden-after;
EOT
# --no-config skips every configuration file, but the runtime-derived installation
# default remains the effective system root.
HOME="$base/home" "$MCPU_CPP" --no-config -dsearch-dirs > "$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" <<EOT
search: $base/I
search: $base/isystem
search: $base/after
EOT
cmp "$base/nostdinc.expected" "$base/nostdinc.out"
# With no explicit directories, --no-config -nostdinc has no search entries.
HOME="$base/home" "$MCPU_CPP" --no-config -nostdinc -dsearch-dirs \
> "$base/empty.out"
test ! -s "$base/empty.out"
|