blob: 0dcd85f2cdcad4153725aff5a6a717b991eabf12 (
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
74
|
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-sys-root-$$"
abs_root="$base/absolute-root"
rel_root="$base/relative-root"
home="$base/home"
mkdir -p "$abs_root/include/as" "$rel_root/include/as" \
"$home/.mcpu/etc" "$base/forbidden"
trap 'rm -rf "$base"' EXIT HUP INT TERM
cat > "$abs_root/include/as/sys-root.h" <<'EOT'
int from_absolute_sys_root = 103;
EOT
cat > "$rel_root/include/as/sys-root.h" <<'EOT'
int from_relative_sys_root = 104;
EOT
cat > "$home/.mcpu/etc/mcpu-cpp.conf" <<EOT
MCPU_CPP_INCLUDE_PATH = $base/forbidden;
MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/forbidden;
MCPU_CPP_SYS_ROOT_SENTINEL = user-config-must-not-be-read;
EOT
cat > "$base/explicit.conf" <<EOT
MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/forbidden;
MCPU_CPP_SYS_ROOT_SENTINEL = explicit-config-must-not-be-read;
EOT
cat > "$base/main.c" <<'EOT'
#lang "as"
#include <sys-root.h>
#endlang
EOT
# An absolute --sys-root replaces the runtime root for the system include tree
# and implies --no-config, including for an explicitly named config file.
HOME="$home" "$MCPU_CPP" --sys-root="$abs_root" \
--config-file "$base/explicit.conf" -dconfig > "$base/absolute.config"
grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $abs_root/include;$" \
"$base/absolute.config" >/dev/null
if grep 'MCPU_CPP_SYS_ROOT_SENTINEL\|forbidden' "$base/absolute.config" >/dev/null; then
echo '--sys-root read a configuration file' >&2
exit 1
fi
HOME="$home" "$MCPU_CPP" --sys-root="$abs_root" \
"$base/main.c" -o "$base/absolute.out"
grep '^int from_absolute_sys_root = 103;$' "$base/absolute.out" >/dev/null
# A relative --sys-root is interpreted relative to the invocation working
# directory and becomes an absolute effective system include root.
(
cd "$base"
HOME="$home" "$MCPU_CPP" --sys-root=relative-root -dconfig \
> "$base/relative.config"
HOME="$home" "$MCPU_CPP" --sys-root=relative-root \
"$base/main.c" -o "$base/relative.out"
)
grep "^MCPU_CPP_SYSTEM_INCLUDE_PATH = $rel_root/include;$" \
"$base/relative.config" >/dev/null
grep '^int from_relative_sys_root = 104;$' "$base/relative.out" >/dev/null
# The separated spelling is accepted as the same option.
HOME="$home" "$MCPU_CPP" --sys-root "$abs_root" -dsearch-dirs \
> "$base/separate.search"
grep "^search: $abs_root/include/as$" "$base/separate.search" >/dev/null
grep "^search: $abs_root/include$" "$base/separate.search" >/dev/null
# An empty system root is never accepted.
if HOME="$home" "$MCPU_CPP" --sys-root= -dconfig \
> "$base/empty.out" 2> "$base/empty.err"; then
echo 'empty --sys-root unexpectedly accepted' >&2
exit 1
fi
|