Ninja: remove 'friend' in ninja code

This commit is contained in:
Peter Kümmel 2012-07-18 11:27:49 +02:00
parent c3988ee871
commit 7751966297
5 changed files with 99 additions and 98 deletions

View File

@ -153,6 +153,7 @@ public:
static bool IsMinGW() { return UsingMinGW; } static bool IsMinGW() { return UsingMinGW; }
public: public:
/// Default constructor. /// Default constructor.
cmGlobalNinjaGenerator(); cmGlobalNinjaGenerator();
@ -216,12 +217,12 @@ public:
} }
virtual const char* GetCleanTargetName() const { return "clean"; } virtual const char* GetCleanTargetName() const { return "clean"; }
public:
cmGeneratedFileStream* GetBuildFileStream() const
{ return this->BuildFileStream; }
cmGeneratedFileStream* GetRulesFileStream() const cmGeneratedFileStream* GetBuildFileStream() const {
{ return this->RulesFileStream; } return this->BuildFileStream; }
cmGeneratedFileStream* GetRulesFileStream() const {
return this->RulesFileStream; }
void AddCXXCompileCommand(const std::string &commandLine, void AddCXXCompileCommand(const std::string &commandLine,
const std::string &sourceFile); const std::string &sourceFile);
@ -246,54 +247,10 @@ public:
void AddCustomCommandRule(); void AddCustomCommandRule();
void AddMacOSXContentRule(); void AddMacOSXContentRule();
protected: bool HasCustomCommandOutput(const std::string &output) {
return this->CustomCommandOutputs.find(output) !=
/// Overloaded methods. this->CustomCommandOutputs.end();
/// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() }
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
private:
/// @see cmGlobalGenerator::ComputeTargetObjects
virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
private:
// In order to access the AddDependencyToAll() functions and co.
friend class cmLocalNinjaGenerator;
// In order to access the SeenCustomCommand() function.
friend class cmNinjaTargetGenerator;
friend class cmNinjaNormalTargetGenerator;
friend class cmNinjaUtilityTargetGenerator;
private:
void OpenBuildFileStream();
void CloseBuildFileStream();
void CloseCompileCommandsStream();
void OpenRulesFileStream();
void CloseRulesFileStream();
/// Write the common disclaimer text at the top of each build file.
void WriteDisclaimer(std::ostream& os);
void AddDependencyToAll(cmTarget* target);
void AddDependencyToAll(const std::string& input);
void WriteAssumedSourceDependencies();
void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
void AddTargetAlias(const std::string& alias, cmTarget* target);
void WriteTargetAliases(std::ostream& os);
void WriteBuiltinTargets(std::ostream& os);
void WriteTargetAll(std::ostream& os);
void WriteTargetRebuildManifest(std::ostream& os);
void WriteTargetClean(std::ostream& os);
void WriteTargetHelp(std::ostream& os);
/// Called when we have seen the given custom command. Returns true /// Called when we have seen the given custom command. Returns true
/// if we has seen it before. /// if we has seen it before.
@ -309,11 +266,6 @@ private:
this->AssumedSourceDependencies.erase(output); this->AssumedSourceDependencies.erase(output);
} }
bool HasCustomCommandOutput(const std::string &output) {
return this->CustomCommandOutputs.find(output) !=
this->CustomCommandOutputs.end();
}
void AddAssumedSourceDependencies(const std::string &source, void AddAssumedSourceDependencies(const std::string &source,
const cmNinjaDeps &deps) { const cmNinjaDeps &deps) {
std::set<std::string> &ASD = this->AssumedSourceDependencies[source]; std::set<std::string> &ASD = this->AssumedSourceDependencies[source];
@ -323,11 +275,59 @@ private:
ASD.insert(deps.begin(), deps.end()); ASD.insert(deps.begin(), deps.end());
} }
std::string ninjaCmd() const; void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
void AddDependencyToAll(cmTarget* target);
void AddDependencyToAll(const std::string& input);
const std::vector<cmLocalGenerator*>& GetLocalGenerators() const {
return LocalGenerators; }
bool IsExcluded(cmLocalGenerator* root, cmTarget& target) {
return cmGlobalGenerator::IsExcluded(root, target); }
int GetRuleCmdLength(const std::string& name) {
return RuleCmdLength[name]; }
void AddTargetAlias(const std::string& alias, cmTarget* target);
protected:
/// Overloaded methods.
/// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS()
virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
int GetRuleCmdLength(const std::string& name) { return RuleCmdLength[name]; }
private: private:
/// @see cmGlobalGenerator::ComputeTargetObjects
virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
void OpenBuildFileStream();
void CloseBuildFileStream();
void CloseCompileCommandsStream();
void OpenRulesFileStream();
void CloseRulesFileStream();
/// Write the common disclaimer text at the top of each build file.
void WriteDisclaimer(std::ostream& os);
void WriteAssumedSourceDependencies();
void WriteTargetAliases(std::ostream& os);
void WriteBuiltinTargets(std::ostream& os);
void WriteTargetAll(std::ostream& os);
void WriteTargetRebuildManifest(std::ostream& os);
void WriteTargetClean(std::ostream& os);
void WriteTargetHelp(std::ostream& os);
std::string ninjaCmd() const;
/// The file containing the build statement. (the relation ship of the /// The file containing the build statement. (the relation ship of the
/// compilation DAG). /// compilation DAG).
cmGeneratedFileStream* BuildFileStream; cmGeneratedFileStream* BuildFileStream;

