mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-28 03:38:43 -06:00
Ninja: Simplify top-level "all" target generation
Remove its dedicated implementation and update the per-directory "all" target generation to work for the top-level directory too.
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmGeneratorExpressionEvaluationFile.h"
|
#include "cmGeneratorExpressionEvaluationFile.h"
|
||||||
#include "cmGeneratorTarget.h"
|
#include "cmGeneratorTarget.h"
|
||||||
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmListFileCache.h"
|
#include "cmListFileCache.h"
|
||||||
#include "cmLocalGenerator.h"
|
#include "cmLocalGenerator.h"
|
||||||
#include "cmLocalNinjaGenerator.h"
|
#include "cmLocalNinjaGenerator.h"
|
||||||
@@ -888,11 +889,6 @@ void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
|
|||||||
<< cmVersion::GetMinorVersion() << "\n\n";
|
<< cmVersion::GetMinorVersion() << "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmGlobalNinjaGenerator::AddDependencyToAll(cmGeneratorTarget* target)
|
|
||||||
{
|
|
||||||
this->AppendTargetOutputs(target, this->AllDependencies);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
|
void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies()
|
||||||
{
|
{
|
||||||
for (auto const& asd : this->AssumedSourceDependencies) {
|
for (auto const& asd : this->AssumedSourceDependencies) {
|
||||||
@@ -1091,19 +1087,11 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
|
|||||||
cmGlobalNinjaGenerator::WriteDivider(os);
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
||||||
os << "# Folder targets.\n\n";
|
os << "# Folder targets.\n\n";
|
||||||
|
|
||||||
std::string const& rootBinaryDir =
|
|
||||||
this->LocalGenerators[0]->GetBinaryDirectory();
|
|
||||||
|
|
||||||
std::map<std::string, cmNinjaDeps> targetsPerFolder;
|
std::map<std::string, cmNinjaDeps> targetsPerFolder;
|
||||||
for (cmLocalGenerator const* lg : this->LocalGenerators) {
|
for (cmLocalGenerator const* lg : this->LocalGenerators) {
|
||||||
std::string const& currentBinaryFolder(
|
std::string const& currentBinaryFolder(
|
||||||
lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
|
lg->GetStateSnapshot().GetDirectory().GetCurrentBinary());
|
||||||
|
|
||||||
// Do not generate a rule for the root binary dir.
|
|
||||||
if (currentBinaryFolder == rootBinaryDir) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The directory-level rule should depend on the target-level rules
|
// The directory-level rule should depend on the target-level rules
|
||||||
// for all targets in the directory.
|
// for all targets in the directory.
|
||||||
cmNinjaDeps& folderTargets = targetsPerFolder[currentBinaryFolder];
|
cmNinjaDeps& folderTargets = targetsPerFolder[currentBinaryFolder];
|
||||||
@@ -1121,19 +1109,16 @@ void cmGlobalNinjaGenerator::WriteFolderTargets(std::ostream& os)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// This target has been explicitly un-excluded. The directory-level
|
// This target has been explicitly un-excluded. The directory-level
|
||||||
// rule for every directory between this and the root (exclusive)
|
// rule for every directory between this and the root should depend
|
||||||
// should depend on the target-level rule for this target.
|
// on the target-level rule for this target.
|
||||||
cmStateSnapshot dir =
|
for (cmStateSnapshot dir =
|
||||||
lg->GetStateSnapshot().GetBuildsystemDirectoryParent();
|
lg->GetStateSnapshot().GetBuildsystemDirectoryParent();
|
||||||
cmStateSnapshot parent = dir.GetBuildsystemDirectoryParent();
|
dir.IsValid(); dir = dir.GetBuildsystemDirectoryParent()) {
|
||||||
while (parent.IsValid()) {
|
|
||||||
std::string const& folder = dir.GetDirectory().GetCurrentBinary();
|
std::string const& folder = dir.GetDirectory().GetCurrentBinary();
|
||||||
targetsPerFolder[folder].push_back(gt->GetName());
|
this->AppendTargetOutputs(gt, targetsPerFolder[folder]);
|
||||||
dir = parent;
|
|
||||||
parent = parent.GetBuildsystemDirectoryParent();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
folderTargets.push_back(gt->GetName());
|
this->AppendTargetOutputs(gt, folderTargets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1296,22 +1281,18 @@ void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os)
|
|||||||
cmGlobalNinjaGenerator::WriteDivider(os);
|
cmGlobalNinjaGenerator::WriteDivider(os);
|
||||||
os << "# Built-in targets\n\n";
|
os << "# Built-in targets\n\n";
|
||||||
|
|
||||||
this->WriteTargetAll(os);
|
this->WriteTargetDefault(os);
|
||||||
this->WriteTargetRebuildManifest(os);
|
this->WriteTargetRebuildManifest(os);
|
||||||
this->WriteTargetClean(os);
|
this->WriteTargetClean(os);
|
||||||
this->WriteTargetHelp(os);
|
this->WriteTargetHelp(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os)
|
void cmGlobalNinjaGenerator::WriteTargetDefault(std::ostream& os)
|
||||||
{
|
{
|
||||||
cmNinjaBuild build("phony");
|
|
||||||
build.Comment = "The main all target.";
|
|
||||||
build.Outputs.push_back(this->TargetAll);
|
|
||||||
build.ExplicitDeps = this->AllDependencies;
|
|
||||||
this->WriteBuild(os, build);
|
|
||||||
|
|
||||||
if (!this->HasOutputPathPrefix()) {
|
if (!this->HasOutputPathPrefix()) {
|
||||||
cmGlobalNinjaGenerator::WriteDefault(os, build.Outputs,
|
cmNinjaDeps all;
|
||||||
|
all.push_back(this->TargetAll);
|
||||||
|
cmGlobalNinjaGenerator::WriteDefault(os, all,
|
||||||
"Make the all target the default.");
|
"Make the all target the default.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
#include "cmGeneratedFileStream.h"
|
#include "cmGeneratedFileStream.h"
|
||||||
#include "cmGlobalCommonGenerator.h"
|
#include "cmGlobalCommonGenerator.h"
|
||||||
#include "cmGlobalGenerator.h"
|
|
||||||
#include "cmGlobalGeneratorFactory.h"
|
#include "cmGlobalGeneratorFactory.h"
|
||||||
#include "cmNinjaTypes.h"
|
#include "cmNinjaTypes.h"
|
||||||
#include "cmPolicies.h"
|
#include "cmPolicies.h"
|
||||||
@@ -294,18 +293,12 @@ public:
|
|||||||
cmNinjaDeps& outputs);
|
cmNinjaDeps& outputs);
|
||||||
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
|
void AppendTargetDependsClosure(cmGeneratorTarget const* target,
|
||||||
cmNinjaOuts& outputs, bool omit_self);
|
cmNinjaOuts& outputs, bool omit_self);
|
||||||
void AddDependencyToAll(cmGeneratorTarget* target);
|
|
||||||
|
|
||||||
const std::vector<cmLocalGenerator*>& GetLocalGenerators() const
|
const std::vector<cmLocalGenerator*>& GetLocalGenerators() const
|
||||||
{
|
{
|
||||||
return LocalGenerators;
|
return LocalGenerators;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsExcluded(cmLocalGenerator* root, cmGeneratorTarget* target)
|
|
||||||
{
|
|
||||||
return cmGlobalGenerator::IsExcluded(root, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; }
|
int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; }
|
||||||
|
|
||||||
void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target);
|
void AddTargetAlias(const std::string& alias, cmGeneratorTarget* target);
|
||||||
@@ -372,7 +365,7 @@ private:
|
|||||||
void WriteUnknownExplicitDependencies(std::ostream& os);
|
void WriteUnknownExplicitDependencies(std::ostream& os);
|
||||||
|
|
||||||
void WriteBuiltinTargets(std::ostream& os);
|
void WriteBuiltinTargets(std::ostream& os);
|
||||||
void WriteTargetAll(std::ostream& os);
|
void WriteTargetDefault(std::ostream& os);
|
||||||
void WriteTargetRebuildManifest(std::ostream& os);
|
void WriteTargetRebuildManifest(std::ostream& os);
|
||||||
bool WriteTargetCleanAdditional(std::ostream& os);
|
bool WriteTargetCleanAdditional(std::ostream& os);
|
||||||
void WriteTargetClean(std::ostream& os);
|
void WriteTargetClean(std::ostream& os);
|
||||||
@@ -399,9 +392,6 @@ private:
|
|||||||
/// Length of rule command, used by rsp file evaluation
|
/// Length of rule command, used by rsp file evaluation
|
||||||
std::unordered_map<std::string, int> RuleCmdLength;
|
std::unordered_map<std::string, int> RuleCmdLength;
|
||||||
|
|
||||||
/// The set of dependencies to add to the "all" target.
|
|
||||||
cmNinjaDeps AllDependencies;
|
|
||||||
|
|
||||||
bool UsingGCCOnWindows = false;
|
bool UsingGCCOnWindows = false;
|
||||||
|
|
||||||
/// The set of custom commands we have seen.
|
/// The set of custom commands we have seen.
|
||||||
|
|||||||
@@ -88,12 +88,6 @@ void cmLocalNinjaGenerator::Generate()
|
|||||||
auto tg = cmNinjaTargetGenerator::New(target);
|
auto tg = cmNinjaTargetGenerator::New(target);
|
||||||
if (tg) {
|
if (tg) {
|
||||||
tg->Generate();
|
tg->Generate();
|
||||||
// Add the target to "all" if required.
|
|
||||||
if (!this->GetGlobalNinjaGenerator()->IsExcluded(
|
|
||||||
this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
|
|
||||||
target)) {
|
|
||||||
this->GetGlobalNinjaGenerator()->AddDependencyToAll(target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user