Merge topic 'clean-up-ReadListFile'

81eb2c58 cmMakefile: Simplify filename handling.
5c837686 cmMakefile: Make the IncludeScope more responsible.
c10ab014 cmMakefile: Move IncludeScope.
3404f8a0 cmMakefile: Move ListFile parsing responsibility out of internal method.
a1858136 cmMakefile: Rename parameter.
ad47e6e5 cmMakefile: Inline ReadListFileInternal into caller.
254be613 cmMakefile: Move resource management into the IncludeScope.
826b6e68 cmMakefile: Move IncludeScope to ReadDependentFile.
e53072d6 cmMakefile: Move IncludeScope instance.
b7166afa cmMakefile: Remove File from IncludeScope.
27f229b9 cmMakefile: Move include scope out of ReadListFileInternal.
9166b49d cmMakefile: Change order of raii scopes.
384a0dba cmMakefile: Simplify condition handling.
5e24ff17 cmMakefile: Split file handling from execution.
d5aaa2b9 cmMakefile: Move check for unused variables.
fff3c6cd cmMakefile: Move a container population.
...
This commit is contained in:
Brad King 2015-06-22 13:00:30 -04:00 committed by CMake Topic Stage
commit 24a0825585
2 changed files with 83 additions and 76 deletions

View File

