From b393090c220da61dd1c197adfac42dc47ad74f8a Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Mon, 29 Jul 2024 11:13:08 +0200 Subject: 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. --- src/buildtool/execution_api/common/api_bundle.cpp | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/buildtool/execution_api/common/api_bundle.cpp') 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 const& local_context, - gsl::not_null const& remote_context, - RepositoryConfig const* repo_config) - : hash_function{local_context->storage_config->hash_function}, - local{std::make_shared(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 const& local_context, + gsl::not_null 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(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("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 const& address, gsl::not_null const& authentication, gsl::not_null const& retry_config) const -- cgit v1.2.3