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

View File

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

View File

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

View File

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

View File

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