summaryrefslogtreecommitdiff
path: root/Source/cmMessenger.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-12-07 15:18:17 -0500
committerBrad King <brad.king@kitware.com>2021-12-08 10:03:48 -0500
commit3d378541bb22f00e3a22bf5f12e97b7943a81294 (patch)
tree853fa2666199c276b677e28c6b9c15fce70481c9 /Source/cmMessenger.cxx
parent642238b3021ccb1923e57563bb61e0abb0111c84 (diff)
downloadcmake-3d378541bb22f00e3a22bf5f12e97b7943a81294.tar.gz
cmMessenger: Adopt backtrace printing functions
Move backtrace printing functions from `cmListFileBacktrace` over to `cmMessenger`, their primary caller. Thread `cmMessenger` instances through APIs needed to update other call sites.
Diffstat (limited to 'Source/cmMessenger.cxx')
-rw-r--r--Source/cmMessenger.cxx58
1 files changed, 56 insertions, 2 deletions
diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx
index 2eead6b596..52c9dd0872 100644
--- a/Source/cmMessenger.cxx
+++ b/Source/cmMessenger.cxx
@@ -4,6 +4,8 @@
#include "cmDocumentationFormatter.h"
#include "cmMessageMetadata.h"
+#include "cmState.h"
+#include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -151,6 +153,42 @@ static void displayMessage(MessageType t, std::ostringstream& msg)
}
}
+namespace {
+void PrintCallStack(std::ostream& out, cmListFileBacktrace bt)
+{
+ // The call stack exists only if we have at least two calls on top
+ // of the bottom.
+ if (bt.Empty()) {
+ return;
+ }
+ bt = bt.Pop();
+ if (bt.Empty()) {
+ return;
+ }
+
+ bool first = true;
+ cmStateSnapshot bottom = bt.GetBottom();
+ for (; !bt.Empty(); bt = bt.Pop()) {
+ cmListFileContext lfc = bt.Top();
+ if (lfc.Name.empty() &&
+ lfc.Line != cmListFileContext::DeferPlaceholderLine) {
+ // Skip this whole-file scope. When we get here we already will
+ // have printed a more-specific context within the file.
+ continue;
+ }
+ if (first) {
+ first = false;
+ out << "Call Stack (most recent call first):\n";
+ }
+ if (bottom.GetState()->GetProjectKind() == cmState::ProjectKind::Normal) {
+ lfc.FilePath = cmSystemTools::RelativeIfUnder(
+ bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
+ }
+ out << " " << lfc << "\n";
+ }
+}
+}
+
void cmMessenger::IssueMessage(MessageType t, const std::string& text,
const cmListFileBacktrace& backtrace) const
{
@@ -176,12 +214,28 @@ void cmMessenger::DisplayMessage(MessageType t, const std::string& text,
}
// Add the immediate context.
- backtrace.PrintTitle(msg);
+ this->PrintBacktraceTitle(msg, backtrace);
printMessageText(msg, text);
// Add the rest of the context.
- backtrace.PrintCallStack(msg);
+ PrintCallStack(msg, backtrace);
displayMessage(t, msg);
}
+
+void cmMessenger::PrintBacktraceTitle(std::ostream& out,
+ cmListFileBacktrace const& bt) const
+{
+ // The title exists only if we have a call on top of the bottom.
+ if (bt.Empty()) {
+ return;
+ }
+ cmListFileContext lfc = bt.Top();
+ cmStateSnapshot bottom = bt.GetBottom();
+ if (bottom.GetState()->GetProjectKind() == cmState::ProjectKind::Normal) {
+ lfc.FilePath = cmSystemTools::RelativeIfUnder(
+ bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
+ }
+ out << (lfc.Line ? " at " : " in ") << lfc;
+}