Skip to content

Commit 48cec33

Browse files
authored
fix(toolchain): list '*' reflects effective project-aware toolchain (#140)
`mcpp toolchain default` and `mcpp toolchain list`'s `*` marker read only the global config.toml [toolchain] default, but the build resolver (prepare.cppm) reads the project mcpp.toml [toolchain] FIRST — it shadows the global default. So in a project with a [toolchain] section, `list` could mark `*` on a different toolchain than `mcpp run` actually resolves (the reported gcc@16.1.0-vs-gcc@15.1.0-musl divergence). Compute the effective default the same way a build does (project mcpp.toml [toolchain] for the current platform, else global config), mark `*` on it, and print a note when it comes from the project so it never silently disagrees with the build. --target overrides are not folded in (they only apply with an explicit --target).
1 parent d237dee commit 48cec33

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

src/toolchain/lifecycle.cppm

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import mcpp.config;
1313
import mcpp.fetcher;
1414
import mcpp.fetcher.progress;
1515
import mcpp.manifest;
16+
import mcpp.platform;
1617
import mcpp.toolchain.detect;
1718
import mcpp.toolchain.registry;
1819
import mcpp.toolchain.post_install;
@@ -151,8 +152,34 @@ list_available_xpkg_versions(const mcpp::config::GlobalConfig& cfg,
151152
// preserves the shared setup (cfg load + xlings bootstrap progress)
152153

153154
// `mcpp toolchain list` — installed + available toolchains.
155+
// The toolchain that `mcpp build`/`run` actually resolves from the current
156+
// directory. A project mcpp.toml `[toolchain]` shadows the global config
157+
// default (see prepare.cppm resolution order), so `mcpp toolchain default`
158+
// and `mcpp toolchain list`'s `*` — which read only the global config — can
159+
// otherwise disagree with what a build in this directory really uses.
160+
// (`--target` overrides are intentionally not folded in: they only take
161+
// effect when an explicit `--target` is passed.)
162+
struct EffectiveDefault {
163+
std::string spec;
164+
bool fromProject = false;
165+
};
166+
167+
EffectiveDefault effective_default_toolchain(const mcpp::config::GlobalConfig& cfg) {
168+
std::error_code ec;
169+
auto mpath = std::filesystem::current_path(ec) / "mcpp.toml";
170+
if (!ec && std::filesystem::exists(mpath, ec)) {
171+
if (auto m = mcpp::manifest::load(mpath)) {
172+
if (auto t = m->toolchain.for_platform(mcpp::platform::name);
173+
t && !t->empty())
174+
return { *t, true };
175+
}
176+
}
177+
return { cfg.defaultToolchain, false };
178+
}
179+
154180
export int toolchain_list(const mcpp::config::GlobalConfig& cfg) {
155181
auto pkgsDir = cfg.xlingsHome() / "data" / "xpkgs";
182+
auto effective = effective_default_toolchain(cfg);
156183
auto pathCtx = mcpp::fetcher::make_path_ctx(&cfg);
157184
struct Row {
158185
std::string compiler;
@@ -178,7 +205,7 @@ export int toolchain_list(const mcpp::config::GlobalConfig& cfg) {
178205
r.version = vEntry.path().filename().string();
179206
r.bin = bin;
180207
r.isDefault = mcpp::toolchain::matches_default_toolchain(
181-
cfg.defaultToolchain, r.compiler, r.version);
208+
effective.spec, r.compiler, r.version);
182209
installed.push_back(std::move(r));
183210
}
184211
}
@@ -196,6 +223,15 @@ export int toolchain_list(const mcpp::config::GlobalConfig& cfg) {
196223
mcpp::toolchain::display_label(r.compiler, r.version),
197224
mcpp::ui::shorten_path(r.bin, pathCtx));
198225
}
226+
// Explain the `*` when it reflects a project override rather than
227+
// the global default, so it never silently disagrees with what a
228+
// build in this directory resolves.
229+
if (effective.fromProject) {
230+
std::println(" (* = effective toolchain from project mcpp.toml "
231+
"[toolchain]; global default is '{}')",
232+
cfg.defaultToolchain.empty() ? "<none>"
233+
: cfg.defaultToolchain);
234+
}
199235
}
200236

201237
// ─── Available section ──────────────────────────────────────────

0 commit comments

Comments
 (0)