Add a flag to warn about system files

This commit is contained in:
Ben Boeckel 2010-09-01 11:24:20 -04:00
parent fff9f6d6f7
commit 74997000c8
6 changed files with 32 additions and 7 deletions

View File

@ -21,6 +21,7 @@ int cmCommandArgument_yyparse( yyscan_t yyscanner );
cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
{
this->WarnUninitialized = false;
this->CheckSystemVars = false;
this->FileLine = -1;
this->FileName = 0;
this->RemoveEmpty = true;
@ -129,10 +130,14 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
// not been "cleared"/initialized with a set(foo ) call
if(this->WarnUninitialized && !this->Makefile->VariableInitialized(var))
{
cmOStringStream msg;
msg << this->FileName << ":" << this->FileLine << ":" <<
" warning: uninitialized variable \'" << var << "\'";
cmSystemTools::Message(msg.str().c_str());
const char* root = this->Makefile->GetDefinition("CMAKE_ROOT");
if (this->CheckSystemVars || strstr(this->FileName, root) != this->FileName)
{
cmOStringStream msg;
msg << this->FileName << ":" << this->FileLine << ":" <<
" warning: uninitialized variable \'" << var << "\'";
cmSystemTools::Message(msg.str().c_str());
}
}
return 0;
}
@ -331,6 +336,7 @@ void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf)
{
this->Makefile = mf;
this->WarnUninitialized = mf->GetCMakeInstance()->GetWarnUninitialized();
this->CheckSystemVars = mf->GetCMakeInstance()->GetCheckSystemVars();
}
void cmCommandArgumentParserHelper::SetResult(const char* value)

View File

@ -97,6 +97,7 @@ private:
std::string Result;
const char* FileName;
bool WarnUninitialized;
bool CheckSystemVars;
long FileLine;
bool EscapeQuotes;
std::string ErrorString;

View File

@ -93,6 +93,7 @@ cmMakefile::cmMakefile(): Internal(new Internals)
this->Initialize();
this->PreOrder = false;
this->WarnUnused = false;
this->CheckSystemVars = false;
}
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
@ -136,6 +137,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
this->Properties = mf.Properties;
this->PreOrder = mf.PreOrder;
this->WarnUnused = mf.WarnUnused;
this->CheckSystemVars = mf.CheckSystemVars;
this->ListFileStack = mf.ListFileStack;
this->Initialize();
}
@ -774,6 +776,7 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
this->Internal->VarUsageStack.push(std::set<cmStdString>());
}
}
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
}
bool cmMakefile::NeedBackwardsCompatibility(unsigned int major,
@ -3386,9 +3389,14 @@ void cmMakefile::PopScope()
init.erase(*it);
if (this->WarnUnused && usage.find(*it) == usage.end())
{
cmOStringStream m;
m << "unused variable \'" << *it << "\'";
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
const char* cdir = this->ListFileStack.back().c_str();
const char* root = this->GetDefinition("CMAKE_ROOT");
if (this->CheckSystemVars || strstr(cdir, root) != cdir)
{
cmOStringStream m;
m << "unused variable \'" << *it << "\'";
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
}
}
else
{

View File

@ -935,6 +935,7 @@ private:
// Unused variable flags
bool WarnUnused;
bool CheckSystemVars;
// stack of list files being read
std::deque<cmStdString> ListFileStack;

View File

@ -150,6 +150,7 @@ cmake::cmake()
this->WarnUninitialized = false;
this->WarnUnused = false;
this->WarnUnusedCli = true;
this->CheckSystemVars = false;
this->SuppressDevWarnings = false;
this->DoSuppressDevWarnings = false;
this->DebugOutput = false;
@ -656,6 +657,11 @@ void cmake::SetArgs(const std::vector<std::string>& args)
std::cout << "Finding unused variables given on the command line.\n";
this->SetWarnUnusedCli(true);
}
else if(arg.find("--check-system-vars",0) == 0)
{
std::cout << "Also check system files when warning about unused and uninitialized variables.\n";
this->SetCheckSystemVars(true);
}
else if(arg.find("-G",0) == 0)
{
std::string value = arg.substr(2);

View File

@ -312,6 +312,8 @@ class cmake
void SetWarnUnused(bool b) { this->WarnUnused = b;}
bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b;}
bool GetCheckSystemVars() { return this->CheckSystemVars;}
void SetCheckSystemVars(bool b) { this->CheckSystemVars = b;}
void MarkCliAsUsed(const std::string& variable);
@ -455,6 +457,7 @@ private:
bool WarnUninitialized;
bool WarnUnused;
bool WarnUnusedCli;
bool CheckSystemVars;
std::map<std::string, bool> UsedCliVariables;
std::string CMakeEditCommand;
std::string CMakeCommand;