summaryrefslogtreecommitdiffstats
path: root/Source/cmLocalGenerator.cxx
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2021-11-14 08:22:33 (GMT)
committerBrad King <brad.king@kitware.com>2021-11-18 17:02:37 (GMT)
commite37511ae7eb68a46fb9edb9f00d3fc179f713e45 (patch)
tree98bde246d5424c4552bb1b0149f96449d948bd86 /Source/cmLocalGenerator.cxx
parent90e1206f253c0acbef37668403133585a31b2a92 (diff)
downloadCMake-e37511ae7eb68a46fb9edb9f00d3fc179f713e45.zip
CMake-e37511ae7eb68a46fb9edb9f00d3fc179f713e45.tar.gz
CMake-e37511ae7eb68a46fb9edb9f00d3fc179f713e45.tar.bz2
cmMakefile: Simplify detail:::Add{Custom,Utility}Command
Note 1: `detail::AddCustomCommandToTarget()` resets cc, since cc is not moved away. Note 2: In `detail::AddUtilityCommand()`, a few vars are preserved before using. Their refs will be alive in most cases, but cc might be destroyed in the future.
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r--Source/cmLocalGenerator.cxx206
1 files changed, 94 insertions, 112 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index d1f642f..98f8fcc 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1072,11 +1072,22 @@ cmTarget* cmLocalGenerator::AddCustomCommandToTarget(
return nullptr;
}
- detail::AddCustomCommandToTarget(
- *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, t, byproducts,
- depends, commandLines, type, comment, workingDir, escapeOldStyle,
- uses_terminal, depfile, job_pool, command_expand_lists, stdPipesUTF8,
- cmp0116);
+ auto cc = cm::make_unique<cmCustomCommand>();
+ cc->SetBacktrace(this->DirectoryBacktrace);
+ cc->SetByproducts(byproducts);
+ cc->SetDepends(depends);
+ cc->SetCommandLines(commandLines);
+ cc->SetComment(comment);
+ cc->SetWorkingDirectory(workingDir);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetUsesTerminal(uses_terminal);
+ cc->SetDepfile(depfile);
+ cc->SetJobPool(job_pool);
+ cc->SetCommandExpandLists(command_expand_lists);
+ cc->SetStdPipesUTF8(stdPipesUTF8);
+ cc->SetCMP0116Status(cmp0116);
+ detail::AddCustomCommandToTarget(*this, cmCommandOrigin::Generator, t, type,
+ std::move(cc));
return t;
}
@@ -1113,11 +1124,25 @@ cmSourceFile* cmLocalGenerator::AddCustomCommandToOutput(
return nullptr;
}
- return detail::AddCustomCommandToOutput(
- *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, outputs,
- byproducts, depends, main_dependency, implicit_depends, commandLines,
- comment, workingDir, replace, escapeOldStyle, uses_terminal,
- command_expand_lists, depfile, job_pool, stdPipesUTF8, cmp0116);
+ auto cc = cm::make_unique<cmCustomCommand>();
+ cc->SetBacktrace(this->DirectoryBacktrace);
+ cc->SetOutputs(outputs);
+ cc->SetByproducts(byproducts);
+ cc->SetDepends(depends);
+ cc->SetImplicitDepends(implicit_depends);
+ cc->SetCommandLines(commandLines);
+ cc->SetComment(comment);
+ cc->SetWorkingDirectory(workingDir);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetUsesTerminal(uses_terminal);
+ cc->SetCommandExpandLists(command_expand_lists);
+ cc->SetDepfile(depfile);
+ cc->SetJobPool(job_pool);
+ cc->SetStdPipesUTF8(stdPipesUTF8);
+ cc->SetCMP0116Status(cmp0116);
+ return detail::AddCustomCommandToOutput(*this, cmCommandOrigin::Generator,
+ main_dependency, std::move(cc),
+ replace);
}
cmTarget* cmLocalGenerator::AddUtilityCommand(
@@ -1136,10 +1161,21 @@ cmTarget* cmLocalGenerator::AddUtilityCommand(
return target;
}
- detail::AddUtilityCommand(
- *this, this->DirectoryBacktrace, cmCommandOrigin::Generator, target,
- workingDir, byproducts, depends, commandLines, escapeOldStyle, comment,
- uses_terminal, command_expand_lists, job_pool, stdPipesUTF8, cmp0116);
+ auto cc = cm::make_unique<cmCustomCommand>();
+ cc->SetBacktrace(this->DirectoryBacktrace);
+ cc->SetWorkingDirectory(workingDir);
+ cc->SetByproducts(byproducts);
+ cc->SetDepends(depends);
+ cc->SetCommandLines(commandLines);
+ cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->SetComment(comment);
+ cc->SetUsesTerminal(uses_terminal);
+ cc->SetCommandExpandLists(command_expand_lists);
+ cc->SetJobPool(job_pool);
+ cc->SetStdPipesUTF8(stdPipesUTF8);
+ cc->SetCMP0116Status(cmp0116);
+ detail::AddUtilityCommand(*this, cmCommandOrigin::Generator, target,
+ std::move(cc));
return target;
}
@@ -4051,19 +4087,16 @@ std::string ComputeCustomCommandRuleFileName(cmLocalGenerator& lg,
h.HashString(output).substr(0, 16));
}
-cmSourceFile* AddCustomCommand(
- cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
- cmCommandOrigin origin, const std::vector<std::string>& outputs,
- const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends, const std::string& main_dependency,
- const cmImplicitDependsList& implicit_depends,
- const cmCustomCommandLines& commandLines, const char* comment,
- const char* workingDir, bool replace, bool escapeOldStyle,
- bool uses_terminal, bool command_expand_lists, const std::string& depfile,
- const std::string& job_pool, bool stdPipesUTF8,
- cmPolicies::PolicyStatus cmp0116)
+cmSourceFile* AddCustomCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
+ const std::string& main_dependency,
+ std::unique_ptr<cmCustomCommand> cc,
+ bool replace)
{
cmMakefile* mf = lg.GetMakefile();
+ const auto& lfbt = cc->GetBacktrace();
+ const auto& outputs = cc->GetOutputs();
+ const auto& byproducts = cc->GetByproducts();
+ const auto& commandLines = cc->GetCommandLines();
// Choose a source file on which to store the custom command.
cmSourceFile* file = nullptr;
@@ -4118,34 +4151,18 @@ cmSourceFile* AddCustomCommand(
// Attach the custom command to the file.
if (file) {
// Construct a complete list of dependencies.
- std::vector<std::string> depends2(depends);
if (!main_dependency.empty()) {
- depends2.push_back(main_dependency);
- }
-
- std::unique_ptr<cmCustomCommand> cc = cm::make_unique<cmCustomCommand>();
- cc->SetByproducts(byproducts);
- cc->SetDepends(std::move(depends2));
- cc->SetOutputs(outputs);
- cc->SetCommandLines(commandLines);
- cc->SetComment(comment);
- cc->SetBacktrace(lfbt);
- cc->SetWorkingDirectory(workingDir);
- cc->SetStdPipesUTF8(stdPipesUTF8);
- cc->SetEscapeOldStyle(escapeOldStyle);
+ cc->AppendDepends({ main_dependency });
+ }
+
cc->SetEscapeAllowMakeVars(true);
- cc->SetImplicitDepends(implicit_depends);
- cc->SetUsesTerminal(uses_terminal);
- cc->SetCommandExpandLists(command_expand_lists);
- cc->SetDepfile(depfile);
- cc->SetJobPool(job_pool);
- cc->SetCMP0116Status(cmp0116);
- file->SetCustomCommand(std::move(cc));
lg.AddSourceOutputs(file, outputs, cmLocalGenerator::OutputRole::Primary,
lfbt, origin);
lg.AddSourceOutputs(file, byproducts,
cmLocalGenerator::OutputRole::Byproduct, lfbt, origin);
+
+ file->SetCustomCommand(std::move(cc));
}
return file;
}
@@ -4174,68 +4191,39 @@ bool AnyTargetCommandOutputMatches(
}
namespace detail {
-void AddCustomCommandToTarget(cmLocalGenerator& lg,
- const cmListFileBacktrace& lfbt,
- cmCommandOrigin origin, cmTarget* target,
- const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines,
- cmCustomCommandType type, const char* comment,
- const char* workingDir, bool escapeOldStyle,
- bool uses_terminal, const std::string& depfile,
- const std::string& job_pool,
- bool command_expand_lists, bool stdPipesUTF8,
- cmPolicies::PolicyStatus cmp0116)
+void AddCustomCommandToTarget(cmLocalGenerator& lg, cmCommandOrigin origin,
+ cmTarget* target, cmCustomCommandType type,
+ std::unique_ptr<cmCustomCommand> cc)
{
// Add the command to the appropriate build step for the target.
- cmCustomCommand cc;
- cc.SetByproducts(byproducts);
- cc.SetDepends(depends);
- cc.SetCommandLines(commandLines);
- cc.SetComment(comment);
- cc.SetBacktrace(lfbt);
- cc.SetWorkingDirectory(workingDir);
- cc.SetStdPipesUTF8(stdPipesUTF8);
- cc.SetEscapeOldStyle(escapeOldStyle);
- cc.SetEscapeAllowMakeVars(true);
- cc.SetUsesTerminal(uses_terminal);
- cc.SetCommandExpandLists(command_expand_lists);
- cc.SetDepfile(depfile);
- cc.SetJobPool(job_pool);
- cc.SetCMP0116Status(cmp0116);
- cc.SetTarget(target->GetName());
+ cc->SetEscapeAllowMakeVars(true);
+ cc->SetTarget(target->GetName());
+
+ lg.AddTargetByproducts(target, cc->GetByproducts(), cc->GetBacktrace(),
+ origin);
+
switch (type) {
case cmCustomCommandType::PRE_BUILD:
- target->AddPreBuildCommand(std::move(cc));
+ target->AddPreBuildCommand(std::move(*cc));
break;
case cmCustomCommandType::PRE_LINK:
- target->AddPreLinkCommand(std::move(cc));
+ target->AddPreLinkCommand(std::move(*cc));
break;
case cmCustomCommandType::POST_BUILD:
- target->AddPostBuildCommand(std::move(cc));
+ target->AddPostBuildCommand(std::move(*cc));
break;
}
- lg.AddTargetByproducts(target, byproducts, lfbt, origin);
+ cc.reset();
}
-cmSourceFile* AddCustomCommandToOutput(
- cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
- cmCommandOrigin origin, const std::vector<std::string>& outputs,
- const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends, const std::string& main_dependency,
- const cmImplicitDependsList& implicit_depends,
- const cmCustomCommandLines& commandLines, const char* comment,
- const char* workingDir, bool replace, bool escapeOldStyle,
- bool uses_terminal, bool command_expand_lists, const std::string& depfile,
- const std::string& job_pool, bool stdPipesUTF8,
- cmPolicies::PolicyStatus cmp0116)
+cmSourceFile* AddCustomCommandToOutput(cmLocalGenerator& lg,
+ cmCommandOrigin origin,
+ const std::string& main_dependency,
+ std::unique_ptr<cmCustomCommand> cc,
+ bool replace)
{
- return AddCustomCommand(lg, lfbt, origin, outputs, byproducts, depends,
- main_dependency, implicit_depends, commandLines,
- comment, workingDir, replace, escapeOldStyle,
- uses_terminal, command_expand_lists, depfile,
- job_pool, stdPipesUTF8, cmp0116);
+ return AddCustomCommand(lg, origin, main_dependency, std::move(cc), replace);
}
void AppendCustomCommandToOutput(cmLocalGenerator& lg,
@@ -4278,33 +4266,27 @@ void AppendCustomCommandToOutput(cmLocalGenerator& lg,
lfbt);
}
-void AddUtilityCommand(cmLocalGenerator& lg, const cmListFileBacktrace& lfbt,
- cmCommandOrigin origin, cmTarget* target,
- const char* workingDir,
- const std::vector<std::string>& byproducts,
- const std::vector<std::string>& depends,
- const cmCustomCommandLines& commandLines,
- bool escapeOldStyle, const char* comment,
- bool uses_terminal, bool command_expand_lists,
- const std::string& job_pool, bool stdPipesUTF8,
- cmPolicies::PolicyStatus cmp0116)
+void AddUtilityCommand(cmLocalGenerator& lg, cmCommandOrigin origin,
+ cmTarget* target, std::unique_ptr<cmCustomCommand> cc)
{
+ // They might be moved away
+ auto byproducts = cc->GetByproducts();
+ auto lfbt = cc->GetBacktrace();
+
// Use an empty comment to avoid generation of default comment.
- if (!comment) {
- comment = "";
+ if (!cc->GetComment()) {
+ cc->SetComment("");
}
// Create the generated symbolic output name of the utility target.
std::string output =
lg.CreateUtilityOutput(target->GetName(), byproducts, lfbt);
+ cc->SetOutputs(output);
std::string no_main_dependency;
- cmImplicitDependsList no_implicit_depends;
- cmSourceFile* rule = AddCustomCommand(
- lg, lfbt, origin, { output }, byproducts, depends, no_main_dependency,
- no_implicit_depends, commandLines, comment, workingDir,
- /*replace=*/false, escapeOldStyle, uses_terminal, command_expand_lists,
- /*depfile=*/"", job_pool, stdPipesUTF8, cmp0116);
+ cmSourceFile* rule =
+ AddCustomCommand(lg, origin, no_main_dependency, std::move(cc),
+ /*replace=*/false);
if (rule) {
lg.AddTargetByproducts(target, byproducts, lfbt, origin);
}