Browse Source

cmCustomCommandGenerator: Refactor OUTPUT and DEPENDS path evaluation

* Use value semantics.
* Normalize paths in a separate loop.
* If CollapseFullPath is used, ConvertToUnixSlashes is unnecessary.
Brad King 5 years ago
parent
commit
5d23c5446e
1 changed files with 20 additions and 17 deletions
  1. 20 17
      Source/cmCustomCommandGenerator.cxx

+ 20 - 17
Source/cmCustomCommandGenerator.cxx

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