summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-12 16:09:28 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-16 17:51:12 +0200
commit62d204ff4cc94c12c1635f189255710901682825 (patch)
tree0c5cdc5faf98d28ddf74721280756804a6decf83 /src
parentde3ef374983d987d8ffd8e8516a4877fe68b3e4e (diff)
downloadjustbuild-62d204ff4cc94c12c1635f189255710901682825.tar.gz
Remove the RemoteExecutionConfig singleton
...and replace it with passed instances created early via a builder pattern. Tests are also updated accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/common/api_bundle.cpp2
-rw-r--r--src/buildtool/execution_api/remote/TARGETS6
-rw-r--r--src/buildtool/execution_api/remote/config.cpp100
-rw-r--r--src/buildtool/execution_api/remote/config.hpp147
-rw-r--r--src/buildtool/graph_traverser/graph_traverser.hpp3
-rw-r--r--src/buildtool/main/install_cas.cpp2
-rw-r--r--src/buildtool/main/main.cpp147
-rw-r--r--src/buildtool/serve_api/remote/configuration_client.cpp2
-rw-r--r--src/buildtool/serve_api/remote/target_client.cpp5
-rw-r--r--src/buildtool/serve_api/serve_service/configuration.cpp2
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp2
-rw-r--r--src/other_tools/just_mr/fetch.cpp16
-rw-r--r--src/other_tools/just_mr/setup.cpp15
-rw-r--r--src/other_tools/just_mr/setup_utils.cpp22
-rw-r--r--src/other_tools/just_mr/setup_utils.hpp6
15 files changed, 247 insertions, 230 deletions
diff --git a/src/buildtool/execution_api/common/api_bundle.cpp b/src/buildtool/execution_api/common/api_bundle.cpp
index d9a588a3..7cb307eb 100644
--- a/src/buildtool/execution_api/common/api_bundle.cpp
+++ b/src/buildtool/execution_api/common/api_bundle.cpp
@@ -31,7 +31,7 @@ ApiBundle::ApiBundle(
repo_config)}, // needed by remote
auth{*authentication}, // needed by remote
remote_config{*remote_exec_config}, // needed by remote
- remote{CreateRemote(remote_exec_config->RemoteAddress())} {}
+ remote{CreateRemote(remote_exec_config->remote_address)} {}
auto ApiBundle::CreateRemote(std::optional<ServerAddress> const& address) const
-> gsl::not_null<IExecutionApi::Ptr> {
diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS
index f4aec5db..d93eb280 100644
--- a/src/buildtool/execution_api/remote/TARGETS
+++ b/src/buildtool/execution_api/remote/TARGETS
@@ -95,11 +95,13 @@
, "srcs": ["config.cpp"]
, "deps":
[ ["src/buildtool/common/remote", "remote_common"]
- , ["@", "json", "", "json"]
+ , ["src/utils/cpp", "expected"]
]
, "stage": ["src", "buildtool", "execution_api", "remote"]
, "private-deps":
- [ ["src/buildtool/file_system", "file_system_manager"]
+ [ ["@", "fmt", "", "fmt"]
+ , ["@", "json", "", "json"]
+ , ["src/buildtool/file_system", "file_system_manager"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/logging", "logging"]
]
diff --git a/src/buildtool/execution_api/remote/config.cpp b/src/buildtool/execution_api/remote/config.cpp
index 5ee0f32e..ac211061 100644
--- a/src/buildtool/execution_api/remote/config.cpp
+++ b/src/buildtool/execution_api/remote/config.cpp
@@ -14,32 +14,94 @@
#include "src/buildtool/execution_api/remote/config.hpp"
+#include <exception>
#include <fstream>
-#include <utility>
+#include "fmt/core.h"
+#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"
-[[nodiscard]] auto RemoteExecutionConfig::SetRemoteExecutionDispatch(
- const std::filesystem::path& filename) noexcept -> bool {
- try {
- if (auto dispatch_info = FileSystemManager::ReadFile(filename)) {
- auto parsed = ParseDispatch(*dispatch_info);
- if (not parsed) {
- Logger::Log(LogLevel::Warning, std::move(parsed).error());
- return false;
+auto RemoteExecutionConfig::Builder::Build() const noexcept
+ -> expected<RemoteExecutionConfig, std::string> {
+ // To not duplicate default arguments in builder, create a default config
+ // and copy arguments from there.
+ RemoteExecutionConfig const default_config;
+
+ // Set remote endpoint.
+ auto remote_address = default_config.remote_address;
+ if (remote_address_raw_.has_value()) {
+ if (not(remote_address = ParseAddress(*remote_address_raw_))) {
+ return unexpected{
+ fmt::format("Failed to set remote endpoint address {}",
+ nlohmann::json(*remote_address_raw_).dump())};
+ }
+ }
+ // Set cache endpoint.
+ auto cache_address = default_config.cache_address;
+ if (cache_address_raw_.has_value()) {
+ cache_address = ParseAddress(*cache_address_raw_);
+ // Cache endpoint can be in the usual "host:port" or the literal
+ // "local", so we only fail if we cannot parse a non-"local" string,
+ // because parsing a "local" literal will correctly return a nullopt.
+ bool const is_parsed = cache_address.has_value();
+ bool const is_local = *cache_address_raw_ == "local";
+ if (not is_local and not is_parsed) {
+ return unexpected{
+ fmt::format("Failed to set cache endpoint address {}",
+ nlohmann::json(*cache_address_raw_).dump())};
+ }
+ }
+ else {
+ // If cache address not explicitly set, it defaults to remote address.
+ cache_address = remote_address;
+ }
+
+ // Set dispatch info.
+ auto dispatch = default_config.dispatch;
+ if (dispatch_file_.has_value()) {
+ try {
+ if (auto dispatch_info =
+ FileSystemManager::ReadFile(*dispatch_file_)) {
+ auto parsed = ParseDispatch(*dispatch_info);
+ if (not parsed) {
+ return unexpected{parsed.error()};
+ }
+ dispatch = *std::move(parsed);
}
- Instance().dispatch_ = *std::move(parsed);
- return true;
+ else {
+ return unexpected{
+ fmt::format("Failed to read json file {}",
+ nlohmann::json(*dispatch_file_).dump())};
+ }
+ } catch (std::exception const& e) {
+ return unexpected{fmt::format(
+ "Assigning the endpoint configuration failed with:\n{}",
+ e.what())};
}
- Logger::Log(LogLevel::Warning,
- "Failed to read json file {}",
- filename.string());
- } catch (std::exception const& e) {
- Logger::Log(LogLevel::Warning,
- "Failure assigning the endpoint configuration: {}",
- e.what());
}
- return false;
+
+ // Set platform properties.
+ auto platform_properties = default_config.platform_properties;
+ for (auto const& property : platform_properties_raw_) {
+ if (auto pair = ParseProperty(property)) {
+ try {
+ platform_properties.insert(*std::move(pair));
+ } catch (std::exception const& e) {
+ return unexpected{fmt::format("Failed to insert property {}",
+ nlohmann::json(property).dump())};
+ }
+ }
+ else {
+ return unexpected{fmt::format("Adding platform property {} failed.",
+ nlohmann::json(property).dump())};
+ }
+ }
+
+ return RemoteExecutionConfig{
+ .remote_address = std::move(remote_address),
+ .dispatch = std::move(dispatch),
+ .cache_address = std::move(cache_address),
+ .platform_properties = std::move(platform_properties)};
}
diff --git a/src/buildtool/execution_api/remote/config.hpp b/src/buildtool/execution_api/remote/config.hpp
index ea7a7093..45420c80 100644
--- a/src/buildtool/execution_api/remote/config.hpp
+++ b/src/buildtool/execution_api/remote/config.hpp
@@ -15,132 +15,81 @@
#ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP
#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP
-#include <cstdint>
-#include <exception>
#include <filesystem>
#include <map>
#include <optional>
-#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
-#include "nlohmann/json.hpp"
#include "src/buildtool/common/remote/remote_common.hpp"
+#include "src/utils/cpp/expected.hpp"
-class RemoteExecutionConfig {
- public:
- // Obtain global instance
- [[nodiscard]] static auto Instance() noexcept -> RemoteExecutionConfig& {
- static RemoteExecutionConfig config;
- return config;
- }
+struct RemoteExecutionConfig final {
+ class Builder;
- // Set remote execution and cache address, unsets if parsing `address` fails
- [[nodiscard]] static auto SetRemoteAddress(
- std::string const& address) noexcept -> bool {
- auto& inst = Instance();
- return static_cast<bool>(inst.remote_address_ = inst.cache_address_ =
- ParseAddress(address));
- }
+ // Server address of remote execution.
+ std::optional<ServerAddress> const remote_address = {};
- // Set remote-execution dispatch property list
- [[nodiscard]] static auto SetRemoteExecutionDispatch(
- const std::filesystem::path& filename) noexcept -> bool;
+ // Server dispatch data
+ std::vector<DispatchEndpoint> const dispatch = {};
- // Set specific cache address, unsets if parsing `address` fails
- [[nodiscard]] static auto SetCacheAddress(
- std::string const& address) noexcept -> bool {
- return static_cast<bool>(Instance().cache_address_ =
- ParseAddress(address));
- }
+ // Server address of cache endpoint for rebuild.
+ std::optional<ServerAddress> const cache_address = {};
- // Add platform property from string of form "key:val"
- [[nodiscard]] static auto AddPlatformProperty(
- std::string const& property) noexcept -> bool {
- if (auto pair = ParseProperty(property)) {
- Instance().platform_properties_[std::move(pair->first)] =
- std::move(pair->second);
- return true;
- }
- return false;
- }
+ // Platform properties for execution.
+ ExecutionProperties const platform_properties = {};
+};
- // Remote execution address, if set
- [[nodiscard]] static auto RemoteAddress() noexcept
- -> std::optional<ServerAddress> {
- return Instance().remote_address_;
+class RemoteExecutionConfig::Builder final {
+ public:
+ // Set remote execution and cache address. If it fails to parse during
+ // config build, will reset the fields.
+ auto SetRemoteAddress(std::optional<std::string> address) noexcept
+ -> Builder& {
+ remote_address_raw_ = std::move(address);
+ return *this;
}
- // Cache address, if set
- [[nodiscard]] static auto CacheAddress() noexcept
- -> std::optional<ServerAddress> {
- return Instance().cache_address_;
+ // Set remote-execution dispatch property list filename.
+ auto SetRemoteExecutionDispatch(
+ std::optional<std::filesystem::path> filename) noexcept -> Builder& {
+ dispatch_file_ = std::move(filename);
+ return *this;
}
- // Instance dispatch list
- [[nodiscard]] static auto DispatchList() noexcept
- -> std::vector<DispatchEndpoint> {
- return Instance().dispatch_;
+ // Set specific cache address. If it fails to parse during config build,
+ // will reset the field.
+ auto SetCacheAddress(std::optional<std::string> address) noexcept
+ -> Builder& {
+ cache_address_raw_ = std::move(address);
+ return *this;
}
- [[nodiscard]] static auto PlatformProperties() noexcept
- -> ExecutionProperties {
- return Instance().platform_properties_;
+ // Set platform properties given as "key:val" strings.
+ auto SetPlatformProperties(std::vector<std::string> properties) noexcept
+ -> Builder& {
+ platform_properties_raw_ = std::move(properties);
+ return *this;
}
- /// \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 "";
- }
- }
+ /// \brief Parse the set data to finalize creation of RemoteExecutionConfig.
+ /// \return RemoteExecutionConfig on success, an error string on failure.
+ [[nodiscard]] auto Build() const noexcept
+ -> expected<RemoteExecutionConfig, std::string>;
private:
- // Server address of remote execution.
- std::optional<ServerAddress> remote_address_{};
+ // Server address of remote execution; needs parsing.
+ std::optional<std::string> remote_address_raw_{};
- // Server dispatch data
- std::vector<DispatchEndpoint> dispatch_{};
+ // Server dispatch data file; needs parsing.
+ std::optional<std::filesystem::path> dispatch_file_{};
- // Server address of cache endpoint for rebuild.
- std::optional<ServerAddress> cache_address_{};
+ // Server address of cache endpoint for rebuild; needs parsing.
+ std::optional<std::string> cache_address_raw_{};
- // Platform properties for execution.
- ExecutionProperties platform_properties_{};
+ // Platform properties for execution; needs parsing.
+ std::vector<std::string> platform_properties_raw_{};
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_CONFIG_HPP
diff --git a/src/buildtool/graph_traverser/graph_traverser.hpp b/src/buildtool/graph_traverser/graph_traverser.hpp
index 796fd042..5ba2f09d 100644
--- a/src/buildtool/graph_traverser/graph_traverser.hpp
+++ b/src/buildtool/graph_traverser/graph_traverser.hpp
@@ -388,8 +388,7 @@ class GraphTraverser {
DependencyGraph const& g,
std::vector<ArtifactIdentifier> const& artifact_ids) const -> bool {
// setup rebuilder with api for cache endpoint
- auto api_cached =
- apis_.CreateRemote(apis_.remote_config.CacheAddress());
+ auto api_cached = apis_.CreateRemote(apis_.remote_config.cache_address);
Rebuilder executor{repo_config_,
&*apis_.local,
&*apis_.remote,
diff --git a/src/buildtool/main/install_cas.cpp b/src/buildtool/main/install_cas.cpp
index dcf696ab..21f694e3 100644
--- a/src/buildtool/main/install_cas.cpp
+++ b/src/buildtool/main/install_cas.cpp
@@ -76,7 +76,7 @@ namespace {
auto FetchAndInstallArtifacts(ApiBundle const& apis,
FetchArguments const& clargs) -> bool {
auto object_info = ObjectInfoFromLiberalString(
- clargs.object_id, apis.remote_config.RemoteAddress().has_value());
+ clargs.object_id, apis.remote_config.remote_address.has_value());
if (clargs.remember) {
if (not apis.remote->ParallelRetrieveToCas(
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 5e296482..2efecb87 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -148,45 +148,21 @@ void SetupLogging(LogArguments const& clargs) {
return std::nullopt;
}
-void SetupRemoteExecutionConfig(EndpointArguments const& eargs,
- RebuildArguments const& rargs) {
- using RemoteConfig = RemoteExecutionConfig;
- for (auto const& property : eargs.platform_properties) {
- if (not RemoteConfig::AddPlatformProperty(property)) {
- Logger::Log(LogLevel::Error,
- "Adding platform property '{}' failed.",
- property);
- std::exit(kExitFailure);
- }
- }
- if (eargs.remote_execution_address) {
- if (not RemoteConfig::SetRemoteAddress(
- *eargs.remote_execution_address)) {
- Logger::Log(LogLevel::Error,
- "Setting remote execution address '{}' failed.",
- *eargs.remote_execution_address);
- std::exit(kExitFailure);
- }
- }
- if (eargs.remote_execution_dispatch_file) {
- if (not RemoteConfig::SetRemoteExecutionDispatch(
- *eargs.remote_execution_dispatch_file)) {
- Logger::Log(
- LogLevel::Error,
- "Setting remote execution dispatch based on file '{}' failed.",
- eargs.remote_execution_dispatch_file->string());
- std::exit(kExitFailure);
- }
- }
- if (rargs.cache_endpoint) {
- if (not(RemoteConfig::SetCacheAddress(*rargs.cache_endpoint) ==
- (*rargs.cache_endpoint != "local"))) {
- Logger::Log(LogLevel::Error,
- "Setting cache endpoint address '{}' failed.",
- *rargs.cache_endpoint);
- std::exit(kExitFailure);
- }
+[[nodiscard]] auto CreateRemoteExecutionConfig(EndpointArguments const& eargs,
+ RebuildArguments const& rargs)
+ -> std::optional<RemoteExecutionConfig> {
+ RemoteExecutionConfig::Builder builder;
+ builder.SetRemoteAddress(eargs.remote_execution_address)
+ .SetRemoteExecutionDispatch(eargs.remote_execution_dispatch_file)
+ .SetPlatformProperties(eargs.platform_properties)
+ .SetCacheAddress(rargs.cache_endpoint);
+
+ auto config = builder.Build();
+ if (config) {
+ return *std::move(config);
}
+ Logger::Log(LogLevel::Error, config.error());
+ return std::nullopt;
}
[[nodiscard]] auto CreateServeConfig(ServeArguments const& srvargs,
@@ -295,12 +271,14 @@ void SetupFileChunker() {
/// \brief Write backend description (which determines the target cache shard)
/// to CAS.
-void StoreTargetCacheShard(StorageConfig const& storage_config,
- Storage const& storage) noexcept {
+void StoreTargetCacheShard(
+ StorageConfig const& storage_config,
+ Storage const& storage,
+ RemoteExecutionConfig const& remote_exec_config) noexcept {
auto backend_description =
- DescribeBackend(RemoteExecutionConfig::RemoteAddress(),
- RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList());
+ DescribeBackend(remote_exec_config.remote_address,
+ remote_exec_config.platform_properties,
+ remote_exec_config.dispatch);
if (not backend_description) {
Logger::Log(LogLevel::Error, backend_description.error());
std::exit(kExitFailure);
@@ -841,8 +819,6 @@ auto main(int argc, char* argv[]) -> int {
return kExitFailure;
}
- SetupRemoteExecutionConfig(arguments.endpoint, arguments.rebuild);
-
auto serve_config = CreateServeConfig(
arguments.serve, arguments.common, arguments.build, arguments.tc);
if (not serve_config) {
@@ -856,17 +832,25 @@ auto main(int argc, char* argv[]) -> int {
}
if (arguments.cmd == SubCommand::kExecute) {
+ // Set up remote execution config.
+ auto remote_exec_config = CreateRemoteExecutionConfig(
+ arguments.endpoint, arguments.rebuild);
+ if (not remote_exec_config) {
+ return kExitFailure;
+ }
+
// Set up storage for server-side operation.
auto const storage_config =
CreateStorageConfig(arguments.endpoint,
- RemoteExecutionConfig::RemoteAddress(),
- RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList());
+ remote_exec_config->remote_address,
+ remote_exec_config->platform_properties,
+ remote_exec_config->dispatch);
if (not storage_config) {
return kExitFailure;
}
auto const storage = Storage::Create(&*storage_config);
- StoreTargetCacheShard(*storage_config, storage);
+ StoreTargetCacheShard(
+ *storage_config, storage, *remote_exec_config);
SetupExecutionServiceConfig(arguments.service);
ApiBundle const exec_apis{&*storage_config,
@@ -874,7 +858,7 @@ auto main(int argc, char* argv[]) -> int {
&*local_exec_config,
/*repo_config=*/nullptr,
&*auth_config,
- &RemoteExecutionConfig::Instance()};
+ &*remote_exec_config};
if (not ServerImpl::Instance().Run(
*storage_config, storage, exec_apis)) {
return kExitFailure;
@@ -889,27 +873,36 @@ auto main(int argc, char* argv[]) -> int {
arguments.service.info_file,
arguments.service.pid_file);
if (serve_server) {
+ // Set up remote execution config.
+ auto remote_exec_config = CreateRemoteExecutionConfig(
+ arguments.endpoint, arguments.rebuild);
+ if (not remote_exec_config) {
+ return kExitFailure;
+ }
+
// Set up storage for server-side operation.
- auto const storage_config = CreateStorageConfig(
- arguments.endpoint,
- RemoteExecutionConfig::RemoteAddress(),
- RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList());
+ auto const storage_config =
+ CreateStorageConfig(arguments.endpoint,
+ remote_exec_config->remote_address,
+ remote_exec_config->platform_properties,
+ remote_exec_config->dispatch);
if (not storage_config) {
return kExitFailure;
}
auto const storage = Storage::Create(&*storage_config);
- StoreTargetCacheShard(*storage_config, storage);
+ StoreTargetCacheShard(
+ *storage_config, storage, *remote_exec_config);
ApiBundle const serve_apis{&*storage_config,
&storage,
&*local_exec_config,
/*repo_config=*/nullptr,
&*auth_config,
- &RemoteExecutionConfig::Instance()};
+ &*remote_exec_config};
auto serve =
ServeApi::Create(*serve_config, &storage, &serve_apis);
- bool with_execute = not RemoteExecutionConfig::RemoteAddress();
+ bool with_execute =
+ not remote_exec_config->remote_address.has_value();
return serve_server->Run(*serve_config,
*storage_config,
storage,
@@ -924,29 +917,33 @@ auto main(int argc, char* argv[]) -> int {
}
// If no execution endpoint was given, the client should default to the
- // serve endpoint, if given
- if (not RemoteExecutionConfig::RemoteAddress() and
- arguments.serve.remote_serve_address) {
- if (!RemoteExecutionConfig::SetRemoteAddress(
- *arguments.serve.remote_serve_address)) {
- Logger::Log(LogLevel::Error,
- "Setting remote execution address '{}' failed.",
- *arguments.serve.remote_serve_address);
- std::exit(kExitFailure);
- }
+ // serve endpoint, if given.
+ if (not arguments.endpoint.remote_execution_address.has_value() and
+ arguments.serve.remote_serve_address.has_value()) {
+ // replace the remote execution address
+ arguments.endpoint.remote_execution_address =
+ *arguments.serve.remote_serve_address;
+ // Inform user of the change
Logger::Log(LogLevel::Info,
"Using '{}' as the remote execution endpoint.",
*arguments.serve.remote_serve_address);
}
+ // Set up remote execution config.
+ auto remote_exec_config =
+ CreateRemoteExecutionConfig(arguments.endpoint, arguments.rebuild);
+ if (not remote_exec_config) {
+ return kExitFailure;
+ }
+
// Set up storage for client-side operation. This needs to have all the
// correct remote endpoint info in order to instantiate the
// correctly-sharded target cache.
auto const storage_config =
CreateStorageConfig(arguments.endpoint,
- RemoteExecutionConfig::RemoteAddress(),
- RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList());
+ remote_exec_config->remote_address,
+ remote_exec_config->platform_properties,
+ remote_exec_config->dispatch);
#else
// For bootstrapping the TargetCache sharding is not needed, so we can
// default all execution arguments.
@@ -958,7 +955,7 @@ auto main(int argc, char* argv[]) -> int {
auto const storage = Storage::Create(&*storage_config);
#ifndef BOOTSTRAP_BUILD_TOOL
- StoreTargetCacheShard(*storage_config, storage);
+ StoreTargetCacheShard(*storage_config, storage, *remote_exec_config);
#endif // BOOTSTRAP_BUILD_TOOL
auto jobs = arguments.build.build_jobs > 0 ? arguments.build.build_jobs
@@ -989,15 +986,15 @@ auto main(int argc, char* argv[]) -> int {
&*local_exec_config,
&repo_config,
&*auth_config,
- &RemoteExecutionConfig::Instance()};
+ &*remote_exec_config};
GraphTraverser const traverser{
{jobs,
std::move(arguments.build),
std::move(stage_args),
std::move(rebuild_args)},
&repo_config,
- RemoteExecutionConfig::PlatformProperties(),
- RemoteExecutionConfig::DispatchList(),
+ remote_exec_config->platform_properties,
+ remote_exec_config->dispatch,
&stats,
&progress,
&main_apis,
diff --git a/src/buildtool/serve_api/remote/configuration_client.cpp b/src/buildtool/serve_api/remote/configuration_client.cpp
index 46ef4cfc..07fddf12 100644
--- a/src/buildtool/serve_api/remote/configuration_client.cpp
+++ b/src/buildtool/serve_api/remote/configuration_client.cpp
@@ -24,7 +24,7 @@
#include "src/buildtool/serve_api/remote/config.hpp"
auto ConfigurationClient::CheckServeRemoteExecution() const noexcept -> bool {
- auto const client_remote_address = remote_config_.RemoteAddress();
+ auto const client_remote_address = remote_config_.remote_address;
if (!client_remote_address) {
logger_.Emit(LogLevel::Error,
"Internal error: the remote execution endpoint should "
diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp
index d36b518e..1d3a385b 100644
--- a/src/buildtool/serve_api/remote/target_client.cpp
+++ b/src/buildtool/serve_api/remote/target_client.cpp
@@ -60,7 +60,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key,
request.mutable_target_cache_key_id()->CopyFrom(key_dgst);
// add execution properties to request
- for (auto const& [k, v] : apis_.remote_config.PlatformProperties()) {
+ for (auto const& [k, v] : apis_.remote_config.platform_properties) {
auto* prop = request.add_execution_properties();
prop->set_name(k);
prop->set_value(v);
@@ -70,8 +70,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key,
// to remote cas
auto dispatch_list = nlohmann::json::array();
try {
- for (auto const& [props, endpoint] :
- apis_.remote_config.DispatchList()) {
+ for (auto const& [props, endpoint] : apis_.remote_config.dispatch) {
auto entry = nlohmann::json::array();
entry.push_back(nlohmann::json(props));
entry.push_back(endpoint.ToJson());
diff --git a/src/buildtool/serve_api/serve_service/configuration.cpp b/src/buildtool/serve_api/serve_service/configuration.cpp
index 427ee075..a5bd7655 100644
--- a/src/buildtool/serve_api/serve_service/configuration.cpp
+++ b/src/buildtool/serve_api/serve_service/configuration.cpp
@@ -23,7 +23,7 @@ auto ConfigurationService::RemoteExecutionEndpoint(
const ::justbuild::just_serve::RemoteExecutionEndpointRequest* /*request*/,
::justbuild::just_serve::RemoteExecutionEndpointResponse* response)
-> ::grpc::Status {
- auto address = remote_config_.RemoteAddress();
+ auto address = remote_config_.remote_address;
response->set_address(address ? address->ToJson().dump() : std::string());
return ::grpc::Status::OK;
}
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index cbd62bda..dd430ace 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -138,7 +138,7 @@ auto TargetService::ServeTarget(
}
// start filling in the backend description
- auto const address = apis_.remote_config.RemoteAddress();
+ auto const address = apis_.remote_config.remote_address;
// read in the execution properties.
// Important: we will need to pass these platform properties also to the
// executor (via the graph_traverser) in order for the build to be properly
diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp
index e2b7f542..8798c371 100644
--- a/src/other_tools/just_mr/fetch.cpp
+++ b/src/other_tools/just_mr/fetch.cpp
@@ -397,29 +397,33 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config,
Logger::Log(LogLevel::Info, "Found {} to fetch", fetchables);
}
- // setup the APIs for archive fetches; only happens if in native mode
- JustMR::Utils::SetupRemoteConfig(common_args.remote_execution_address,
- common_args.remote_serve_address);
+ // setup remote execution config
+ auto remote_exec_config = JustMR::Utils::CreateRemoteExecutionConfig(
+ common_args.remote_execution_address, common_args.remote_serve_address);
+ if (not remote_exec_config) {
+ return kExitConfigError;
+ }
- // setup authentication
+ // setup authentication config
auto auth_config = JustMR::Utils::CreateAuthConfig(auth_args);
if (not auth_config) {
return kExitConfigError;
}
- // setup local execution
+ // setup local execution config
auto local_exec_config =
JustMR::Utils::CreateLocalExecutionConfig(common_args);
if (not local_exec_config) {
return kExitConfigError;
}
+ // setup the APIs for archive fetches; only happens if in native mode
ApiBundle const apis{&storage_config,
&storage,
&*local_exec_config,
/*repo_config=*/nullptr,
&*auth_config,
- &RemoteExecutionConfig::Instance()};
+ &*remote_exec_config};
bool const has_remote_api =
apis.local != apis.remote and not common_args.compatible;
diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp
index 61c3c120..228c0ee0 100644
--- a/src/other_tools/just_mr/setup.cpp
+++ b/src/other_tools/just_mr/setup.cpp
@@ -116,17 +116,20 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config,
JustMR::Utils::ReachableRepositories(repos, *main, setup_repos);
}
- // setup the APIs for archive fetches; only happens if in native mode
- JustMR::Utils::SetupRemoteConfig(common_args.remote_execution_address,
- common_args.remote_serve_address);
+ // setup remote execution config
+ auto remote_exec_config = JustMR::Utils::CreateRemoteExecutionConfig(
+ common_args.remote_execution_address, common_args.remote_serve_address);
+ if (not remote_exec_config) {
+ return std::nullopt;
+ }
- // setup authentication
+ // setup authentication config
auto auth_config = JustMR::Utils::CreateAuthConfig(auth_args);
if (not auth_config) {
return std::nullopt;
}
- // setup local execution
+ // setup local execution config
auto local_exec_config =
JustMR::Utils::CreateLocalExecutionConfig(common_args);
if (not local_exec_config) {
@@ -138,7 +141,7 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config,
&*local_exec_config,
/*repo_config=*/nullptr,
&*auth_config,
- &RemoteExecutionConfig::Instance()};
+ &*remote_exec_config};
bool const has_remote_api =
apis.local != apis.remote and not common_args.compatible;
diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp
index ae6f5a28..4e5e5ad3 100644
--- a/src/other_tools/just_mr/setup_utils.cpp
+++ b/src/other_tools/just_mr/setup_utils.cpp
@@ -233,23 +233,23 @@ auto CreateLocalExecutionConfig(MultiRepoCommonArguments const& cargs) noexcept
return std::nullopt;
}
-void SetupRemoteConfig(
+auto CreateRemoteExecutionConfig(
std::optional<std::string> const& remote_exec_addr,
- std::optional<std::string> const& remote_serve_addr) noexcept {
+ std::optional<std::string> const& remote_serve_addr) noexcept
+ -> std::optional<RemoteExecutionConfig> {
// if only a serve endpoint address is given, we assume it is one that acts
// also as remote-execution
auto remote_addr = remote_exec_addr ? remote_exec_addr : remote_serve_addr;
- if (not remote_addr) {
- return;
- }
- // setup remote
- if (not RemoteExecutionConfig::SetRemoteAddress(*remote_addr)) {
- Logger::Log(LogLevel::Error,
- "setting remote execution address '{}' failed.",
- *remote_addr);
- std::exit(kExitConfigError);
+ RemoteExecutionConfig::Builder builder;
+ auto config = builder.SetRemoteAddress(remote_addr).Build();
+
+ if (config) {
+ return *std::move(config);
}
+
+ Logger::Log(LogLevel::Error, config.error());
+ return std::nullopt;
}
auto CreateServeConfig(
diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp
index f96ca81e..66691441 100644
--- a/src/other_tools/just_mr/setup_utils.hpp
+++ b/src/other_tools/just_mr/setup_utils.hpp
@@ -25,6 +25,7 @@
#include "src/buildtool/build_engine/expression/configuration.hpp"
#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
+#include "src/buildtool/execution_api/remote/config.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/other_tools/just_mr/cli.hpp"
@@ -70,9 +71,10 @@ void DefaultReachableRepositories(
MultiRepoCommonArguments const& cargs) noexcept
-> std::optional<LocalExecutionConfig>;
-void SetupRemoteConfig(
+[[nodiscard]] auto CreateRemoteExecutionConfig(
std::optional<std::string> const& remote_exec_addr,
- std::optional<std::string> const& remote_serve_addr) noexcept;
+ std::optional<std::string> const& remote_serve_addr) noexcept
+ -> std::optional<RemoteExecutionConfig>;
/// \brief Setup of a 'just serve' remote API based on just-mr arguments.
/// \returns RemoteServeConfig if initialization was successful or std::nullopt