diff options
author | Brad King <brad.king@kitware.com> | 2021-12-07 21:05:55 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-12-08 15:03:48 (GMT) |
commit | 56dc22d48829860b50a441dcc26de14150ad724c (patch) | |
tree | c0f2f90a4b03f510c1590b97215b366ef77f21ac | |
parent | c749982c13fa00a968fe0b171946b96d0884ea54 (diff) | |
download | CMake-56dc22d48829860b50a441dcc26de14150ad724c.zip CMake-56dc22d48829860b50a441dcc26de14150ad724c.tar.gz CMake-56dc22d48829860b50a441dcc26de14150ad724c.tar.bz2 |
cmMessenger: Make relative path conversion more explicit
Move the decision to convert to call stacks to relative paths out to the
client. Avoid using `cmState` to make the decision ourselves.
-rw-r--r-- | Source/cmMessenger.cxx | 26 | ||||
-rw-r--r-- | Source/cmMessenger.h | 6 | ||||
-rw-r--r-- | Source/cmake.cxx | 6 |
3 files changed, 26 insertions, 12 deletions
diff --git a/Source/cmMessenger.cxx b/Source/cmMessenger.cxx index 52c9dd0..6dd192e 100644 --- a/Source/cmMessenger.cxx +++ b/Source/cmMessenger.cxx @@ -4,8 +4,6 @@ #include "cmDocumentationFormatter.h" #include "cmMessageMetadata.h" -#include "cmState.h" -#include "cmStateSnapshot.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -14,6 +12,7 @@ #endif #include <sstream> +#include <utility> #include "cmsys/Terminal.h" @@ -154,7 +153,8 @@ static void displayMessage(MessageType t, std::ostringstream& msg) } namespace { -void PrintCallStack(std::ostream& out, cmListFileBacktrace bt) +void PrintCallStack(std::ostream& out, cmListFileBacktrace bt, + cm::optional<std::string> const& topSource) { // The call stack exists only if we have at least two calls on top // of the bottom. @@ -167,7 +167,6 @@ void PrintCallStack(std::ostream& out, cmListFileBacktrace bt) } bool first = true; - cmStateSnapshot bottom = bt.GetBottom(); for (; !bt.Empty(); bt = bt.Pop()) { cmListFileContext lfc = bt.Top(); if (lfc.Name.empty() && @@ -180,9 +179,8 @@ void PrintCallStack(std::ostream& out, cmListFileBacktrace bt) 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); + if (topSource) { + lfc.FilePath = cmSystemTools::RelativeIfUnder(*topSource, lfc.FilePath); } out << " " << lfc << "\n"; } @@ -219,7 +217,7 @@ void cmMessenger::DisplayMessage(MessageType t, const std::string& text, printMessageText(msg, text); // Add the rest of the context. - PrintCallStack(msg, backtrace); + PrintCallStack(msg, backtrace, this->TopSource); displayMessage(t, msg); } @@ -232,10 +230,14 @@ void cmMessenger::PrintBacktraceTitle(std::ostream& out, 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); + if (this->TopSource) { + lfc.FilePath = + cmSystemTools::RelativeIfUnder(*this->TopSource, lfc.FilePath); } out << (lfc.Line ? " at " : " in ") << lfc; } + +void cmMessenger::SetTopSource(cm::optional<std::string> topSource) +{ + this->TopSource = std::move(topSource); +} diff --git a/Source/cmMessenger.h b/Source/cmMessenger.h index 8287e70..451add0 100644 --- a/Source/cmMessenger.h +++ b/Source/cmMessenger.h @@ -7,6 +7,8 @@ #include <iosfwd> #include <string> +#include <cm/optional> + #include "cmListFileCache.h" #include "cmMessageType.h" @@ -20,6 +22,8 @@ public: void DisplayMessage(MessageType t, std::string const& text, cmListFileBacktrace const& backtrace) const; + void SetTopSource(cm::optional<std::string> topSource); + void SetSuppressDevWarnings(bool suppress) { this->SuppressDevWarnings = suppress; @@ -56,6 +60,8 @@ private: bool IsMessageTypeVisible(MessageType t) const; MessageType ConvertMessageType(MessageType t) const; + cm::optional<std::string> TopSource; + bool SuppressDevWarnings = false; bool SuppressDeprecatedWarnings = false; bool DevWarningsAsErrors = false; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index d927d27..9efdb54 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -1706,6 +1706,12 @@ void cmake::SetHomeDirectory(const std::string& dir) if (this->CurrentSnapshot.IsValid()) { this->CurrentSnapshot.SetDefinition("CMAKE_SOURCE_DIR", dir); } + + if (this->State->GetProjectKind() == cmState::ProjectKind::Normal) { + this->Messenger->SetTopSource(this->GetHomeDirectory()); + } else { + this->Messenger->SetTopSource(cm::nullopt); + } } std::string const& cmake::GetHomeDirectory() const |