find_package: Improve debug logging output

The find_package debug log messages are now easier to read when enabled by the
`--debug-find` command-line option or `CMAKE_FIND_DEBUG_MODE` variable.
This commit is contained in:
Robert Maynard 2020-01-01 14:46:16 -05:00
parent 23e782ce05
commit 6c92df382f
4 changed files with 45 additions and 17 deletions

View File

@ -161,6 +161,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
} }
this->DebugMode = ComputeIfDebugModeWanted(); this->DebugMode = ComputeIfDebugModeWanted();
this->DebugBuffer.clear();
// Lookup target architecture, if any. // Lookup target architecture, if any.
if (const char* arch = if (const char* arch =
@ -575,6 +576,7 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
} }
this->AppendSuccessInformation(); this->AppendSuccessInformation();
return loadedPackage; return loadedPackage;
} }
@ -708,7 +710,7 @@ bool cmFindPackageCommand::FindModule(bool& found)
debugBuffer = debugBuffer =
cmStrCat(debugBuffer, "The file was found at\n ", mfile, "\n"); cmStrCat(debugBuffer, "The file was found at\n ", mfile, "\n");
} }
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
if (!mfile.empty()) { if (!mfile.empty()) {
@ -841,6 +843,11 @@ bool cmFindPackageCommand::HandlePackageMode(
result = false; result = false;
} }
if (this->DebugMode) {
this->DebugMessage(this->DebugBuffer);
this->DebugBuffer.clear();
}
// package not found // package not found
if (result && !found) { if (result && !found) {
// warn if package required or neither quiet nor in config mode // warn if package required or neither quiet nor in config mode
@ -1001,6 +1008,11 @@ bool cmFindPackageCommand::FindConfig()
// Look for the project's configuration file. // Look for the project's configuration file.
bool found = false; bool found = false;
if (this->DebugMode) {
this->DebugBuffer = cmStrCat(this->DebugBuffer,
"find_package considered the following "
"locations for the Config module:\n");
}
// Search for frameworks. // Search for frameworks.
if (!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) { if (!found && (this->SearchFrameworkFirst || this->SearchFrameworkOnly)) {
@ -1027,6 +1039,16 @@ bool cmFindPackageCommand::FindConfig()
found = this->FindAppBundleConfig(); found = this->FindAppBundleConfig();
} }
if (this->DebugMode) {
if (found) {
this->DebugBuffer = cmStrCat(
this->DebugBuffer, "The file was found at\n ", this->FileFound, "\n");
} else {
this->DebugBuffer =
cmStrCat(this->DebugBuffer, "The file was not found.\n");
}
}
// Store the entry in the cache so it can be set by the user. // Store the entry in the cache so it can be set by the user.
std::string init; std::string init;
if (found) { if (found) {
@ -1040,6 +1062,7 @@ bool cmFindPackageCommand::FindConfig()
// We force the value since we do not get here if it was already set. // We force the value since we do not get here if it was already set.
this->Makefile->AddCacheDefinition(this->Variable, init.c_str(), this->Makefile->AddCacheDefinition(this->Variable, init.c_str(),
help.c_str(), cmStateEnums::PATH, true); help.c_str(), cmStateEnums::PATH, true);
return found; return found;
} }
@ -1244,7 +1267,7 @@ void cmFindPackageCommand::FillPrefixesPackageRoot()
std::string debugBuffer = "<PackageName>_ROOT CMake variable " std::string debugBuffer = "<PackageName>_ROOT CMake variable "
"[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n"; "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1280,7 +1303,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
"\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env " "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env "
"variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); "variables [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
collectPathsForDebug(debugBuffer, paths, debugOffset); collectPathsForDebug(debugBuffer, paths, debugOffset);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1304,7 +1327,7 @@ void cmFindPackageCommand::FillPrefixesCMakeVariable()
"\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables " "\nCMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables "
"[CMAKE_FIND_USE_CMAKE_PATH].\n"); "[CMAKE_FIND_USE_CMAKE_PATH].\n");
collectPathsForDebug(debugBuffer, paths, debugOffset); collectPathsForDebug(debugBuffer, paths, debugOffset);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1329,7 +1352,7 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment()
std::string debugBuffer = "Standard system environment variables " std::string debugBuffer = "Standard system environment variables "
"[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n"; "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1359,7 +1382,7 @@ void cmFindPackageCommand::FillPrefixesUserRegistry()
"CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n"; "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n";
collectPathsForDebug(debugBuffer, collectPathsForDebug(debugBuffer,
this->LabeledPaths[PathLabel::UserRegistry]); this->LabeledPaths[PathLabel::UserRegistry]);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1379,7 +1402,7 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry()
"[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n"; "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n";
collectPathsForDebug(debugBuffer, collectPathsForDebug(debugBuffer,
this->LabeledPaths[PathLabel::SystemRegistry]); this->LabeledPaths[PathLabel::SystemRegistry]);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1558,7 +1581,7 @@ void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
std::string debugBuffer = "CMake variables defined in the Platform file " std::string debugBuffer = "CMake variables defined in the Platform file "
"[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n"; "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1573,7 +1596,7 @@ void cmFindPackageCommand::FillPrefixesUserGuess()
std::string debugBuffer = std::string debugBuffer =
"Paths specified by the find_package PATHS option.\n"; "Paths specified by the find_package PATHS option.\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1588,7 +1611,7 @@ void cmFindPackageCommand::FillPrefixesUserHints()
std::string debugBuffer = std::string debugBuffer =
"Paths specified by the find_package HINTS option.\n"; "Paths specified by the find_package HINTS option.\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
this->DebugMessage(debugBuffer); this->DebugBuffer = cmStrCat(this->DebugBuffer, debugBuffer, "\n");
} }
} }
@ -1634,8 +1657,7 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
for (std::string const& c : this->Configs) { for (std::string const& c : this->Configs) {
file = cmStrCat(dir, '/', c); file = cmStrCat(dir, '/', c);
if (this->DebugMode) { if (this->DebugMode) {
std::string msg = "Checking file [" + file + "]\n"; this->DebugBuffer = cmStrCat(this->DebugBuffer, " ", file, "\n");
this->DebugMessage(msg);
} }
if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) { if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) {
// Allow resolving symlinks when the config file is found through a link // Allow resolving symlinks when the config file is found through a link

View File

@ -183,6 +183,7 @@ private:
std::vector<std::string> Names; std::vector<std::string> Names;
std::vector<std::string> Configs; std::vector<std::string> Configs;
std::set<std::string> IgnoredPaths; std::set<std::string> IgnoredPaths;
std::string DebugBuffer;
/*! the selected sortOrder (None by default)*/ /*! the selected sortOrder (None by default)*/
SortOrderType SortOrder; SortOrderType SortOrder;

View File

@ -1,6 +1,7 @@
CMake Debug Log at FromPATHEnv.cmake:5 \(find_package\): CMake Debug Log at FromPATHEnv.cmake:5 \(find_package\):
find_package considered the following paths for Resolved.cmake find_package considered the following paths for Resolved.cmake.*
.* .*/Modules/FindResolved.cmake.*
The file was not found.*
<PackageName>_ROOT CMake variable.* <PackageName>_ROOT CMake variable.*
CMAKE_PREFIX_PATH variable.* CMAKE_PREFIX_PATH variable.*
CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables.* CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables.*
@ -13,4 +14,7 @@ CMake Debug Log at FromPATHEnv.cmake:5 \(find_package\):
CMake variables defined in the Platform file.* CMake variables defined in the Platform file.*
CMake System Package Registry.* CMake System Package Registry.*
Paths specified by the find_package PATHS option.* Paths specified by the find_package PATHS option.*
Checking file.*\[.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake\] find_package considered the following locations for the Config module:.*
.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake.*
The file was found at.*
.*Tests/RunCMake/find_package/PackageRoot/ResolvedConfig\.cmake

View File

@ -9,8 +9,9 @@
CMake System Package Registry.* CMake System Package Registry.*
Paths specified by the find_package PATHS option.* Paths specified by the find_package PATHS option.*
.* .*
Checking file \[.*NotHereConfig.cmake\].* .*NotHereConfig.cmake
Checking file \[.*nothere-config.cmake\].* .*nothere-config.cmake
.*
CMake Warning at MissingConfigDebug.cmake:3 \(message\): CMake Warning at MissingConfigDebug.cmake:3 \(message\):
This warning must be reachable. This warning must be reachable.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):