Ninja: don't pollute the rules file with useless comments

This commit is contained in:
Peter Kuemmel 2012-06-10 20:20:29 +02:00
parent 343ff7a72e
commit ba8d0db217
5 changed files with 35 additions and 5 deletions

View File

@ -43,12 +43,13 @@ void cmGlobalNinjaGenerator::WriteComment(std::ostream& os,
std::string replace = comment; std::string replace = comment;
std::string::size_type lpos = 0; std::string::size_type lpos = 0;
std::string::size_type rpos; std::string::size_type rpos;
os << "\n#############################################\n";
while((rpos = replace.find('\n', lpos)) != std::string::npos) while((rpos = replace.find('\n', lpos)) != std::string::npos)
{ {
os << "# " << replace.substr(lpos, rpos - lpos) << "\n"; os << "# " << replace.substr(lpos, rpos - lpos) << "\n";
lpos = rpos + 1; lpos = rpos + 1;
} }
os << "# " << replace.substr(lpos) << "\n"; os << "# " << replace.substr(lpos) << "\n\n";
} }
static bool IsIdentChar(char c) static bool IsIdentChar(char c)
@ -318,6 +319,8 @@ void cmGlobalNinjaGenerator::WriteRule(std::ostream& os,
cmGlobalNinjaGenerator::Indent(os, 1); cmGlobalNinjaGenerator::Indent(os, 1);
os << "generator = 1\n"; os << "generator = 1\n";
} }
os << "\n";
} }
void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os, void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os,
@ -374,12 +377,21 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator()
, CompileCommandsStream(0) , CompileCommandsStream(0)
, Rules() , Rules()
, AllDependencies() , AllDependencies()
, CommentStream(0)
{ {
// // Ninja is not ported to non-Unix OS yet. // // Ninja is not ported to non-Unix OS yet.
// this->ForceUnixPaths = true; // this->ForceUnixPaths = true;
this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake"; this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake";
this->ClearCommentStream();
} }
void cmGlobalNinjaGenerator::ClearCommentStream()
{
delete CommentStream;
CommentStream = new cmsys_ios::stringstream(std::ios::out);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Virtual public methods. // Virtual public methods.
@ -537,7 +549,13 @@ void cmGlobalNinjaGenerator::AddRule(const std::string& name,
{ {
// Do not add the same rule twice. // Do not add the same rule twice.
if (this->HasRule(name)) if (this->HasRule(name))
{
this->ClearCommentStream();
return; return;
}
*this->RulesFileStream << this->GetCommentStream().str();
this->ClearCommentStream();
this->Rules.insert(name); this->Rules.insert(name);
cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream, cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream,

View File

@ -16,6 +16,8 @@
# include "cmGlobalGenerator.h" # include "cmGlobalGenerator.h"
# include "cmNinjaTypes.h" # include "cmNinjaTypes.h"
//#define NINJA_GEN_VERBOSE_FILES
class cmLocalGenerator; class cmLocalGenerator;
class cmGeneratedFileStream; class cmGeneratedFileStream;
class cmGeneratorTarget; class cmGeneratorTarget;
@ -215,6 +217,11 @@ public:
cmGeneratedFileStream* GetRulesFileStream() const cmGeneratedFileStream* GetRulesFileStream() const
{ return this->RulesFileStream; } { return this->RulesFileStream; }
void ClearCommentStream();
cmsys_ios::stringstream& GetCommentStream() const
{ return *this->CommentStream; }
void AddCXXCompileCommand(const std::string &commandLine, void AddCXXCompileCommand(const std::string &commandLine,
const std::string &sourceFile); const std::string &sourceFile);
@ -346,6 +353,9 @@ private:
static cmLocalGenerator* LocalGenerator; static cmLocalGenerator* LocalGenerator;
static bool UsingMinGW; static bool UsingMinGW;
cmsys_ios::stringstream* CommentStream;
}; };
#endif // ! cmGlobalNinjaGenerator_h #endif // ! cmGlobalNinjaGenerator_h

View File

@ -46,7 +46,9 @@ void cmLocalNinjaGenerator::Generate()
this->SetConfigName(); this->SetConfigName();
this->WriteProcessedMakefile(this->GetBuildFileStream()); this->WriteProcessedMakefile(this->GetBuildFileStream());
#ifdef NINJA_GEN_VERBOSE_FILES
this->WriteProcessedMakefile(this->GetRulesFileStream()); this->WriteProcessedMakefile(this->GetRulesFileStream());
#endif
this->WriteBuildFileTop(); this->WriteBuildFileTop();

View File

@ -96,13 +96,11 @@ void cmNinjaNormalTargetGenerator::Generate()
#endif #endif
this->WriteLinkStatement(); this->WriteLinkStatement();
} }
this->GetBuildFileStream() << "\n";
this->GetRulesFileStream() << "\n";
} }
void cmNinjaNormalTargetGenerator::WriteLanguagesRules() void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
{ {
#ifdef NINJA_GEN_VERBOSE_FILES
cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream()); cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream());
this->GetRulesFileStream() this->GetRulesFileStream()
<< "# Rules for each languages for " << "# Rules for each languages for "
@ -110,6 +108,7 @@ void cmNinjaNormalTargetGenerator::WriteLanguagesRules()
<< " target " << " target "
<< this->GetTargetName() << this->GetTargetName()
<< "\n\n"; << "\n\n";
#endif
std::set<cmStdString> languages; std::set<cmStdString> languages;
this->GetTarget()->GetLanguages(languages); this->GetTarget()->GetLanguages(languages);

View File

@ -309,10 +309,11 @@ void
cmNinjaTargetGenerator cmNinjaTargetGenerator
::WriteLanguageRules(const std::string& language) ::WriteLanguageRules(const std::string& language)
{ {
#ifdef NINJA_GEN_VERBOSE_FILES
this->GetRulesFileStream() this->GetRulesFileStream()
<< "# Rules for language " << language << "\n\n"; << "# Rules for language " << language << "\n\n";
#endif
this->WriteCompileRule(language); this->WriteCompileRule(language);
this->GetRulesFileStream() << "\n";
} }
void void