Skip to content

Commit 593d126

Browse files
committed
test-infra: give each leg its own build dir so parallel legs never collide
scripts/build.sh, test.sh, and clean.sh hardcoded build/c, and clean.sh rm -rf'd it unconditionally. Running the container legs concurrently with a native macOS build then had them delete and relink each other's objects mid-build (ld "file cannot be opened"). Thread a BUILD_DIR through the three scripts (default build/c) and point every compose service at its own dir (build/linux-arm64, build/linux-amd64, build/win-cross, build/alpine); native macOS keeps build/c exclusively. Also run the lint service in CI-parity mode (--ci: cppcheck + clang-format only), matching CI, since clang-tidy is in neither the lint image nor the CI job. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent ba91c6c commit 593d126

4 files changed

Lines changed: 48 additions & 31 deletions

File tree

‎scripts/build.sh‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ done
3333
# shellcheck source=env.sh
3434
source "$ROOT/scripts/env.sh"
3535

36-
# Parse remaining arguments
36+
# Parse remaining arguments. BUILD_DIR is tracked for the clean step below so
37+
# containerized legs can build in their own directory instead of deleting and
38+
# clobbering the host's native build/c artifacts.
3739
WITH_UI=false
3840
VERSION=""
41+
BUILD_DIR="build/c"
3942
EXTRA_MAKE_ARGS=()
4043

4144
prev_arg=""
@@ -55,6 +58,10 @@ for arg in "$@"; do
5558
;;
5659
--arch|--arch=*)
5760
;; # already handled
61+
BUILD_DIR=*)
62+
BUILD_DIR="${arg#BUILD_DIR=}"
63+
EXTRA_MAKE_ARGS+=("$arg")
64+
;;
5865
CC=*|CXX=*)
5966
export "${arg}"
6067
EXTRA_MAKE_ARGS+=("$arg")
@@ -85,7 +92,7 @@ echo " ui=$WITH_UI version=${VERSION:-dev}"
8592
verify_compiler "$CC"
8693

8794
# Step 1: Clean C build artifacts only (not node_modules — npm ci handles that)
88-
rm -rf "$ROOT/build/c"
95+
rm -rf "${ROOT:?}/${BUILD_DIR}"
8996

9097
# Step 2: Build (Makefile applies $ARCHFLAGS for the target arch on macOS)
9198
if $WITH_UI; then
@@ -96,4 +103,4 @@ else
96103
CFLAGS_EXTRA="$CFLAGS_EXTRA" "${EXTRA_MAKE_ARGS[@]+"${EXTRA_MAKE_ARGS[@]}"}"
97104
fi
98105

99-
echo "=== Build complete: build/c/codebase-memory-mcp ==="
106+
echo "=== Build complete: ${BUILD_DIR}/codebase-memory-mcp ==="

‎scripts/clean.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ set -euo pipefail
1111

1212
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1313

14-
echo "=== Cleaning build artifacts ==="
14+
# Containerized legs build in their own directory (BUILD_DIR env) so a
15+
# container clean never deletes the host's native build/c mid-build.
16+
BUILD_DIR="${BUILD_DIR:-build/c}"
17+
18+
echo "=== Cleaning build artifacts ($BUILD_DIR) ==="
1519

1620
# C build artifacts
17-
rm -rf "$ROOT/build/c"
21+
rm -rf "${ROOT:?}/${BUILD_DIR}"
1822

1923
# Frontend build artifacts
2024
rm -rf "$ROOT/graph-ui/dist"

‎scripts/test.sh‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ done
3838
# shellcheck source=env.sh
3939
source "$ROOT/scripts/env.sh"
4040

41-
# Forward CC/CXX and collect make-passthrough args
41+
# Forward CC/CXX and collect make-passthrough args. BUILD_DIR is honored for
42+
# the explicit target path below so containerized legs can build in their own
43+
# directory instead of clobbering the host's native build/c artifacts.
4244
MAKE_ARGS=""
45+
BUILD_DIR="build/c"
4346
for arg in "$@"; do
4447
case "$arg" in
4548
CC=*|CXX=*) export "${arg}" ;;
4649
--arch|--arch=*) ;; # already handled
4750
arm64|x86_64) ;; # already handled
51+
BUILD_DIR=*) BUILD_DIR="${arg#BUILD_DIR=}"; MAKE_ARGS="$MAKE_ARGS $arg" ;;
4852
*=*) MAKE_ARGS="$MAKE_ARGS $arg" ;; # forward any VAR=VAL to make
4953
esac
5054
done
@@ -66,15 +70,15 @@ bash "$ROOT/tests/test_security_fuzz_harness.sh"
6670
# Verify compiler supports target arch
6771
verify_compiler "$CC"
6872

