From 2d0e0b73b777e5e0940a1ec241635aeb651c23f2 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 3 Dec 2024 12:40:04 +0100 Subject: Cache lookup: support rehash function --- src/buildtool/computed_roots/TARGETS | 1 + src/buildtool/computed_roots/lookup_cache.cpp | 16 +++------------- src/buildtool/computed_roots/lookup_cache.hpp | 11 +++++++---- 3 files changed, 11 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/buildtool/computed_roots/TARGETS b/src/buildtool/computed_roots/TARGETS index e1d9bd79..4ff979b0 100644 --- a/src/buildtool/computed_roots/TARGETS +++ b/src/buildtool/computed_roots/TARGETS @@ -72,6 +72,7 @@ , ["src/buildtool/common", "cli"] , ["src/buildtool/common", "common"] , ["src/buildtool/crypto", "hash_function"] + , ["src/buildtool/execution_api/utils", "rehash_utils"] , ["src/buildtool/file_system", "file_root"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/file_system", "git_cas"] diff --git a/src/buildtool/computed_roots/lookup_cache.cpp b/src/buildtool/computed_roots/lookup_cache.cpp index 000cdbee..0555c74b 100644 --- a/src/buildtool/computed_roots/lookup_cache.cpp +++ b/src/buildtool/computed_roots/lookup_cache.cpp @@ -27,7 +27,6 @@ #include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/build_engine/expression/target_result.hpp" #include "src/buildtool/computed_roots/artifacts_root.hpp" -#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" #include "src/buildtool/storage/target_cache_entry.hpp" @@ -36,7 +35,8 @@ auto LookupCache(BuildMaps::Target::ConfiguredTarget const& ctarget, gsl::not_null const& repository_config, Storage const& storage, - AsyncMapConsumerLoggerPtr const& logger) + AsyncMapConsumerLoggerPtr const& logger, + std::optional const& rehash) -> expected, std::monostate> { auto const* target_root = repository_config->TargetRoot(ctarget.target.ToModule().repository); @@ -102,16 +102,6 @@ auto LookupCache(BuildMaps::Target::ConfiguredTarget const& ctarget, if (not flexible_vars) { return unexpected(std::monostate{}); } - // TODO(aehlig): Support re-hashing in case of compatible mode, so that - // cache lookups can be used in this case as well. - if (storage.GetHashFunction().GetType() != HashFunction::Type::GitSHA1) { - // So far, transforming the result of a cache hit in memory into - // a git root is only implemented for GitSHA1. Therefore, do not - // try to look up cache hits, and simply pretend a non hit. - return expected, std::monostate>( - std::nullopt); - } - auto effective_config = ctarget.config.Prune(*flexible_vars); auto cache_key = storage.TargetCache().ComputeKey( *repo_key, ctarget.target.GetNamedTarget(), effective_config); @@ -141,7 +131,7 @@ auto LookupCache(BuildMaps::Target::ConfiguredTarget const& ctarget, msg), fatal); }); - auto root = ArtifactsRoot(result->artifact_stage, wrapped_logger); + auto root = ArtifactsRoot(result->artifact_stage, wrapped_logger, rehash); if (not root) { return unexpected(std::monostate{}); } diff --git a/src/buildtool/computed_roots/lookup_cache.hpp b/src/buildtool/computed_roots/lookup_cache.hpp index 0f8096d1..a613313e 100644 --- a/src/buildtool/computed_roots/lookup_cache.hpp +++ b/src/buildtool/computed_roots/lookup_cache.hpp @@ -22,14 +22,17 @@ #include "gsl/gsl" #include "src/buildtool/build_engine/target_map/configured_target.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/execution_api/utils/rehash_utils.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/storage/storage.hpp" #include "src/utils/cpp/expected.hpp" -auto LookupCache(BuildMaps::Target::ConfiguredTarget const& ctarget, - gsl::not_null const& repository_config, - Storage const& storage, - AsyncMapConsumerLoggerPtr const& logger) +auto LookupCache( + BuildMaps::Target::ConfiguredTarget const& ctarget, + gsl::not_null const& repository_config, + Storage const& storage, + AsyncMapConsumerLoggerPtr const& logger, + std::optional const& rehash = std::nullopt) -> expected, std::monostate>; #endif -- cgit v1.2.3