1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-21 23:00:50 +08:00

cmGlobCacheEntry: Add helper to carry CONFIGURE_DEPENDS glob cache arguments

This commit is contained in:
Arctic Lampyrid
2024-03-19 11:32:22 +08:00
parent c61bbf48c5
commit f578515d02
9 changed files with 66 additions and 38 deletions

View File

@@ -4,11 +4,13 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include <cm3p/json/value.h> #include <cm3p/json/value.h>
#include "cmFileAPI.h" #include "cmFileAPI.h"
#include "cmGlobCacheEntry.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h" #include "cmLocalGenerator.h"
#include "cmMakefile.h" #include "cmMakefile.h"

View File

@@ -41,6 +41,7 @@
#include "cmFileTimes.h" #include "cmFileTimes.h"
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h" #include "cmGeneratorExpression.h"
#include "cmGlobCacheEntry.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmHexFileConverter.h" #include "cmHexFileConverter.h"
#include "cmList.h" #include "cmList.h"
@@ -810,10 +811,15 @@ bool HandleGlobImpl(std::vector<std::string> const& args, bool recurse,
std::sort(foundFiles.begin(), foundFiles.end()); std::sort(foundFiles.begin(), foundFiles.end());
foundFiles.erase(std::unique(foundFiles.begin(), foundFiles.end()), foundFiles.erase(std::unique(foundFiles.begin(), foundFiles.end()),
foundFiles.end()); foundFiles.end());
cm->AddGlobCacheEntry( auto entry = cmGlobCacheEntry{
recurse, (recurse ? g.GetRecurseListDirs() : g.GetListDirs()), recurse,
(recurse ? g.GetRecurseListDirs() : g.GetListDirs()),
(recurse ? g.GetRecurseThroughSymlinks() : false), (recurse ? g.GetRecurseThroughSymlinks() : false),
(g.GetRelative() ? g.GetRelative() : ""), expr, foundFiles, variable, (g.GetRelative() ? g.GetRelative() : ""),
expr,
foundFiles
};
cm->AddGlobCacheEntry(entry, variable,
status.GetMakefile().GetBacktrace()); status.GetMakefile().GetBacktrace());
} else { } else {
warnConfigureLate = true; warnConfigureLate = true;

30
Source/cmGlobCacheEntry.h Normal file
View File

@@ -0,0 +1,30 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
#include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector>
struct cmGlobCacheEntry
{
const bool Recurse;
const bool ListDirectories;
const bool FollowSymlinks;
const std::string Relative;
const std::string Expression;
std::vector<std::string> Files;
cmGlobCacheEntry(bool recurse, bool listDirectories, bool followSymlinks,
std::string relative, std::string expression,
std::vector<std::string> files)
: Recurse(recurse)
, ListDirectories(listDirectories)
, FollowSymlinks(followSymlinks)
, Relative(std::move(relative))
, Expression(std::move(expression))
, Files(std::move(files))
{
}
};

View File

@@ -7,6 +7,7 @@
#include "cmsys/FStream.hxx" #include "cmsys/FStream.hxx"
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmGlobCacheEntry.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmMessenger.h" #include "cmMessenger.h"
@@ -145,19 +146,18 @@ void cmGlobVerificationManager::CacheEntryKey::PrintGlobCommand(
} }
void cmGlobVerificationManager::AddCacheEntry( void cmGlobVerificationManager::AddCacheEntry(
const bool recurse, const bool listDirectories, const bool followSymlinks, const cmGlobCacheEntry& entry, const std::string& variable,
const std::string& relative, const std::string& expression,
const std::vector<std::string>& files, const std::string& variable,
const cmListFileBacktrace& backtrace, cmMessenger* messenger) const cmListFileBacktrace& backtrace, cmMessenger* messenger)
{ {
CacheEntryKey key = CacheEntryKey(recurse, listDirectories, followSymlinks, CacheEntryKey key =
relative, expression); CacheEntryKey(entry.Recurse, entry.ListDirectories, entry.FollowSymlinks,
entry.Relative, entry.Expression);
CacheEntryValue& value = this->Cache[key]; CacheEntryValue& value = this->Cache[key];
if (!value.Initialized) { if (!value.Initialized) {
value.Files = files; value.Files = entry.Files;
value.Initialized = true; value.Initialized = true;
value.Backtraces.emplace_back(variable, backtrace); value.Backtraces.emplace_back(variable, backtrace);
} else if (value.Initialized && value.Files != files) { } else if (value.Initialized && value.Files != entry.Files) {
std::ostringstream message; std::ostringstream message;
message << std::boolalpha; message << std::boolalpha;
message << "The glob expression\n "; message << "The glob expression\n ";

View File

@@ -13,6 +13,7 @@
#include "cmListFileCache.h" #include "cmListFileCache.h"
class cmMessenger; class cmMessenger;
struct cmGlobCacheEntry;
/** \class cmGlobVerificationManager /** \class cmGlobVerificationManager
* \brief Class for expressing build-time dependencies on glob expressions. * \brief Class for expressing build-time dependencies on glob expressions.
@@ -28,10 +29,7 @@ protected:
bool SaveVerificationScript(const std::string& path, cmMessenger* messenger); bool SaveVerificationScript(const std::string& path, cmMessenger* messenger);
//! Add an entry into the glob cache //! Add an entry into the glob cache
void AddCacheEntry(bool recurse, bool listDirectories, bool followSymlinks, void AddCacheEntry(const cmGlobCacheEntry& entry,
const std::string& relative,
const std::string& expression,
const std::vector<std::string>& files,
const std::string& variable, const std::string& variable,
const cmListFileBacktrace& bt, cmMessenger* messenger); const cmListFileBacktrace& bt, cmMessenger* messenger);

View File

@@ -16,6 +16,7 @@
#include "cmCommand.h" #include "cmCommand.h"
#include "cmDefinitions.h" #include "cmDefinitions.h"
#include "cmExecutionStatus.h" #include "cmExecutionStatus.h"
#include "cmGlobCacheEntry.h"
#include "cmGlobVerificationManager.h" #include "cmGlobVerificationManager.h"
#include "cmList.h" #include "cmList.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
@@ -238,15 +239,13 @@ bool cmState::SaveVerificationScript(const std::string& path,
messenger); messenger);
} }
void cmState::AddGlobCacheEntry( void cmState::AddGlobCacheEntry(const cmGlobCacheEntry& entry,
bool recurse, bool listDirectories, bool followSymlinks, const std::string& variable,
const std::string& relative, const std::string& expression, cmListFileBacktrace const& backtrace,
const std::vector<std::string>& files, const std::string& variable, cmMessenger* messenger)
cmListFileBacktrace const& backtrace, cmMessenger* messenger)
{ {
this->GlobVerificationManager->AddCacheEntry( this->GlobVerificationManager->AddCacheEntry(entry, variable, backtrace,
recurse, listDirectories, followSymlinks, relative, expression, files, messenger);
variable, backtrace, messenger);
} }
void cmState::RemoveCacheEntry(std::string const& key) void cmState::RemoveCacheEntry(std::string const& key)

View File

@@ -34,6 +34,7 @@ class cmStateSnapshot;
class cmMessenger; class cmMessenger;
class cmExecutionStatus; class cmExecutionStatus;
class cmListFileBacktrace; class cmListFileBacktrace;
struct cmGlobCacheEntry;
struct cmListFileArgument; struct cmListFileArgument;
template <typename T> template <typename T>
@@ -263,10 +264,7 @@ private:
std::string const& GetGlobVerifyScript() const; std::string const& GetGlobVerifyScript() const;
std::string const& GetGlobVerifyStamp() const; std::string const& GetGlobVerifyStamp() const;
bool SaveVerificationScript(const std::string& path, cmMessenger* messenger); bool SaveVerificationScript(const std::string& path, cmMessenger* messenger);
void AddGlobCacheEntry(bool recurse, bool listDirectories, void AddGlobCacheEntry(const cmGlobCacheEntry& entry,
bool followSymlinks, const std::string& relative,
const std::string& expression,
const std::vector<std::string>& files,
const std::string& variable, const std::string& variable,
cmListFileBacktrace const& bt, cmListFileBacktrace const& bt,
cmMessenger* messenger); cmMessenger* messenger);

View File

@@ -48,6 +48,7 @@
#include "cmExternalMakefileProjectGenerator.h" #include "cmExternalMakefileProjectGenerator.h"
#include "cmFileTimeCache.h" #include "cmFileTimeCache.h"
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
#include "cmGlobCacheEntry.h"
#include "cmGlobalGenerator.h" #include "cmGlobalGenerator.h"
#include "cmGlobalGeneratorFactory.h" #include "cmGlobalGeneratorFactory.h"
#include "cmLinkLineComputer.h" #include "cmLinkLineComputer.h"
@@ -2949,16 +2950,12 @@ std::string const& cmake::GetGlobVerifyStamp() const
return this->State->GetGlobVerifyStamp(); return this->State->GetGlobVerifyStamp();
} }
void cmake::AddGlobCacheEntry(bool recurse, bool listDirectories, void cmake::AddGlobCacheEntry(const cmGlobCacheEntry& entry,
bool followSymlinks, const std::string& relative,
const std::string& expression,
const std::vector<std::string>& files,
const std::string& variable, const std::string& variable,
cmListFileBacktrace const& backtrace) cmListFileBacktrace const& backtrace)
{ {
this->State->AddGlobCacheEntry(recurse, listDirectories, followSymlinks, this->State->AddGlobCacheEntry(entry, variable, backtrace,
relative, expression, files, variable, this->Messenger.get());
backtrace, this->Messenger.get());
} }
std::vector<std::string> cmake::GetAllExtensions() const std::vector<std::string> cmake::GetAllExtensions() const

View File

@@ -53,6 +53,7 @@ class cmMakefile;
class cmMessenger; class cmMessenger;
class cmVariableWatch; class cmVariableWatch;
struct cmBuildOptions; struct cmBuildOptions;
struct cmGlobCacheEntry;
/** \brief Represents a cmake invocation. /** \brief Represents a cmake invocation.
* *
@@ -351,10 +352,7 @@ public:
bool DoWriteGlobVerifyTarget() const; bool DoWriteGlobVerifyTarget() const;
std::string const& GetGlobVerifyScript() const; std::string const& GetGlobVerifyScript() const;
std::string const& GetGlobVerifyStamp() const; std::string const& GetGlobVerifyStamp() const;
void AddGlobCacheEntry(bool recurse, bool listDirectories, void AddGlobCacheEntry(const cmGlobCacheEntry& entry,
bool followSymlinks, const std::string& relative,
const std::string& expression,
const std::vector<std::string>& files,
const std::string& variable, const std::string& variable,
cmListFileBacktrace const& bt); cmListFileBacktrace const& bt);