mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-23 00:48:55 +08:00
cmFindCommonDebugState: adopt event writing logic
This lays the groundwork for `find_package` also using the same triggering logic.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <cm/optional>
|
#include <cm/optional>
|
||||||
@@ -37,6 +38,13 @@ cmFindBase::cmFindBase(std::string findCommandName, cmExecutionStatus& status)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmFindBase::~cmFindBase()
|
||||||
|
{
|
||||||
|
if (this->DebugState) {
|
||||||
|
this->DebugState->Write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
bool cmFindBase::ParseArguments(std::vector<std::string> const& argsIn)
|
||||||
{
|
{
|
||||||
if (argsIn.size() < 2) {
|
if (argsIn.size() < 2) {
|
||||||
@@ -640,25 +648,22 @@ cmFindBaseDebugState::cmFindBaseDebugState(cmFindBase const* findBase)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
cmFindBaseDebugState::~cmFindBaseDebugState()
|
cmFindBaseDebugState::~cmFindBaseDebugState() = default;
|
||||||
|
|
||||||
|
void cmFindBaseDebugState::FoundAtImpl(std::string const& path,
|
||||||
|
std::string regexName)
|
||||||
{
|
{
|
||||||
bool found = !this->FoundSearchLocation.path.empty();
|
this->FoundSearchLocation = DebugLibState{ std::move(regexName), path };
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
void cmFindBaseDebugState::FailedAtImpl(std::string const& path,
|
||||||
// Write find event to the configure log if the log exists
|
std::string regexName)
|
||||||
if (cmConfigureLog* log =
|
{
|
||||||
this->FindCommand->Makefile->GetCMakeInstance()->GetConfigureLog()) {
|
this->FailedSearchLocations.emplace_back(std::move(regexName), path);
|
||||||
// Write event if any of:
|
}
|
||||||
// - the variable was not defined (first run)
|
|
||||||
// - the variable found state does not match the new found state (state
|
|
||||||
// transition)
|
|
||||||
if (!this->FindBaseCommand->IsDefined() ||
|
|
||||||
this->FindBaseCommand->IsFound() != found) {
|
|
||||||
this->WriteFindEvent(*log, *this->FindCommand->Makefile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
void cmFindBaseDebugState::WriteDebug() const
|
||||||
|
{
|
||||||
// clang-format off
|
// clang-format off
|
||||||
auto buffer =
|
auto buffer =
|
||||||
cmStrCat(
|
cmStrCat(
|
||||||
@@ -713,21 +718,9 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
|
|||||||
this->FindCommand->DebugMessage(buffer);
|
this->FindCommand->DebugMessage(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmFindBaseDebugState::FoundAtImpl(std::string const& path,
|
|
||||||
std::string regexName)
|
|
||||||
{
|
|
||||||
this->FoundSearchLocation = DebugLibState{ std::move(regexName), path };
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmFindBaseDebugState::FailedAtImpl(std::string const& path,
|
|
||||||
std::string regexName)
|
|
||||||
{
|
|
||||||
this->FailedSearchLocations.emplace_back(std::move(regexName), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
void cmFindBaseDebugState::WriteFindEvent(cmConfigureLog& log,
|
void cmFindBaseDebugState::WriteEvent(cmConfigureLog& log,
|
||||||
cmMakefile const& mf) const
|
cmMakefile const& mf) const
|
||||||
{
|
{
|
||||||
log.BeginEvent("find-v1", mf);
|
log.BeginEvent("find-v1", mf);
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ class cmFindBase : public cmFindCommon
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmFindBase(std::string findCommandName, cmExecutionStatus& status);
|
cmFindBase(std::string findCommandName, cmExecutionStatus& status);
|
||||||
virtual ~cmFindBase() = default;
|
~cmFindBase() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called when the command is first encountered in
|
* This is called when the command is first encountered in
|
||||||
@@ -42,8 +42,8 @@ protected:
|
|||||||
friend class cmFindBaseDebugState;
|
friend class cmFindBaseDebugState;
|
||||||
void ExpandPaths();
|
void ExpandPaths();
|
||||||
|
|
||||||
bool IsFound() const;
|
bool IsFound() const override;
|
||||||
bool IsDefined() const;
|
bool IsDefined() const override;
|
||||||
|
|
||||||
void NormalizeFindResult();
|
void NormalizeFindResult();
|
||||||
void StoreFindResult(std::string const& value);
|
void StoreFindResult(std::string const& value);
|
||||||
@@ -114,8 +114,9 @@ private:
|
|||||||
std::string path;
|
std::string path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void WriteDebug() const override;
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
void WriteFindEvent(cmConfigureLog& log, cmMakefile const& mf) const;
|
void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const override;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmFindBase const* const FindBaseCommand;
|
cmFindBase const* const FindBaseCommand;
|
||||||
|
@@ -71,6 +71,8 @@ cmFindCommon::cmFindCommon(cmExecutionStatus& status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmFindCommon::~cmFindCommon() = default;
|
||||||
|
|
||||||
void cmFindCommon::SetError(std::string const& e)
|
void cmFindCommon::SetError(std::string const& e)
|
||||||
{
|
{
|
||||||
this->Status.SetError(e);
|
this->Status.SetError(e);
|
||||||
@@ -492,6 +494,26 @@ void cmFindCommonDebugState::FailedAt(std::string const& path,
|
|||||||
this->FailedAtImpl(path, regexName);
|
this->FailedAtImpl(path, regexName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmFindCommonDebugState::Write()
|
||||||
|
{
|
||||||
|
#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:
|
||||||
|
// - the variable was not defined (first run)
|
||||||
|
// - the variable found state does not match the new found state (state
|
||||||
|
// transition)
|
||||||
|
if (!this->FindCommand->IsDefined() ||
|
||||||
|
this->FindCommand->IsFound() != this->IsFound) {
|
||||||
|
this->WriteEvent(*log, *this->FindCommand->Makefile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this->WriteDebug();
|
||||||
|
}
|
||||||
|
|
||||||
bool cmFindCommonDebugState::TrackSearchProgress() const
|
bool cmFindCommonDebugState::TrackSearchProgress() const
|
||||||
{
|
{
|
||||||
// Track search progress if debugging or logging the configure.
|
// Track search progress if debugging or logging the configure.
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
#include "cmSearchPath.h"
|
#include "cmSearchPath.h"
|
||||||
#include "cmWindowsRegistry.h"
|
#include "cmWindowsRegistry.h"
|
||||||
|
|
||||||
|
class cmConfigureLog;
|
||||||
class cmFindCommonDebugState;
|
class cmFindCommonDebugState;
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
class cmMakefile;
|
class cmMakefile;
|
||||||
@@ -29,6 +30,7 @@ class cmFindCommon
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cmFindCommon(cmExecutionStatus& status);
|
cmFindCommon(cmExecutionStatus& status);
|
||||||
|
virtual ~cmFindCommon();
|
||||||
|
|
||||||
void SetError(std::string const& e);
|
void SetError(std::string const& e);
|
||||||
|
|
||||||
@@ -80,6 +82,9 @@ protected:
|
|||||||
RootPathModeBoth
|
RootPathModeBoth
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual bool IsFound() const = 0;
|
||||||
|
virtual bool IsDefined() const = 0;
|
||||||
|
|
||||||
/** Construct the various path groups and labels */
|
/** Construct the various path groups and labels */
|
||||||
void InitializeSearchPathGroups();
|
void InitializeSearchPathGroups();
|
||||||
|
|
||||||
@@ -171,11 +176,18 @@ public:
|
|||||||
void FailedAt(std::string const& path,
|
void FailedAt(std::string const& path,
|
||||||
std::string regexName = std::string());
|
std::string regexName = std::string());
|
||||||
|
|
||||||
|
void Write();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void FoundAtImpl(std::string const& path, std::string regexName) = 0;
|
virtual void FoundAtImpl(std::string const& path, std::string regexName) = 0;
|
||||||
virtual void FailedAtImpl(std::string const& path,
|
virtual void FailedAtImpl(std::string const& path,
|
||||||
std::string regexName) = 0;
|
std::string regexName) = 0;
|
||||||
|
|
||||||
|
virtual void WriteDebug() const = 0;
|
||||||
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
|
virtual void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
cmFindCommon const* const FindCommand;
|
cmFindCommon const* const FindCommand;
|
||||||
std::string const CommandName;
|
std::string const CommandName;
|
||||||
std::string const Mode;
|
std::string const Mode;
|
||||||
|
@@ -60,6 +60,8 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class cmConfigureLog;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using pdt = cmFindPackageCommand::PackageDescriptionType;
|
using pdt = cmFindPackageCommand::PackageDescriptionType;
|
||||||
@@ -600,6 +602,20 @@ void cmFindPackageCommand::InheritOptions(cmFindPackageCommand* other)
|
|||||||
this->Quiet = other->Quiet;
|
this->Quiet = other->Quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmFindPackageCommand::IsFound() const
|
||||||
|
{
|
||||||
|
// TODO: track the actual found state.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmFindPackageCommand::IsDefined() const
|
||||||
|
{
|
||||||
|
// A `find_package` always needs to be rerun because it could create
|
||||||
|
// variables, provide commands, or targets. Therefore it is never
|
||||||
|
// "predefined" whether it is found or not.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
|
||||||
{
|
{
|
||||||
if (args.empty()) {
|
if (args.empty()) {
|
||||||
@@ -3365,7 +3381,7 @@ bool cmFindPackage(std::vector<std::string> const& args,
|
|||||||
cmFindPackageDebugState::cmFindPackageDebugState(
|
cmFindPackageDebugState::cmFindPackageDebugState(
|
||||||
cmFindPackageCommand const* findPackage)
|
cmFindPackageCommand const* findPackage)
|
||||||
: cmFindCommonDebugState("find_package", findPackage)
|
: cmFindCommonDebugState("find_package", findPackage)
|
||||||
, FindPackageCommand(findPackage)
|
// , FindPackageCommand(findPackage)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3384,3 +3400,18 @@ void cmFindPackageDebugState::FailedAtImpl(std::string const& path,
|
|||||||
(void)path;
|
(void)path;
|
||||||
(void)regexName;
|
(void)regexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmFindPackageDebugState::WriteDebug() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
|
void cmFindPackageDebugState::WriteEvent(cmConfigureLog& log,
|
||||||
|
cmMakefile const& mf) const
|
||||||
|
{
|
||||||
|
(void)log;
|
||||||
|
(void)mf;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@@ -32,7 +32,9 @@ namespace std {
|
|||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class cmConfigureLog;
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
|
class cmMakefile;
|
||||||
class cmPackageState;
|
class cmPackageState;
|
||||||
class cmSearchPath;
|
class cmSearchPath;
|
||||||
|
|
||||||
@@ -95,6 +97,9 @@ private:
|
|||||||
|
|
||||||
void InheritOptions(cmFindPackageCommand* other);
|
void InheritOptions(cmFindPackageCommand* other);
|
||||||
|
|
||||||
|
bool IsFound() const override;
|
||||||
|
bool IsDefined() const override;
|
||||||
|
|
||||||
// Try to find a package, assuming most state has already been set up. This
|
// Try to find a package, assuming most state has already been set up. This
|
||||||
// is used for recursive dependency solving, particularly when importing
|
// is used for recursive dependency solving, particularly when importing
|
||||||
// packages via CPS. Bypasses providers if argsForProvider is empty.
|
// packages via CPS. Bypasses providers if argsForProvider is empty.
|
||||||
@@ -353,5 +358,10 @@ private:
|
|||||||
void FoundAtImpl(std::string const& path, std::string regexName) override;
|
void FoundAtImpl(std::string const& path, std::string regexName) override;
|
||||||
void FailedAtImpl(std::string const& path, std::string regexName) override;
|
void FailedAtImpl(std::string const& path, std::string regexName) override;
|
||||||
|
|
||||||
cmFindPackageCommand const* const FindPackageCommand;
|
void WriteDebug() const override;
|
||||||
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
|
void WriteEvent(cmConfigureLog& log, cmMakefile const& mf) const override;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// cmFindPackageCommand const* const FindPackageCommand;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user