diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2023-03-07 15:35:10 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2023-03-13 17:28:59 +0100 |
commit | 600876757ffe49248c34bab33d0d9247e60232f0 (patch) | |
tree | 46222384693cf36b8306cce7030b5bde482deed4 /src | |
parent | f4cbd6a77213d12884a767e65da71d77a0fbf3ac (diff) | |
download | justbuild-600876757ffe49248c34bab33d0d9247e60232f0.tar.gz |
TargetCache: Drop dependency on execution api
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/target_cache.cpp | 20 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/target_cache.hpp | 32 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 31 |
4 files changed, 34 insertions, 50 deletions
diff --git a/src/buildtool/build_engine/target_map/TARGETS b/src/buildtool/build_engine/target_map/TARGETS index d2204331..82d1eca8 100644 --- a/src/buildtool/build_engine/target_map/TARGETS +++ b/src/buildtool/build_engine/target_map/TARGETS @@ -96,7 +96,6 @@ , ["src/buildtool/file_system", "file_storage"] , ["src/buildtool/file_system", "object_type"] , ["src/buildtool/logging", "logging"] - , ["src/buildtool/execution_api/common", "common"] ] , "stage": ["src", "buildtool", "build_engine", "target_map"] , "private-deps": diff --git a/src/buildtool/build_engine/target_map/target_cache.cpp b/src/buildtool/build_engine/target_map/target_cache.cpp index 48e761fd..3e149ddd 100644 --- a/src/buildtool/build_engine/target_map/target_cache.cpp +++ b/src/buildtool/build_engine/target_map/target_cache.cpp @@ -28,11 +28,13 @@ #endif auto TargetCache::Store(TargetCacheKey const& key, - TargetCacheEntry const& value) const noexcept -> bool { + TargetCacheEntry const& value, + ArtifactDownloader const& downloader) const noexcept + -> bool { // Before a target-cache entry is stored in local CAS, make sure any created // artifact for this target is downloaded from the remote CAS to the local // CAS. - if (not DownloadKnownArtifacts(value)) { + if (not DownloadKnownArtifacts(value, downloader)) { return false; } if (auto digest = CAS().StoreBlobFromBytes(value.ToJson().dump(2))) { @@ -89,17 +91,11 @@ auto TargetCache::Read(TargetCacheKey const& key) const noexcept } auto TargetCache::DownloadKnownArtifacts( - TargetCacheEntry const& value) const noexcept -> bool { + TargetCacheEntry const& value, + ArtifactDownloader const& downloader) const noexcept -> bool { std::vector<Artifact::ObjectInfo> artifacts_info; - if (not value.ToArtifacts(&artifacts_info)) { - return false; - } -#ifndef BOOTSTRAP_BUILD_TOOL - // Sync KNOWN artifacts from remote to local CAS. - return remote_api_->RetrieveToCas(artifacts_info, local_api_); -#else - return true; -#endif + return downloader and value.ToArtifacts(&artifacts_info) and + downloader(artifacts_info); } auto TargetCache::ComputeCacheDir(int index) -> std::filesystem::path { diff --git a/src/buildtool/build_engine/target_map/target_cache.hpp b/src/buildtool/build_engine/target_map/target_cache.hpp index d920c7e9..8bce88c0 100644 --- a/src/buildtool/build_engine/target_map/target_cache.hpp +++ b/src/buildtool/build_engine/target_map/target_cache.hpp @@ -30,12 +30,12 @@ #include "src/buildtool/file_system/file_storage.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: + using ArtifactDownloader = + std::function<bool(std::vector<Artifact::ObjectInfo> const&)>; + TargetCache() = default; TargetCache(TargetCache const&) = delete; TargetCache(TargetCache&&) = delete; @@ -49,39 +49,25 @@ class TargetCache { } // Store new key entry pair in the target cache. - [[nodiscard]] auto Store(TargetCacheKey const& key, - TargetCacheEntry const& value) const noexcept - -> bool; + [[nodiscard]] auto Store( + TargetCacheKey const& key, + TargetCacheEntry const& value, + ArtifactDownloader const& downloader) const noexcept -> bool; // Read existing entry and object info for given key from the target cache. [[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 - -> void { - local_api_ = api; - }; - - auto SetRemoteApi(gsl::not_null<IExecutionApi*> const& api) noexcept - -> void { - remote_api_ = api; - }; -#endif - private: Logger logger_{"TargetCache"}; FileStorage<ObjectType::File, StoreMode::LastWins, /*kSetEpochTime=*/false> file_store_{ComputeCacheDir(0)}; -#ifndef BOOTSTRAP_BUILD_TOOL - IExecutionApi* local_api_{}; - IExecutionApi* remote_api_{}; -#endif [[nodiscard]] auto DownloadKnownArtifacts( - TargetCacheEntry const& value) const noexcept -> bool; + TargetCacheEntry const& value, + ArtifactDownloader const& downloader) const noexcept -> bool; [[nodiscard]] static auto CAS() noexcept -> LocalCAS<ObjectType::File>& { return LocalCAS<ObjectType::File>::Instance(); } diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index a3f985b7..5b72b640 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -1209,24 +1209,27 @@ void WriteTargetCacheEntries( gsl::not_null<IExecutionApi*> const& local_api, gsl::not_null<IExecutionApi*> const& remote_api) { auto ts = TaskSystem{jobs}; - TargetCache::Instance().SetLocalApi(local_api); - TargetCache::Instance().SetRemoteApi(remote_api); + auto downloader = [&local_api, &remote_api](auto infos) { + return remote_api->RetrieveToCas(infos, local_api); + }; for (auto const& [key, target] : cache_targets) { - ts.QueueTask([&key = key, &target = target, &extra_infos]() { - if (auto entry = - TargetCacheEntry::FromTarget(target, extra_infos)) { - if (not TargetCache::Instance().Store(key, *entry)) { + ts.QueueTask( + [&key = key, &target = target, &extra_infos, &downloader]() { + if (auto entry = + TargetCacheEntry::FromTarget(target, extra_infos)) { + if (not TargetCache::Instance().Store( + key, *entry, downloader)) { + Logger::Log(LogLevel::Warning, + "Failed writing target cache entry for {}", + key.Id().ToString()); + } + } + else { Logger::Log(LogLevel::Warning, - "Failed writing target cache entry for {}", + "Failed creating target cache entry for {}", key.Id().ToString()); } - } - else { - Logger::Log(LogLevel::Warning, - "Failed creating target cache entry for {}", - key.Id().ToString()); - } - }); + }); } } #endif |