|
@@ -14,6 +14,7 @@
|
|
|
#include <cmext/string_view>
|
|
|
|
|
|
#include "cmCMakePath.h"
|
|
|
+#include "cmConfigureLog.h"
|
|
|
#include "cmExecutionStatus.h"
|
|
|
#include "cmList.h"
|
|
|
#include "cmListFileCache.h"
|
|
@@ -642,6 +643,24 @@ cmFindBaseDebugState::cmFindBaseDebugState(std::string commandName,
|
|
|
|
|
|
cmFindBaseDebugState::~cmFindBaseDebugState()
|
|
|
{
|
|
|
+ bool found = !this->FoundSearchLocation.path.empty();
|
|
|
+
|
|
|
+#ifndef CMAKE_BOOTSTRAP
|
|
|
+ // Write find event to the configure log if the log exists
|
|
|
+ if (cmConfigureLog* log =
|
|
|
+ this->FindCommand->Makefile->GetCMakeInstance()->GetConfigureLog()) {
|
|
|
+ // Write event if any of:
|
|
|
+ // - debug mode is enabled
|
|
|
+ // - the variable was not defined (first run)
|
|
|
+ // - the variable found state does not match the new found state (state
|
|
|
+ // transition)
|
|
|
+ if (this->FindCommand->DebugMode || !this->FindCommand->IsDefined() ||
|
|
|
+ this->FindCommand->IsFound() != found) {
|
|
|
+ this->WriteFindEvent(*log, *this->FindCommand->Makefile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
if (!this->FindCommand->DebugMode) {
|
|
|
return;
|
|
|
}
|
|
@@ -690,7 +709,7 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|
|
buffer += cmStrCat(path, '\n');
|
|
|
}
|
|
|
|
|
|
- if (!this->FoundSearchLocation.path.empty()) {
|
|
|
+ if (found) {
|
|
|
buffer += cmStrCat("The item was found at\n ",
|
|
|
this->FoundSearchLocation.path, '\n');
|
|
|
} else {
|
|
@@ -703,7 +722,7 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|
|
void cmFindBaseDebugState::FoundAt(std::string const& path,
|
|
|
std::string regexName)
|
|
|
{
|
|
|
- if (this->FindCommand->DebugMode) {
|
|
|
+ if (this->TrackSearchProgress()) {
|
|
|
this->FoundSearchLocation = DebugLibState{ std::move(regexName), path };
|
|
|
}
|
|
|
}
|
|
@@ -711,7 +730,74 @@ void cmFindBaseDebugState::FoundAt(std::string const& path,
|
|
|
void cmFindBaseDebugState::FailedAt(std::string const& path,
|
|
|
std::string regexName)
|
|
|
{
|
|
|
- if (this->FindCommand->DebugMode) {
|
|
|
+ if (this->TrackSearchProgress()) {
|
|
|
this->FailedSearchLocations.emplace_back(std::move(regexName), path);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#ifndef CMAKE_BOOTSTRAP
|
|
|
+void cmFindBaseDebugState::WriteFindEvent(cmConfigureLog& log,
|
|
|
+ cmMakefile const& mf) const
|
|
|
+{
|
|
|
+ log.BeginEvent("find-v1", mf);
|
|
|
+
|
|
|
+ // Mode is the Command name without the "find_" prefix
|
|
|
+ log.WriteValue("mode"_s, this->CommandName.substr(5));
|
|
|
+ log.WriteValue("variable"_s, this->FindCommand->VariableName);
|
|
|
+ log.WriteValue("description"_s, this->FindCommand->VariableDocumentation);
|
|
|
+
|
|
|
+ // Yes, this needs to return a `std::string`. If it returns a `const char*`,
|
|
|
+ // the `WriteValue` method prefers the `bool` overload. There's no overload
|
|
|
+ // for a `cm::string_view` because the underlying JSON library doesn't
|
|
|
+ // support `string_view` arguments itself.
|
|
|
+ auto search_opt_to_str = [](bool first, bool last,
|
|
|
+ bool only) -> std::string {
|
|
|
+ return first ? "FIRST" : (last ? "LAST" : (only ? "ONLY" : "NEVER"));
|
|
|
+ };
|
|
|
+ log.BeginObject("settings"_s);
|
|
|
+ log.WriteValue("SearchFramework"_s,
|
|
|
+ search_opt_to_str(this->FindCommand->SearchFrameworkFirst,
|
|
|
+ this->FindCommand->SearchFrameworkLast,
|
|
|
+ this->FindCommand->SearchFrameworkOnly));
|
|
|
+ log.WriteValue("SearchAppBundle"_s,
|
|
|
+ search_opt_to_str(this->FindCommand->SearchAppBundleFirst,
|
|
|
+ this->FindCommand->SearchAppBundleLast,
|
|
|
+ this->FindCommand->SearchAppBundleOnly));
|
|
|
+ log.WriteValue("CMAKE_FIND_USE_CMAKE_PATH"_s,
|
|
|
+ !this->FindCommand->NoCMakePath);
|
|
|
+ log.WriteValue("CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH"_s,
|
|
|
+ !this->FindCommand->NoCMakeEnvironmentPath);
|
|
|
+ log.WriteValue("CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH"_s,
|
|
|
+ !this->FindCommand->NoSystemEnvironmentPath);
|
|
|
+ log.WriteValue("CMAKE_FIND_USE_CMAKE_SYSTEM_PATH"_s,
|
|
|
+ !this->FindCommand->NoCMakeSystemPath);
|
|
|
+ log.WriteValue("CMAKE_FIND_USE_INSTALL_PREFIX"_s,
|
|
|
+ !this->FindCommand->NoCMakeInstallPath);
|
|
|
+ log.EndObject();
|
|
|
+
|
|
|
+ log.WriteValue("names"_s, this->FindCommand->Names);
|
|
|
+ std::vector<std::string> directories;
|
|
|
+ directories.reserve(this->FailedSearchLocations.size());
|
|
|
+ for (auto const& location : this->FailedSearchLocations) {
|
|
|
+ directories.push_back(location.path);
|
|
|
+ }
|
|
|
+ log.WriteValue("candidate_directories"_s, this->FindCommand->SearchPaths);
|
|
|
+ log.WriteValue("searched_directories"_s, directories);
|
|
|
+ if (!this->FoundSearchLocation.path.empty()) {
|
|
|
+ log.WriteValue("found"_s, this->FoundSearchLocation.path);
|
|
|
+ } else {
|
|
|
+ log.WriteValue("found"_s, false);
|
|
|
+ }
|
|
|
+ log.EndEvent();
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+bool cmFindBaseDebugState::TrackSearchProgress() const
|
|
|
+{
|
|
|
+ // Track search progress if debugging or logging the configure.
|
|
|
+ return this->FindCommand->DebugMode
|
|
|
+#ifndef CMAKE_BOOTSTRAP
|
|
|
+ || this->FindCommand->Makefile->GetCMakeInstance()->GetConfigureLog()
|
|
|
+#endif
|
|
|
+ ;
|
|
|
+}
|