summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/common/api_bundle.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-29 11:13:08 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-07-30 12:10:06 +0200
commitb393090c220da61dd1c197adfac42dc47ad74f8a (patch)
tree72fb8ea9e5a9a4f9c01017c0601720b98909e3a8 /src/buildtool/execution_api/common/api_bundle.cpp
parent6089297787902f9a38a678e2ffdf639e779a1594 (diff)
downloadjustbuild-b393090c220da61dd1c197adfac42dc47ad74f8a.tar.gz
ApiBundle: Use a creator method instead of constructor
This will allow for ApiBundle to be used together with the TestApi implementation of IExecutionApi in tests. Also rename CreateRemote method to MakeRemote in order to remove any semantical confusion.
Diffstat (limited to 'src/buildtool/execution_api/common/api_bundle.cpp')
-rw-r--r--src/buildtool/execution_api/common/api_bundle.cpp35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/buildtool/execution_api/common/api_bundle.cpp b/src/buildtool/execution_api/common/api_bundle.cpp
index 15e84440..8808e5d8 100644
--- a/src/buildtool/execution_api/common/api_bundle.cpp
+++ b/src/buildtool/execution_api/common/api_bundle.cpp
@@ -18,16 +18,33 @@
#include "src/buildtool/execution_api/local/local_api.hpp"
#include "src/buildtool/execution_api/remote/bazel/bazel_api.hpp"
-ApiBundle::ApiBundle(gsl::not_null<LocalContext const*> const& local_context,
- gsl::not_null<RemoteContext const*> const& remote_context,
- RepositoryConfig const* repo_config)
- : hash_function{local_context->storage_config->hash_function},
- local{std::make_shared<LocalApi>(local_context, repo_config)},
- remote{CreateRemote(remote_context->exec_config->remote_address,
- remote_context->auth,
- remote_context->retry_config)} {}
+/// \note Some logic from MakeRemote is duplicated here as that method cannot
+/// be used without the hash_function field being set prior to the call.
+auto ApiBundle::Create(
+ gsl::not_null<LocalContext const*> const& local_context,
+ gsl::not_null<RemoteContext const*> const& remote_context,
+ RepositoryConfig const* repo_config) -> ApiBundle {
+ auto const hash_fct = local_context->storage_config->hash_function;
+ IExecutionApi::Ptr local_api =
+ std::make_shared<LocalApi>(local_context, repo_config);
+ IExecutionApi::Ptr remote_api = local_api;
+ if (auto const address = remote_context->exec_config->remote_address) {
+ ExecutionConfiguration config;
+ config.skip_cache_lookup = false;
+ remote_api = std::make_shared<BazelApi>("remote-execution",
+ address->host,
+ address->port,
+ remote_context->auth,
+ remote_context->retry_config,
+ config,
+ hash_fct);
+ }
+ return ApiBundle{.hash_function = hash_fct,
+ .local = std::move(local_api),
+ .remote = std::move(remote_api)};
+}
-auto ApiBundle::CreateRemote(
+auto ApiBundle::MakeRemote(
std::optional<ServerAddress> const& address,
gsl::not_null<Auth const*> const& authentication,
gsl::not_null<RetryConfig const*> const& retry_config) const