Merge topic 'minor-cleanups'

61d52e6e cmListFileBacktrace: Hide the context-stack implementation detail.
a271f7f1 cmTarget: Simplify CMP0023 message loop.
f4300cd4 cmTarget: Simplify output computation.
65a42849 cmTarget: Store context in stack only if different.
9645cba3 cmListFileContext: Implement EqualityComparable.
52a8d19c cmTarget: Store only cmListFileContext for CMP0023 handling.
59ba1215 cmTarget: Remove needless iteration.
18f810a8 cmListFileContext: Sort by line before file.
e96b5d14 cmListFileContext: Implement LessThanComparable.
7eb0dfa0 cmMakefile: Use std::set::insert API to simplify CMP0054 handling.
f9785e0c cmMakefile: Simplify CMP0054 handling.
e17b5e42 cmMakefile: Add access to the top-level execution context.
1ec1bf9f if(): Test the effect of cmMakefileCall use in elseif() handling.
9b4aefad cmMakefile: Replace deques with vectors.
This commit is contained in:
Brad King 2015-05-19 11:09:36 -04:00 committed by CMake Topic Stage
commit 0cbc69b9ea
13 changed files with 113 additions and 105 deletions

View File

@ -143,7 +143,7 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
cmListFileContext lfc;
lfc.FilePath = this->FileName;
lfc.Line = this->FileLine;
bt.push_back(lfc);
bt.Append(lfc);
msg << "uninitialized variable \'" << var << "\'";
this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
msg.str(), bt);

View File

@ -112,10 +112,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN)
{
bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported(
this->Makefile.GetBacktrace()[0]);
if(!hasBeenReported)
if(!this->Makefile.HasCMP0054AlreadyBeenReported())
{
std::ostringstream e;
e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)) << "\n";
@ -161,10 +158,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword,
if(isKeyword && argument.WasQuoted() &&
this->Policy54Status == cmPolicies::WARN)
{
bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported(
this->Makefile.GetBacktrace()[0]);
if(!hasBeenReported)
if(!this->Makefile.HasCMP0054AlreadyBeenReported())
{
std::ostringstream e;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054) << "\n";

View File

@ -400,6 +400,11 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
}
}
void cmListFileBacktrace::Append(cmListFileContext const& context)
{
this->push_back(context);
}
//----------------------------------------------------------------------------
void cmListFileBacktrace::MakeRelative()
{
@ -416,6 +421,31 @@ void cmListFileBacktrace::MakeRelative()
this->Relative = true;
}
void cmListFileBacktrace::PrintTitle(std::ostream& out)
{
if (this->empty())
{
return;
}
out << (this->front().Line ? " at " : " in ") << this->front();
}
void cmListFileBacktrace::PrintCallStack(std::ostream& out)
{
if (size() <= 1)
{
return;
}
const_iterator i = this->begin() + 1;
out << "Call Stack (most recent call first):\n";
while(i != this->end())
{
cmListFileContext const& lfc = *i;
out << " " << lfc << "\n";
++i;
}
}
//----------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
@ -431,3 +461,22 @@ std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
}
return os;
}
bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
if(lhs.Line != rhs.Line)
{
return lhs.Line < rhs.Line;
}
return lhs.FilePath < rhs.FilePath;
}
bool operator==(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
return lhs.Line == rhs.Line && lhs.FilePath == rhs.FilePath;
}
bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
{
return !(lhs == rhs);
}

View File

