backtrace: Convert to local paths in IssueMessage

This is the only place we care show the FilePath to the user, so defer
the expensive relative path calculation until here.
This commit is contained in:
Ben Boeckel 2014-03-12 17:59:42 -04:00
parent a08292059e
commit 2a1b2d8486
13 changed files with 66 additions and 22 deletions

View File

@ -137,7 +137,7 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
this->Makefile->GetHomeOutputDirectory()))
{
cmOStringStream msg;
cmListFileBacktrace bt;
cmListFileBacktrace bt(this->Makefile->GetLocalGenerator());
cmListFileContext lfc;
lfc.FilePath = this->FileName;
lfc.Line = this->FileLine;

View File

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

View File

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

View File

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

View File

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

View File

@ -22,6 +22,11 @@ class cmTarget;
//----------------------------------------------------------------------------
struct cmGeneratorExpressionContext
{
cmGeneratorExpressionContext()
: Backtrace(NULL)
{
}
cmListFileBacktrace Backtrace;
std::set<cmTarget*> DependTargets;
std::set<cmTarget const*> AllTargets;

View File

@ -12,6 +12,7 @@
#include "cmListFileCache.h"
#include "cmListFileLexer.h"
#include "cmLocalGenerator.h"
#include "cmSystemTools.h"
#include "cmMakefile.h"
#include "cmVersion.h"
@ -407,6 +408,23 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
}
}
//----------------------------------------------------------------------------
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;
}
//----------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
{

View File

@ -14,6 +14,8 @@
#include "cmStandardIncludes.h"
class cmLocalGenerator;
/** \class cmListFileCache
* \brief A class to cache list file contents.
*
@ -66,7 +68,20 @@ struct cmListFileFunction: public cmListFileContext
std::vector<cmListFileArgument> Arguments;
};
class cmListFileBacktrace: public std::vector<cmListFileContext> {};
class cmListFileBacktrace: public std::vector<cmListFileContext>
{
public:
cmListFileBacktrace(cmLocalGenerator* localGen)
: LocalGenerator(localGen)
, Relative(localGen ? false : true)
{
}
void MakeRelative();
private:
cmLocalGenerator* LocalGenerator;
bool Relative;
};
struct cmListFile
{

View File

@ -310,7 +310,12 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
std::string const& text) const
{
// Collect context information.
cmListFileBacktrace backtrace;
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))
@ -335,11 +340,6 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
lfc.FilePath = this->ListFileStack.back();
}
lfc.Line = 0;
if(!this->GetCMakeInstance()->GetIsInTryCompile())
{
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
cmLocalGenerator::HOME);
}
backtrace.push_back(lfc);
}
@ -350,14 +350,11 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
//----------------------------------------------------------------------------
cmListFileBacktrace cmMakefile::GetBacktrace() const
{
cmListFileBacktrace backtrace;
cmListFileBacktrace backtrace(this->GetLocalGenerator());
for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
i != this->CallStack.rend(); ++i)
{
cmListFileContext lfc = *(*i).Context;
lfc.FilePath = this->LocalGenerator->Convert(lfc.FilePath,
cmLocalGenerator::HOME);
backtrace.push_back(lfc);
backtrace.push_back(*i->Context);
}
return backtrace;
}
@ -1919,7 +1916,7 @@ void cmMakefile::CheckForUnused(const char* reason,
if (this->WarnUnused && !this->VariableUsed(name))
{
std::string path;
cmListFileBacktrace bt;
cmListFileBacktrace bt(this->GetLocalGenerator());
if (this->CallStack.size())
{
const cmListFileContext* file = this->CallStack.back().Context;
@ -2870,7 +2867,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
this->GetHomeOutputDirectory()))
{
cmOStringStream msg;
cmListFileBacktrace bt;
cmListFileBacktrace bt(this->GetLocalGenerator());
cmListFileContext lfc;
lfc.FilePath = filename;
lfc.Line = line;

View File

@ -87,10 +87,12 @@ class cmTargetInternals
{
public:
cmTargetInternals()
: Backtrace(NULL)
{
this->PolicyWarnedCMP0022 = false;
}
cmTargetInternals(cmTargetInternals const&)
: Backtrace(NULL)
{
this->PolicyWarnedCMP0022 = false;
}
@ -1324,9 +1326,10 @@ void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
: "plain");
s << "The uses of the " << sigString << " signature are here:\n";
std::set<std::string> emitted;
for(std::vector<cmListFileBacktrace>::const_iterator it = sigs.begin();
for(std::vector<cmListFileBacktrace>::iterator it = sigs.begin();
it != sigs.end(); ++it)
{
it->MakeRelative();
cmListFileBacktrace::const_iterator i = it->begin();
if(i != it->end())
{

View File

@ -17,11 +17,11 @@
//----------------------------------------------------------------------------
cmTest::cmTest(cmMakefile* mf)
: Backtrace(mf->GetBacktrace())
{
this->Makefile = mf;
this->OldStyle = true;
this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
this->Backtrace = this->Makefile->GetBacktrace();
}
//----------------------------------------------------------------------------

View File

@ -2562,8 +2562,11 @@ static bool cmakeCheckStampList(const char* stampList)
//----------------------------------------------------------------------------
void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace)
cmListFileBacktrace const& bt)
{
cmListFileBacktrace backtrace = bt;
backtrace.MakeRelative();
cmOStringStream msg;
bool isError = false;
// Construct the message header.

View File

@ -360,7 +360,7 @@ class cmake
/** Display a message to the user. */
void IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace = cmListFileBacktrace());
cmListFileBacktrace const& backtrace = cmListFileBacktrace(NULL));
///! run the --build option
int Build(const std::string& dir,
const std::string& target,