diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/TARGETS | 2 | ||||
-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 | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/config.hpp | 39 |
5 files changed, 41 insertions, 23 deletions
diff --git a/src/buildtool/build_engine/target_map/TARGETS b/src/buildtool/build_engine/target_map/TARGETS index 15e14142..abf20ccc 100644 --- a/src/buildtool/build_engine/target_map/TARGETS +++ b/src/buildtool/build_engine/target_map/TARGETS @@ -100,9 +100,7 @@ , "stage": ["src", "buildtool", "build_engine", "target_map"] , "private-deps": [ ["@", "fmt", "", "fmt"] - , ["src/buildtool/compatibility", "compatibility"] , ["src/buildtool/execution_api/local", "config"] - , ["src/buildtool/execution_api/remote", "config"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/logging", "log_level"] ] diff --git a/src/buildtool/build_engine/target_map/target_cache.cpp b/src/buildtool/build_engine/target_map/target_cache.cpp index e08697db..493b7505 100644 --- a/src/buildtool/build_engine/target_map/target_cache.cpp +++ b/src/buildtool/build_engine/target_map/target_cache.cpp @@ -20,9 +20,7 @@ #include <fmt/core.h> #include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/compatibility/native_support.hpp" #include "src/buildtool/execution_api/local/config.hpp" -#include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -95,19 +93,7 @@ auto TargetCache::DownloadKnownArtifacts( } auto TargetCache::ComputeCacheDir(int index) -> std::filesystem::path { - return LocalExecutionConfig::TargetCacheDir(index) / ExecutionBackendId(); -} - -auto TargetCache::ExecutionBackendId() -> std::string { - auto address = RemoteExecutionConfig::RemoteAddress(); - auto properties = RemoteExecutionConfig::PlatformProperties(); - auto backend_desc = nlohmann::json{ - {"remote_address", - address ? nlohmann::json{fmt::format( - "{}:{}", address->host, address->port)} - : nlohmann::json{}}, - {"platform_properties", - properties}}.dump(2); - return NativeSupport::Unprefix( - CAS().StoreBlobFromBytes(backend_desc).value().hash()); + [[maybe_unused]] auto id = CAS().StoreBlobFromBytes( + LocalExecutionConfig::ExecutionBackendDescription()); + return LocalExecutionConfig::TargetCacheDir(index); } diff --git a/src/buildtool/build_engine/target_map/target_cache.hpp b/src/buildtool/build_engine/target_map/target_cache.hpp index 6ea29f31..d920c7e9 100644 --- a/src/buildtool/build_engine/target_map/target_cache.hpp +++ b/src/buildtool/build_engine/target_map/target_cache.hpp @@ -18,7 +18,6 @@ #include <filesystem> #include <functional> #include <optional> -#include <string> #include <utility> #include <gsl-lite/gsl-lite.hpp> @@ -88,7 +87,6 @@ class TargetCache { } [[nodiscard]] static auto ComputeCacheDir(int index) -> std::filesystem::path; - [[nodiscard]] static auto ExecutionBackendId() -> std::string; }; namespace std { diff --git a/src/buildtool/execution_api/local/TARGETS b/src/buildtool/execution_api/local/TARGETS index d07b06a1..ecf6b9ca 100644 --- a/src/buildtool/execution_api/local/TARGETS +++ b/src/buildtool/execution_api/local/TARGETS @@ -7,6 +7,7 @@ , ["@", "json", "", "json"] , ["@", "gsl-lite", "", "gsl-lite"] , ["src/buildtool/common", "common"] + , ["src/buildtool/execution_api/remote", "config"] , ["src/buildtool/compatibility", "compatibility"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/file_system", "object_type"] 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; |