diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-01 17:44:23 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 14:52:07 +0200 |
commit | 2bc6d309c00161b2315b9f98645810699fff3126 (patch) | |
tree | 8185d375463e79b39485448920fa68cca2a206a2 /src/buildtool/storage/target_cache_entry.cpp | |
parent | abae1d3c8032fec872bda44de7f7d754654cf201 (diff) | |
download | justbuild-2bc6d309c00161b2315b9f98645810699fff3126.tar.gz |
Use HashFunction::Type to deserialize ArtifactDescription
Diffstat (limited to 'src/buildtool/storage/target_cache_entry.cpp')
-rw-r--r-- | src/buildtool/storage/target_cache_entry.cpp | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/src/buildtool/storage/target_cache_entry.cpp b/src/buildtool/storage/target_cache_entry.cpp index becc6a13..f6659256 100644 --- a/src/buildtool/storage/target_cache_entry.cpp +++ b/src/buildtool/storage/target_cache_entry.cpp @@ -25,6 +25,7 @@ #include "src/utils/cpp/gsl.hpp" auto TargetCacheEntry::FromTarget( + HashFunction::Type hash_type, AnalysedTargetPtr const& target, std::unordered_map<ArtifactDescription, Artifact::ObjectInfo> const& replacements) noexcept -> std::optional<TargetCacheEntry> { @@ -42,17 +43,18 @@ auto TargetCacheEntry::FromTarget( if (not implied.empty()) { (*desc)["implied export targets"] = implied; } - return TargetCacheEntry{*desc}; + return TargetCacheEntry{hash_type, *desc}; } -auto TargetCacheEntry::FromJson(nlohmann::json desc) noexcept +auto TargetCacheEntry::FromJson(HashFunction::Type hash_type, + nlohmann::json desc) noexcept -> TargetCacheEntry { - return TargetCacheEntry(std::move(desc)); + return TargetCacheEntry(hash_type, std::move(desc)); } auto TargetCacheEntry::ToResult() const noexcept -> std::optional<TargetResult> { - return TargetResult::FromJson(desc_); + return TargetResult::FromJson(hash_type_, desc_); } auto TargetCacheEntry::ToImplied() const noexcept -> std::set<std::string> { @@ -93,9 +95,10 @@ auto TargetCacheEntry::ToImpliedIds(std::string const& entry_key_hash) return result; } -[[nodiscard]] auto ToObjectInfo(nlohmann::json const& json) +[[nodiscard]] static auto ToObjectInfo(HashFunction::Type hash_type, + nlohmann::json const& json) -> Artifact::ObjectInfo { - auto const& desc = ArtifactDescription::FromJson(json); + auto const desc = ArtifactDescription::FromJson(hash_type, json); // The assumption is that all artifacts mentioned in a target cache // entry are KNOWN to the remote side. ExpectsAudit(desc and desc->IsKnown()); @@ -104,7 +107,8 @@ auto TargetCacheEntry::ToImpliedIds(std::string const& entry_key_hash) return *info; } -[[nodiscard]] auto ScanArtifactMap( +[[nodiscard]] static auto ScanArtifactMap( + HashFunction::Type hash_type, gsl::not_null<std::vector<Artifact::ObjectInfo>*> const& infos, nlohmann::json const& json) -> bool { if (not json.is_object()) { @@ -114,11 +118,14 @@ auto TargetCacheEntry::ToImpliedIds(std::string const& entry_key_hash) std::transform(json.begin(), json.end(), std::back_inserter(*infos), - [](auto const& item) { return ToObjectInfo(item); }); + [hash_type](auto const& item) { + return ToObjectInfo(hash_type, item); + }); return true; } -[[nodiscard]] auto ScanProvidesMap( +[[nodiscard]] static auto ScanProvidesMap( + HashFunction::Type hash_type, gsl::not_null<std::vector<Artifact::ObjectInfo>*> const& infos, nlohmann::json const& json) -> bool { if (not json.is_object()) { @@ -127,13 +134,13 @@ auto TargetCacheEntry::ToImpliedIds(std::string const& entry_key_hash) auto const& nodes = json["nodes"]; auto const& provided_artifacts = json["provided_artifacts"]; infos->reserve(infos->size() + provided_artifacts.size()); - std::transform( - provided_artifacts.begin(), - provided_artifacts.end(), - std::back_inserter(*infos), - [&nodes](auto const& item) { - return ToObjectInfo(nodes[item.template get<std::string>()]); - }); + std::transform(provided_artifacts.begin(), + provided_artifacts.end(), + std::back_inserter(*infos), + [hash_type, &nodes](auto const& item) { + return ToObjectInfo( + hash_type, nodes[item.template get<std::string>()]); + }); return true; } @@ -141,9 +148,9 @@ auto TargetCacheEntry::ToArtifacts( gsl::not_null<std::vector<Artifact::ObjectInfo>*> const& infos) const noexcept -> bool { try { - if (ScanArtifactMap(infos, desc_["artifacts"]) and - ScanArtifactMap(infos, desc_["runfiles"]) and - ScanProvidesMap(infos, desc_["provides"])) { + if (ScanArtifactMap(hash_type_, infos, desc_["artifacts"]) and + ScanArtifactMap(hash_type_, infos, desc_["runfiles"]) and + ScanProvidesMap(hash_type_, infos, desc_["provides"])) { return true; } } catch (std::exception const& ex) { |