Ninja: Fix depfile binding with spaces in path

In build statements we use a single `DEP_FILE = ...` binding that is
shared between `depfile = $DEP_FILE` and `command = ... $DEP_FILE ...`
bindings in the corresponding rule.  In cases that the command's shell
argument needs quoting, add a separate `depfile = ...` binding to the
build statement to express the depfile path without quoting.  Otherwise
`ninja` tries to open a file path that contains literal quotes.

Fixes: #26287
This commit is contained in:
Brad King
2024-09-12 10:54:56 -04:00
parent ad66be9943
commit b11323f1e4
8 changed files with 78 additions and 8 deletions
+10 -4
View File
@@ -2495,16 +2495,22 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
this->Generator->Configs[config].ExtraFiles.push_back(std::move(output));
}
void cmNinjaTargetGenerator::AddDepfileBinding(
cmNinjaVars& vars, std::string const& depfile) const
void cmNinjaTargetGenerator::AddDepfileBinding(cmNinjaVars& vars,
std::string depfile) const
{
vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
depfile, cmOutputConverter::SHELL);
std::string depfileForShell =
this->GetLocalGenerator()->ConvertToOutputFormat(depfile,
cmOutputConverter::SHELL);
if (depfile != depfileForShell) {
vars["depfile"] = std::move(depfile);
}
vars["DEP_FILE"] = std::move(depfileForShell);
}
void cmNinjaTargetGenerator::RemoveDepfileBinding(cmNinjaVars& vars) const
{
vars.erase("DEP_FILE");
vars.erase("depfile");
}
void cmNinjaTargetGenerator::addPoolNinjaVariable(
+1 -1
View File
@@ -42,7 +42,7 @@ public:
std::string GetTargetName() const;
void AddDepfileBinding(cmNinjaVars& vars, std::string const& depfile) const;
void AddDepfileBinding(cmNinjaVars& vars, std::string depfile) const;
void RemoveDepfileBinding(cmNinjaVars& vars) const;
protected: