Skip to content

Commit a6a0154

Browse files
committed
test(e2e): 267 —— MCPP_TARGET_REQUESTED 的契约,以及它为什么不是 MCPP_TARGET
MCPP_TARGET 在没人指名目标时用宿主填上,对「这是给哪台机器的」是对的,而对平台包 必须问的另一个问题无用:**这次构建有没有被指向一个目标**。 ⚠️ 这个问题的两种读法都已经在 openkal-macos 上被实测判错过: · 用宿主读 → 交叉对,而 Mac 上 --target aarch64-macos 得到 library not found for -lSystem · 用 MCPP_TARGET 读 → 交叉对,本机构建得到 undefined symbol: wcslen(它从不为空, 于是包里三个名字的 stub 遮蔽了厂商完整的那份) 断言:本机构建为空;指名目标时携带被指名的三元组。 ⚠️ 探针以**非零退出**汇报 —— mcpp 只打印失败的构建程序的输出,返回零的探针输出会被 丢弃,那样这个测试什么都不断言。 ⚠️ 同一行上带阳性对照(MCPP_TARGET 必须被填上):没有它,mcpp 若停止设置全部变量, 上面那条断言同样会通过。 注入核验:把 MCPP_TARGET_REQUESTED 也改成「空则填宿主」⇒ 测试报 'should be empty for a native build' 并退非零。
1 parent 671a68a commit a6a0154

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env bash
2+
# requires: unix-shell
3+
# `MCPP_TARGET_REQUESTED` — the value a build program needs and `MCPP_TARGET`
4+
# cannot give it.
5+
#
6+
# ⭐⭐ WHY THE TWO VARIABLES ARE NOT THE SAME QUESTION.
7+
#
8+
# `MCPP_TARGET` answers "which machine is this for", and it is filled in with
9+
# the host when nobody named a target — which is right for that question and
10+
# makes it useless for a different one a platform package has to ask: **was this
11+
# build POINTED at a target**, or is it an ordinary native build?
12+
#
13+
# The two differ even when the triples are equal. `mcpp build --target
14+
# aarch64-macos` on an arm64 Mac names the very machine the host is, and yet it
15+
# is the dependency graph that supplies the target side — so mcpp puts no system
16+
# SDK on the link, and the package that knows the system is the only thing that
17+
# can name one. A native build on the same machine gets the SDK and needs
18+
# nothing from the package.
19+
#
20+
# ⚠️ Both readings of that question have already been measured wrong in
21+
# `openkal-macos`:
22+
#
23+
# from the host → right for the cross, and `library not found for -lSystem`
24+
# for `--target aarch64-macos` ON a Mac
25+
# from MCPP_TARGET → right for the cross, and `undefined symbol: wcslen` for
26+
# the native build, because it is never empty and the
27+
# package's three-name stub shadowed the vendor's complete one
28+
#
29+
# ⇒ The assertions below are the contract those two attempts needed: EMPTY for a
30+
# native build, and the requested triple otherwise.
31+
#
32+
# ⚠️ `"$MCPP"`, never a bare `mcpp`: the harness passes the binary under test,
33+
# and a bare name resolves through PATH to whichever engine is installed.
34+
set -e
35+
36+
TMP=$(mktemp -d)
37+
trap "rm -rf $TMP" EXIT
38+
cd "$TMP"
39+
40+
mkdir -p src
41+
cat > mcpp.toml <<'EOF'
42+
[package]
43+
name = "target-requested-probe"
44+
version = "0.1.0"
45+
EOF
46+
printf 'int main() { return 0; }\n' > src/main.cpp
47+
48+
# ⚠️ The build program reports through a NON-ZERO exit, because mcpp prints what
49+
# it captured only from a program that failed. A probe that returned zero would
50+
# have its output discarded and this test would assert nothing.
51+
cat > build.mcpp <<'EOF'
52+
import mcpp;
53+
import std;
54+
int main() {
55+
const char* t = std::getenv("MCPP_TARGET");
56+
const char* r = std::getenv("MCPP_TARGET_REQUESTED");
57+
std::cerr << "PROBE target=[" << (t ? t : "") << "] "
58+
<< "requested=[" << (r ? r : "") << "]\n";
59+
return 1;
60+
}
61+
EOF
62+
63+
# ── A native build: nobody named a target ──────────────────────────────────
64+
native=$("$MCPP" build 2>&1 || true)
65+
echo "$native" | grep -q 'PROBE ' || {
66+
echo "the build program did not report; mcpp prints a failing program's output" >&2
67+
echo "$native" >&2
68+
exit 1
69+
}
70+
echo "$native" | grep -qE 'requested=\[\]' || {
71+
echo "MCPP_TARGET_REQUESTED should be empty for a native build" >&2
72+
echo "$native" | grep 'PROBE ' >&2
73+
exit 1
74+
}
75+
# ⚠️ And the positive control on the same line: `MCPP_TARGET` must be filled in.
76+
# Without this the assertion above would also pass if mcpp had stopped setting
77+
# any of them.
78+
echo "$native" | grep -qE 'target=\[[a-z0-9_]+-[a-z0-9-]+\]' || {
79+
echo "MCPP_TARGET should carry the host triple for a native build" >&2
80+
echo "$native" | grep 'PROBE ' >&2
81+
exit 1
82+
}
83+
84+
# ── A build pointed at a target ────────────────────────────────────────────
85+
# x86_64-linux-musl is chosen because every host in this suite can resolve it
86+
# without a payload download beyond what the other cross tests already use.
87+
cross=$("$MCPP" build --target x86_64-linux-musl 2>&1 || true)
88+
echo "$cross" | grep -q 'PROBE ' || {
89+
echo "the build program did not report on the cross build" >&2
90+
echo "$cross" >&2
91+
exit 1
92+
}
93+
echo "$cross" | grep -qE 'requested=\[x86_64-linux-musl\]' || {
94+
echo "MCPP_TARGET_REQUESTED should carry the triple that was named" >&2
95+
echo "$cross" | grep 'PROBE ' >&2
96+
exit 1
97+
}
98+
99+
echo "MCPP_TARGET_REQUESTED distinguishes a native build from a named target"

0 commit comments

Comments
 (0)