69-
# Step 1: Clean
70-
scripts/clean.sh
73+
# Step 1: Clean (scoped to this leg's build directory)
74+
BUILD_DIR="$BUILD_DIR" scripts/clean.sh
7175

7276
# Step 2 + 3: Build, then run every suite as parallel processes (identical
7377
# gate quality — see the ZERO-LOSS CONTRACT in scripts/run-tests-parallel.sh:
7478
# the suite set is enumerated from the runner itself and union-guarded, and
7579
# pass/fail/skip totals aggregate to the same numbers as the sequential run).
7680
# CBM_TEST_SEQUENTIAL=1 restores the single-process runner.
77-
make -j"$NPROC" -f Makefile.cbm build/c/test-runner $MAKE_ARGS
81+
make -j"$NPROC" -f Makefile.cbm "$BUILD_DIR/test-runner" $MAKE_ARGS
7882
if [ "${CBM_TEST_SEQUENTIAL:-0}" = "1" ]; then
7983
make -f Makefile.cbm test $MAKE_ARGS
8084
else

‎test-infrastructure/docker-compose.yml‎

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ services:
2525
environment:
2626
CCACHE_DIR: /root/.ccache
2727
CCACHE_MAXSIZE: 1500M
28-
command: ["CC=gcc", "CXX=g++"]
28+
command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-arm64"]
2929

3030
test-amd64:
3131
build:
@@ -39,7 +39,7 @@ services:
3939
environment:
4040
CCACHE_DIR: /root/.ccache
4141
CCACHE_MAXSIZE: 1500M
42-
command: ["CC=gcc", "CXX=g++"]
42+
command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-amd64"]
4343

4444
# ── Linux production build (-O2 -Werror) ───────────────────
4545
build:
@@ -50,7 +50,7 @@ services:
5050
volumes:
5151
- ..:/src
5252
entrypoint: ["scripts/build.sh"]
53-
command: ["CC=gcc", "CXX=g++"]
53+
command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-arm64"]
5454

5555
build-amd64:
5656
build:
@@ -60,7 +60,7 @@ services:
6060
volumes:
6161
- ..:/src
6262
entrypoint: ["scripts/build.sh"]
63-
command: ["CC=gcc", "CXX=g++"]
63+
command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/linux-amd64"]
6464

