Add a flag to warn about system files
This commit is contained in:
parent
fff9f6d6f7
commit
74997000c8
@ -21,6 +21,7 @@ int cmCommandArgument_yyparse( yyscan_t yyscanner );
|
|||||||
cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
|
cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
|
||||||
{
|
{
|
||||||
this->WarnUninitialized = false;
|
this->WarnUninitialized = false;
|
||||||
|
this->CheckSystemVars = false;
|
||||||
this->FileLine = -1;
|
this->FileLine = -1;
|
||||||
this->FileName = 0;
|
this->FileName = 0;
|
||||||
this->RemoveEmpty = true;
|
this->RemoveEmpty = true;
|
||||||
@ -129,10 +130,14 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
|
|||||||
// not been "cleared"/initialized with a set(foo ) call
|
// not been "cleared"/initialized with a set(foo ) call
|
||||||
if(this->WarnUninitialized && !this->Makefile->VariableInitialized(var))
|
if(this->WarnUninitialized && !this->Makefile->VariableInitialized(var))
|
||||||
{
|
{
|
||||||
cmOStringStream msg;
|
const char* root = this->Makefile->GetDefinition("CMAKE_ROOT");
|
||||||
msg << this->FileName << ":" << this->FileLine << ":" <<
|
if (this->CheckSystemVars || strstr(this->FileName, root) != this->FileName)
|
||||||
" warning: uninitialized variable \'" << var << "\'";
|
{
|
||||||
cmSystemTools::Message(msg.str().c_str());
|
cmOStringStream msg;
|
||||||
|
msg << this->FileName << ":" << this->FileLine << ":" <<
|
||||||
|
" warning: uninitialized variable \'" << var << "\'";
|
||||||
|
cmSystemTools::Message(msg.str().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -331,6 +336,7 @@ void cmCommandArgumentParserHelper::SetMakefile(const cmMakefile* mf)
|
|||||||
{
|
{
|
||||||
this->Makefile = mf;
|
this->Makefile = mf;
|
||||||
this->WarnUninitialized = mf->GetCMakeInstance()->GetWarnUninitialized();
|
this->WarnUninitialized = mf->GetCMakeInstance()->GetWarnUninitialized();
|
||||||
|
this->CheckSystemVars = mf->GetCMakeInstance()->GetCheckSystemVars();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCommandArgumentParserHelper::SetResult(const char* value)
|
void cmCommandArgumentParserHelper::SetResult(const char* value)
|
||||||
|
@ -97,6 +97,7 @@ private:
|
|||||||
std::string Result;
|
std::string Result;
|
||||||
const char* FileName;
|
const char* FileName;
|
||||||
bool WarnUninitialized;
|
bool WarnUninitialized;
|
||||||
|
bool CheckSystemVars;
|
||||||
long FileLine;
|
long FileLine;
|
||||||
bool EscapeQuotes;
|
bool EscapeQuotes;
|
||||||
std::string ErrorString;
|
std::string ErrorString;
|
||||||
|
@ -93,6 +93,7 @@ cmMakefile::cmMakefile(): Internal(new Internals)
|
|||||||
this->Initialize();
|
this->Initialize();
|
||||||
this->PreOrder = false;
|
this->PreOrder = false;
|
||||||
this->WarnUnused = false;
|
this->WarnUnused = false;
|
||||||
|
this->CheckSystemVars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
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->Properties = mf.Properties;
|
||||||
this->PreOrder = mf.PreOrder;
|
this->PreOrder = mf.PreOrder;
|
||||||
this->WarnUnused = mf.WarnUnused;
|
this->WarnUnused = mf.WarnUnused;
|
||||||
|
this->CheckSystemVars = mf.CheckSystemVars;
|
||||||
this->ListFileStack = mf.ListFileStack;
|
this->ListFileStack = mf.ListFileStack;
|
||||||
this->Initialize();
|
this->Initialize();
|
||||||
}
|
}
|
||||||
@ -774,6 +776,7 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
|
|||||||
this->Internal->VarUsageStack.push(std::set<cmStdString>());
|
this->Internal->VarUsageStack.push(std::set<cmStdString>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this->CheckSystemVars = this->GetCMakeInstance()->GetCheckSystemVars();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmMakefile::NeedBackwardsCompatibility(unsigned int major,
|
bool cmMakefile::NeedBackwardsCompatibility(unsigned int major,
|
||||||
@ -3386,9 +3389,14 @@ void cmMakefile::PopScope()
|
|||||||
init.erase(*it);
|
init.erase(*it);
|
||||||
if (this->WarnUnused && usage.find(*it) == usage.end())
|
if (this->WarnUnused && usage.find(*it) == usage.end())
|
||||||
{
|
{
|
||||||
cmOStringStream m;
|
const char* cdir = this->ListFileStack.back().c_str();
|
||||||
m << "unused variable \'" << *it << "\'";
|
const char* root = this->GetDefinition("CMAKE_ROOT");
|
||||||
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
|
if (this->CheckSystemVars || strstr(cdir, root) != cdir)
|
||||||
|
{
|
||||||
|
cmOStringStream m;
|
||||||
|
m << "unused variable \'" << *it << "\'";
|
||||||
|
this->IssueMessage(cmake::AUTHOR_WARNING, m.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -935,6 +935,7 @@ private:
|
|||||||
|
|
||||||
// Unused variable flags
|
// Unused variable flags
|
||||||
bool WarnUnused;
|
bool WarnUnused;
|
||||||
|
bool CheckSystemVars;
|
||||||
|
|
||||||
// stack of list files being read
|
// stack of list files being read
|
||||||
std::deque<cmStdString> ListFileStack;
|
std::deque<cmStdString> ListFileStack;
|
||||||
|
@ -150,6 +150,7 @@ cmake::cmake()
|
|||||||
this->WarnUninitialized = false;
|
this->WarnUninitialized = false;
|
||||||
this->WarnUnused = false;
|
this->WarnUnused = false;
|
||||||
this->WarnUnusedCli = true;
|
this->WarnUnusedCli = true;
|
||||||
|
this->CheckSystemVars = false;
|
||||||
this->SuppressDevWarnings = false;
|
this->SuppressDevWarnings = false;
|
||||||
this->DoSuppressDevWarnings = false;
|
this->DoSuppressDevWarnings = false;
|
||||||
this->DebugOutput = 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";
|
std::cout << "Finding unused variables given on the command line.\n";
|
||||||
this->SetWarnUnusedCli(true);
|
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)
|
else if(arg.find("-G",0) == 0)
|
||||||
{
|
{
|
||||||
std::string value = arg.substr(2);
|
std::string value = arg.substr(2);
|
||||||
|
@ -312,6 +312,8 @@ class cmake
|
|||||||
void SetWarnUnused(bool b) { this->WarnUnused = b;}
|
void SetWarnUnused(bool b) { this->WarnUnused = b;}
|
||||||
bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
|
bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
|
||||||
void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b;}
|
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);
|
void MarkCliAsUsed(const std::string& variable);
|
||||||
|
|
||||||
@ -455,6 +457,7 @@ private:
|
|||||||
bool WarnUninitialized;
|
bool WarnUninitialized;
|
||||||
bool WarnUnused;
|
bool WarnUnused;
|
||||||
bool WarnUnusedCli;
|
bool WarnUnusedCli;
|
||||||
|
bool CheckSystemVars;
|
||||||
std::map<std::string, bool> UsedCliVariables;
|
std::map<std::string, bool> UsedCliVariables;
|
||||||
std::string CMakeEditCommand;
|
std::string CMakeEditCommand;
|
||||||
std::string CMakeCommand;
|
std::string CMakeCommand;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user