diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/absent_target_map.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/export.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/storage/TARGETS | 3 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache.hpp | 11 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache.tpp | 26 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache_key.cpp | 48 | ||||
-rw-r--r-- | src/buildtool/storage/target_cache_key.hpp | 9 |
7 files changed, 41 insertions, 62 deletions
diff --git a/src/buildtool/build_engine/target_map/absent_target_map.cpp b/src/buildtool/build_engine/target_map/absent_target_map.cpp index 7cfbc160..6cff055d 100644 --- a/src/buildtool/build_engine/target_map/absent_target_map.cpp +++ b/src/buildtool/build_engine/target_map/absent_target_map.cpp @@ -62,8 +62,8 @@ void WithFlexibleVariables( /*fatal=*/true); return; } - auto target_cache_key = - TargetCacheKey::Create(*repo_key, target_name, effective_config); + auto target_cache_key = Storage::Instance().TargetCache().ComputeKey( + *repo_key, target_name, effective_config); if (not target_cache_key) { (*logger)(fmt::format("Could not produce cache key for target {}", key.target.ToString()), diff --git a/src/buildtool/build_engine/target_map/export.cpp b/src/buildtool/build_engine/target_map/export.cpp index ca539d87..719223e5 100644 --- a/src/buildtool/build_engine/target_map/export.cpp +++ b/src/buildtool/build_engine/target_map/export.cpp @@ -132,7 +132,7 @@ void ExportRule( auto repo_key = repo_config->RepositoryKey(target_name.repository); auto target_cache_key = repo_key - ? TargetCacheKey::Create(*repo_key, target_name, effective_config) + ? target_cache.ComputeKey(*repo_key, target_name, effective_config) : std::nullopt; if (target_cache_key) { diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS index b82f6393..c9551874 100644 --- a/src/buildtool/storage/TARGETS +++ b/src/buildtool/storage/TARGETS @@ -37,8 +37,7 @@ ] , "private-hdrs": ["compactification_task.hpp"] , "srcs": - [ "target_cache_key.cpp" - , "target_cache_entry.cpp" + [ "target_cache_entry.cpp" , "garbage_collector.cpp" , "compactifier.cpp" , "compactification_task.cpp" diff --git a/src/buildtool/storage/target_cache.hpp b/src/buildtool/storage/target_cache.hpp index e54c2e42..b20b71e3 100644 --- a/src/buildtool/storage/target_cache.hpp +++ b/src/buildtool/storage/target_cache.hpp @@ -22,6 +22,8 @@ #include "gsl/gsl" #include "nlohmann/json.hpp" +#include "src/buildtool/build_engine/base_maps/entity_name_data.hpp" +#include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/common/artifact.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -93,6 +95,15 @@ class TargetCache { TargetCacheEntry const& value, ArtifactDownloader const& downloader) const noexcept -> bool; + /// \brief Calculate TargetCacheKey based on auxiliary information. + /// Doesn't create a TargetCacheEntry in the TargetCache. + /// \return TargetCacheKey on success. + [[nodiscard]] auto ComputeKey( + std::string const& repo_key, + BuildMaps::Base::NamedTarget const& target_name, + Configuration const& effective_config) const noexcept + -> std::optional<TargetCacheKey>; + /// \brief Read existing entry and object info from the target cache. /// \param key The target-cache key to read the entry from. /// \param shard Optional explicit shard, if the default is not intended. diff --git a/src/buildtool/storage/target_cache.tpp b/src/buildtool/storage/target_cache.tpp index 7be62c35..10e1784f 100644 --- a/src/buildtool/storage/target_cache.tpp +++ b/src/buildtool/storage/target_cache.tpp @@ -40,6 +40,32 @@ auto TargetCache<kDoGlobalUplink>::Store( } template <bool kDoGlobalUplink> +auto TargetCache<kDoGlobalUplink>::ComputeKey( + std::string const& repo_key, + BuildMaps::Base::NamedTarget const& target_name, + Configuration const& effective_config) const noexcept + -> std::optional<TargetCacheKey> { + try { + // target's repository is content-fixed, we can compute a cache key + auto target_desc = nlohmann::json{ + {"repo_key", repo_key}, + {"target_name", + nlohmann::json{target_name.module, target_name.name}.dump()}, + {"effective_config", effective_config.ToString()}}; + if (auto target_key = + cas_->StoreBlob(target_desc.dump(2), /*is_executable=*/false)) { + return TargetCacheKey{ + {ArtifactDigest{*target_key}, ObjectType::File}}; + } + } catch (std::exception const& ex) { + logger_->Emit(LogLevel::Error, + "Creating target cache key failed with:\n{}", + ex.what()); + } + return std::nullopt; +} + +template <bool kDoGlobalUplink> auto TargetCache<kDoGlobalUplink>::Read( TargetCacheKey const& key) const noexcept -> std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>> { diff --git a/src/buildtool/storage/target_cache_key.cpp b/src/buildtool/storage/target_cache_key.cpp deleted file mode 100644 index 3cea7152..00000000 --- a/src/buildtool/storage/target_cache_key.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/buildtool/storage/target_cache_key.hpp" - -#include <exception> - -#include "nlohmann/json.hpp" -#include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/file_system/object_type.hpp" -#include "src/buildtool/logging/log_level.hpp" -#include "src/buildtool/logging/logger.hpp" -#include "src/buildtool/storage/storage.hpp" - -auto TargetCacheKey::Create(std::string const& repo_key, - BuildMaps::Base::NamedTarget const& target_name, - Configuration const& effective_config) noexcept - -> std::optional<TargetCacheKey> { - try { - // target's repository is content-fixed, we can compute a cache key - auto target_desc = nlohmann::json{ - {"repo_key", repo_key}, - {"target_name", - nlohmann::json{target_name.module, target_name.name}.dump()}, - {"effective_config", effective_config.ToString()}}; - if (auto target_key = Storage::Instance().CAS().StoreBlob( - target_desc.dump(2), /*is_executable=*/false)) { - return TargetCacheKey{ - {ArtifactDigest{*target_key}, ObjectType::File}}; - } - } catch (std::exception const& ex) { - Logger::Log(LogLevel::Error, - "Creating target cache key failed with:\n{}", - ex.what()); - } - return std::nullopt; -} diff --git a/src/buildtool/storage/target_cache_key.hpp b/src/buildtool/storage/target_cache_key.hpp index d901fb9e..e5d3ee1b 100644 --- a/src/buildtool/storage/target_cache_key.hpp +++ b/src/buildtool/storage/target_cache_key.hpp @@ -15,23 +15,14 @@ #ifndef INCLUDED_SRC_BUILDTOOL_STORAGE_TARGET_CACHE_KEY_HPP #define INCLUDED_SRC_BUILDTOOL_STORAGE_TARGET_CACHE_KEY_HPP -#include <functional> -#include <optional> #include <utility> -#include "src/buildtool/build_engine/base_maps/entity_name_data.hpp" -#include "src/buildtool/build_engine/expression/configuration.hpp" #include "src/buildtool/common/artifact.hpp" // Key for target cache. Created from target name and effective config. class TargetCacheKey { public: explicit TargetCacheKey(Artifact::ObjectInfo id) : id_{std::move(id)} {} - [[nodiscard]] static auto Create( - std::string const& repo_key, - BuildMaps::Base::NamedTarget const& target_name, - Configuration const& effective_config) noexcept - -> std::optional<TargetCacheKey>; [[nodiscard]] auto Id() const& -> Artifact::ObjectInfo const& { return id_; |