@ -62,13 +62,16 @@ struct cmListFileContext
};
std::ostream& operator<<(std::ostream&, cmListFileContext const&);
bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs);
bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs);
bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs);
struct cmListFileFunction: public cmListFileContext
{
std::vector<cmListFileArgument> Arguments;
};
class cmListFileBacktrace: public std::vector<cmListFileContext>
class cmListFileBacktrace: private std::vector<cmListFileContext>
{
public:
cmListFileBacktrace(cmLocalGenerator* localGen)
@ -77,7 +80,12 @@ class cmListFileBacktrace: public std::vector<cmListFileContext>
{
}
void Append(cmListFileContext const& context);
void MakeRelative();
void PrintTitle(std::ostream& out);
void PrintCallStack(std::ostream& out);
private:
cmLocalGenerator* LocalGenerator;
bool Relative;

View File

@ -350,7 +350,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t,
lfc.FilePath = this->ListFileStack.back();
}
lfc.Line = 0;
backtrace.push_back(lfc);
backtrace.Append(lfc);
}
// Issue the message.
@ -364,11 +364,17 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const
for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin();
i != this->CallStack.rend(); ++i)
{
backtrace.push_back(*i->Context);
backtrace.Append(*i->Context);
}
return backtrace;
}
//----------------------------------------------------------------------------
cmListFileContext cmMakefile::GetExecutionContext() const
{
return *this->CallStack.back().Context;
}
//----------------------------------------------------------------------------
void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const
{
@ -1929,9 +1935,9 @@ void cmMakefile::CheckForUnused(const char* reason,
cmListFileBacktrace bt(this->GetLocalGenerator());
if (!this->CallStack.empty())
{
const cmListFileContext* file = this->CallStack.back().Context;
bt.push_back(*file);
path = file->FilePath.c_str();
cmListFileContext file = this->GetExecutionContext();
bt.Append(file);
path = file.FilePath;
}
else
{
@ -1940,7 +1946,7 @@ void cmMakefile::CheckForUnused(const char* reason,
cmListFileContext lfc;
lfc.FilePath = path;
lfc.Line = 0;
bt.push_back(lfc);
bt.Append(lfc);
}
if (this->CheckSystemVars ||
cmSystemTools::IsSubDirectory(path,
@ -2870,7 +2876,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew(
cmListFileContext lfc;
lfc.FilePath = filename;
lfc.Line = line;
bt.push_back(lfc);
bt.Append(lfc);
msg << "uninitialized variable \'" << lookup << "\'";
this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING,
msg.str(), bt);
@ -3403,7 +3409,7 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
if(!this->CallStack.empty())
{
// Record the context in which the blocker is created.
fb->SetStartingContext(*(this->CallStack.back().Context));
fb->SetStartingContext(this->GetExecutionContext());
}
this->FunctionBlockers.push_back(fb);
@ -4364,7 +4370,7 @@ std::string cmMakefile::GetListFileStack() const
size_t depth = this->ListFileStack.size();
if (depth > 0)
{
std::deque<std::string>::const_iterator it = this->ListFileStack.end();
std::vector<std::string>::const_iterator it = this->ListFileStack.end();
do
{
if (depth != this->ListFileStack.size())
@ -4928,20 +4934,9 @@ bool cmMakefile::SetPolicyVersion(const char *version)
}
//----------------------------------------------------------------------------
bool cmMakefile::HasCMP0054AlreadyBeenReported(
cmListFileContext context) const
bool cmMakefile::HasCMP0054AlreadyBeenReported() const
{
cmCMP0054Id id(context);
bool alreadyReported =
this->CMP0054ReportedIds.find(id) != this->CMP0054ReportedIds.end();
if(!alreadyReported)
{
this->CMP0054ReportedIds.insert(id);
}
return alreadyReported;
return !this->CMP0054ReportedIds.insert(this->GetExecutionContext()).second;
}
//----------------------------------------------------------------------------

View File

@ -35,7 +35,6 @@
#endif
#include <stack>
#include <deque>
class cmFunctionBlocker;
class cmCommand;
@ -387,33 +386,13 @@ public:
*/
cmPolicies *GetPolicies() const;
struct cmCMP0054Id
{
cmCMP0054Id(cmListFileContext const& context):
Context(context)
{
}
bool operator< (cmCMP0054Id const& id) const
{
if(this->Context.FilePath != id.Context.FilePath)
return this->Context.FilePath < id.Context.FilePath;
return this->Context.Line < id.Context.Line;
}
cmListFileContext Context;
};
mutable std::set<cmCMP0054Id> CMP0054ReportedIds;
mutable std::set<cmListFileContext> CMP0054ReportedIds;
/**
* Determine if the given context, name pair has already been reported
* in context of CMP0054.
*/
bool HasCMP0054AlreadyBeenReported(
cmListFileContext context) const;
bool HasCMP0054AlreadyBeenReported() const;
bool IgnoreErrorsCMP0061() const;
@ -611,6 +590,7 @@ public:
* Get the current context backtrace.
*/
cmListFileBacktrace GetBacktrace() const;
cmListFileContext GetExecutionContext() const;
/**
* Get the vector of files created by this makefile
@ -963,7 +943,7 @@ private:
bool CheckSystemVars;
// stack of list files being read
std::deque<std::string> ListFileStack;
std::vector<std::string> ListFileStack;
// stack of commands being invoked.
struct CallStackEntry
@ -971,7 +951,7 @@ private:
cmListFileContext const* Context;
cmExecutionStatus* Status;
};
typedef std::deque<CallStackEntry> CallStackType;
typedef std::vector<CallStackEntry> CallStackType;
CallStackType CallStack;
friend class cmMakefileCall;

View File

@ -1239,8 +1239,11 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
ret = false;
}
}
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
this->TLLCommands.push_back(std::make_pair(signature, lfbt));
cmListFileContext lfc = this->Makefile->GetExecutionContext();
if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc)
{
this->TLLCommands.push_back(std::make_pair(signature, lfc));
}
return ret;
}
@ -1248,39 +1251,19 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
void cmTarget::GetTllSignatureTraces(std::ostringstream &s,
TLLSignature sig) const
{
std::vector<cmListFileBacktrace> sigs;
typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword"
: "plain");
s << "The uses of the " << sigString << " signature are here:\n";
typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
cmLocalGenerator* lg = this->GetMakefile()->GetLocalGenerator();
for(Container::const_iterator it = this->TLLCommands.begin();
it != this->TLLCommands.end(); ++it)
{
if (it->first == sig)
{
sigs.push_back(it->second);
}
}
if (!sigs.empty())
{
const char *sigString
= (sig == cmTarget::KeywordTLLSignature ? "keyword"
: "plain");
s << "The uses of the " << sigString << " signature are here:\n";
UNORDERED_SET<std::string> emitted;
for(std::vector<cmListFileBacktrace>::iterator it = sigs.begin();
it != sigs.end(); ++it)
{
it->MakeRelative();
cmListFileBacktrace::const_iterator i = it->begin();
if(i != it->end())
{
cmListFileContext const& lfc = *i;
std::ostringstream line;
line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
if (emitted.insert(line.str()).second)
{
s << line.str();
}
++i;
}
cmListFileContext lfc = it->second;
lfc.FilePath = lg->Convert(lfc.FilePath, cmLocalGenerator::HOME);
s << " * " << lfc << std::endl;
}
}
}

View File

@ -641,7 +641,7 @@ private:
// directories.
std::set<std::string> SystemIncludeDirectories;
std::vector<std::pair<TLLSignature, cmListFileBacktrace> > TLLCommands;
std::vector<std::pair<TLLSignature, cmListFileContext> > TLLCommands;
#if defined(_WIN32) && !defined(__CYGWIN__)
/**

View File

@ -2485,13 +2485,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
}
// Add the immediate context.
cmListFileBacktrace::const_iterator i = backtrace.begin();
if(i != backtrace.end())
{
cmListFileContext const& lfc = *i;
msg << (lfc.Line? " at ": " in ") << lfc;
++i;
}
backtrace.PrintTitle(msg);
// Add the message text.
{
@ -2502,16 +2496,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
}
// Add the rest of the context.
if(i != backtrace.end())
{
msg << "Call Stack (most recent call first):\n";
while(i != backtrace.end())
{
cmListFileContext const& lfc = *i;
msg << " " << lfc << "\n";
++i;
}
}
backtrace.PrintCallStack(msg);
// Add a note about warning suppression.
if(t == cmake::AUTHOR_WARNING)

View File

@ -2,3 +2,4 @@ include(RunCMake)
run_cmake(IsDirectory)
run_cmake(IsDirectoryLong)
run_cmake(elseif-message)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,8 @@
CMake Error at elseif-message.cmake:[0-9]+ \(elseif\):
given arguments:
"Unknown" "arguments"
Unknown arguments specified
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,4 @@
if (0)
elseif(Unknown arguments)
endif()