Skip to content

Commit c047dcd

Browse files
committed
fix: accept split toolchain remove specs
1 parent b5630e2 commit c047dcd

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

‎src/cli.cppm‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,12 @@ int run(int argc, char** argv) {
795795
"Default build target <triple> (omit = host)")))
796796
.subcommand(cl::App("remove")
797797
.description("Uninstall a toolchain")
798-
.arg(cl::Arg("spec").help("<family>@<version>").required())
798+
// Match `default`: accept either `gcc@16.1.0` or `gcc 16.1.0`.
799+
// Partial-version spelling follows `default` too.
800+
.arg(cl::Arg("spec")
801+
.help("<family>[@<version>] (version may be partial)")
802+
.required())
803+
.arg(cl::Arg("version").help("(optional, alternative to @-form)"))
799804
.option(cl::Option("target").takes_value().help(
800805
"Remove the payload for <triple> instead of the host one")))
801806
.action(wrap_rc(cmd_toolchain)))

‎src/cli/cmd_toolchain.cppm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export int cmd_toolchain(const mcpplibs::cmdline::ParsedArgs& parsed) {
5656
return mcpp::toolchain::toolchain_set_default(
5757
*cfg, sub_parsed.positional(0), sub_parsed.positional(1), targetArg);
5858
if (subname == "remove")
59-
return mcpp::toolchain::toolchain_remove(*cfg, sub_parsed.positional(0), targetArg);
59+
return mcpp::toolchain::toolchain_remove(
60+
*cfg, sub_parsed.positional(0), sub_parsed.positional(1), targetArg);
6061

6162
mcpp::ui::error(std::format("unknown toolchain subcommand '{}'", subname));
6263
return 2;

‎src/toolchain/lifecycle.cppm‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,9 +1269,10 @@ export int toolchain_set_default(const mcpp::config::GlobalConfig& cfg,
12691269
// `mcpp toolchain remove <spec> [--target <triple>]` — uninstall a payload.
12701270
export int toolchain_remove(const mcpp::config::GlobalConfig& cfg,
12711271
const std::string& pos0,
1272+
const std::string& pos1,
12721273
const std::string& targetArg = {}) {
12731274
auto xlEnv = mcpp::config::make_xlings_env(cfg);
1274-
auto parsedSpec = mcpp::toolchain::parse_toolchain_spec(pos0);
1275+
auto parsedSpec = mcpp::toolchain::parse_toolchain_spec(pos0, pos1);
12751276
if (parsedSpec && mcpp::toolchain::is_system_toolchain(*parsedSpec)) {
12761277
mcpp::ui::error(
12771278
"msvc@system is the machine's own Visual Studio, managed by the "
@@ -1281,7 +1282,8 @@ export int toolchain_remove(const mcpp::config::GlobalConfig& cfg,
12811282
return 1;
12821283
}
12831284
if (!parsedSpec || parsedSpec->version.empty()) {
1284-
mcpp::ui::error(std::format("invalid spec '{}'", pos0));
1285+
const auto input = pos1.empty() ? pos0 : std::format("{} {}", pos0, pos1);
1286+
mcpp::ui::error(std::format("invalid spec '{}'", input));
12851287
return 2;
12861288
}
12871289
mcpp::toolchain::print_compat_hint(*parsedSpec);

‎tests/e2e/26_toolchain_management.sh‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ if [[ $rc -ne 0 ]]; then
6060
exit 1
6161
fi
6262
grep -q 'Installed' /tmp/_inst.log || { cat /tmp/_inst.log; echo "FAIL: no Installed line"; exit 1; }
63+
# Both accepted spellings should work when the payload is already installed.
64+
"$MCPP" toolchain install gcc@16.1.0 > /tmp/_inst_at.log 2>&1 || {
65+
cat /tmp/_inst_at.log; echo "FAIL: @-form install failed"; exit 1; }
6366

6467
# 4) toolchain list now non-empty
6568
out=$("$MCPP" toolchain list 2>&1)
@@ -71,6 +74,10 @@ echo "$out" | grep -q '16.1.0' || { echo "FAIL: list missing version: $out"; exi
7174
grep -q 'Default' /tmp/_def.log || { cat /tmp/_def.log; echo "FAIL: no Default msg"; exit 1; }
7275
out=$("$MCPP" toolchain list 2>&1)
7376
echo "$out" | grep -q '\*' || { echo "FAIL: default mark missing: $out"; exit 1; }
77+
"$MCPP" toolchain default gcc 16.1.0 > /tmp/_def_split.log 2>&1 || {
78+
cat /tmp/_def_split.log; echo "FAIL: space-separated default failed"; exit 1; }
79+
grep -q 'Default' /tmp/_def_split.log || {
80+
cat /tmp/_def_split.log; echo "FAIL: no Default msg for space-separated form"; exit 1; }
7481

7582
# 6) Build now succeeds (project has no [toolchain]; uses global default)
7683
"$MCPP" build > /tmp/_build.log 2>&1 || { cat /tmp/_build.log; echo "FAIL: build failed"; exit 1; }
@@ -98,8 +105,22 @@ echo "$out" | grep -q 'default toolchain = gcc@16.1.0' || {
98105

99106
# 9) Remove
100107
rm -rf target
101-
"$MCPP" toolchain remove gcc@16.1.0 > /tmp/_rm.log 2>&1
102-
grep -q 'Removed' /tmp/_rm.log || { cat /tmp/_rm.log; echo "FAIL: no Removed msg"; exit 1; }
108+
"$MCPP" toolchain remove gcc 16.1.0 > /tmp/_rm.log 2>&1
109+
grep -q 'Removed' /tmp/_rm.log || { cat /tmp/_rm.log; echo "FAIL: no Removed msg for space-separated form"; exit 1; }
110+
# The issue's cross-target spelling should parse too and reach the payload
111+
# lookup, even when that target is not installed in this test workspace.
112+
rc=0
113+
"$MCPP" toolchain remove gcc 16.1.0 --target x86_64-linux-musl > /tmp/_rm_target.log 2>&1 || rc=$?
114+
[[ "$rc" -ne 0 ]] || { echo "FAIL: removing an absent target toolchain should fail"; exit 1; }
115+
grep -q 'is not installed' /tmp/_rm_target.log || {
116+
cat /tmp/_rm_target.log; echo "FAIL: split form with --target did not reach installed-payload check"; exit 1; }
117+
# The compact spelling remains valid too; after removal it should reach the
118+
# installed-payload check rather than fail spec parsing.
119+
rc=0
120+
"$MCPP" toolchain remove gcc@16.1.0 > /tmp/_rm_at.log 2>&1 || rc=$?
121+
[[ "$rc" -ne 0 ]] || { echo "FAIL: removing an absent toolchain should fail"; exit 1; }
122+
grep -q 'is not installed' /tmp/_rm_at.log || {
123+
cat /tmp/_rm_at.log; echo "FAIL: @-form remove did not reach installed-payload check"; exit 1; }
103124

104125
# 10) After removing, the toolchain dir is gone, but config.toml still
105126
# points to it as default. Verify list shows nothing for that compiler now.

0 commit comments

Comments
 (0)