cmFindBase: Track initial state with an enum

When logging a `WriteFindBaseEvent`, one of the triggers to log is the
change in the "found" status of a `find_` command. Track the difference
between "undefined", "found", and "tried before, but not found" so that
the transition can be detected reliably.

Co-Authored-by: Ryan Krattiger <ryan.krattiger@kitware.com>
This commit is contained in:
Ben Boeckel
2025-04-04 14:48:22 +02:00
parent 9debf90d87
commit 58b5d41a4f
5 changed files with 33 additions and 13 deletions

View File

@@ -79,8 +79,8 @@ bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
return false;
}
this->VariableName = args[0];
if (this->CheckForVariableDefined()) {
this->AlreadyDefined = true;
this->InitialState = this->GetInitialState();
if (this->IsFound()) {
return true;
}
@@ -470,7 +470,7 @@ void cmFindBase::FillUserGuessPath()
paths.AddSuffixes(this->SearchPathSuffixes);
}
bool cmFindBase::CheckForVariableDefined()
cmFindBase::FindState cmFindBase::GetInitialState()
{
if (cmValue value = this->Makefile->GetDefinition(this->VariableName)) {
cmState* state = this->Makefile->GetState();
@@ -496,10 +496,21 @@ bool cmFindBase::CheckForVariableDefined()
if (cached && cacheType == cmStateEnums::UNINITIALIZED) {
this->AlreadyInCacheWithoutMetaInfo = true;
}
return true;
return FindState::Found;
}
return FindState::NotFound;
}
return false;
return FindState::Undefined;
}
bool cmFindBase::IsFound() const
{
return this->InitialState == FindState::Found;
}
bool cmFindBase::IsDefined() const
{
return this->InitialState != FindState::Undefined;
}
void cmFindBase::NormalizeFindResult()

View File

@@ -40,10 +40,8 @@ protected:
friend class cmFindBaseDebugState;
void ExpandPaths();
// see if the VariableName is already set,
// also copy the documentation from the cache to VariableDocumentation
// if it has documentation in the cache
bool CheckForVariableDefined();
bool IsFound() const;
bool IsDefined() const;
void NormalizeFindResult();
void StoreFindResult(std::string const& value);
@@ -62,7 +60,6 @@ protected:
// CMAKE_*_PATH CMAKE_SYSTEM_*_PATH FRAMEWORK|LIBRARY|INCLUDE|PROGRAM
std::string EnvironmentPath; // LIB,INCLUDE
bool AlreadyDefined = false;
bool AlreadyInCacheWithoutMetaInfo = false;
bool StoreResultInCache = true;
@@ -71,6 +68,18 @@ protected:
std::string ValidatorName;
private:
enum class FindState
{
Undefined,
Found,
NotFound,
};
// see if the VariableName is already set,
// also copy the documentation from the cache to VariableDocumentation
// if it has documentation in the cache
FindState GetInitialState();
FindState InitialState = FindState::Undefined;
// Add pieces of the search.
void FillPackageRootPath();
void FillCMakeVariablePath();

View File

@@ -44,7 +44,7 @@ bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
if (this->AlreadyDefined) {
if (this->IsFound()) {
this->NormalizeFindResult();
return true;
}

View File

@@ -37,7 +37,7 @@ bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
if (this->AlreadyDefined) {
if (this->IsFound()) {
this->NormalizeFindResult();
return true;
}

View File

@@ -195,7 +195,7 @@ bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
}
this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
if (this->AlreadyDefined) {
if (this->IsFound()) {
this->NormalizeFindResult();
return true;
}