Skip to content

Commit 35c2dc6

Browse files
authored
test: Clang incremental and BMI cache E2E tests (#36)
39_llvm_incremental.sh: per-file dyndep with clang-scan-deps. 40_llvm_bmi_cache.sh: dependency BMI cache reuse.
1 parent 2e7fe50 commit 35c2dc6

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

tests/e2e/39_llvm_incremental.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
# 39_llvm_incremental.sh — Clang per-file incremental rebuild via clang-scan-deps dyndep.
3+
set -e
4+
5+
LLVM_ROOT="${HOME}/.mcpp/registry/data/xpkgs/xim-x-llvm/20.1.7"
6+
if [[ ! -x "$LLVM_ROOT/bin/clang++" ]]; then
7+
echo "SKIP: xlings llvm@20.1.7 is not installed"
8+
exit 0
9+
fi
10+
if [[ ! -f "$LLVM_ROOT/share/libc++/v1/std.cppm" ]]; then
11+
echo "SKIP: xlings llvm@20.1.7 has no libc++ std.cppm"
12+
exit 0
13+
fi
14+
15+
TMP=$(mktemp -d)
16+
trap "rm -rf $TMP" EXIT
17+
export MCPP_HOME="$TMP/mcpp-home"
18+
source "$(dirname "$0")/_inherit_toolchain.sh"
19+
20+
mkdir -p "$TMP/proj/src"
21+
cd "$TMP/proj"
22+
23+
cat > mcpp.toml <<'EOF'
24+
[package]
25+
name = "llvm_inc"
26+
version = "0.1.0"
27+
[toolchain]
28+
linux = "llvm@20.1.7"
29+
EOF
30+
31+
cat > src/greet.cppm <<'EOF'
32+
export module llvm_inc.greet;
33+
import std;
34+
export std::string greet() { return "hello"; }
35+
EOF
36+
37+
cat > src/main.cpp <<'EOF'
38+
import std;
39+
import llvm_inc.greet;
40+
int main() { std::println("{}", greet()); }
41+
EOF
42+
43+
# First build (full)
44+
"$MCPP" build --no-cache > /dev/null 2>&1
45+
46+
# Second build (no-op) should be fast
47+
out=$("$MCPP" build 2>&1)
48+
[[ "$out" == *"Finished"* ]] || { echo "FAIL: no-op rebuild failed: $out"; exit 1; }
49+
50+
# Touch greet.cppm only; rebuild should NOT recompile main.cpp
51+
sleep 1
52+
touch src/greet.cppm
53+
out=$("$MCPP" build --verbose 2>&1)
54+
echo "$out" | grep -q "greet.cppm" || { echo "FAIL: greet.cppm not rebuilt: $out"; exit 1; }
55+
# main.cpp should NOT appear in ninja output (it wasn't touched)
56+
if echo "$out" | grep -q "MOD obj/main.o\|OBJ obj/main.o"; then
57+
# Note: main.o MAY be relinked but should NOT be recompiled from source
58+
# Check specifically for compilation (not linking)
59+
if echo "$out" | grep -q "\-c.*main.cpp"; then
60+
echo "FAIL: main.cpp was recompiled when only greet.cppm changed"
61+
exit 1
62+
fi
63+
fi
64+
65+
echo "OK"

tests/e2e/40_llvm_bmi_cache.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
# 40_llvm_bmi_cache.sh — Clang BMI cache reuse for dependency packages.
3+
set -e
4+
5+
LLVM_ROOT="${HOME}/.mcpp/registry/data/xpkgs/xim-x-llvm/20.1.7"
6+
if [[ ! -x "$LLVM_ROOT/bin/clang++" ]]; then
7+
echo "SKIP: xlings llvm@20.1.7 is not installed"
8+
exit 0
9+
fi
10+
if [[ ! -f "$LLVM_ROOT/share/libc++/v1/std.cppm" ]]; then
11+
echo "SKIP: xlings llvm@20.1.7 has no libc++ std.cppm"
12+
exit 0
13+
fi
14+
15+
TMP=$(mktemp -d)
16+
trap "rm -rf $TMP" EXIT
17+
export MCPP_HOME="$TMP/mcpp-home"
18+
source "$(dirname "$0")/_inherit_toolchain.sh"
19+
20+
# mcpplibs packages live in a separate registry namespace; inherit it so the
21+
# index lookup for mcpplibs.cmdline succeeds in the isolated MCPP_HOME.
22+
USER_MCPP="${HOME}/.mcpp"
23+
if [[ -d "$USER_MCPP/registry/data/mcpplibs" ]]; then
24+
mkdir -p "$MCPP_HOME/registry/data"
25+
[[ -e "$MCPP_HOME/registry/data/mcpplibs" ]] \
26+
|| ln -sf "$USER_MCPP/registry/data/mcpplibs" "$MCPP_HOME/registry/data/mcpplibs"
27+
fi
28+
29+
mkdir -p "$TMP/proj/src"
30+
cd "$TMP/proj"
31+
32+
cat > mcpp.toml <<'EOF'
33+
[package]
34+
name = "llvm_cache"
35+
version = "0.1.0"
36+
[toolchain]
37+
linux = "llvm@20.1.7"
38+
[dependencies]
39+
"mcpplibs.cmdline" = "0.0.1"
40+
EOF
41+
42+
cat > src/main.cpp <<'EOF'
43+
import std;
44+
import mcpplibs.cmdline;
45+
int main() {
46+
std::println("cache test ok");
47+
return 0;
48+
}
49+
EOF
50+
51+
# First build — should compile the dependency
52+
out1=$("$MCPP" build --no-cache 2>&1)
53+
echo "$out1" | grep -q "Compiling.*mcpplibs.cmdline" || {
54+
# It's OK if it says "Cached" because global cache may exist
55+
echo "$out1" | grep -q "Cached.*mcpplibs.cmdline" || {
56+
echo "FAIL: mcpplibs.cmdline not mentioned in first build: $out1"
57+
exit 1
58+
}
59+
}
60+
61+
# Second build (clean target, keep BMI cache) — dependency should be cached
62+
rm -rf target
63+
out2=$("$MCPP" build 2>&1)
64+
echo "$out2" | grep -q "Cached.*mcpplibs.cmdline" || {
65+
echo "FAIL: mcpplibs.cmdline not cached on second build: $out2"
66+
exit 1
67+
}
68+
69+
echo "OK"

0 commit comments

Comments
 (0)