Ninja,Make,FASTBuild: Avoid unnecessary Windows short paths in placeholders

Only the classic Borland `make` and Watcom `wmake` tools need short paths.

Co-authored-by: Brad King <brad.king@kitware.com>
Fixes: #16138
This commit is contained in:
Robert Maynard
2026-02-24 11:56:23 -05:00
committed by Brad King
co-authored by Brad King
parent 8099fe4436
commit d314cad7f1
11 changed files with 60 additions and 29 deletions
+4 -1
View File
@@ -231,7 +231,10 @@ cmLocalGenerator::CreateRulePlaceholderExpander(cmBuildStep buildStep) const
{
return cm::make_unique<cmRulePlaceholderExpander>(
buildStep, this->Compilers, this->VariableMappings, this->CompilerSysroot,
this->LinkerSysroot);
this->LinkerSysroot,
this->GetState()->UseWatcomWMake() || this->GetState()->UseBorlandMake()
? cmRulePlaceholderExpander::UseShortPaths::Yes
: cmRulePlaceholderExpander::UseShortPaths::No);
}
cmLocalGenerator::~cmLocalGenerator() = default;
+20 -6
View File
@@ -11,13 +11,26 @@
cmRulePlaceholderExpander::cmRulePlaceholderExpander(
cmBuildStep buildStep, std::map<std::string, std::string> compilers,
std::map<std::string, std::string> variableMappings,
std::string compilerSysroot, std::string linkerSysroot)
std::string compilerSysroot, std::string linkerSysroot,
UseShortPaths useShortPaths)
: BuildStep(buildStep)
, Compilers(std::move(compilers))
, VariableMappings(std::move(variableMappings))
, CompilerSysroot(std::move(compilerSysroot))
, LinkerSysroot(std::move(linkerSysroot))
{
if (useShortPaths == UseShortPaths::Yes) {
this->ConvertToOutputForExisting =
[this](cm::string_view path) -> std::string {
return this->OutputConverter->ConvertToOutputForExisting(path);
};
} else {
this->ConvertToOutputForExisting =
[this](cm::string_view path) -> std::string {
return this->OutputConverter->ConvertToOutputFormat(
path, cmOutputConverter::SHELL);
};
}
}
std::string cmRulePlaceholderExpander::ExpandVariable(
@@ -30,8 +43,8 @@ std::string cmRulePlaceholderExpander::ExpandVariable(
}
if (this->ReplaceValues->Linker) {
if (variable == "CMAKE_LINKER") {
auto result = this->OutputConverter->ConvertToOutputForExisting(
this->ReplaceValues->Linker);
auto result =
this->ConvertToOutputForExisting(this->ReplaceValues->Linker);
if (this->ReplaceValues->Launcher) {
// Add launcher as part of expansion so that it always appears
// immediately before the command itself, regardless of whether the
@@ -301,8 +314,9 @@ std::string cmRulePlaceholderExpander::ExpandVariable(
auto compIt = this->Compilers.find(variable);
if (compIt != this->Compilers.end()) {
std::string ret = this->OutputConverter->ConvertToOutputForExisting(
this->VariableMappings["CMAKE_" + compIt->second + "_COMPILER"]);
std::string const& compilerPath =
this->VariableMappings["CMAKE_" + compIt->second + "_COMPILER"];
std::string ret = this->ConvertToOutputForExisting(compilerPath);
std::string const& compilerArg1 =
this->VariableMappings["CMAKE_" + compIt->second + "_COMPILER_ARG1"];
std::string const& compilerTarget =
@@ -365,7 +379,7 @@ std::string cmRulePlaceholderExpander::ExpandVariable(
auto mapIt = this->VariableMappings.find(variable);
if (mapIt != this->VariableMappings.end()) {
if (variable.find("_FLAG") == std::string::npos) {
return this->OutputConverter->ConvertToOutputForExisting(mapIt->second);
return this->ConvertToOutputForExisting(mapIt->second);
}
return mapIt->second;
}
+12 -1
View File
@@ -5,9 +5,12 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <functional>
#include <map>
#include <string>
#include <cm/string_view>
#include "cmGeneratorOptions.h"
#include "cmPlaceholderExpander.h"
@@ -16,10 +19,17 @@ class cmOutputConverter;
class cmRulePlaceholderExpander : public cmPlaceholderExpander
{
public:
enum class UseShortPaths
{
No,
Yes,
};
cmRulePlaceholderExpander(
cmBuildStep buildStep, std::map<std::string, std::string> compilers,
std::map<std::string, std::string> variableMappings,
std::string compilerSysroot, std::string linkerSysroot);
std::string compilerSysroot, std::string linkerSysroot,
UseShortPaths useShortPaths);
void SetTargetImpLib(std::string const& targetImpLib)
{
@@ -95,6 +105,7 @@ private:
std::map<std::string, std::string> VariableMappings;
std::string CompilerSysroot;
std::string LinkerSysroot;
std::function<std::string(cm::string_view)> ConvertToOutputForExisting;
cmOutputConverter* OutputConverter = nullptr;
RuleVariables const* ReplaceValues = nullptr;
@@ -1,2 +1,2 @@
[ ,][/-][Mm][Aa][Cc][Hh][Ii][Nn][Ee]:[A-Za-z0-9_]+[ ]|[Vv][Cc](98|7)\\\\[Bb][Ii][Nn]\\\\[Ll][Ii][Nn][Kk]\.[Ee][Xx][Ee] [^
[ ,][/-][Mm][Aa][Cc][Hh][Ii][Nn][Ee]:[A-Za-z0-9_]+[ ]|[Vv][Cc](98|7)\\\\[Bb][Ii][Nn]\\\\[Ll][Ii][Nn][Kk]\.[Ee][Xx][Ee]"? [^
]*@[^ ]+\\\\nm
@@ -1 +1,2 @@
swiftc(\.exe)? .* -output-file-map CMakeFiles(/|\\)greetings_default\.dir(/|\\)(Debug)?(/|\\)output-file-map\.json .*
swiftc(\.exe)?"? [^
]* -output-file-map CMakeFiles(/|\\)greetings_default\.dir(/|\\)(Debug)?(/|\\)output-file-map\.json .*
@@ -1 +1,2 @@
swiftc(\.exe)? .* -emit-module -emit-module-path El(/|\\)((Debug|Release)(/|\\))?El\.swiftmodule(/|\\)[-_a-z0-9]+\.swiftmodule -module-name El
swiftc(\.exe)?"? [^
]* -emit-module -emit-module-path El(/|\\)((Debug|Release)(/|\\))?El\.swiftmodule(/|\\)[-_a-z0-9]+\.swiftmodule -module-name El
@@ -1 +1,2 @@
swiftc(\.exe)? .* -emit-module -emit-module-path El(/|\\)((Debug|Release)(/|\\))?El\.swiftmodule -module-name El
swiftc(\.exe)?"? [^
]* -emit-module -emit-module-path El(/|\\)((Debug|Release)(/|\\))?El\.swiftmodule -module-name El
@@ -1,2 +1,2 @@
swiftc(\.exe)? -j [0-9]+ -num-threads [0-9]+ -c @CMakeFiles(/|\\)L\.dir(/|\\)(Debug(/|\\))?L\.o(bj)?\.swift\.rsp
.*swiftc(\.exe)? -emit-library -static -o (Debug(/|\\))?(libL\.a|L\.lib) @CMakeFiles(/|\\)L\.(Debug\.)?rsp
swiftc(\.exe)?"? -j [0-9]+ -num-threads [0-9]+ -c @CMakeFiles(/|\\)L\.dir(/|\\)(Debug(/|\\))?L\.o(bj)?\.swift\.rsp
.*swiftc(\.exe)?"? -emit-library -static -o (Debug(/|\\))?(libL\.a|L\.lib) @CMakeFiles(/|\\)L\.(Debug\.)?rsp
@@ -1,20 +1,20 @@
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library -static[^
]* -emit-module -emit-module-path (Debug/|Release/)?StaticLibrary\.swiftmodule[^
]* -module-name StaticLibrary [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library[^
]* -emit-module -emit-module-path (debug|release)/modules/DynamicLibrary\.swiftmodule[^
]* -module-name DynamicLibrary [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -emit-library [^
]* -Xlinker -install_name -Xlinker @rpath/libDynamicLibrary\.dylib -o ([A-Za-z]+/)?libDynamicLibrary\.dylib [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library[^
]* -emit-module -emit-module-path Modules/(Debug/|Release/)?DynamicLibrary2\.swiftmodule[^
]* -module-name DynamicLibrary2[^
]*
.*swiftc(\.exe)? -j [0-9]+ -num-threads [0-9]+ -c -module-name Executable
.*swiftc(\.exe)?"? -j [0-9]+ -num-threads [0-9]+ -c -module-name Executable
@@ -1,20 +1,20 @@
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library -static[^
]* -emit-module -emit-module-path (Debug\\|Release\\)?StaticLibrary\.swiftmodule[^
]* -module-name StaticLibrary [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library[^
]* -emit-module -emit-module-path (debug|release)\\modules\\DynamicLibrary\.swiftmodule[^
]* -module-name DynamicLibrary [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -emit-library [^
]* -Xlinker -implib:(Debug\\|Release\\)?DynamicLibrary\.lib +-o ([A-Za-z]+/)?(Debug\\|Release\\)?DynamicLibrary\.dll [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library[^
]* -emit-module -emit-module-path Modules\\(Debug\\|Release\\)?DynamicLibrary2\.swiftmodule[^
]* -module-name DynamicLibrary2 [^
]*
.*swiftc(\.exe)? -j [0-9]+ -num-threads [0-9]+ -c -module-name Executable
.*swiftc(\.exe)?"? -j [0-9]+ -num-threads [0-9]+ -c -module-name Executable
@@ -1,20 +1,20 @@
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library -static[^
]* -emit-module -emit-module-path (Debug/|Release/)?StaticLibrary\.swiftmodule[^
]* -module-name StaticLibrary [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library[^
]* -emit-module -emit-module-path (debug|release)/modules/DynamicLibrary\.swiftmodule[^
]* -module-name DynamicLibrary [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -emit-library [^
]* -Xlinker -soname -Xlinker libDynamicLibrary\.so -o ([A-Za-z]+/)?libDynamicLibrary\.so [^
]*
.*swiftc(\.exe)? [^
.*swiftc(\.exe)?"? [^
]* -parse-as-library[^
]* -emit-module -emit-module-path Modules/(Debug/|Release/)?DynamicLibrary2\.swiftmodule[^
]* -module-name DynamicLibrary2[^
]*
.*swiftc(\.exe)? -j [0-9]+ -num-threads [0-9]+ -c -module-name Executable
.*swiftc(\.exe)?"? -j [0-9]+ -num-threads [0-9]+ -c -module-name Executable