@ -409,12 +409,12 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff,
class cmMakefile::IncludeScope class cmMakefile::IncludeScope
{ {
public: public:
IncludeScope(cmMakefile* mf, const char* fname, bool noPolicyScope); IncludeScope(cmMakefile* mf, std::string const& filenametoread,
bool noPolicyScope);
~IncludeScope(); ~IncludeScope();
void Quiet() { this->ReportError = false; } void Quiet() { this->ReportError = false; }
private: private:
cmMakefile* Makefile; cmMakefile* Makefile;
const char* File;
bool NoPolicyScope; bool NoPolicyScope;
bool CheckCMP0011; bool CheckCMP0011;
bool ReportError; bool ReportError;
@ -422,9 +422,10 @@ private:
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, const char* fname, cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf,
std::string const& filenametoread,
bool noPolicyScope): bool noPolicyScope):
Makefile(mf), File(fname), NoPolicyScope(noPolicyScope), Makefile(mf), NoPolicyScope(noPolicyScope),
CheckCMP0011(false), ReportError(true) CheckCMP0011(false), ReportError(true)
{ {
if(!this->NoPolicyScope) if(!this->NoPolicyScope)
@ -458,6 +459,7 @@ cmMakefile::IncludeScope::IncludeScope(cmMakefile* mf, const char* fname,
// The included file cannot pop our policy scope. // The included file cannot pop our policy scope.
this->Makefile->PushPolicyBarrier(); this->Makefile->PushPolicyBarrier();
this->Makefile->ListFileStack.push_back(filenametoread);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -487,6 +489,7 @@ cmMakefile::IncludeScope::~IncludeScope()
this->EnforceCMP0011(); this->EnforceCMP0011();
} }
} }
this->Makefile->ListFileStack.pop_back();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -501,7 +504,8 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
{ {
std::ostringstream w; std::ostringstream w;
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0011) << "\n" w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0011) << "\n"
<< "The included script\n " << this->File << "\n" << "The included script\n "
<< this->Makefile->ListFileStack.back() << "\n"
<< "affects policy settings. " << "affects policy settings. "
<< "CMake is implying the NO_POLICY_SCOPE option for compatibility, " << "CMake is implying the NO_POLICY_SCOPE option for compatibility, "
<< "so the effects are applied to the including context."; << "so the effects are applied to the including context.";
@ -513,7 +517,8 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
{ {
std::ostringstream e; std::ostringstream e;
e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0011) << "\n" e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0011) << "\n"
<< "The included script\n " << this->File << "\n" << "The included script\n "
<< this->Makefile->ListFileStack.back() << "\n"
<< "affects policy settings, so it requires this policy to be set."; << "affects policy settings, so it requires this policy to be set.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
} }
@ -527,40 +532,77 @@ void cmMakefile::IncludeScope::EnforceCMP0011()
} }
} }
bool cmMakefile::ProcessBuildsystemFile(const char* listfile) bool cmMakefile::ProcessBuildsystemFile(const char* filename)
{ {
this->AddDefinition("CMAKE_PARENT_LIST_FILE", listfile); this->AddDefinition("CMAKE_PARENT_LIST_FILE", filename);
std::string curSrc = this->GetCurrentSourceDirectory(); std::string curSrc = this->GetCurrentSourceDirectory();
bool result = this->ReadListFile(listfile, true,
curSrc == this->GetHomeDirectory()); this->ListFileStack.push_back(filename);
cmListFile listFile;
if (!listFile.ParseFile(filename, curSrc == this->GetHomeDirectory(), this))
{
return false;
}
this->PushPolicyBarrier();
this->ReadListFile(listFile, filename);
this->PopPolicyBarrier(!cmSystemTools::GetFatalErrorOccured());
this->EnforceDirectoryLevelRules(); this->EnforceDirectoryLevelRules();
return result; return true;
} }
bool cmMakefile::ReadDependentFile(const char* listfile, bool noPolicyScope) bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope)
{ {
this->AddDefinition("CMAKE_PARENT_LIST_FILE", this->AddDefinition("CMAKE_PARENT_LIST_FILE",
this->GetDefinition("CMAKE_CURRENT_LIST_FILE")); this->GetDefinition("CMAKE_CURRENT_LIST_FILE"));
bool result = this->ReadListFile(listfile, noPolicyScope, false); std::string filenametoread =
this->ListFileStack.pop_back(); cmSystemTools::CollapseFullPath(filename,
return result; this->GetCurrentSourceDirectory());
IncludeScope incScope(this, filenametoread, noPolicyScope);
cmListFile listFile;
if (!listFile.ParseFile(filenametoread.c_str(), false, this))
{
incScope.Quiet();
return false;
}
this->ReadListFile(listFile, filenametoread);
if(cmSystemTools::GetFatalErrorOccured())
{
incScope.Quiet();
}
return true;
} }
bool cmMakefile::ReadListFile(const char* listfile) bool cmMakefile::ReadListFile(const char* filename)
{
bool result = this->ReadListFile(listfile, true, false);
this->ListFileStack.pop_back();
return result;
}
bool cmMakefile::ReadListFile(const char* listfile,
bool noPolicyScope,
bool requireProjectCommand)
{ {
std::string filenametoread = std::string filenametoread =
cmSystemTools::CollapseFullPath(listfile, cmSystemTools::CollapseFullPath(filename,
this->GetCurrentSourceDirectory()); this->GetCurrentSourceDirectory());
this->ListFileStack.push_back(filenametoread);
cmListFile listFile;
if (!listFile.ParseFile(filenametoread.c_str(), false, this))
{
return false;
}
this->PushPolicyBarrier();
this->ReadListFile(listFile, filenametoread);
this->PopPolicyBarrier(!cmSystemTools::GetFatalErrorOccured());
this->ListFileStack.pop_back();
return true;
}
void cmMakefile::ReadListFile(cmListFile const& listFile,
std::string const& filenametoread)
{
// add this list file to the list of dependencies
this->ListFiles.push_back(filenametoread);
std::string currentParentFile std::string currentParentFile
= this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE"); = this->GetSafeDefinition("CMAKE_PARENT_LIST_FILE");
std::string currentFile std::string currentFile
@ -574,55 +616,19 @@ bool cmMakefile::ReadListFile(const char* listfile,
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR"); this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
this->ListFileStack.push_back(filenametoread);
bool res = this->ReadListFileInternal(filenametoread.c_str(),
noPolicyScope, requireProjectCommand);
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
cmSystemTools::GetFilenamePath(currentFile).c_str());
this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
if (res)
{
this->CheckForUnusedVariables();
}
return res;
}
bool cmMakefile::ReadListFileInternal(const char* filenametoread,
bool noPolicyScope,
bool requireProjectCommand)
{
cmListFile cacheFile;
if( !cacheFile.ParseFile(filenametoread, requireProjectCommand, this) )
{
return false;
}
// add this list file to the list of dependencies
this->ListFiles.push_back( filenametoread);
// Enforce balanced blocks (if/endif, function/endfunction, etc.). // Enforce balanced blocks (if/endif, function/endfunction, etc.).
{
LexicalPushPop lexScope(this); LexicalPushPop lexScope(this);
IncludeScope incScope(this, filenametoread, noPolicyScope);
// Run the parsed commands. // Run the parsed commands.
const size_t numberFunctions = cacheFile.Functions.size(); const size_t numberFunctions = listFile.Functions.size();
for(size_t i =0; i < numberFunctions; ++i) for(size_t i =0; i < numberFunctions; ++i)
{ {
cmExecutionStatus status; cmExecutionStatus status;
this->ExecuteCommand(cacheFile.Functions[i],status); this->ExecuteCommand(listFile.Functions[i],status);
if(cmSystemTools::GetFatalErrorOccured()) if(cmSystemTools::GetFatalErrorOccured())
{ {
// Exit early due to error. // Exit early due to error.
lexScope.Quiet(); lexScope.Quiet();
incScope.Quiet();
break; break;
} }
if(status.GetReturnInvoked()) if(status.GetReturnInvoked())
@ -631,9 +637,15 @@ bool cmMakefile::ReadListFileInternal(const char* filenametoread,
break; break;
} }
} }
} this->CheckForUnusedVariables();
return true; this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentParentFile.c_str());
this->AddDefinition("CMAKE_CURRENT_LIST_FILE", currentFile.c_str());
this->AddDefinition("CMAKE_CURRENT_LIST_DIR",
cmSystemTools::GetFilenamePath(currentFile).c_str());
this->MarkVariableAsUsed("CMAKE_PARENT_LIST_FILE");
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_FILE");
this->MarkVariableAsUsed("CMAKE_CURRENT_LIST_DIR");
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -79,11 +79,11 @@ public:
*/ */
~cmMakefile(); ~cmMakefile();
bool ReadListFile(const char* listfile); bool ReadListFile(const char* filename);
bool ReadDependentFile(const char* listfile, bool noPolicyScope = true); bool ReadDependentFile(const char* filename, bool noPolicyScope = true);
bool ProcessBuildsystemFile(const char* listfile); bool ProcessBuildsystemFile(const char* filename);
/** /**
* Add a function blocker to this makefile * Add a function blocker to this makefile
@ -918,13 +918,8 @@ private:
cmState::Snapshot StateSnapshot; cmState::Snapshot StateSnapshot;
bool ReadListFile(const char* listfile, void ReadListFile(cmListFile const& listFile,
bool noPolicyScope, const std::string& filenametoread);
bool requireProjectCommand);
bool ReadListFileInternal(const char* filenametoread,
bool noPolicyScope,
bool requireProjectCommand);
bool ParseDefineFlag(std::string const& definition, bool remove); bool ParseDefineFlag(std::string const& definition, bool remove);