diff options
Diffstat (limited to 'src/buildtool/execution_api')
-rw-r--r-- | src/buildtool/execution_api/remote/TARGETS | 5 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/config.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/config.hpp | 42 |
3 files changed, 46 insertions, 3 deletions
diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS index ef019f4d..f4aec5db 100644 --- a/src/buildtool/execution_api/remote/TARGETS +++ b/src/buildtool/execution_api/remote/TARGETS @@ -93,7 +93,10 @@ , "name": ["config"] , "hdrs": ["config.hpp"] , "srcs": ["config.cpp"] - , "deps": [["src/buildtool/common/remote", "remote_common"]] + , "deps": + [ ["src/buildtool/common/remote", "remote_common"] + , ["@", "json", "", "json"] + ] , "stage": ["src", "buildtool", "execution_api", "remote"] , "private-deps": [ ["src/buildtool/file_system", "file_system_manager"] diff --git a/src/buildtool/execution_api/remote/config.cpp b/src/buildtool/execution_api/remote/config.cpp index 2f166f8c..5ee0f32e 100644 --- a/src/buildtool/execution_api/remote/config.cpp +++ b/src/buildtool/execution_api/remote/config.cpp @@ -14,11 +14,9 @@ #include "src/buildtool/execution_api/remote/config.hpp" -#include <exception> #include <fstream> #include <utility> -#include "nlohmann/json.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" diff --git a/src/buildtool/execution_api/remote/config.hpp b/src/buildtool/execution_api/remote/config.hpp index bad729ab..7167a3ad 100644 --- a/src/buildtool/execution_api/remote/config.hpp +++ b/src/buildtool/execution_api/remote/config.hpp @@ -16,6 +16,7 @@ #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP #include <cstdint> +#include <exception> #include <filesystem> #include <map> #include <optional> @@ -24,6 +25,7 @@ #include <utility> #include <vector> +#include "nlohmann/json.hpp" #include "src/buildtool/common/remote/remote_common.hpp" class RemoteExecutionConfig { @@ -87,6 +89,46 @@ class RemoteExecutionConfig { return Instance().platform_properties_; } + /// \brief String representation of the used execution backend. + [[nodiscard]] static auto DescribeBackend() noexcept -> std::string { + auto address = RemoteAddress(); + auto properties = PlatformProperties(); + auto dispatch = DispatchList(); + auto description = nlohmann::json{ + {"remote_address", address ? address->ToJson() : nlohmann::json{}}, + {"platform_properties", properties}}; + if (!dispatch.empty()) { + try { + // only add the dispatch list, if not empty, so that keys remain + // not only more readable, but also backwards compatible with + // earlier versions. + auto dispatch_list = nlohmann::json::array(); + for (auto const& [props, endpoint] : dispatch) { + auto entry = nlohmann::json::array(); + entry.push_back(nlohmann::json(props)); + entry.push_back(endpoint.ToJson()); + dispatch_list.push_back(entry); + } + description["endpoint dispatch list"] = dispatch_list; + } catch (std::exception const& e) { + Logger::Log(LogLevel::Error, + "Failed to serialize endpoint dispatch list: {}", + e.what()); + } + } + 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 description.dump( + 2, ' ', false, nlohmann::json::error_handler_t::replace); + } catch (...) { + return ""; + } + } + private: // Server address of remote execution. std::optional<ServerAddress> remote_address_{}; |