Skip to content

Commit dee8eac

Browse files
committed
fix(bench): the harness could not drive the xmake arm it had just built
两处 harness 与描述之间的错配。都是「手工跑得通、harness 跑不通」—— 这类差异最容易被读成「引擎不行」。 **1. `--buildfiles` 没转绝对路径。** 每个引擎都以该目录为 cwd 启动,而 xmake 又 把同一个路径当 `-P` 收下,于是相对路径解析两次: --buildfiles bench/projects/xlings → bench/projects/xlings/bench/projects/xlings error: project not found! 从仓库根手工跑同一条命令是好的 —— 那里没有可供翻倍的前缀。和这套件已经修过一次 的 `--buildir` 翻倍是同一个形状,所以修在解析处一次,而不是每个适配器里各修一遍。 **2. payload 驱动经 `CXX` 传给 xmake 是错的机制。** 真实工程的描述把 payload 定义成一个 xmake **工具链**(编译器 + 它的 `-B<binutils>`/`--sysroot`,见 ../common/xmake/payload.lua);只设 `CXX` 等于把编译器给了 xrepo 而**不给那些 flag**,于是每个依赖包都用它构建并失败: => install cmdline 0.0.2 .. failed => install mbedtls v3.6.7 .. failed => install ftxui v6.1.9 .. failed 而 `xmake f --toolchain=mcpp-gcc` 手工跑是成功的,因为工具链把两半一起给了。 生成的 fixture 没有这个定义(bench.fixture.buildfiles 把 flag 内联写进描述), 所以它仍走 CXX —— 两种情况按「描述是否在树之外」区分。fixture 已回归验证未受影响。
1 parent e49c828 commit dee8eac

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

bench/src/engines/xmake.cppm

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ import bench.protocol;
66
import bench.spec;
77
import bench.platform;
88
import bench.engines.engine;
9+
import bench.toolchain;
910

1011
namespace bench::engines {
1112

13+
// The toolchain name ../common/xmake/payload.lua defines for a payload driver.
14+
// Empty when the request is not a payload one (a bare `gcc`/`clang`/a path), in
15+
// which case there is nothing pinned to name.
16+
inline std::string payload_toolchain(std::string_view compiler) {
17+
if (!compiler.starts_with("payload:")) return {};
18+
return toolchain::resolves_to_clang(compiler) ? "mcpp-clang" : "mcpp-gcc";
19+
}
20+
1221
class XmakeEngine : public Engine {
1322
public:
1423
std::string_view name() const override { return "xmake"; }
@@ -30,8 +39,33 @@ public:
3039
"-m", job.profile == "debug" ? "debug" : "release",
3140
"-o", job.build_dir.string(),
3241
};
33-
if (job.compiler == "clang") argv.push_back("--toolchain=llvm");
42+
// ── How the payload driver is pinned, and why it is not always CXX ──
43+
//
44+
// A real project's description (bench/projects/*/xmake.lua) DEFINES the
45+
// payload as an xmake toolchain — compiler and its `-B<binutils>` /
46+
// `--sysroot` flags together — in ../common/xmake/payload.lua. Naming
47+
// that toolchain is the only way to get both halves.
3448
//
49+
// Setting CXX instead hands xrepo a compiler WITHOUT those flags, and
50+
// xmake then builds every dependency package with it. They fail:
51+
// => install cmdline 0.0.2 .. failed
52+
// => install mbedtls v3.6.7 .. failed
53+
// => install ftxui v6.1.9 .. failed
54+
// — while the identical `xmake f --toolchain=mcpp-gcc` run by hand
55+
// succeeds, because there the toolchain carries the flags.
56+
//
57+
// The generated fixture has no such definition (bench.fixture.buildfiles
58+
// writes the payload flags inline), so it still takes CXX. The two cases
59+
// are told apart by whether the description lives beside the tree.
60+
const bool own_description = !job.buildfile_dir.empty() &&
61+
job.buildfile_dir != job.project_dir;
62+
if (own_description) {
63+
if (const auto tc = payload_toolchain(job.compiler); !tc.empty()) {
64+
argv.push_back("--toolchain=" + tc);
65+
return platform::run(argv, job.buildfile_dir, job.log_path, job.timeout_s);
66+
}
67+
}
68+
if (job.compiler == "clang") argv.push_back("--toolchain=llvm");
3569
// The driver is pinned through CXX so every engine compiles with the
3670
// SAME binary; without it xmake resolves whatever `g++` means on this
3771
// host, and the comparison silently becomes compiler-vs-compiler.

bench/src/main.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,23 @@ std::expected<Options, std::string> parse(int argc, char** argv) {
189189
else if (a == "--list") { o.list = true; }
190190
else if (a == "--analyze") { auto v = value(a); if (!v) return std::unexpected(v.error()); o.analyze = *v; }
191191
else if (a == "--project") { auto v = value(a); if (!v) return std::unexpected(v.error()); o.project = *v; }
192-
else if (a == "--buildfiles"){ auto v = value(a); if (!v) return std::unexpected(v.error()); o.buildfiles = *v; }
192+
// ABSOLUTE, resolved against the cwd the harness was STARTED in.
193+
//
194+
// Every engine is spawned with its cwd set to this directory, and xmake
195+
// is then handed it again as `-P`. A relative path therefore resolves
196+
// twice: `--buildfiles bench/projects/xlings` became
197+
// `bench/projects/xlings/bench/projects/xlings` and the whole arm failed
198+
// with `error: project not found!` — while the identical command run by
199+
// hand from the repository root worked, because there the doubling had
200+
// nothing to double against. Same shape as the `--buildir` doubling this
201+
// suite already fixed once; the fix belongs here, once, rather than in
202+
// each adapter.
203+
else if (a == "--buildfiles"){
204+
auto v = value(a); if (!v) return std::unexpected(v.error());
205+
std::error_code ec;
206+
auto abs = std::filesystem::absolute(*v, ec);
207+
o.buildfiles = ec ? std::filesystem::path(*v) : abs;
208+
}
193209
else if (a == "--hub") { auto v = value(a); if (!v) return std::unexpected(v.error()); o.hub = *v; }
194210
else if (a == "--leaf") { auto v = value(a); if (!v) return std::unexpected(v.error()); o.leaf = *v; }
195211
else if (a == "--body") { auto v = value(a); if (!v) return std::unexpected(v.error()); o.body = *v; }

0 commit comments

Comments
 (0)