1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-18 17:31:57 +08:00

cmCustomCommandGenerator: Refactor OUTPUT and DEPENDS path evaluation

* Use value semantics.
* Normalize paths in a separate loop.
* If CollapseFullPath is used, ConvertToUnixSlashes is unnecessary.
This commit is contained in:
Brad King
2020-10-27 10:14:45 -04:00
parent 24156c0269
commit 5d23c5446e

View File

@@ -24,22 +24,25 @@
#include "cmTransformDepfile.h" #include "cmTransformDepfile.h"
namespace { namespace {
void AppendPaths(const std::vector<std::string>& inputs, std::vector<std::string> EvaluatePaths(std::vector<std::string> const& paths,
cmGeneratorExpression const& ge, cmLocalGenerator* lg, cmGeneratorExpression const& ge,
std::string const& config, std::vector<std::string>& output) cmLocalGenerator* lg,
std::string const& config)
{ {
for (std::string const& in : inputs) { std::vector<std::string> result;
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(in); for (std::string const& p : paths) {
std::vector<std::string> result = std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(p);
cmExpandedList(cge->Evaluate(lg, config)); std::string const& ep = cge->Evaluate(lg, config);
for (std::string& it : result) { cm::append(result, cmExpandedList(ep));
cmSystemTools::ConvertToUnixSlashes(it);
if (cmSystemTools::FileIsFullPath(it)) {
it = cmSystemTools::CollapseFullPath(it);
}
}
cm::append(output, result);
} }
for (std::string& p : result) {
if (cmSystemTools::FileIsFullPath(p)) {
p = cmSystemTools::CollapseFullPath(p);
} else {
cmSystemTools::ConvertToUnixSlashes(p);
}
}
return result;
} }
} }
@@ -121,10 +124,10 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
this->CommandLines.push_back(std::move(argv)); this->CommandLines.push_back(std::move(argv));
} }
AppendPaths(cc.GetOutputs(), ge, this->LG, this->Config, this->Outputs); this->Outputs = EvaluatePaths(cc.GetOutputs(), ge, this->LG, this->Config);
AppendPaths(cc.GetByproducts(), ge, this->LG, this->Config, this->Byproducts =
this->Byproducts); EvaluatePaths(cc.GetByproducts(), ge, this->LG, this->Config);
AppendPaths(cc.GetDepends(), ge, this->LG, this->Config, this->Depends); this->Depends = EvaluatePaths(cc.GetDepends(), ge, this->LG, this->Config);
const std::string& workingdirectory = this->CC->GetWorkingDirectory(); const std::string& workingdirectory = this->CC->GetWorkingDirectory();
if (!workingdirectory.empty()) { if (!workingdirectory.empty()) {