-
Notifications
You must be signed in to change notification settings - Fork 521
Expand file tree
/
Copy pathcheck_sw_sim_boundary.sh
More file actions
executable file
·143 lines (127 loc) · 5.03 KB
/
Copy pathcheck_sw_sim_boundary.sh
File metadata and controls
executable file
·143 lines (127 loc) · 5.03 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# CI guard for the sw/ ↔ sim/ + hw/ bidirectional isolation rule.
#
# Vortex's source tree separates the install-facing software stack
# (sw/kernel/, sw/runtime/) from the internal hardware (hw/*) and
# simulator (sim/*) implementations. The isolation is bidirectional:
#
# - sw/kernel and sw/runtime files MUST NOT include or reference
# anything in hw/* or sim/* (would bleed internals into the SDK).
#
# - sim/* and hw/* files MUST NOT include or reference anything in
# sw/kernel/ or sw/runtime/ (would couple the simulator/RTL to
# the install-facing surface).
#
# sw/common/ is the shared escape hatch — vortex-internal, never
# installed, accessible from all four layers.
#
# See AGENTS.md §6 and docs/coding_guidelines_cpp.md §8.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
fail=0
###############################################################################
# 1. #include scans
###############################################################################
scan_includes() {
local label="$1"; shift
local pattern="$1"; shift
local hits
hits=$(grep -rnE "$pattern" "$@" \
--include='*.c' --include='*.cpp' --include='*.cc' \
--include='*.h' --include='*.hpp' --include='*.sv' \
2>/dev/null || true)
if [ -n "$hits" ]; then
echo "ERROR: $label" >&2
echo >&2
echo "$hits" >&2
echo >&2
fail=1
fi
}
# sw/kernel + sw/runtime must not include from hw/ or sim/.
scan_includes \
"sw/kernel or sw/runtime references hw/ or sim/ headers:" \
'#[[:space:]]*include[[:space:]]*[<"]([./]*(hw|sim)/[^">]+)[>"]' \
"$ROOT/sw/kernel" "$ROOT/sw/runtime"
# sim + hw must not include from sw/kernel or sw/runtime.
# (sw/common is allowed via -Isw/common; sibling files within sw/common
# are themselves not the install-facing layer.)
SW_PUBLIC_HEADERS=$(cd "$ROOT/sw/kernel/include" 2>/dev/null && ls *.h 2>/dev/null | tr '\n' '|' | sed 's/|$//')$(cd "$ROOT/sw/runtime/include" 2>/dev/null && echo -n "|" && ls *.h 2>/dev/null | tr '\n' '|' | sed 's/|$//')
if [ -n "$SW_PUBLIC_HEADERS" ]; then
scan_includes \
"sim/ or hw/ references sw/kernel/include or sw/runtime/include headers:" \
"#[[:space:]]*include[[:space:]]*[<\"]($SW_PUBLIC_HEADERS|sw/(kernel|runtime)/[^\">]+)[>\"]" \
"$ROOT/sim" "$ROOT/hw"
fi
###############################################################################
# 2. Build-flag scans — Makefiles must not add cross-layer -I paths
###############################################################################
# Build-flag scans use `find` + `grep -l`-style filtering since some
# grep builds handle --include/--exclude inconsistently against
# arbitrary file extensions. Only true Makefile / .mk / .in files are
# scanned; stamp files (configure artifacts) are filtered explicitly.
scan_makefile_flags() {
local label="$1"; shift
local pattern="$1"; shift
local hits=""
local f
while IFS= read -r f; do
local m
m=$(grep -nE -- "$pattern" "$f" 2>/dev/null || true)
if [ -n "$m" ]; then
hits+="${f}:${m}"$'\n'
fi
done < <(find "$@" \
\( -name 'Makefile' -o -name '*.mk' -o -name '*.in' \) \
-not -name '*.stamp' \
-type f 2>/dev/null)
if [ -n "$hits" ]; then
echo "ERROR: $label" >&2
echo >&2
printf '%s' "$hits" >&2
echo >&2
fail=1
fi
}
# sim/* and hw/* Makefiles must not -I into sw/kernel or sw/runtime.
scan_makefile_flags \
"sim/ or hw/ Makefile adds -Isw/{kernel,runtime}/include:" \
'-I[^[:space:]]*sw/(kernel|runtime)/include' \
"$ROOT/sim" "$ROOT/hw"
# sw/kernel and sw/runtime Makefiles must not -I into hw/ or sim/.
# Exception: sw/runtime/opae links against the FPGA AFU shell defined
# in hw/syn/altera/opae/ — a HW-bound integration that can't be
# relocated. Skipped via path exclusion below.
SW_BUILD_DIRS=()
for d in "$ROOT/sw/kernel" "$ROOT/sw/runtime"; do
[ -d "$d" ] && SW_BUILD_DIRS+=("$d")
done
# Build the exclusion-aware list of files to scan.
sw_files=$(find "${SW_BUILD_DIRS[@]}" \
\( -name 'Makefile' -o -name '*.mk' -o -name '*.in' \) \
-not -name '*.stamp' \
-not -path '*/sw/runtime/opae/*' \
-type f 2>/dev/null)
if [ -n "$sw_files" ]; then
hits=""
while IFS= read -r f; do
m=$(grep -nE -- '-I[^[:space:]]*(hw|sim)/' "$f" 2>/dev/null || true)
if [ -n "$m" ]; then
hits+="${f}:${m}"$'\n'
fi
done <<< "$sw_files"
if [ -n "$hits" ]; then
echo "ERROR: sw/kernel or sw/runtime Makefile adds -Ihw/ or -Isim/:" >&2
echo >&2
printf '%s' "$hits" >&2
echo >&2
fail=1
fi
fi
###############################################################################
if [ "$fail" -ne 0 ]; then
echo "sw/ ↔ sim/+hw/ boundary check FAILED — see violations above." >&2
echo "See AGENTS.md §6 and docs/coding_guidelines_cpp.md §8." >&2
exit 1
fi
echo "sw/ ↔ sim/+hw/ boundary check OK"