summaryrefslogtreecommitdiff
path: root/Source/cmCustomCommandGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmCustomCommandGenerator.cxx')
-rw-r--r--Source/cmCustomCommandGenerator.cxx68
1 files changed, 36 insertions, 32 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index fe228ff2d..c1f412df8 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -2,6 +2,10 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCustomCommandGenerator.h"
+#include <cstddef>
+#include <memory>
+#include <utility>
+
#include "cmAlgorithms.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandLines.h"
@@ -10,11 +14,28 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmStateTypes.h"
+#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
-#include <memory> // IWYU pragma: keep
-#include <stddef.h>
-#include <utility>
+namespace {
+void AppendPaths(const std::vector<std::string>& inputs,
+ cmGeneratorExpression const& ge, cmLocalGenerator* lg,
+ std::string const& config, std::vector<std::string>& output)
+{
+ 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);
+ }
+ }
+ cmAppend(output, result);
+ }
+}
+}
cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
std::string config,
@@ -24,18 +45,18 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
, LG(lg)
, OldStyle(cc.GetEscapeOldStyle())
, MakeVars(cc.GetEscapeAllowMakeVars())
- , GE(new cmGeneratorExpression(cc.GetBacktrace()))
, EmulatorsWithArguments(cc.GetCommandLines().size())
{
+ cmGeneratorExpression ge(cc.GetBacktrace());
+
const cmCustomCommandLines& cmdlines = this->CC.GetCommandLines();
for (cmCustomCommandLine const& cmdline : cmdlines) {
cmCustomCommandLine argv;
for (std::string const& clarg : cmdline) {
- std::unique_ptr<cmCompiledGeneratorExpression> cge =
- this->GE->Parse(clarg);
+ std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(clarg);
std::string parsed_arg = cge->Evaluate(this->LG, this->Config);
if (this->CC.GetCommandExpandLists()) {
- cmAppend(argv, cmSystemTools::ExpandedListArgument(parsed_arg));
+ cmAppend(argv, cmExpandedList(parsed_arg));
} else {
argv.push_back(std::move(parsed_arg));
}
@@ -45,29 +66,20 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
// lists on an empty command may have left this empty.
// FIXME: Should we define behavior for removing empty commands?
if (argv.empty()) {
- argv.push_back(std::string());
+ argv.emplace_back();
}
this->CommandLines.push_back(std::move(argv));
}
- std::vector<std::string> depends = this->CC.GetDepends();
- for (std::string const& d : depends) {
- std::unique_ptr<cmCompiledGeneratorExpression> cge = this->GE->Parse(d);
- std::vector<std::string> result = cmSystemTools::ExpandedListArgument(
- cge->Evaluate(this->LG, this->Config));
- for (std::string& it : result) {
- if (cmSystemTools::FileIsFullPath(it)) {
- it = cmSystemTools::CollapseFullPath(it);
- }
- }
- cmAppend(this->Depends, result);
- }
+ AppendPaths(cc.GetByproducts(), ge, this->LG, this->Config,
+ this->Byproducts);
+ AppendPaths(cc.GetDepends(), ge, this->LG, this->Config, this->Depends);
const std::string& workingdirectory = this->CC.GetWorkingDirectory();
if (!workingdirectory.empty()) {
std::unique_ptr<cmCompiledGeneratorExpression> cge =
- this->GE->Parse(workingdirectory);
+ ge.Parse(workingdirectory);
this->WorkingDirectory = cge->Evaluate(this->LG, this->Config);
// Convert working directory to a full path.
if (!this->WorkingDirectory.empty()) {
@@ -80,11 +92,6 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc,
this->FillEmulatorsWithArguments();
}
-cmCustomCommandGenerator::~cmCustomCommandGenerator()
-{
- delete this->GE;
-}
-
unsigned int cmCustomCommandGenerator::GetNumberOfCommands() const
{
return static_cast<unsigned int>(this->CC.GetCommandLines().size());
@@ -108,8 +115,7 @@ void cmCustomCommandGenerator::FillEmulatorsWithArguments()
continue;
}
- cmSystemTools::ExpandListArgument(emulator_property,
- this->EmulatorsWithArguments[c]);
+ cmExpandList(emulator_property, this->EmulatorsWithArguments[c]);
}
}
}
@@ -169,9 +175,7 @@ std::string escapeForShellOldStyle(const std::string& str)
std::string temp = str;
if (temp.find(" ") != std::string::npos &&
temp.find("\"") == std::string::npos) {
- result = "\"";
- result += str;
- result += "\"";
+ result = cmStrCat('"', str, '"');
return result;
}
return str;
@@ -240,7 +244,7 @@ std::vector<std::string> const& cmCustomCommandGenerator::GetOutputs() const
std::vector<std::string> const& cmCustomCommandGenerator::GetByproducts() const
{
- return this->CC.GetByproducts();
+ return this->Byproducts;
}
std::vector<std::string> const& cmCustomCommandGenerator::GetDepends() const