diff options
author | Sascha Roloff <sascha.roloff@huawei.com> | 2023-01-12 21:03:40 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-01-20 15:27:28 +0100 |
commit | 3430425a300159c4a8a0f67cbbd0c3098daa9dfc (patch) | |
tree | d91c38e8e992977004338e01a3ec03ca5d26cce7 /src/buildtool/execution_api/local/config.hpp | |
parent | dc47c8e0878565770120d6511016a31c72df6ada (diff) | |
download | justbuild-3430425a300159c4a8a0f67cbbd0c3098daa9dfc.tar.gz |
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.
Diffstat (limited to 'src/buildtool/execution_api/local/config.hpp')
-rw-r--r-- | src/buildtool/execution_api/local/config.hpp | 39 |
1 files changed, 37 insertions, 2 deletions
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 <string> #include <vector> +#include <fmt/core.h> #include <gsl-lite/gsl-lite.hpp> +#include <nlohmann/json.hpp> #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<ObjectType::File>( + 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<std::string> { return Data().launcher; |