From 3430425a300159c4a8a0f67cbbd0c3098daa9dfc Mon Sep 17 00:00:00 2001 From: Sascha Roloff Date: Thu, 12 Jan 2023 21:03:40 +0100 Subject: Move execution-backend-id calculation from target-level cache to local config This code movement is required to break a cyclic dependency coming with the introduction of the garbage collector. target_cache depends on garbage_collector and garbage_collector would depend on target_cache to determine the target-level-cache directory. After moving this calculation to a more general location, the cycle is broken. --- src/buildtool/execution_api/local/config.hpp | 39 ++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/buildtool/execution_api/local/config.hpp') diff --git a/src/buildtool/execution_api/local/config.hpp b/src/buildtool/execution_api/local/config.hpp index 409c07ac..3faeb303 100644 --- a/src/buildtool/execution_api/local/config.hpp +++ b/src/buildtool/execution_api/local/config.hpp @@ -28,10 +28,13 @@ #include #include +#include #include +#include #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -177,12 +180,44 @@ class LocalExecutionConfig { return CacheRootDir(index) / "ac"; } - /// \brief Target cache directory - [[nodiscard]] static auto TargetCacheDir(int index) noexcept + /// \brief Target cache root directory + [[nodiscard]] static auto TargetCacheRoot(int index) noexcept -> std::filesystem::path { return CacheRootDir(index) / "tc"; } + /// \brief Target cache directory for the used execution backend. + [[nodiscard]] static auto TargetCacheDir(int index) noexcept + -> std::filesystem::path { + return TargetCacheRoot(index) / + ArtifactDigest::Create( + ExecutionBackendDescription()) + .hash(); + } + + /// \brief String representation of the used execution backend. + [[nodiscard]] static auto ExecutionBackendDescription() noexcept + -> std::string { + auto address = RemoteExecutionConfig::RemoteAddress(); + auto properties = RemoteExecutionConfig::PlatformProperties(); + try { + // json::dump with json::error_handler_t::replace will not throw an + // exception if invalid UTF-8 sequences are detected in the input. + // Instead, it will replace them with the UTF-8 replacement + // character, but still it needs to be inside a try-catch clause to + // ensure the noexcept modifier of the enclosing function. + return nlohmann::json{ + {"remote_address", + address ? nlohmann::json{fmt::format( + "{}:{}", address->host, address->port)} + : nlohmann::json{}}, + {"platform_properties", properties}} + .dump(2, ' ', false, nlohmann::json::error_handler_t::replace); + } catch (...) { + return ""; + } + } + [[nodiscard]] static auto GetLauncher() noexcept -> std::vector { return Data().launcher; -- cgit v1.2.3