mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +08:00
cmFindBaseDebugState: factor out a base class
This will be used to share logic with `find_package` writing events.
This commit is contained in:
@@ -635,8 +635,8 @@ void cmFindBase::StoreFindResult(std::string const& value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmFindBaseDebugState::cmFindBaseDebugState(cmFindBase const* findBase)
|
cmFindBaseDebugState::cmFindBaseDebugState(cmFindBase const* findBase)
|
||||||
: FindCommand(findBase)
|
: cmFindCommonDebugState(findBase->FindCommandName, findBase)
|
||||||
, CommandName(findBase->FindCommandName)
|
, FindBaseCommand(findBase)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,8 +653,9 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|||||||
// - the variable was not defined (first run)
|
// - the variable was not defined (first run)
|
||||||
// - the variable found state does not match the new found state (state
|
// - the variable found state does not match the new found state (state
|
||||||
// transition)
|
// transition)
|
||||||
if (this->FindCommand->DebugMode || !this->FindCommand->IsDefined() ||
|
if (this->FindCommand->DebugModeEnabled() ||
|
||||||
this->FindCommand->IsFound() != found) {
|
!this->FindBaseCommand->IsDefined() ||
|
||||||
|
this->FindBaseCommand->IsFound() != found) {
|
||||||
this->WriteFindEvent(*log, *this->FindCommand->Makefile);
|
this->WriteFindEvent(*log, *this->FindCommand->Makefile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -668,17 +669,17 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|||||||
auto buffer =
|
auto buffer =
|
||||||
cmStrCat(
|
cmStrCat(
|
||||||
this->CommandName, " called with the following settings:"
|
this->CommandName, " called with the following settings:"
|
||||||
"\n VAR: ", this->FindCommand->VariableName,
|
"\n VAR: ", this->FindBaseCommand->VariableName,
|
||||||
"\n NAMES: ", cmWrap('"', this->FindCommand->Names, '"', "\n "),
|
"\n NAMES: ", cmWrap('"', this->FindBaseCommand->Names, '"', "\n "),
|
||||||
"\n Documentation: ", this->FindCommand->VariableDocumentation,
|
"\n Documentation: ", this->FindBaseCommand->VariableDocumentation,
|
||||||
"\n Framework"
|
"\n Framework"
|
||||||
"\n Only Search Frameworks: ", this->FindCommand->SearchFrameworkOnly,
|
"\n Only Search Frameworks: ", this->FindBaseCommand->SearchFrameworkOnly,
|
||||||
"\n Search Frameworks Last: ", this->FindCommand->SearchFrameworkLast,
|
"\n Search Frameworks Last: ", this->FindBaseCommand->SearchFrameworkLast,
|
||||||
"\n Search Frameworks First: ", this->FindCommand->SearchFrameworkFirst,
|
"\n Search Frameworks First: ", this->FindBaseCommand->SearchFrameworkFirst,
|
||||||
"\n AppBundle"
|
"\n AppBundle"
|
||||||
"\n Only Search AppBundle: ", this->FindCommand->SearchAppBundleOnly,
|
"\n Only Search AppBundle: ", this->FindBaseCommand->SearchAppBundleOnly,
|
||||||
"\n Search AppBundle Last: ", this->FindCommand->SearchAppBundleLast,
|
"\n Search AppBundle Last: ", this->FindBaseCommand->SearchAppBundleLast,
|
||||||
"\n Search AppBundle First: ", this->FindCommand->SearchAppBundleFirst,
|
"\n Search AppBundle First: ", this->FindBaseCommand->SearchAppBundleFirst,
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
@@ -708,7 +709,7 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|||||||
buffer += cmStrCat(path, '\n');
|
buffer += cmStrCat(path, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (this->HasBeenFound()) {
|
||||||
buffer += cmStrCat("The item was found at\n ",
|
buffer += cmStrCat("The item was found at\n ",
|
||||||
this->FoundSearchLocation.path, '\n');
|
this->FoundSearchLocation.path, '\n');
|
||||||
} else {
|
} else {
|
||||||
@@ -718,20 +719,16 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|||||||
this->FindCommand->DebugMessage(buffer);
|
this->FindCommand->DebugMessage(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmFindBaseDebugState::FoundAt(std::string const& path,
|
void cmFindBaseDebugState::FoundAtImpl(std::string const& path,
|
||||||
std::string regexName)
|
std::string regexName)
|
||||||
{
|
{
|
||||||
if (this->TrackSearchProgress()) {
|
this->FoundSearchLocation = DebugLibState{ std::move(regexName), path };
|
||||||
this->FoundSearchLocation = DebugLibState{ std::move(regexName), path };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmFindBaseDebugState::FailedAt(std::string const& path,
|
void cmFindBaseDebugState::FailedAtImpl(std::string const& path,
|
||||||
std::string regexName)
|
std::string regexName)
|
||||||
{
|
{
|
||||||
if (this->TrackSearchProgress()) {
|
this->FailedSearchLocations.emplace_back(std::move(regexName), path);
|
||||||
this->FailedSearchLocations.emplace_back(std::move(regexName), path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
@@ -742,8 +739,9 @@ void cmFindBaseDebugState::WriteFindEvent(cmConfigureLog& log,
|
|||||||
|
|
||||||
// Mode is the Command name without the "find_" prefix
|
// Mode is the Command name without the "find_" prefix
|
||||||
log.WriteValue("mode"_s, this->CommandName.substr(5));
|
log.WriteValue("mode"_s, this->CommandName.substr(5));
|
||||||
log.WriteValue("variable"_s, this->FindCommand->VariableName);
|
log.WriteValue("variable"_s, this->FindBaseCommand->VariableName);
|
||||||
log.WriteValue("description"_s, this->FindCommand->VariableDocumentation);
|
log.WriteValue("description"_s,
|
||||||
|
this->FindBaseCommand->VariableDocumentation);
|
||||||
|
|
||||||
// Yes, this needs to return a `std::string`. If it returns a `const char*`,
|
// 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
|
// the `WriteValue` method prefers the `bool` overload. There's no overload
|
||||||
@@ -774,7 +772,7 @@ void cmFindBaseDebugState::WriteFindEvent(cmConfigureLog& log,
|
|||||||
!this->FindCommand->NoCMakeInstallPath);
|
!this->FindCommand->NoCMakeInstallPath);
|
||||||
log.EndObject();
|
log.EndObject();
|
||||||
|
|
||||||
log.WriteValue("names"_s, this->FindCommand->Names);
|
log.WriteValue("names"_s, this->FindBaseCommand->Names);
|
||||||
std::vector<std::string> directories;
|
std::vector<std::string> directories;
|
||||||
directories.reserve(this->FailedSearchLocations.size());
|
directories.reserve(this->FailedSearchLocations.size());
|
||||||
for (auto const& location : this->FailedSearchLocations) {
|
for (auto const& location : this->FailedSearchLocations) {
|
||||||
@@ -790,13 +788,3 @@ void cmFindBaseDebugState::WriteFindEvent(cmConfigureLog& log,
|
|||||||
log.EndEvent();
|
log.EndEvent();
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
@@ -92,17 +92,16 @@ private:
|
|||||||
void FillUserGuessPath();
|
void FillUserGuessPath();
|
||||||
};
|
};
|
||||||
|
|
||||||
class cmFindBaseDebugState
|
class cmFindBaseDebugState : public cmFindCommonDebugState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit cmFindBaseDebugState(cmFindBase const* findBase);
|
explicit cmFindBaseDebugState(cmFindBase const* findBase);
|
||||||
~cmFindBaseDebugState();
|
~cmFindBaseDebugState() override;
|
||||||
|
|
||||||
void FoundAt(std::string const& path, std::string regexName = std::string());
|
|
||||||
void FailedAt(std::string const& path,
|
|
||||||
std::string regexName = std::string());
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void FoundAtImpl(std::string const& path, std::string regexName) override;
|
||||||
|
void FailedAtImpl(std::string const& path, std::string regexName) override;
|
||||||
|
|
||||||
struct DebugLibState
|
struct DebugLibState
|
||||||
{
|
{
|
||||||
DebugLibState() = default;
|
DebugLibState() = default;
|
||||||
@@ -119,9 +118,7 @@ private:
|
|||||||
void WriteFindEvent(cmConfigureLog& log, cmMakefile const& mf) const;
|
void WriteFindEvent(cmConfigureLog& log, cmMakefile const& mf) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmFindBase const* FindCommand;
|
cmFindBase const* const FindBaseCommand;
|
||||||
std::string CommandName;
|
|
||||||
bool TrackSearchProgress() const;
|
|
||||||
std::vector<DebugLibState> FailedSearchLocations;
|
std::vector<DebugLibState> FailedSearchLocations;
|
||||||
DebugLibState FoundSearchLocation;
|
DebugLibState FoundSearchLocation;
|
||||||
};
|
};
|
||||||
|
@@ -457,3 +457,44 @@ void cmFindCommon::ComputeFinalPaths(IgnorePaths ignorePaths,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmFindCommonDebugState::cmFindCommonDebugState(std::string name,
|
||||||
|
cmFindCommon const* findCommand)
|
||||||
|
: FindCommand(findCommand)
|
||||||
|
, CommandName(std::move(name))
|
||||||
|
// Strip the `find_` prefix.
|
||||||
|
, Mode(this->CommandName.substr(5))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmFindCommonDebugState::FoundAt(std::string const& path,
|
||||||
|
std::string regexName)
|
||||||
|
{
|
||||||
|
this->IsFound = true;
|
||||||
|
|
||||||
|
if (!this->TrackSearchProgress()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->FoundAtImpl(path, regexName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmFindCommonDebugState::FailedAt(std::string const& path,
|
||||||
|
std::string regexName)
|
||||||
|
{
|
||||||
|
if (!this->TrackSearchProgress()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->FailedAtImpl(path, regexName);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmFindCommonDebugState::TrackSearchProgress() const
|
||||||
|
{
|
||||||
|
// Track search progress if debugging or logging the configure.
|
||||||
|
return this->FindCommand->DebugModeEnabled()
|
||||||
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
|
|| this->FindCommand->Makefile->GetCMakeInstance()->GetConfigureLog()
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
}
|
||||||
|
@@ -35,6 +35,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
friend class cmSearchPath;
|
friend class cmSearchPath;
|
||||||
friend class cmFindBaseDebugState;
|
friend class cmFindBaseDebugState;
|
||||||
|
friend class cmFindCommonDebugState;
|
||||||
|
|
||||||
/** Used to define groups of path labels */
|
/** Used to define groups of path labels */
|
||||||
class PathGroup : public cmPathLabel
|
class PathGroup : public cmPathLabel
|
||||||
@@ -157,3 +158,29 @@ protected:
|
|||||||
cmMakefile* Makefile;
|
cmMakefile* Makefile;
|
||||||
cmExecutionStatus& Status;
|
cmExecutionStatus& Status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class cmFindCommonDebugState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
cmFindCommonDebugState(std::string name, cmFindCommon const* findCommand);
|
||||||
|
virtual ~cmFindCommonDebugState() = default;
|
||||||
|
|
||||||
|
void FoundAt(std::string const& path, std::string regexName = std::string());
|
||||||
|
void FailedAt(std::string const& path,
|
||||||
|
std::string regexName = std::string());
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void FoundAtImpl(std::string const& path, std::string regexName) = 0;
|
||||||
|
virtual void FailedAtImpl(std::string const& path,
|
||||||
|
std::string regexName) = 0;
|
||||||
|
|
||||||
|
cmFindCommon const* const FindCommand;
|
||||||
|
std::string const CommandName;
|
||||||
|
std::string const Mode;
|
||||||
|
bool HasBeenFound() const { return this->IsFound; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool TrackSearchProgress() const;
|
||||||
|
|
||||||
|
bool IsFound{ false };
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user