Ninja: Skip generating empty phony rules

Ninja generator ensures that all custom commands being target
dependencies are run before other source compilations. However in case
there are no such dependencies it currently generates empty phony rules
which clutter the build graph.

Teach the Ninja generator to produce such rules only when necessary.
This commit is contained in:
Adam Strzelecki 2014-06-27 22:13:52 +02:00 committed by Brad King
parent 7243c95129
commit 93371ed592
2 changed files with 21 additions and 14 deletions

View File

@ -542,22 +542,24 @@ cmNinjaTargetGenerator
std::back_inserter(orderOnlyDeps), MapToNinjaPath()); std::back_inserter(orderOnlyDeps), MapToNinjaPath());
} }
cmNinjaDeps orderOnlyTarget; if (!orderOnlyDeps.empty())
orderOnlyTarget.push_back(this->OrderDependsTargetForTarget()); {
this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(), cmNinjaDeps orderOnlyTarget;
"Order-only phony target for " orderOnlyTarget.push_back(this->OrderDependsTargetForTarget());
+ this->GetTargetName(), this->GetGlobalGenerator()->WritePhonyBuild(this->GetBuildFileStream(),
orderOnlyTarget, "Order-only phony target for "
cmNinjaDeps(), + this->GetTargetName(),
cmNinjaDeps(), orderOnlyTarget,
orderOnlyDeps); cmNinjaDeps(),
cmNinjaDeps(),
orderOnlyDeps);
}
std::vector<cmSourceFile const*> objectSources; std::vector<cmSourceFile const*> objectSources;
this->GeneratorTarget->GetObjectSources(objectSources, config); this->GeneratorTarget->GetObjectSources(objectSources, config);
for(std::vector<cmSourceFile const*>::const_iterator for(std::vector<cmSourceFile const*>::const_iterator
si = objectSources.begin(); si != objectSources.end(); ++si) si = objectSources.begin(); si != objectSources.end(); ++si)
{ {
this->WriteObjectBuildStatement(*si); this->WriteObjectBuildStatement(*si, !orderOnlyDeps.empty());
} }
std::string def = this->GeneratorTarget->GetModuleDefinitionFile(config); std::string def = this->GeneratorTarget->GetModuleDefinitionFile(config);
if(!def.empty()) if(!def.empty())
@ -570,7 +572,8 @@ cmNinjaTargetGenerator
void void
cmNinjaTargetGenerator cmNinjaTargetGenerator
::WriteObjectBuildStatement(cmSourceFile const* source) ::WriteObjectBuildStatement(
cmSourceFile const* source, bool writeOrderDependsTargetForTarget)
{ {
std::string comment; std::string comment;
const std::string language = source->GetLanguage(); const std::string language = source->GetLanguage();
@ -599,7 +602,10 @@ cmNinjaTargetGenerator
} }
cmNinjaDeps orderOnlyDeps; cmNinjaDeps orderOnlyDeps;
orderOnlyDeps.push_back(this->OrderDependsTargetForTarget()); if (writeOrderDependsTargetForTarget)
{
orderOnlyDeps.push_back(this->OrderDependsTargetForTarget());
}
// If the source file is GENERATED and does not have a custom command // If the source file is GENERATED and does not have a custom command
// (either attached to this source file or another one), assume that one of // (either attached to this source file or another one), assume that one of

View File

@ -114,7 +114,8 @@ protected:
void WriteLanguageRules(const std::string& language); void WriteLanguageRules(const std::string& language);
void WriteCompileRule(const std::string& language); void WriteCompileRule(const std::string& language);
void WriteObjectBuildStatements(); void WriteObjectBuildStatements();
void WriteObjectBuildStatement(cmSourceFile const* source); void WriteObjectBuildStatement(cmSourceFile const* source,
bool writeOrderDependsTargetForTarget);
void WriteCustomCommandBuildStatement(cmCustomCommand *cc); void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
cmNinjaDeps GetObjects() const cmNinjaDeps GetObjects() const