6565
# ── Windows cross-compile + test (llvm-mingw + Wine) ────────
6666
build-windows:
@@ -79,12 +79,13 @@ services:
7979
volumes:
8080
- ..:/src
8181
command: >-
82-
make -j4 -f Makefile.cbm clean-c &&
83-
make -j4 -f Makefile.cbm build/c/test-runner
82+
make -j4 -f Makefile.cbm clean-c BUILD_DIR=build/win-cross &&
83+
make -j4 -f Makefile.cbm build/win-cross/test-runner
84+
BUILD_DIR=build/win-cross
8485
CC=x86_64-w64-mingw32-clang
8586
CXX=x86_64-w64-mingw32-clang++ &&
8687
echo '=== Running tests under Wine ===' &&
87-
WINEDEBUG=-all wine64 build/c/test-runner.exe &&
88+
WINEDEBUG=-all wine64 build/win-cross/test-runner.exe &&
8889
echo '=== Windows test: OK ==='
8990
9091
# ── Smoke test (build + run smoke-test.sh) ──────────────────
@@ -98,8 +99,8 @@ services:
9899
entrypoint: ["/bin/bash", "-c"]
99100
command:
100101
- |
101-
scripts/build.sh CC=gcc CXX=g++ &&
102-
scripts/smoke-test.sh ./build/c/codebase-memory-mcp
102+
scripts/build.sh CC=gcc CXX=g++ BUILD_DIR=build/linux-arm64 &&
103+
scripts/smoke-test.sh ./build/linux-arm64/codebase-memory-mcp
103104
104105
smoke-amd64:
105106
build:
@@ -111,8 +112,8 @@ services:
111112
entrypoint: ["/bin/bash", "-c"]
112113
command:
113114
- |
114-
scripts/build.sh CC=gcc CXX=g++ &&
115-
scripts/smoke-test.sh ./build/c/codebase-memory-mcp
115+
scripts/build.sh CC=gcc CXX=g++ BUILD_DIR=build/linux-amd64 &&
116+
scripts/smoke-test.sh ./build/linux-amd64/codebase-memory-mcp
116117
117118
# ── Windows smoke (cross-compile + Wine) ──────────────────
118119
smoke-windows:
@@ -125,9 +126,9 @@ services:
125126
entrypoint: ["/bin/bash", "-c"]
126127
command:
127128
- |
128-
scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ &&
129-
mv build/c/codebase-memory-mcp build/c/codebase-memory-mcp.exe 2>/dev/null || true &&
130-
WINEDEBUG=-all scripts/smoke-test.sh ./build/c/codebase-memory-mcp.exe
129+
scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ BUILD_DIR=build/win-cross &&
130+
mv build/win-cross/codebase-memory-mcp build/win-cross/codebase-memory-mcp.exe 2>/dev/null || true &&
131+
WINEDEBUG=-all scripts/smoke-test.sh ./build/win-cross/codebase-memory-mcp.exe
131132
132133
# ── Windows soak (cross-compile + Wine) ───────────────────
133134
soak-windows:
@@ -140,9 +141,9 @@ services:
140141
entrypoint: ["/bin/bash", "-c"]
141142
command:
142143
- |
143-
scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ &&
144-
mv build/c/codebase-memory-mcp build/c/codebase-memory-mcp.exe 2>/dev/null || true &&
145-
CBM_DIAGNOSTICS=1 WINEDEBUG=-all scripts/soak-test.sh ./build/c/codebase-memory-mcp.exe 10
144+
scripts/build.sh CC=x86_64-w64-mingw32-clang CXX=x86_64-w64-mingw32-clang++ BUILD_DIR=build/win-cross &&
145+
mv build/win-cross/codebase-memory-mcp build/win-cross/codebase-memory-mcp.exe 2>/dev/null || true &&
146+
CBM_DIAGNOSTICS=1 WINEDEBUG=-all scripts/soak-test.sh ./build/win-cross/codebase-memory-mcp.exe 10
146147
147148
# ── Linux portable (Alpine musl static) ────────────────────
148149
test-portable:
@@ -153,7 +154,7 @@ services:
153154
volumes:
154155
- ..:/src
155156
entrypoint: ["bash", "scripts/test.sh"]
156-
command: ["CC=gcc", "CXX=g++"]
157+
command: ["CC=gcc", "CXX=g++", "BUILD_DIR=build/alpine"]
157158

158159
build-portable:
159160
build:
@@ -163,7 +164,7 @@ services:
163164
volumes:
164165
- ..:/src
165166
entrypoint: ["bash", "scripts/build.sh"]
166-
command: ["CC=gcc", "CXX=g++", "STATIC=1"]
167+
command: ["CC=gcc", "CXX=g++", "STATIC=1", "BUILD_DIR=build/alpine"]
167168

168169
smoke-portable:
169170
build:
@@ -175,10 +176,10 @@ services:
175176
entrypoint: ["bash", "-c"]
176177
command:
177178
- |
178-
scripts/build.sh CC=gcc CXX=g++ STATIC=1 &&
179-
file build/c/codebase-memory-mcp | grep -q "statically linked" &&
179+
scripts/build.sh CC=gcc CXX=g++ STATIC=1 BUILD_DIR=build/alpine &&
180+
file build/alpine/codebase-memory-mcp | grep -q "statically linked" &&
180181
echo "=== Verified: statically linked ===" &&
181-
scripts/smoke-test.sh ./build/c/codebase-memory-mcp
182+
scripts/smoke-test.sh ./build/alpine/codebase-memory-mcp
182183
183184
# ── Lint ────────────────────────────────────────────────────
184185
lint:
@@ -187,6 +188,7 @@ services:
187188
dockerfile: test-infrastructure/Dockerfile.lint
188189
volumes:
189190
- ..:/src
191+
command: ["--ci", "CLANG_FORMAT=clang-format-20"]
190192

191193
volumes:
192194
cbm-ccache-arm64:

0 commit comments

Comments
 (0)