diff options
author | Brad King <brad.king@kitware.com> | 2008-03-13 17:48:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-03-13 17:48:57 (GMT) |
commit | f7f03347a64c629149803594b92c2b4b40e783fd (patch) | |
tree | 5035b672977616bb63be8f10fc2605e7dac83741 /Source/cmMakefile.cxx | |
parent | 73df9a5cd4f6ac66ea71c073ce3e01d68c512074 (diff) | |
download | CMake-f7f03347a64c629149803594b92c2b4b40e783fd.zip CMake-f7f03347a64c629149803594b92c2b4b40e783fd.tar.gz CMake-f7f03347a64c629149803594b92c2b4b40e783fd.tar.bz2 |
ENH: Improve new error/warning message generation
- Add cmListFileBacktrace to record stack traces
- Move main IssueMessage method to the cmake class instance
(make the backtrace an explicit argument)
- Change cmMakefile::IssueMessage to construct a backtrace
and call the cmake instance version
- Record a backtrace at the point a target is created
(useful later for messages issued by generators)
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r-- | Source/cmMakefile.cxx | 122 |
1 files changed, 31 insertions, 91 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 79fca4a..4819c63 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -35,8 +35,6 @@ #include "cmake.h" #include <stdlib.h> // required for atoi -#include "cmDocumentationFormatterText.h" - #include <cmsys/RegularExpression.hxx> #include <cmsys/auto_ptr.hxx> @@ -287,108 +285,51 @@ bool cmMakefile::CommandExists(const char* name) const void cmMakefile::IssueMessage(cmake::MessageType t, std::string const& text) const { - cmOStringStream 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 - { - msg << "CMake Warning"; - if(t == cmake::AUTHOR_WARNING) - { - if(this->IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) - { - return; - } - msg << "(dev)"; - } - msg << ":"; - } - - // Add the immediate context. - CallStackType::const_reverse_iterator i = this->CallStack.rbegin(); - if(i != this->CallStack.rend()) + // Collect context information. + cmListFileBacktrace backtrace; + if(!this->CallStack.empty()) { - if(isError) + if((t == cmake::FATAL_ERROR) || (t == cmake::INTERNAL_ERROR)) { - (*i).Status->SetNestedError(true); + this->CallStack.back().Status->SetNestedError(true); } - cmListFileContext const& lfc = *(*i).Context; - msg - << " at " - << this->LocalGenerator->Convert(lfc.FilePath.c_str(), - cmLocalGenerator::HOME) - << ":" << lfc.Line << " " << lfc.Name; - ++i; + this->GetBacktrace(backtrace); } else if(!this->ListFileStack.empty()) { // We are processing the project but are not currently executing a // command. Add whatever context information we have. - if(this->LocalGenerator->GetParent()) - { - msg << " in directory " - << this->LocalGenerator->Convert(this->GetCurrentDirectory(), - cmLocalGenerator::HOME); - } - else if(this->GetCMakeInstance()->GetIsInTryCompile()) - { - msg << " in directory " << this->GetCurrentDirectory(); - } - else + cmListFileContext lfc; + lfc.FilePath = this->ListFileStack.back(); + lfc.Line = 0; + if(!this->GetCMakeInstance()->GetIsInTryCompile()) { - msg << " in top-level directory"; + lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath.c_str(), + cmLocalGenerator::HOME); } + backtrace.push_back(lfc); } - // Add the message text. - { - msg << " {\n"; - cmDocumentationFormatterText formatter; - formatter.SetIndent(" "); - formatter.PrintFormatted(msg, text.c_str()); - msg << "}"; - } - - // Add the rest of the context. - if(i != this->CallStack.rend()) - { - msg << " with call stack {\n"; - while(i != this->CallStack.rend()) - { - cmListFileContext const& lfc = *(*i).Context; - msg << " " - << this->LocalGenerator->Convert(lfc.FilePath.c_str(), - cmLocalGenerator::HOME) - << ":" << lfc.Line << " " << lfc.Name << "\n"; - ++i; - } - msg << "}\n"; - } - else - { - msg << "\n"; - } + // Issue the message. + this->GetCMakeInstance()->IssueMessage(t, text, backtrace); +} - // Output the message. - if(isError) +//---------------------------------------------------------------------------- +bool cmMakefile::GetBacktrace(cmListFileBacktrace& backtrace) const +{ + if(this->CallStack.empty()) { - cmSystemTools::SetErrorOccured(); - cmSystemTools::Message(msg.str().c_str(), "Error"); + return false; } - else + for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin(); + i != this->CallStack.rend(); ++i) { - cmSystemTools::Message(msg.str().c_str(), "Warning"); + cmListFileContext lfc = *(*i).Context; + lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath.c_str(), + cmLocalGenerator::HOME); + backtrace.push_back(lfc); } + return true; } //---------------------------------------------------------------------------- @@ -1647,12 +1588,11 @@ cmTarget* cmMakefile::AddExecutable(const char *exeName, cmTarget* cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name) { - cmTargets::iterator it; - cmTarget target; + cmTargets::iterator it = + this->Targets.insert(cmTargets::value_type(name, cmTarget())).first; + cmTarget& target = it->second; target.SetType(type, name); target.SetMakefile(this); - it=this->Targets.insert( - cmTargets::value_type(target.GetName(), target)).first; this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it); return &it->second; } |