summaryrefslogtreecommitdiff
path: root/src/buildtool/build_engine/target_map/target_cache.hpp
diff options
context:
space:
mode:
authorSascha Roloff <sascha.roloff@huawei.com>2022-12-21 16:24:27 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-01-20 13:57:18 +0100
commitee549fa1ca1ff4a075c9b2634808525b014818ea (patch)
treece709bd351412e73766340439b991a5215e69d1e /src/buildtool/build_engine/target_map/target_cache.hpp
parent56828d241a618c94f0526b5fd498b7f3ce540230 (diff)
downloadjustbuild-ee549fa1ca1ff4a075c9b2634808525b014818ea.tar.gz
Refactor target cache key and entry to separate files and targets
Diffstat (limited to 'src/buildtool/build_engine/target_map/target_cache.hpp')
-rw-r--r--src/buildtool/build_engine/target_map/target_cache.hpp95
1 files changed, 20 insertions, 75 deletions
diff --git a/src/buildtool/build_engine/target_map/target_cache.hpp b/src/buildtool/build_engine/target_map/target_cache.hpp
index fe32d3dd..b6b54ce0 100644
--- a/src/buildtool/build_engine/target_map/target_cache.hpp
+++ b/src/buildtool/build_engine/target_map/target_cache.hpp
@@ -15,80 +15,28 @@
#ifndef INCLUDED_SRC_BUILDTOOL_BUILD_ENGINE_TARGET_MAP_TARGET_CACHE_HPP
#define INCLUDED_SRC_BUILDTOOL_BUILD_ENGINE_TARGET_MAP_TARGET_CACHE_HPP
-#include <unordered_map>
+#include <filesystem>
+#include <functional>
+#include <optional>
+#include <string>
+#include <utility>
+#include <gsl-lite/gsl-lite.hpp>
#include <nlohmann/json.hpp>
-#include "src/buildtool/build_engine/analysed_target/analysed_target.hpp"
-#include "src/buildtool/build_engine/base_maps/entity_name.hpp"
+#include "src/buildtool/build_engine/target_map/target_cache_entry.hpp"
+#include "src/buildtool/build_engine/target_map/target_cache_key.hpp"
#include "src/buildtool/common/artifact.hpp"
-#ifndef BOOTSTRAP_BUILD_TOOL
-#include "src/buildtool/execution_api/common/execution_api.hpp"
-#endif
#include "src/buildtool/execution_api/local/file_storage.hpp"
#include "src/buildtool/execution_api/local/local_cas.hpp"
-#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/logger.hpp"
+#ifndef BOOTSTRAP_BUILD_TOOL
+#include "src/buildtool/execution_api/common/execution_api.hpp"
+#endif
class TargetCache {
public:
- // Key for target cache. Created from target name and effective config.
- class Key {
- public:
- [[nodiscard]] static auto Create(
- BuildMaps::Base::EntityName const& target,
- Configuration const& effective_config) noexcept
- -> std::optional<Key>;
-
- [[nodiscard]] auto Id() const& -> Artifact::ObjectInfo const& {
- return id_;
- }
- [[nodiscard]] auto Id() && -> Artifact::ObjectInfo {
- return std::move(id_);
- }
- [[nodiscard]] auto operator==(Key const& other) const -> bool {
- return this->Id() == other.Id();
- }
-
- private:
- explicit Key(Artifact::ObjectInfo id) : id_{std::move(id)} {}
- Artifact::ObjectInfo id_;
- };
-
- // Entry for target cache. Created from target, contains TargetResult.
- class Entry {
- friend class TargetCache;
-
- public:
- // Create the entry from target with replacement artifacts/infos.
- // Replacement artifacts must replace all non-known artifacts by known.
- [[nodiscard]] static auto FromTarget(
- AnalysedTargetPtr const& target,
- std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const&
- replacements) noexcept -> std::optional<Entry>;
-
- // Obtain TargetResult from cache entry.
- [[nodiscard]] auto ToResult() const noexcept
- -> std::optional<TargetResult>;
-
- // Obtain all artifacts from cache entry (all should be known
- // artifacts).
- [[nodiscard]] auto ToArtifacts(
- gsl::not_null<std::vector<Artifact::ObjectInfo>*> const& infos)
- const noexcept -> bool;
-
- private:
- nlohmann::json desc_;
-
- explicit Entry(nlohmann::json desc) : desc_(std::move(desc)) {}
- [[nodiscard]] auto ToJson() const& -> nlohmann::json const& {
- return desc_;
- }
- [[nodiscard]] auto ToJson() && -> nlohmann::json {
- return std::move(desc_);
- }
- };
-
TargetCache() = default;
TargetCache(TargetCache const&) = delete;
TargetCache(TargetCache&&) = delete;
@@ -102,12 +50,13 @@ class TargetCache {
}
// Store new key entry pair in the target cache.
- [[nodiscard]] auto Store(Key const& key, Entry const& value) const noexcept
+ [[nodiscard]] auto Store(TargetCacheKey const& key,
+ TargetCacheEntry const& value) const noexcept
-> bool;
// Read existing entry and object info for given key from the target cache.
- [[nodiscard]] auto Read(Key const& key) const noexcept
- -> std::optional<std::pair<Entry, Artifact::ObjectInfo>>;
+ [[nodiscard]] auto Read(TargetCacheKey const& key) const noexcept
+ -> std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>>;
#ifndef BOOTSTRAP_BUILD_TOOL
auto SetLocalApi(gsl::not_null<IExecutionApi*> const& api) noexcept
@@ -132,12 +81,8 @@ class TargetCache {
IExecutionApi* remote_api_{};
#endif
- [[nodiscard]] auto DownloadKnownArtifacts(Entry const& value) const noexcept
- -> bool;
- [[nodiscard]] auto CollectKnownArtifacts(
- gsl::not_null<std::vector<Artifact::ObjectInfo>*> const& infos,
- gsl::not_null<std::unordered_set<std::string>*> const& hashes,
- ExpressionPtr const& expr) const noexcept -> bool;
+ [[nodiscard]] auto DownloadKnownArtifacts(
+ TargetCacheEntry const& value) const noexcept -> bool;
[[nodiscard]] static auto CAS() noexcept -> LocalCAS<ObjectType::File>& {
return LocalCAS<ObjectType::File>::Instance();
}
@@ -147,8 +92,8 @@ class TargetCache {
namespace std {
template <>
-struct hash<TargetCache::Key> {
- [[nodiscard]] auto operator()(TargetCache::Key const& k) const {
+struct hash<TargetCacheKey> {
+ [[nodiscard]] auto operator()(TargetCacheKey const& k) const {
return std::hash<Artifact::ObjectInfo>{}(k.Id());
}
};