diff options
author | Brad King <brad.king@kitware.com> | 2023-03-16 21:16:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-03-20 17:13:30 (GMT) |
commit | 1b7c26da49e7e1a337f66951424bda8d3f4067fc (patch) | |
tree | 8c766ceaaaa7984f39d7547513418ebc88b8ec17 /Source/cmLocalNinjaGenerator.cxx | |
parent | ffd8537acf4ff938ec87b134f3b72e1a22d1b1d3 (diff) | |
download | CMake-1b7c26da49e7e1a337f66951424bda8d3f4067fc.zip CMake-1b7c26da49e7e1a337f66951424bda8d3f4067fc.tar.gz CMake-1b7c26da49e7e1a337f66951424bda8d3f4067fc.tar.bz2 |
Ninja: Wrap rules using '>' shell redirection with 'cmd /C' on Windows
This is needed for the clang-scan-deps rule added by commit 0e21e55fc5
(Clang: Record Clang 16.0 C++ modules flags only for GNU-like front-end,
2023-03-16).
Fixes: #24611
Diffstat (limited to 'Source/cmLocalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmLocalNinjaGenerator.cxx | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 77c5a76..3443cd3 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -456,6 +456,22 @@ std::string cmLocalNinjaGenerator::WriteCommandScript( return scriptPath; } +#ifdef _WIN32 +namespace { +bool RuleNeedsCMD(std::string const& cmd) +{ + std::vector<std::string> args; + cmSystemTools::ParseWindowsCommandLine(cmd.c_str(), args); + auto it = std::find_if(args.cbegin(), args.cend(), + [](std::string const& arg) -> bool { + // FIXME: Detect more windows shell operators. + return cmHasLiteralPrefix(arg, ">"); + }); + return it != args.cend(); +} +} +#endif + std::string cmLocalNinjaGenerator::BuildCommandLine( std::vector<std::string> const& cmdLines, std::string const& outputConfig, std::string const& commandConfig, std::string const& customStep, @@ -499,7 +515,8 @@ std::string cmLocalNinjaGenerator::BuildCommandLine( std::ostringstream cmd; #ifdef _WIN32 - bool const needCMD = cmdLines.size() > 1; + bool const needCMD = + cmdLines.size() > 1 || (customStep.empty() && RuleNeedsCMD(cmdLines[0])); for (auto li = cmdLines.begin(); li != cmdLines.end(); ++li) { if (li != cmdLines.begin()) { cmd << " && "; |