View File

@ -61,7 +61,7 @@ void cmLocalNinjaGenerator::Generate()
tg->Generate(); tg->Generate();
// Add the target to "all" if required. // Add the target to "all" if required.
if (!this->GetGlobalNinjaGenerator()->IsExcluded( if (!this->GetGlobalNinjaGenerator()->IsExcluded(
this->GetGlobalNinjaGenerator()->LocalGenerators[0], this->GetGlobalNinjaGenerator()->GetLocalGenerators()[0],
t->second)) t->second))
this->GetGlobalNinjaGenerator()->AddDependencyToAll(&t->second); this->GetGlobalNinjaGenerator()->AddDependencyToAll(&t->second);
delete tg; delete tg;

View File

@ -45,7 +45,6 @@ public:
/// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory() /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory()
virtual std::string GetTargetDirectory(cmTarget const& target) const; virtual std::string GetTargetDirectory(cmTarget const& target) const;
public:
const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const; const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
cmGlobalNinjaGenerator* GetGlobalNinjaGenerator(); cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
@ -67,17 +66,43 @@ public:
std::string GetHomeRelativeOutputPath() const std::string GetHomeRelativeOutputPath() const
{ return this->HomeRelativeOutputPath; } { return this->HomeRelativeOutputPath; }
protected: std::string ConvertToNinjaPath(const char *path);
struct map_to_ninja_path {
cmLocalNinjaGenerator *LocalGenerator;
map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
: LocalGenerator(LocalGen) {}
std::string operator()(const std::string &path) {
return LocalGenerator->ConvertToNinjaPath(path.c_str());
}
};
map_to_ninja_path MapToNinjaPath() {
return map_to_ninja_path(this);
}
void ExpandRuleVariables(std::string& string,
const RuleVariables& replaceValues) {
return cmLocalGenerator::
ExpandRuleVariables(string, replaceValues); }
std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
void AppendCustomCommandLines(const cmCustomCommand *cc,
std::vector<std::string> &cmdLines);
void AppendCustomCommandDeps(const cmCustomCommand *cc,
cmNinjaDeps &ninjaDeps);
virtual std::string ConvertToLinkReference(std::string const& lib); virtual std::string ConvertToLinkReference(std::string const& lib);
protected:
virtual std::string ConvertToIncludeReference(std::string const& path); virtual std::string ConvertToIncludeReference(std::string const& path);
private:
friend class cmGlobalNinjaGenerator;
// In order to access to protected member of the local generator.
friend class cmNinjaTargetGenerator;
friend class cmNinjaNormalTargetGenerator;
friend class cmNinjaUtilityTargetGenerator;
private: private:
cmGeneratedFileStream& GetBuildFileStream() const; cmGeneratedFileStream& GetBuildFileStream() const;
@ -90,38 +115,13 @@ private:
void SetConfigName(); void SetConfigName();
std::string ConvertToNinjaPath(const char *path);
struct map_to_ninja_path;
friend struct map_to_ninja_path;
struct map_to_ninja_path {
cmLocalNinjaGenerator *LocalGenerator;
map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
: LocalGenerator(LocalGen) {}
std::string operator()(const std::string &path) {
return LocalGenerator->ConvertToNinjaPath(path.c_str());
}
};
map_to_ninja_path MapToNinjaPath() {
return map_to_ninja_path(this);
}
void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
void AppendCustomCommandDeps(const cmCustomCommand *cc,
cmNinjaDeps &ninjaDeps);
std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
void AppendCustomCommandLines(const cmCustomCommand *cc,
std::vector<std::string> &cmdLines);
void WriteCustomCommandRule(); void WriteCustomCommandRule();
void WriteCustomCommandBuildStatement(cmCustomCommand const *cc, void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
const cmNinjaDeps& orderOnlyDeps); const cmNinjaDeps& orderOnlyDeps);
void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
void WriteCustomCommandBuildStatements(); void WriteCustomCommandBuildStatements();
private:
std::string ConfigName; std::string ConfigName;
std::string HomeRelativeOutputPath; std::string HomeRelativeOutputPath;

View File

@ -91,7 +91,7 @@ cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const
const char* cmNinjaTargetGenerator::GetConfigName() const const char* cmNinjaTargetGenerator::GetConfigName() const
{ {
return this->LocalGenerator->ConfigName.c_str(); return this->LocalGenerator->GetConfigName();
} }
// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. // TODO: Picked up from cmMakefileTargetGenerator. Refactor it.

View File

@ -126,7 +126,7 @@ protected:
private: private:
cmNinjaTargetGenerator* Generator; cmNinjaTargetGenerator* Generator;
}; };
friend class MacOSXContentGeneratorType;
protected: protected:
MacOSXContentGeneratorType MacOSXContentGenerator; MacOSXContentGeneratorType MacOSXContentGenerator;
@ -134,6 +134,7 @@ protected:
cmOSXBundleGenerator* OSXBundleGenerator; cmOSXBundleGenerator* OSXBundleGenerator;
std::set<cmStdString> MacContentFolders; std::set<cmStdString> MacContentFolders;
private: private:
cmTarget* Target; cmTarget* Target;
cmGeneratorTarget* GeneratorTarget; cmGeneratorTarget* GeneratorTarget;