summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/just_mr/TARGETS3
-rw-r--r--src/other_tools/just_mr/fetch.cpp10
-rw-r--r--src/other_tools/just_mr/setup.cpp9
-rw-r--r--src/other_tools/just_mr/setup_utils.cpp33
-rw-r--r--src/other_tools/just_mr/setup_utils.hpp10
5 files changed, 33 insertions, 32 deletions
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index b6c6022a..f5f64e99 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -85,7 +85,7 @@
[ ["src/buildtool/build_engine/expression", "expression_ptr_interface"]
, ["src/buildtool/build_engine/expression", "expression"]
, ["src/buildtool/execution_api/common", "common"]
- , ["src/buildtool/serve_api/remote", "serve_api"]
+ , ["src/buildtool/serve_api/remote", "config"]
, "cli"
]
, "stage": ["src", "other_tools", "just_mr"]
@@ -98,7 +98,6 @@
, ["src/buildtool/auth", "auth"]
, ["src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["src/buildtool/execution_api/remote", "bazel"]
- , ["src/buildtool/serve_api/remote", "config"]
]
}
, "fetch":
diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp
index ebba56e5..0f0a0ef1 100644
--- a/src/other_tools/just_mr/fetch.cpp
+++ b/src/other_tools/just_mr/fetch.cpp
@@ -401,13 +401,13 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config,
bool remote_compatible{common_args.compatible == true};
// setup the API for serving roots
- bool serve_api_exists = JustMR::Utils::SetupServeApi(
+ auto serve_config = JustMR::Utils::CreateServeConfig(
common_args.remote_serve_address, auth_args);
+ if (not serve_config) {
+ return kExitConfigError;
+ }
- auto serve = serve_api_exists
- ? ServeApi::Create(RemoteServeConfig::Instance())
- : std::nullopt;
-
+ auto serve = ServeApi::Create(*serve_config);
// check configuration of the serve endpoint provided
if (serve) {
// if we have a remote endpoint explicitly given by the user, it must
diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp
index 47993e34..b0f81a08 100644
--- a/src/other_tools/just_mr/setup.cpp
+++ b/src/other_tools/just_mr/setup.cpp
@@ -119,12 +119,13 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config,
bool remote_compatible{common_args.compatible == true};
// setup the API for serving roots
- bool serve_api_exists = JustMR::Utils::SetupServeApi(
+ auto serve_config = JustMR::Utils::CreateServeConfig(
common_args.remote_serve_address, auth_args);
+ if (not serve_config) {
+ return std::nullopt;
+ }
- auto serve = serve_api_exists
- ? ServeApi::Create(RemoteServeConfig::Instance())
- : std::nullopt;
+ auto serve = ServeApi::Create(*serve_config);
// check configuration of the serve endpoint provided
if (serve) {
diff --git a/src/other_tools/just_mr/setup_utils.cpp b/src/other_tools/just_mr/setup_utils.cpp
index 916d1e60..7c09b580 100644
--- a/src/other_tools/just_mr/setup_utils.cpp
+++ b/src/other_tools/just_mr/setup_utils.cpp
@@ -15,10 +15,8 @@
#include "src/other_tools/just_mr/setup_utils.hpp"
#include <fstream>
-#include <memory>
-#include <optional>
-#include <string>
#include <unordered_set>
+#include <variant>
#include "nlohmann/json.hpp"
#include "src/buildtool/auth/authentication.hpp"
@@ -28,7 +26,6 @@
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
-#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
namespace {
@@ -265,22 +262,24 @@ auto GetRemoteApi(std::optional<std::string> const& remote_exec_addr,
return nullptr;
}
-auto SetupServeApi(std::optional<std::string> const& remote_serve_addr,
- MultiRepoRemoteAuthArguments const& auth) noexcept -> bool {
- if (remote_serve_addr) {
+auto CreateServeConfig(std::optional<std::string> const& remote_serve_addr,
+ MultiRepoRemoteAuthArguments const& auth) noexcept
+ -> std::optional<RemoteServeConfig> {
+ RemoteServeConfig::Builder builder;
+ auto result = builder.SetRemoteAddress(remote_serve_addr).Build();
+
+ if (auto* config = std::get_if<RemoteServeConfig>(&result)) {
// setup authentication
SetupAuthConfig(auth);
- // setup remote
- if (not RemoteServeConfig::Instance().SetRemoteAddress(
- *remote_serve_addr)) {
- Logger::Log(LogLevel::Error,
- "setting remote serve service address '{}' failed.",
- *remote_serve_addr);
- std::exit(kExitConfigError);
- }
- return true;
+ return std::move(*config);
+ }
+
+ if (auto* error = std::get_if<std::string>(&result)) {
+ Logger::Log(LogLevel::Error, *error);
+ return std::nullopt;
}
- return false;
+ Logger::Log(LogLevel::Error, "Unknown error occured");
+ return std::nullopt;
}
} // namespace JustMR::Utils
diff --git a/src/other_tools/just_mr/setup_utils.hpp b/src/other_tools/just_mr/setup_utils.hpp
index 278658c1..cc3ab86a 100644
--- a/src/other_tools/just_mr/setup_utils.hpp
+++ b/src/other_tools/just_mr/setup_utils.hpp
@@ -24,7 +24,7 @@
#include "src/buildtool/build_engine/expression/configuration.hpp"
#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
#include "src/buildtool/execution_api/common/execution_api.hpp"
-#include "src/buildtool/serve_api/remote/serve_api.hpp"
+#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/other_tools/just_mr/cli.hpp"
/* Setup-related constants and utilities for just-mr */
@@ -69,10 +69,12 @@ void DefaultReachableRepositories(
MultiRepoRemoteAuthArguments const& auth) noexcept -> IExecutionApi::Ptr;
/// \brief Setup of a 'just serve' remote API based on just-mr arguments.
-/// \returns Flag stating whether a serve API is available or not.
-[[nodiscard]] auto SetupServeApi(
+/// \returns RemoteServeConfig if initialization was successfull or std::nullopt
+/// if failed.
+[[nodiscard]] auto CreateServeConfig(
std::optional<std::string> const& remote_serve_addr,
- MultiRepoRemoteAuthArguments const& auth) noexcept -> bool;
+ MultiRepoRemoteAuthArguments const& auth) noexcept
+ -> std::optional<RemoteServeConfig>;
} // namespace Utils