summaryrefslogtreecommitdiff
path: root/tests/t0044-configured-search-order.sh
blob: 980790f302bd3849313fed0279298879dd1ad9bf (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
set -eu
base="${TMPDIR-/tmp}/mcpu-cpp-config-order-$$"
mkdir -p \
  "$base/cmd-I" \
  "$base/cmd-isystem" \
  "$base/config-as" \
  "$base/config-user" \
  "$base/system/as" \
  "$base/cmd-after" \
  "$base/config-after"
trap 'rm -rf "$base"' EXIT HUP INT TERM

cat > "$base/config" <<EOT
MCPU_CPP_AS_INCLUDE_PATH = $base/config-as;
MCPU_CPP_INCLUDE_PATH = $base/config-user;
MCPU_CPP_SYSTEM_INCLUDE_PATH = $base/system;
MCPU_CPP_AFTER_INCLUDE_PATH = $base/config-after;
EOT

cat > "$base/main.c" <<'EOT'
#lang "as"
#include <same.h>
#endlang
EOT

cat > "$base/cmd-I/same.h" <<'EOT'
from_explicit_I
#include_next <same.h>
EOT
cat > "$base/cmd-isystem/same.h" <<'EOT'
from_explicit_isystem
#include_next <same.h>
EOT
cat > "$base/config-as/same.h" <<'EOT'
from_config_language
#include_next <same.h>
EOT
cat > "$base/config-user/same.h" <<'EOT'
from_config_user
#include_next <same.h>
EOT
cat > "$base/system/as/same.h" <<'EOT'
from_system_language
#include_next <same.h>
EOT
cat > "$base/system/same.h" <<'EOT'
from_system_root
#include_next <same.h>
EOT
cat > "$base/cmd-after/same.h" <<'EOT'
from_explicit_idirafter
#include_next <same.h>
EOT
cat > "$base/config-after/same.h" <<'EOT'
from_config_after
EOT

# Deliberately scramble command-line option order.  Semantic classes, not
# argv order, define precedence.
"$MCPU_CPP" --config-file "$base/config" \
  -idirafter "$base/cmd-after" \
  -isystem "$base/cmd-isystem" \
  -I "$base/cmd-I" \
  "$base/main.c" -o "$base/out"

awk '
  /from_explicit_I/          { a = NR }
  /from_explicit_isystem/    { b = NR }
  /from_config_language/     { c = NR }
  /from_config_user/         { d = NR }
  /from_system_language/     { e = NR }
  /from_system_root/         { f = NR }
  /from_explicit_idirafter/  { g = NR }
  /from_config_after/        { h = NR }
  END { exit !(a && a < b && b < c && c < d && d < e && e < f && f < g && g < h) }
' "$base/out"

# An empty MCPU_CPP_SYSTEM_INCLUDE_PATH disables the complete configured
# system tree, including the automatically derived <lang> subdirectory.
cat > "$base/no-system.conf" <<EOT
MCPU_CPP_SYSTEM_INCLUDE_PATH = ;
EOT
cat > "$base/system-only.c" <<'EOT'
#lang "as"
#include <system-only.h>
#endlang
EOT
cat > "$base/system/as/system-only.h" <<'EOT'
system_only_header
EOT
if "$MCPU_CPP" --config-file "$base/no-system.conf" \
     "$base/system-only.c" -o "$base/no-system.out" 2>"$base/no-system.err"; then
  echo 'empty MCPU_CPP_SYSTEM_INCLUDE_PATH did not disable system includes' >&2
  exit 1
fi

# -nostdinc suppresses the configured system tree for one invocation but does
# not suppress explicit -isystem or either after class.
cat > "$base/nostdinc.c" <<'EOT'
#lang "as"
#include <nostdinc.h>
#endlang
EOT
cat > "$base/system/as/nostdinc.h" <<'EOT'
wrong_configured_system
EOT
cat > "$base/cmd-after/nostdinc.h" <<'EOT'
from_after_with_nostdinc
EOT
"$MCPU_CPP" --config-file "$base/config" -nostdinc \
  -idirafter "$base/cmd-after" "$base/nostdinc.c" -o "$base/nostdinc.out"
grep '^from_after_with_nostdinc$' "$base/nostdinc.out" >/dev/null
! grep '^wrong_configured_system$' "$base/nostdinc.out" >/dev/null