mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-13 17:47:49 +08:00
cmGlobalNinjaGenerator: Factor out custom command output collection
De-duplicate code paths calling ConvertToNinjaPath and SeenCustomCommandOutput on custom command outputs and custom target byproducts.
This commit is contained in:
@@ -310,11 +310,21 @@ void cmGlobalNinjaGenerator::AddCustomCommandRule()
|
||||
this->AddRule(rule);
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::CCOutputs::Add(
|
||||
std::vector<std::string> const& paths)
|
||||
{
|
||||
for (std::string const& path : paths) {
|
||||
std::string out = this->GG->ConvertToNinjaPath(path);
|
||||
this->GG->SeenCustomCommandOutput(out);
|
||||
this->ExplicitOuts.emplace_back(std::move(out));
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
|
||||
std::string const& command, std::string const& description,
|
||||
std::string const& comment, std::string const& depfile,
|
||||
std::string const& job_pool, bool uses_terminal, bool restat,
|
||||
std::string const& config, cmNinjaDeps outputs, cmNinjaDeps explicitDeps,
|
||||
std::string const& config, CCOutputs outputs, cmNinjaDeps explicitDeps,
|
||||
cmNinjaDeps orderOnlyDeps)
|
||||
{
|
||||
this->AddCustomCommandRule();
|
||||
@@ -330,7 +340,7 @@ void cmGlobalNinjaGenerator::WriteCustomCommandBuild(
|
||||
{
|
||||
cmNinjaBuild build("CUSTOM_COMMAND");
|
||||
build.Comment = comment;
|
||||
build.Outputs = std::move(outputs);
|
||||
build.Outputs = std::move(outputs.ExplicitOuts);
|
||||
build.ExplicitDeps = std::move(explicitDeps);
|
||||
build.OrderOnlyDeps = std::move(orderOnlyDeps);
|
||||
|
||||
@@ -1201,6 +1211,8 @@ void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os) const
|
||||
void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
|
||||
{
|
||||
for (auto const& asd : this->AssumedSourceDependencies) {
|
||||
CCOutputs outputs(this);
|
||||
outputs.ExplicitOuts.emplace_back(asd.first);
|
||||
cmNinjaDeps orderOnlyDeps;
|
||||
std::copy(asd.second.begin(), asd.second.end(),
|
||||
std::back_inserter(orderOnlyDeps));
|
||||
@@ -1209,7 +1221,7 @@ void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
|
||||
"Assume dependencies for generated source file.",
|
||||
/*depfile*/ "", /*job_pool*/ "",
|
||||
/*uses_terminal*/ false,
|
||||
/*restat*/ true, std::string(), cmNinjaDeps(1, asd.first), cmNinjaDeps(),
|
||||
/*restat*/ true, std::string(), outputs, cmNinjaDeps(),
|
||||
std::move(orderOnlyDeps));
|
||||
}
|
||||
}
|
||||
|
@@ -110,13 +110,26 @@ public:
|
||||
void WriteBuild(std::ostream& os, cmNinjaBuild const& build,
|
||||
int cmdLineLimit = 0, bool* usedResponseFile = nullptr);
|
||||
|
||||
class CCOutputs
|
||||
{
|
||||
cmGlobalNinjaGenerator* GG;
|
||||
|
||||
public:
|
||||
CCOutputs(cmGlobalNinjaGenerator* gg)
|
||||
: GG(gg)
|
||||
{
|
||||
}
|
||||
void Add(std::vector<std::string> const& outputs);
|
||||
cmNinjaDeps ExplicitOuts;
|
||||
};
|
||||
|
||||
void WriteCustomCommandBuild(std::string const& command,
|
||||
std::string const& description,
|
||||
std::string const& comment,
|
||||
std::string const& depfile,
|
||||
std::string const& pool, bool uses_terminal,
|
||||
bool restat, std::string const& config,
|
||||
cmNinjaDeps outputs,
|
||||
CCOutputs outputs,
|
||||
cmNinjaDeps explicitDeps = cmNinjaDeps(),
|
||||
cmNinjaDeps orderOnlyDeps = cmNinjaDeps());
|
||||
|
||||
|
@@ -638,18 +638,11 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
||||
}
|
||||
}
|
||||
|
||||
cmNinjaDeps ninjaOutputs(outputs.size() + byproducts.size());
|
||||
std::transform(outputs.begin(), outputs.end(), ninjaOutputs.begin(),
|
||||
gg->MapToNinjaPath());
|
||||
std::transform(byproducts.begin(), byproducts.end(),
|
||||
ninjaOutputs.begin() + outputs.size(),
|
||||
gg->MapToNinjaPath());
|
||||
cmGlobalNinjaGenerator::CCOutputs ccOutputs(gg);
|
||||
ccOutputs.Add(outputs);
|
||||
ccOutputs.Add(byproducts);
|
||||
|
||||
for (std::string const& ninjaOutput : ninjaOutputs) {
|
||||
gg->SeenCustomCommandOutput(ninjaOutput);
|
||||
}
|
||||
|
||||
std::string mainOutput = ninjaOutputs[0];
|
||||
std::string mainOutput = ccOutputs.ExplicitOuts[0];
|
||||
|
||||
cmNinjaDeps ninjaDeps;
|
||||
this->AppendCustomCommandDeps(ccg, ninjaDeps, fileConfig);
|
||||
@@ -660,7 +653,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
||||
if (cmdLines.empty()) {
|
||||
cmNinjaBuild build("phony");
|
||||
build.Comment = cmStrCat("Phony custom command for ", mainOutput);
|
||||
build.Outputs = std::move(ninjaOutputs);
|
||||
build.Outputs = std::move(ccOutputs.ExplicitOuts);
|
||||
build.ExplicitDeps = std::move(ninjaDeps);
|
||||
build.OrderOnlyDeps = orderOnlyDeps;
|
||||
gg->WriteBuild(this->GetImplFileStream(fileConfig), build);
|
||||
@@ -710,8 +703,7 @@ void cmLocalNinjaGenerator::WriteCustomCommandBuildStatement(
|
||||
this->ConstructComment(ccg), comment, depfile, cc->GetJobPool(),
|
||||
cc->GetUsesTerminal(),
|
||||
/*restat*/ !symbolic || !byproducts.empty(), fileConfig,
|
||||
std::move(ninjaOutputs), std::move(ninjaDeps),
|
||||
std::move(orderOnlyDeps));
|
||||
std::move(ccOutputs), std::move(ninjaDeps), std::move(orderOnlyDeps));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -73,7 +73,8 @@ void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements(
|
||||
cmNinjaBuild phonyBuild("phony");
|
||||
std::vector<std::string> commands;
|
||||
cmNinjaDeps deps;
|
||||
cmNinjaDeps util_outputs(1, utilCommandName);
|
||||
cmGlobalNinjaGenerator::CCOutputs util_outputs(gg);
|
||||
util_outputs.ExplicitOuts.emplace_back(utilCommandName);
|
||||
|
||||
bool uses_terminal = false;
|
||||
{
|
||||
@@ -86,10 +87,7 @@ void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements(
|
||||
cmCustomCommandGenerator ccg(ci, fileConfig, lg);
|
||||
lg->AppendCustomCommandDeps(ccg, deps, fileConfig);
|
||||
lg->AppendCustomCommandLines(ccg, commands);
|
||||
std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
|
||||
std::transform(ccByproducts.begin(), ccByproducts.end(),
|
||||
std::back_inserter(util_outputs),
|
||||
this->MapToNinjaPath());
|
||||
util_outputs.Add(ccg.GetByproducts());
|
||||
if (ci.GetUsesTerminal()) {
|
||||
uses_terminal = true;
|
||||
}
|
||||
@@ -124,7 +122,8 @@ void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements(
|
||||
if (genTarget->Target->GetType() != cmStateEnums::GLOBAL_TARGET) {
|
||||
lg->AppendTargetOutputs(genTarget, gg->GetByproductsForCleanTarget(),
|
||||
config);
|
||||
std::copy(util_outputs.begin(), util_outputs.end(),
|
||||
std::copy(util_outputs.ExplicitOuts.begin(),
|
||||
util_outputs.ExplicitOuts.end(),
|
||||
std::back_inserter(gg->GetByproductsForCleanTarget()));
|
||||
}
|
||||
lg->AppendTargetDepends(genTarget, deps, config, fileConfig,
|
||||
@@ -166,10 +165,6 @@ void cmNinjaUtilityTargetGenerator::WriteUtilBuildStatements(
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::string const& util_output : util_outputs) {
|
||||
gg->SeenCustomCommandOutput(util_output);
|
||||
}
|
||||
|
||||
std::string ccConfig;
|
||||
if (genTarget->Target->IsPerConfig() &&
|
||||
genTarget->GetType() != cmStateEnums::GLOBAL_TARGET) {
|
||||
|
Reference in New Issue
Block a user