Merge topic 'clean-up-backtrace-handling'
8b4b9631
cmake: Add IssueMessage overload taking a single cmListFileContext.46656aa1
cmake: Extract displayMessage method.55fc5e7c
cmake: Extract printMessageText method.ca7cc2eb
cmake: Extract PrintMessagePreamble method.fa752bf3
cmake: Move isError determination to a more-natural place.
This commit is contained in:
commit
d0f59d3598
|
@ -14,6 +14,7 @@
|
|||
#include "cmSystemTools.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmState.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
|
||||
#include "cmCommandArgumentLexer.h"
|
||||
|
||||
|
@ -139,14 +140,14 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
|
|||
this->Makefile->GetHomeOutputDirectory()))
|
||||
{
|
||||
std::ostringstream msg;
|
||||
cmListFileBacktrace bt(this->Makefile->GetLocalGenerator());
|
||||
cmListFileContext lfc;
|
||||
lfc.FilePath = this->FileName;
|
||||
lfc.FilePath = this->Makefile->GetLocalGenerator()
|
||||
->Convert(this->FileName, cmLocalGenerator::HOME);
|
||||
|
||||
lfc.Line = this->FileLine;
|
||||
bt.Append(lfc);
|
||||
msg << "uninitialized variable \'" << var << "\'";
|
||||
this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
|
||||
msg.str(), bt);
|
||||
msg.str(), lfc);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -249,19 +249,13 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
|
|||
std::string const& text) const
|
||||
{
|
||||
// Collect context information.
|
||||
cmLocalGenerator* localGen = this->GetLocalGenerator();
|
||||
if(this->CallStack.empty() && this->GetCMakeInstance()->GetIsInTryCompile())
|
||||
{
|
||||
localGen = 0;
|
||||
}
|
||||
cmListFileBacktrace backtrace(localGen);
|
||||
if(!this->CallStack.empty())
|
||||
{
|
||||
if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR))
|
||||
{
|
||||
this->CallStack.back().Status->SetNestedError(true);
|
||||
}
|
||||
backtrace = this->GetBacktrace();
|
||||
this->GetCMakeInstance()->IssueMessage(t, text, this->GetBacktrace());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -278,12 +272,15 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
|
|||
// command. Add whatever context information we have.
|
||||
lfc.FilePath = this->ListFileStack.back();
|
||||
}
|
||||
lfc.Line = 0;
|
||||
backtrace.Append(lfc);
|
||||
if(!this->CallStack.empty()
|
||||
|| !this->GetCMakeInstance()->GetIsInTryCompile())
|
||||
{
|
||||
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
|
||||
cmLocalGenerator::HOME);
|
||||
}
|
||||
lfc.Line = 0;
|
||||
this->GetCMakeInstance()->IssueMessage(t, text, lfc);
|
||||
}
|
||||
|
||||
// Issue the message.
|
||||
this->GetCMakeInstance()->IssueMessage(t, text, backtrace);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -1837,22 +1834,22 @@ void cmMakefile::LogUnused(const char* reason,
|
|||
if (this->WarnUnused)
|
||||
{
|
||||
std::string path;
|
||||
cmListFileBacktrace bt(this->GetLocalGenerator());
|
||||
cmListFileContext lfc;
|
||||
if (!this->CallStack.empty())
|
||||
{
|
||||
cmListFileContext file = this->GetExecutionContext();
|
||||
bt.Append(file);
|
||||
path = file.FilePath;
|
||||
lfc = this->GetExecutionContext();
|
||||
path = lfc.FilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
path = this->GetCurrentSourceDirectory();
|
||||
path += "/CMakeLists.txt";
|
||||
cmListFileContext lfc;
|
||||
lfc.FilePath = path;
|
||||
lfc.Line = 0;
|
||||
bt.Append(lfc);
|
||||
}
|
||||
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
|
||||
cmLocalGenerator::HOME);
|
||||
|
||||
if (this->CheckSystemVars ||
|
||||
cmSystemTools::IsSubDirectory(path,
|
||||
this->GetHomeDirectory()) ||
|
||||
|
@ -1865,7 +1862,7 @@ void cmMakefile::LogUnused(const char* reason,
|
|||
msg << "unused variable (" << reason << ") \'" << name << "\'";
|
||||
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
|
||||
msg.str(),
|
||||
bt);
|
||||
lfc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2769,14 +2766,13 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
|
|||
this->GetHomeOutputDirectory()))
|
||||
{
|
||||
std::ostringstream msg;
|
||||
cmListFileBacktrace bt(this->GetLocalGenerator());
|
||||
cmListFileContext lfc;
|
||||
lfc.FilePath = filename;
|
||||
lfc.FilePath = this->LocalGenerator
|
||||
->Convert(filename, cmLocalGenerator::HOME);
|
||||
lfc.Line = line;
|
||||
bt.Append(lfc);
|
||||
msg << "uninitialized variable \'" << lookup << "\'";
|
||||
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
|
||||
msg.str(), bt);
|
||||
msg.str(), lfc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2432,24 +2432,15 @@ static bool cmakeCheckStampList(const char* stampList)
|
|||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
||||
cmListFileBacktrace const& bt)
|
||||
bool cmake::PrintMessagePreamble(cmake::MessageType t, std::ostream& msg)
|
||||
{
|
||||
cmListFileBacktrace backtrace = bt;
|
||||
backtrace.MakeRelative();
|
||||
|
||||
std::ostringstream msg;
|
||||
bool isError = false;
|
||||
// Construct the message header.
|
||||
if(t == cmake::FATAL_ERROR)
|
||||
{
|
||||
isError = true;
|
||||
msg << "CMake Error";
|
||||
}
|
||||
else if(t == cmake::INTERNAL_ERROR)
|
||||
{
|
||||
isError = true;
|
||||
msg << "CMake Internal Error (please report a bug)";
|
||||
}
|
||||
else if(t == cmake::LOG)
|
||||
|
@ -2459,7 +2450,6 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
|||
else if(t == cmake::DEPRECATION_ERROR)
|
||||
{
|
||||
msg << "CMake Deprecation Error";
|
||||
isError = true;
|
||||
}
|
||||
else if (t == cmake::DEPRECATION_WARNING)
|
||||
{
|
||||
|
@ -2475,16 +2465,15 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
|||
"CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
|
||||
if(suppress && cmSystemTools::IsOn(suppress))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
msg << " (dev)";
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Add the immediate context.
|
||||
backtrace.PrintTitle(msg);
|
||||
|
||||
// Add the message text.
|
||||
void printMessageText(std::ostream& msg, std::string const& text)
|
||||
{
|
||||
msg << ":\n";
|
||||
cmDocumentationFormatter formatter;
|
||||
|
@ -2492,8 +2481,8 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
|||
formatter.PrintFormatted(msg, text.c_str());
|
||||
}
|
||||
|
||||
// Add the rest of the context.
|
||||
backtrace.PrintCallStack(msg);
|
||||
void displayMessage(cmake::MessageType t, std::ostringstream& msg)
|
||||
{
|
||||
|
||||
// Add a note about warning suppression.
|
||||
if(t == cmake::AUTHOR_WARNING)
|
||||
|
@ -2522,7 +2511,9 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
|||
#endif
|
||||
|
||||
// Output the message.
|
||||
if(isError)
|
||||
if(t == cmake::FATAL_ERROR
|
||||
|| t == cmake::INTERNAL_ERROR
|
||||
|| t == cmake::DEPRECATION_ERROR)
|
||||
{
|
||||
cmSystemTools::SetErrorOccured();
|
||||
cmSystemTools::Message(msg.str().c_str(), "Error");
|
||||
|
@ -2533,6 +2524,48 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
|||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
||||
cmListFileBacktrace const& bt)
|
||||
{
|
||||
cmListFileBacktrace backtrace = bt;
|
||||
backtrace.MakeRelative();
|
||||
|
||||
std::ostringstream msg;
|
||||
if (!this->PrintMessagePreamble(t, msg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the immediate context.
|
||||
backtrace.PrintTitle(msg);
|
||||
|
||||
printMessageText(msg, text);
|
||||
|
||||
// Add the rest of the context.
|
||||
backtrace.PrintCallStack(msg);
|
||||
|
||||
displayMessage(t, msg);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
|
||||
cmListFileContext const& lfc)
|
||||
{
|
||||
std::ostringstream msg;
|
||||
if (!this->PrintMessagePreamble(t, msg))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Add the immediate context.
|
||||
msg << (lfc.Line ? " at " : " in ") << lfc;
|
||||
|
||||
printMessageText(msg, text);
|
||||
|
||||
displayMessage(t, msg);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::vector<std::string> cmake::GetDebugConfigs()
|
||||
{
|
||||
|
|
|
@ -303,6 +303,9 @@ class cmake
|
|||
/** Display a message to the user. */
|
||||
void IssueMessage(cmake::MessageType t, std::string const& text,
|
||||
cmListFileBacktrace const& backtrace = cmListFileBacktrace(NULL));
|
||||
void IssueMessage(cmake::MessageType t, std::string const& text,
|
||||
cmListFileContext const& lfc);
|
||||
|
||||
///! run the --build option
|
||||
int Build(const std::string& dir,
|
||||
const std::string& target,
|
||||
|
@ -399,6 +402,8 @@ private:
|
|||
|
||||
// Print a list of valid generators to stderr.
|
||||
void PrintGeneratorList();
|
||||
|
||||
bool PrintMessagePreamble(cmake::MessageType t, std::ostream& msg);
|
||||
};
|
||||
|
||||
#define CMAKE_STANDARD_OPTIONS_TABLE \
|
||||
|
|
Loading…
Reference in New Issue