summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-05-19 15:09:36 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-05-19 15:09:36 (GMT)
commit0cbc69b9ea97a44280350a58a365c617896e4589 (patch)
tree0e65541d3986b4b86d3d62fe21545bdf7ad5172a
parent56dc91c3adac1abbd2326fe677b6093c997771c1 (diff)
parent61d52e6e77bef903225bd3bad3e381bac73ee557 (diff)
downloadCMake-0cbc69b9ea97a44280350a58a365c617896e4589.zip
CMake-0cbc69b9ea97a44280350a58a365c617896e4589.tar.gz
CMake-0cbc69b9ea97a44280350a58a365c617896e4589.tar.bz2
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.
-rw-r--r--Source/cmCommandArgumentParserHelper.cxx2
-rw-r--r--Source/cmConditionEvaluator.cxx10
-rw-r--r--Source/cmListFileCache.cxx49
-rw-r--r--Source/cmListFileCache.h10
-rw-r--r--Source/cmMakefile.cxx39
-rw-r--r--Source/cmMakefile.h30
-rw-r--r--Source/cmTarget.cxx43
-rw-r--r--Source/cmTarget.h2
-rw-r--r--Source/cmake.cxx19
-rw-r--r--Tests/RunCMake/if/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/if/elseif-message-result.txt1
-rw-r--r--Tests/RunCMake/if/elseif-message-stderr.txt8
-rw-r--r--Tests/RunCMake/if/elseif-message.cmake4
13 files changed, 113 insertions, 105 deletions
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx
index 0d1c86d..c816c23 100644
--- a/Source/cmCommandArgumentParserHelper.cxx
+++ b/Source/cmCommandArgumentParserHelper.cxx
@@ -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);
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index 73aface..61847d4 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -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";
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index ddcea9b..2756cd2 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -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);
+}
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index 544ff1b..4a1d181 100644
--- a/Source/cmListFileCache.h
+++ b/Source/cmListFileCache.h
@@ -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;
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 99d22d6..3e19cbb 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -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,12 +364,18 @@ 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
{
std::ostringstream msg;
@@ -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;
}
//----------------------------------------------------------------------------
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index e0eef6f..bfd6155 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -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;
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 8a8c163..8feb7a5 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -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;
}
}
}
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index a032414..c5e9fc4 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -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__)
/**
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index c5a98d5..d783976 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -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)
diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake
index 6b6b74b..b5546a7 100644
--- a/Tests/RunCMake/if/RunCMakeTest.cmake
+++ b/Tests/RunCMake/if/RunCMakeTest.cmake
@@ -2,3 +2,4 @@ include(RunCMake)
run_cmake(IsDirectory)
run_cmake(IsDirectoryLong)
+run_cmake(elseif-message)
diff --git a/Tests/RunCMake/if/elseif-message-result.txt b/Tests/RunCMake/if/elseif-message-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/if/elseif-message-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/if/elseif-message-stderr.txt b/Tests/RunCMake/if/elseif-message-stderr.txt
new file mode 100644
index 0000000..c73977c
--- /dev/null
+++ b/Tests/RunCMake/if/elseif-message-stderr.txt
@@ -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\)
diff --git a/Tests/RunCMake/if/elseif-message.cmake b/Tests/RunCMake/if/elseif-message.cmake
new file mode 100644
index 0000000..5930966
--- /dev/null
+++ b/Tests/RunCMake/if/elseif-message.cmake
@@ -0,0 +1,4 @@
+
+if (0)
+elseif(Unknown arguments)
+endif()