Skip to content

Commit 8da71f3

Browse files
committed
run/test: diagnostics name the canonical triple, which is the key the reader wrote
`choose_runner` resolves `[target.<triple>].runner` against the canonical spelling — the output directory's name, and the key every other `[target.<triple>]` reader uses. The four diagnostics it feeds printed `tc.targetTriple`, the spelling the driver reported, which on a Linux host is the same string and on macOS is `arm64-apple-darwin24.6.0`. Two consequences, both user-facing. The not-found message named a triple the author never wrote. The unrunnable message printed a `[target.…]` block to paste whose key no lookup would ever match, so following the advice would have left the artifact running bare a second time. `RunnerChoice` now carries `tripleKey`, derived once beside the lookup that uses it, so the two cannot disagree. The triple is parsed once rather than three times. Measured: e2e 330 §3 asserts the message names the triple the manifest key uses and failed only on macOS ARM64 (run 33609434208).
1 parent b3cf05f commit 8da71f3

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

src/build/execute.cppm

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,22 @@ struct RunnerChoice {
459459
bool freestanding = false; // an EMPTY tmpl is fatal when true
460460
bool fromManifest = false; // the consumer overrode a dependency's
461461
bool ignored = false; // --no-runner dropped a declared template
462+
// The spelling that names this target in the manifest: the canonical form,
463+
// which is also the output directory's name and the key every
464+
// `[target.<triple>]` reader resolves. Every diagnostic below prints this
465+
// rather than `tc.targetTriple`, because each one either names the key the
466+
// author wrote or prints a key to paste, and the driver's own spelling is
467+
// neither — on macOS it is `arm64-apple-darwin24.6.0`, which no
468+
// `[target.…]` lookup matches. Derived here, once, so the lookup and the
469+
// message it produces cannot disagree about which target they mean.
470+
std::string tripleKey;
462471
};
463472

464473
RunnerChoice choose_runner(const BuildContext& ctx, bool noRunner = false) {
465474
RunnerChoice c;
466-
if (auto ft = mcpp::toolchain::triple::parse(ctx.tc.targetTriple))
467-
c.freestanding = ft->is_freestanding();
475+
const auto ft = mcpp::toolchain::triple::parse(ctx.tc.targetTriple);
476+
if (ft) c.freestanding = ft->is_freestanding();
477+
c.tripleKey = ft ? ft->str() : ctx.tc.targetTriple;
468478
// Two producers, ordinary precedence: what the author of THIS project
469479
// wrote beats what a dependency supplied. The dependency is the normal
470480
// case on bare metal (a board-support package computes the emulator's
@@ -485,10 +495,9 @@ RunnerChoice choose_runner(const BuildContext& ctx, bool noRunner = false) {
485495
return it != ctx.manifest.targetOverrides.end() && !it->second.runner.empty()
486496
? &it->second : nullptr;
487497
};
488-
const mcpp::manifest::TargetEntry* entry = nullptr;
489-
if (auto ft = mcpp::toolchain::triple::parse(ctx.tc.targetTriple))
490-
entry = lookup(ft->str());
491-
if (!entry) entry = lookup(ctx.tc.targetTriple);
498+
const mcpp::manifest::TargetEntry* entry = lookup(c.tripleKey);
499+
if (!entry && c.tripleKey != ctx.tc.targetTriple)
500+
entry = lookup(ctx.tc.targetTriple);
492501
if (entry) {
493502
c.tmpl = entry->runner;
494503
c.fromManifest = !ctx.manifest.buildConfig.runner.empty();
@@ -1385,7 +1394,7 @@ export int build_run_target(const std::optional<std::string>& targetName,
13851394
if (!found.program) {
13861395
std::println(stderr, "error: {}",
13871396
mcpp::build::runner_lookup::not_found_message(
1388-
ctx->tc.targetTriple, tmpl.front(), found.searched));
1397+
choice.tripleKey, tmpl.front(), found.searched));
13891398
return 2;
13901399
}
13911400
tmpl.front() = found.program->string();
@@ -1429,7 +1438,7 @@ export int build_run_target(const std::optional<std::string>& targetName,
14291438
std::println(stderr, "error: {}", spawn_failed_message(argv.front(), spawnErr));
14301439
else if (classify(spawnErr) == SpawnClass::Unloadable)
14311440
std::println(stderr, "error: {}",
1432-
unrunnable_message(ctx->tc.targetTriple, exe, spawnErr));
1441+
unrunnable_message(choice.tripleKey, exe, spawnErr));
14331442
else
14341443
std::println(stderr, "error: {}", spawn_failed_message(exe.string(), spawnErr));
14351444
return 2;
@@ -1878,7 +1887,7 @@ export int run_tests(std::span<const std::string> passthrough,
18781887
runnerTmpl.front(), ctx->xlingsDepBinDirs, pathEnv ? pathEnv : "");
18791888
if (found.program) runnerTmpl.front() = found.program->string();
18801889
else invocationNotRunReason = mcpp::build::runner_lookup::not_found_message(
1881-
ctx->tc.targetTriple, runnerTmpl.front(), found.searched);
1890+
runnerChoice.tripleKey, runnerTmpl.front(), found.searched);
18821891
}
18831892
// Set by the first worker whose spawn the kernel refused; every worker
18841893
// checks it before spawning. Workers already past the check may be
@@ -1964,8 +1973,8 @@ export int run_tests(std::span<const std::string> passthrough,
19641973
"this host cannot execute {} artifacts: {} (error {}); "
19651974
"declare [target.{}].runner, or pass --no-runner on a "
19661975
"host that can",
1967-
ctx->tc.targetTriple, errno_text(spawnErr), spawnErr,
1968-
ctx->tc.targetTriple);
1976+
runnerChoice.tripleKey, errno_text(spawnErr), spawnErr,
1977+
runnerChoice.tripleKey);
19691978
else
19701979
reason = spawn_failed_message(r.argv.front(), spawnErr);
19711980
if (!hostCannotRun.exchange(true)) {

0 commit comments

Comments
 (0)