Merge topic 'minor-cleanups'

eb7b6f6d cmVariableWatchCommand: Simplify error reporting.
499ebb65 cmListFileBacktrace: Internalize the step of making paths relative.
80b433b0 cmGlobalGenerator: Don't use else after a return.
52919ac8 cmMakefile: Make cmListFileBacktrace default constructible.
b68f2ea8 cmMakefile: Add API for elseif to create backtrace.
17e13f0a cmMakefile: Simplify CMP0000 handling.
This commit is contained in:
Brad King 2015-06-04 09:13:27 -04:00 committed by CMake Topic Stage
commit b49aef6b10
15 changed files with 59 additions and 75 deletions

View File

@ -17,7 +17,7 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmCustomCommand::cmCustomCommand() cmCustomCommand::cmCustomCommand()
: Backtrace(NULL) : Backtrace()
{ {
this->HaveComment = false; this->HaveComment = false;
this->EscapeOldStyle = true; this->EscapeOldStyle = true;
@ -82,7 +82,7 @@ cmCustomCommand::cmCustomCommand(cmMakefile const* mf,
WorkingDirectory(workingDirectory?workingDirectory:""), WorkingDirectory(workingDirectory?workingDirectory:""),
EscapeAllowMakeVars(false), EscapeAllowMakeVars(false),
EscapeOldStyle(true), EscapeOldStyle(true),
Backtrace(NULL) Backtrace()
{ {
this->EscapeOldStyle = true; this->EscapeOldStyle = true;
this->EscapeAllowMakeVars = false; this->EscapeAllowMakeVars = false;

View File

@ -18,7 +18,7 @@
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmExportBuildFileGenerator::cmExportBuildFileGenerator() cmExportBuildFileGenerator::cmExportBuildFileGenerator()
: Backtrace(NULL) : Backtrace()
{ {
this->Makefile = 0; this->Makefile = 0;
this->ExportSet = 0; this->ExportSet = 0;

View File

@ -34,7 +34,7 @@ cmGeneratorExpression::Parse(std::string const& input)
{ {
return cmsys::auto_ptr<cmCompiledGeneratorExpression>( return cmsys::auto_ptr<cmCompiledGeneratorExpression>(
new cmCompiledGeneratorExpression( new cmCompiledGeneratorExpression(
this->Backtrace ? *this->Backtrace : cmListFileBacktrace(NULL), this->Backtrace ? *this->Backtrace : cmListFileBacktrace(),
input)); input));
} }

View File

@ -35,7 +35,7 @@ cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
const GeneratorExpressionContent *content, const GeneratorExpressionContent *content,
cmGeneratorExpressionDAGChecker *parent) cmGeneratorExpressionDAGChecker *parent)
: Parent(parent), Target(target), Property(property), : Parent(parent), Target(target), Property(property),
Content(content), Backtrace(NULL), TransitivePropertiesOnly(false) Content(content), Backtrace(), TransitivePropertiesOnly(false)
{ {
Initialize(); Initialize();
} }

View File

@ -87,8 +87,7 @@ bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p,
{ {
return true; return true;
} }
else
{
std::ostringstream e; std::ostringstream e;
e << e <<
"Generator\n" "Generator\n"
@ -98,7 +97,6 @@ bool cmGlobalGenerator::SetGeneratorPlatform(std::string const& p,
"was specified."; "was specified.";
mf->IssueMessage(cmake::FATAL_ERROR, e.str()); mf->IssueMessage(cmake::FATAL_ERROR, e.str());
return false; return false;
}
} }
bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts, bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts,
@ -108,8 +106,6 @@ bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts,
{ {
return true; return true;
} }
else
{
std::ostringstream e; std::ostringstream e;
e << e <<
"Generator\n" "Generator\n"
@ -119,7 +115,6 @@ bool cmGlobalGenerator::SetGeneratorToolset(std::string const& ts,
"was specified."; "was specified.";
mf->IssueMessage(cmake::FATAL_ERROR, e.str()); mf->IssueMessage(cmake::FATAL_ERROR, e.str());
return false; return false;
}
} }
std::string cmGlobalGenerator::SelectMakeProgram( std::string cmGlobalGenerator::SelectMakeProgram(

View File

@ -92,10 +92,6 @@ IsFunctionBlocked(const cmListFileFunction& lff,
} }
else else
{ {
// Place this call on the call stack.
cmMakefileCall stack_manager(&mf, this->Functions[c], status);
static_cast<void>(stack_manager);
// if trace is enabled, print the evaluated "elseif" statement // if trace is enabled, print the evaluated "elseif" statement
if(mf.GetCMakeInstance()->GetTrace()) if(mf.GetCMakeInstance()->GetTrace())
{ {
@ -119,7 +115,8 @@ IsFunctionBlocked(const cmListFileFunction& lff,
{ {
std::string err = cmIfCommandError(expandedArguments); std::string err = cmIfCommandError(expandedArguments);
err += errorString; err += errorString;
mf.IssueMessage(messType, err); cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]);
mf.GetCMakeInstance()->IssueMessage(messType, err, bt);
if (messType == cmake::FATAL_ERROR) if (messType == cmake::FATAL_ERROR)
{ {
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();

View File

@ -405,29 +405,17 @@ void cmListFileBacktrace::Append(cmListFileContext const& context)
this->push_back(context); this->push_back(context);
} }
//----------------------------------------------------------------------------
void cmListFileBacktrace::MakeRelative()
{
if (this->Relative)
{
return;
}
for (cmListFileBacktrace::iterator i = this->begin();
i != this->end(); ++i)
{
i->FilePath = this->LocalGenerator->Convert(i->FilePath,
cmLocalGenerator::HOME);
}
this->Relative = true;
}
void cmListFileBacktrace::PrintTitle(std::ostream& out) void cmListFileBacktrace::PrintTitle(std::ostream& out)
{ {
if (this->empty()) if (this->empty())
{ {
return; return;
} }
out << (this->front().Line ? " at " : " in ") << this->front();
cmListFileContext lfc = this->front();
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
cmLocalGenerator::HOME);
out << (lfc.Line ? " at " : " in ") << lfc;
} }
void cmListFileBacktrace::PrintCallStack(std::ostream& out) void cmListFileBacktrace::PrintCallStack(std::ostream& out)
@ -441,7 +429,9 @@ void cmListFileBacktrace::PrintCallStack(std::ostream& out)
out << "Call Stack (most recent call first):\n"; out << "Call Stack (most recent call first):\n";
while(i != this->end()) while(i != this->end())
{ {
cmListFileContext const& lfc = *i; cmListFileContext lfc = *i;
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
cmLocalGenerator::HOME);
out << " " << lfc << "\n"; out << " " << lfc << "\n";
++i; ++i;
} }

View File

@ -74,21 +74,17 @@ struct cmListFileFunction: public cmListFileContext
class cmListFileBacktrace: private std::vector<cmListFileContext> class cmListFileBacktrace: private std::vector<cmListFileContext>
{ {
public: public:
cmListFileBacktrace(cmLocalGenerator* localGen) cmListFileBacktrace(cmLocalGenerator* localGen = 0)
: LocalGenerator(localGen) : LocalGenerator(localGen)
, Relative(localGen ? false : true)
{ {
} }
void Append(cmListFileContext const& context); void Append(cmListFileContext const& context);
void MakeRelative();
void PrintTitle(std::ostream& out); void PrintTitle(std::ostream& out);
void PrintCallStack(std::ostream& out); void PrintCallStack(std::ostream& out);
private: private:
cmLocalGenerator* LocalGenerator; cmLocalGenerator* LocalGenerator;
bool Relative;
}; };
struct cmListFile struct cmListFile

View File

@ -286,6 +286,20 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
return backtrace; return backtrace;
} }
//----------------------------------------------------------------------------
cmListFileBacktrace
cmMakefile::GetBacktrace(cmListFileContext const& lfc) const
{
cmListFileBacktrace backtrace(this->GetLocalGenerator());
backtrace.Append(lfc);
for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
i != this->CallStack.rend(); ++i)
{
backtrace.Append(*i->Context);
}
return backtrace;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
cmListFileContext cmMakefile::GetExecutionContext() const cmListFileContext cmMakefile::GetExecutionContext() const
{ {
@ -519,8 +533,10 @@ bool cmMakefile::ProcessBuildsystemFile(const char* listfile)
{ {
this->AddDefinition("CMAKE_PARENT_LIST_FILE", listfile); this->AddDefinition("CMAKE_PARENT_LIST_FILE", listfile);
std::string curSrc = this->GetCurrentSourceDirectory(); std::string curSrc = this->GetCurrentSourceDirectory();
return this->ReadListFile(listfile, true, bool result = this->ReadListFile(listfile, true,
curSrc == this->GetHomeDirectory()); curSrc == this->GetHomeDirectory());
this->EnforceDirectoryLevelRules();
return result;
} }
bool cmMakefile::ReadDependentFile(const char* listfile, bool noPolicyScope) bool cmMakefile::ReadDependentFile(const char* listfile, bool noPolicyScope)
@ -619,13 +635,6 @@ bool cmMakefile::ReadListFileInternal(const char* filenametoread,
} }
} }
// If this is the directory-level CMakeLists.txt file then perform
// some extra checks.
if(this->ListFileStack.size() == 1)
{
this->EnforceDirectoryLevelRules();
}
return true; return true;
} }

View File

@ -572,6 +572,7 @@ public:
* Get the current context backtrace. * Get the current context backtrace.
*/ */
cmListFileBacktrace GetBacktrace() const; cmListFileBacktrace GetBacktrace() const;
cmListFileBacktrace GetBacktrace(cmListFileContext const& lfc) const;
cmListFileContext GetExecutionContext() const; cmListFileContext GetExecutionContext() const;
/** /**

View File

@ -94,13 +94,13 @@ class cmTargetInternals
{ {
public: public:
cmTargetInternals() cmTargetInternals()
: Backtrace(NULL) : Backtrace()
{ {
this->PolicyWarnedCMP0022 = false; this->PolicyWarnedCMP0022 = false;
this->UtilityItemsDone = false; this->UtilityItemsDone = false;
} }
cmTargetInternals(cmTargetInternals const&) cmTargetInternals(cmTargetInternals const&)
: Backtrace(NULL) : Backtrace()
{ {
this->PolicyWarnedCMP0022 = false; this->PolicyWarnedCMP0022 = false;
this->UtilityItemsDone = false; this->UtilityItemsDone = false;

View File

@ -66,7 +66,7 @@ public:
class cmLinkImplItem: public cmLinkItem class cmLinkImplItem: public cmLinkItem
{ {
public: public:
cmLinkImplItem(): cmLinkItem(), Backtrace(0), FromGenex(false) {} cmLinkImplItem(): cmLinkItem(), Backtrace(), FromGenex(false) {}
cmLinkImplItem(std::string const& n, cmLinkImplItem(std::string const& n,
cmTarget const* t, cmTarget const* t,
cmListFileBacktrace const& bt, cmListFileBacktrace const& bt,

View File

@ -68,11 +68,8 @@ static void cmVariableWatchCommandVariableAccessed(
cmExecutionStatus status; cmExecutionStatus status;
if(!makefile->ExecuteCommand(newLFF,status)) if(!makefile->ExecuteCommand(newLFF,status))
{ {
arg.FilePath = "Unknown";
arg.Line = 0;
std::ostringstream error; std::ostringstream error;
error << "Error in cmake code at\n" error << "Error in cmake code at\nUnknown:0:\n"
<< arg.FilePath << ":" << arg.Line << ":\n"
<< "A command failed during the invocation of callback \"" << "A command failed during the invocation of callback \""
<< data->Command << "\"."; << data->Command << "\".";
cmSystemTools::Error(error.str().c_str()); cmSystemTools::Error(error.str().c_str());

View File

@ -2519,7 +2519,6 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& bt) cmListFileBacktrace const& bt)
{ {
cmListFileBacktrace backtrace = bt; cmListFileBacktrace backtrace = bt;
backtrace.MakeRelative();
std::ostringstream msg; std::ostringstream msg;
if (!this->PrintMessagePreamble(t, msg)) if (!this->PrintMessagePreamble(t, msg))

View File

@ -301,7 +301,7 @@ class cmake
/** Display a message to the user. */ /** Display a message to the user. */
void IssueMessage(cmake::MessageType t, std::string const& text, void IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace = cmListFileBacktrace(NULL)); cmListFileBacktrace const& backtrace = cmListFileBacktrace());
void IssueMessage(cmake::MessageType t, std::string const& text, void IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileContext const& lfc); cmListFileContext const& lfc);