Merge topic 'CreateRulePlaceholderExpander-enhance-memory-management'

72faa9a017 CreateRulePlaceholderExpander(): enhance memory management

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !8456
This commit is contained in:
Brad King
2023-05-05 16:36:00 +00:00
committed by Kitware Robot
10 changed files with 39 additions and 41 deletions

View File

@@ -207,12 +207,12 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
}
}
cmRulePlaceholderExpander* cmLocalGenerator::CreateRulePlaceholderExpander()
const
std::unique_ptr<cmRulePlaceholderExpander>
cmLocalGenerator::CreateRulePlaceholderExpander() const
{
return new cmRulePlaceholderExpander(this->Compilers, this->VariableMappings,
this->CompilerSysroot,
this->LinkerSysroot);
return cm::make_unique<cmRulePlaceholderExpander>(
this->Compilers, this->VariableMappings, this->CompilerSysroot,
this->LinkerSysroot);
}
cmLocalGenerator::~cmLocalGenerator() = default;
@@ -3222,8 +3222,7 @@ void cmLocalGenerator::AppendDependencyInfoLinkerFlags(
auto depFile = this->ConvertToOutputFormat(
this->MaybeRelativeToWorkDir(this->GetLinkDependencyFile(target, config)),
cmOutputConverter::SHELL);
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
cmRulePlaceholderExpander::RuleVariables linkDepsVariables;
linkDepsVariables.DependencyFile = depFile.c_str();
rulePlaceholderExpander->ExpandRuleVariables(this, depFlag,

View File

@@ -137,7 +137,8 @@ public:
return this->GlobalGenerator;
}
virtual cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const;
virtual std::unique_ptr<cmRulePlaceholderExpander>
CreateRulePlaceholderExpander() const;
std::string GetLinkLibsCMP0065(std::string const& linkLanguage,
cmGeneratorTarget& tgt) const;

View File

@@ -47,13 +47,12 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator(cmGlobalGenerator* gg,
// Virtual public methods.
cmRulePlaceholderExpander*
std::unique_ptr<cmRulePlaceholderExpander>
cmLocalNinjaGenerator::CreateRulePlaceholderExpander() const
{
cmRulePlaceholderExpander* ret =
this->cmLocalGenerator::CreateRulePlaceholderExpander();
auto ret = this->cmLocalGenerator::CreateRulePlaceholderExpander();
ret->SetTargetImpLib("$TARGET_IMPLIB");
return ret;
return std::unique_ptr<cmRulePlaceholderExpander>(std::move(ret));
}
cmLocalNinjaGenerator::~cmLocalNinjaGenerator() = default;
@@ -913,8 +912,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
}
vars.Output = output.c_str();
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
std::string launcher = *property_value;
rulePlaceholderExpander->ExpandRuleVariables(this, launcher, vars);

View File

@@ -6,6 +6,7 @@
#include <iosfwd>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -41,7 +42,8 @@ public:
void Generate() override;
cmRulePlaceholderExpander* CreateRulePlaceholderExpander() const override;
std::unique_ptr<cmRulePlaceholderExpander> CreateRulePlaceholderExpander()
const override;
std::string GetTargetDirectory(
cmGeneratorTarget const* target) const override;

View File

@@ -969,8 +969,7 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
*content << dir;
}
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
// Add each command line to the set of commands.
std::vector<std::string> commands1;

View File

@@ -232,8 +232,8 @@ void cmMakefileExecutableTargetGenerator::WriteNvidiaDeviceExecutableRule(
launcher = cmStrCat(val, ' ');
}
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->LocalGenerator->CreateRulePlaceholderExpander();
// Expand placeholders in the commands.
rulePlaceholderExpander->SetTargetImpLib(targetOutput);
@@ -598,8 +598,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
launcher = cmStrCat(val, ' ');
}
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->LocalGenerator->CreateRulePlaceholderExpander();
// Expand placeholders in the commands.
rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);

View File

@@ -373,8 +373,8 @@ void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules(
launcher = cmStrCat(val, ' ');
}
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->LocalGenerator->CreateRulePlaceholderExpander();
// Construct the main link rule and expand placeholders.
rulePlaceholderExpander->SetTargetImpLib(targetOutput);
@@ -696,8 +696,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
}
// Expand the rule variables.
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->LocalGenerator->CreateRulePlaceholderExpander();
bool useWatcomQuote =
this->Makefile->IsOn(linkRuleVar + "_USE_WATCOM_QUOTE");
cmList real_link_commands;

View File

@@ -967,8 +967,8 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
bool const lang_has_assembly = lang_has_preprocessor;
bool const lang_can_export_cmds = lang_has_preprocessor;
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->LocalGenerator->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->LocalGenerator->CreateRulePlaceholderExpander();
// Construct the compile rules.
{
@@ -1789,8 +1789,7 @@ void cmMakefileTargetGenerator::WriteDeviceLinkRule(
vars.Flags = flags.c_str();
std::string compileCmd = this->GetLinkRule("CMAKE_CUDA_DEVICE_LINK_COMPILE");
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
localGen->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander = localGen->CreateRulePlaceholderExpander();
rulePlaceholderExpander->ExpandRuleVariables(localGen, compileCmd, vars);
commands.emplace_back(compileCmd);

View File

@@ -302,8 +302,8 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkRule(
launcher = cmStrCat(val, ' ');
}
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
// Rule for linking library/executable.
std::vector<std::string> linkCmds = this->ComputeDeviceLinkCmd();
@@ -362,8 +362,8 @@ void cmNinjaNormalTargetGenerator::WriteDeviceLinkRules(
std::string compileCmd = this->GetMakefile()->GetRequiredDefinition(
"CMAKE_CUDA_DEVICE_LINK_COMPILE");
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(),
compileCmd, vars);
@@ -511,8 +511,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
launcher = cmStrCat(val, ' ');
}
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
// Rule for linking library/executable.
std::vector<std::string> linkCmds = this->ComputeLinkCmd(config);
@@ -584,8 +584,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
std::string cmd =
this->GetMakefile()->GetDefinition("CMAKE_CREATE_TEXT_STUBS");
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
cmRulePlaceholderExpander::RuleVariables vars;
vars.Target = "$in";
rulePlaceholderExpander->SetTargetImpLib("$out");

View File

@@ -665,8 +665,8 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
std::string const modmapFormat =
this->Makefile->GetSafeDefinition(modmapFormatVar);
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat(
this->ConvertToNinjaPath(this->GetTargetDependInfoPath(lang, config)),
@@ -1865,8 +1865,8 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
this->Makefile->GetRequiredDefinition(cmdVar);
cmList compileCmds(compileCmd);
std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
this->GetLocalGenerator()->CreateRulePlaceholderExpander());
auto rulePlaceholderExpander =
this->GetLocalGenerator()->CreateRulePlaceholderExpander();
for (auto& i : compileCmds) {
// no launcher for CMAKE_EXPORT_COMPILE_COMMANDS