Skip to content

Commit 15ebb4a

Browse files
committed
fix: Windows cmd.exe quoting and clang-scan-deps lookup in cli.cppm
- Replace single-quoted shell arguments with double-quoted ones on Windows for ninja fast-path (-C dir), mcpp run, and mcpp test binary invocations (cmd.exe does not understand POSIX single quotes) - Guard the sandbox PATH prefix injection under #if !defined(_WIN32) since PATH='...':\"$PATH\" is a POSIX-only shell idiom - Replace the inline clang-scan-deps path construction with a call to mcpp::toolchain::clang::find_scan_deps() which already handles .exe on Windows; add the required import mcpp.toolchain.clang
1 parent 9cd7050 commit 15ebb4a

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/cli.cppm

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import mcpp.manifest;
2323
import mcpp.modgraph.graph;
2424
import mcpp.modgraph.scanner;
2525
import mcpp.modgraph.validate;
26+
import mcpp.toolchain.clang;
2627
import mcpp.toolchain.detect;
2728
import mcpp.toolchain.fingerprint;
2829
import mcpp.toolchain.registry;
@@ -2160,9 +2161,8 @@ prepare_build(bool print_fingerprint,
21602161

21612162
// Clang: discover clang-scan-deps for P1689 dyndep scanning.
21622163
if (mcpp::toolchain::is_clang(*tc)) {
2163-
auto sd = tc->binaryPath.parent_path() / "clang-scan-deps";
2164-
if (std::filesystem::exists(sd)) {
2165-
ctx.plan.scanDepsPath = sd;
2164+
if (auto sd = mcpp::toolchain::clang::find_scan_deps(*tc)) {
2165+
ctx.plan.scanDepsPath = *sd;
21662166
}
21672167
}
21682168

@@ -2519,7 +2519,11 @@ std::optional<int> try_fast_build(const std::filesystem::path& projectRoot,
25192519
}
25202520

25212521
// All inputs are older than build.ninja → fast-path: just run ninja.
2522+
#if defined(_WIN32)
2523+
std::string cmd = std::format("{} -C \"{}\"", ninjaProgram, outputDir.string());
2524+
#else
25222525
std::string cmd = std::format("{} -C '{}'", ninjaProgram, outputDir.string());
2526+
#endif
25232527
if (verbose) cmd += " -v";
25242528
cmd += " 2>&1";
25252529

@@ -2608,8 +2612,13 @@ int cmd_run(const mcpplibs::cmdline::ParsedArgs& parsed,
26082612
std::format("`{}`", mcpp::ui::shorten_path(exe, pathCtx)));
26092613
std::println("");
26102614
std::fflush(stdout);
2615+
#if defined(_WIN32)
2616+
std::string cmd = std::format("\"{}\"", exe.string());
2617+
for (auto& a : passthrough) cmd += std::format(" \"{}\"", a);
2618+
#else
26112619
std::string cmd = std::format("'{}'", exe.string());
26122620
for (auto& a : passthrough) cmd += std::format(" '{}'", a);
2621+
#endif
26132622
return std::system(cmd.c_str()) == 0 ? 0 : 1;
26142623
}
26152624

@@ -3151,16 +3160,23 @@ int cmd_test(const mcpplibs::cmdline::ParsedArgs& /*parsed*/,
31513160
// visible to test binaries that shell out to them. The
31523161
// toolchain binary's path encodes the registry root — derive it.
31533162
std::string pathPrefix;
3163+
#if !defined(_WIN32)
31543164
if (auto xpkgs = mcpp::xlings::paths::xpkgs_from_compiler(ctx->tc.binaryPath)) {
31553165
// xpkgs is <registry>/data/xpkgs → registry = xpkgs/../..
31563166
auto registryDir = xpkgs->parent_path().parent_path();
31573167
auto sandboxBin = registryDir / "subos" / "default" / "bin";
31583168
if (std::filesystem::exists(sandboxBin))
31593169
pathPrefix = std::format("PATH='{}':\"$PATH\" ", sandboxBin.string());
31603170
}
3171+
#endif
31613172

3173+
#if defined(_WIN32)
3174+
std::string cmd = std::format("\"{}\"", exe.string());
3175+
for (auto& a : passthrough) cmd += std::format(" \"{}\"", a);
3176+
#else
31623177
std::string cmd = std::format("{}'{}'", pathPrefix, exe.string());
31633178
for (auto& a : passthrough) cmd += std::format(" '{}'", a);
3179+
#endif
31643180
int rc = std::system(cmd.c_str());
31653181
// std::system returns wait status on POSIX, exit code on Windows.
31663182
#if defined(_WIN32)

0 commit comments

Comments
 (0)