diff options
-rw-r--r-- | src/buildtool/main/main.cpp | 5 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/serve_api.hpp | 12 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/target_client.cpp | 18 | ||||
-rw-r--r-- | src/buildtool/serve_api/remote/target_client.hpp | 10 | ||||
-rw-r--r-- | src/other_tools/just_mr/fetch.cpp | 2 | ||||
-rw-r--r-- | src/other_tools/just_mr/setup.cpp | 2 | ||||
-rw-r--r-- | test/buildtool/build_engine/target_map/target_map.test.cpp | 25 |
8 files changed, 44 insertions, 31 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 1043de94..6f9c68ad 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -841,7 +841,7 @@ auto main(int argc, char* argv[]) -> int { if (serve_server) { ApiBundle const serve_apis{ std::nullopt, RemoteExecutionConfig::RemoteAddress()}; - auto serve = ServeApi::Create(*serve_config); + auto serve = ServeApi::Create(*serve_config, &serve_apis); bool with_execute = not RemoteExecutionConfig::RemoteAddress(); return serve_server->Run( *serve_config, serve, serve_apis, with_execute) @@ -928,7 +928,8 @@ auto main(int argc, char* argv[]) -> int { DetermineRoots(&repo_config, arguments.common, arguments.analysis); #ifndef BOOTSTRAP_BUILD_TOOL - std::optional<ServeApi> serve = ServeApi::Create(*serve_config); + std::optional<ServeApi> serve = + ServeApi::Create(*serve_config, &main_apis); #else std::optional<ServeApi> serve; #endif // BOOTSTRAP_BUILD_TOOL diff --git a/src/buildtool/serve_api/remote/TARGETS b/src/buildtool/serve_api/remote/TARGETS index 6443e699..efb923f0 100644 --- a/src/buildtool/serve_api/remote/TARGETS +++ b/src/buildtool/serve_api/remote/TARGETS @@ -36,6 +36,7 @@ , ["src/buildtool/common/remote", "port"] , ["src/buildtool/common/remote", "remote_common"] , ["src/buildtool/file_system/symlinks_map", "pragma_special"] + , ["src/buildtool/execution_api/common", "api_bundle"] , "source_tree_client" , "target_client" , "configuration_client" diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp index 89e287a4..9175857b 100644 --- a/src/buildtool/serve_api/remote/serve_api.hpp +++ b/src/buildtool/serve_api/remote/serve_api.hpp @@ -29,6 +29,7 @@ class ServeApi final {}; #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/port.hpp" #include "src/buildtool/common/remote/remote_common.hpp" +#include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" #include "src/buildtool/serve_api/remote/config.hpp" #include "src/buildtool/serve_api/remote/configuration_client.hpp" @@ -37,8 +38,9 @@ class ServeApi final {}; class ServeApi final { public: - explicit ServeApi(ServerAddress const& address) noexcept - : stc_{address}, tc_{address}, cc_{address} {} + explicit ServeApi(ServerAddress const& address, + gsl::not_null<ApiBundle const*> const& apis) noexcept + : stc_{address}, tc_{address, apis}, cc_{address} {} ~ServeApi() noexcept = default; ServeApi(ServeApi const&) = delete; @@ -47,10 +49,12 @@ class ServeApi final { auto operator=(ServeApi&&) -> ServeApi& = delete; [[nodiscard]] static auto Create( - RemoteServeConfig const& serve_config) noexcept + RemoteServeConfig const& serve_config, + gsl::not_null<ApiBundle const*> const& apis) noexcept -> std::optional<ServeApi> { if (serve_config.remote_address) { - return std::make_optional<ServeApi>(*serve_config.remote_address); + return std::make_optional<ServeApi>(*serve_config.remote_address, + apis); } return std::nullopt; } diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp index 917f1133..d0e6796e 100644 --- a/src/buildtool/serve_api/remote/target_client.cpp +++ b/src/buildtool/serve_api/remote/target_client.cpp @@ -25,7 +25,9 @@ #include "src/buildtool/common/remote/client_common.hpp" #include "src/buildtool/logging/log_level.hpp" -TargetClient::TargetClient(ServerAddress const& address) noexcept { +TargetClient::TargetClient(ServerAddress const& address, + gsl::not_null<ApiBundle const*> const& apis) noexcept + : apis_{*apis} { stub_ = justbuild::just_serve::Target::NewStub( CreateChannelWithCredentials(address.host, address.port)); } @@ -34,17 +36,17 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, const std::string& repo_key) const noexcept -> std::optional<serve_target_result_t> { // make sure the blob containing the key is in the remote cas - if (!local_api_->RetrieveToCas({key.Id()}, &*remote_api_)) { + if (!apis_.local->RetrieveToCas({key.Id()}, &*apis_.remote)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format("Failed to retrieve to remote cas ObjectInfo {}", key.Id().ToString())}; } // make sure the repository configuration blob is in the remote cas - if (!local_api_->RetrieveToCas( + if (!apis_.local->RetrieveToCas( {Artifact::ObjectInfo{.digest = ArtifactDigest{repo_key, 0, false}, .type = ObjectType::File}}, - &*remote_api_)) { + &*apis_.remote)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format("Failed to retrieve to remote cas blob {}", repo_key)}; @@ -90,7 +92,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, } auto const& dispatch_info = Artifact::ObjectInfo{ .digest = ArtifactDigest{*dispatch_dgst}, .type = ObjectType::File}; - if (!local_api_->RetrieveToCas({dispatch_info}, &*remote_api_)) { + if (!apis_.local->RetrieveToCas({dispatch_info}, &*apis_.remote)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format("Failed to upload blob {} to remote cas", @@ -122,8 +124,8 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, ArtifactDigest{response.target_value()}; auto const& obj_info = Artifact::ObjectInfo{ .digest = target_value_dgst, .type = ObjectType::File}; - if (!local_api_->IsAvailable(target_value_dgst)) { - if (!remote_api_->RetrieveToCas({obj_info}, &*local_api_)) { + if (!apis_.local->IsAvailable(target_value_dgst)) { + if (!apis_.remote->RetrieveToCas({obj_info}, &*apis_.local)) { return serve_target_result_t{ std::in_place_index<1>, fmt::format( @@ -132,7 +134,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, } } auto const& target_value_str = - local_api_->RetrieveToMemory(obj_info); + apis_.local->RetrieveToMemory(obj_info); if (!target_value_str) { return serve_target_result_t{ std::in_place_index<1>, diff --git a/src/buildtool/serve_api/remote/target_client.hpp b/src/buildtool/serve_api/remote/target_client.hpp index bc3aa382..35bb2d29 100644 --- a/src/buildtool/serve_api/remote/target_client.hpp +++ b/src/buildtool/serve_api/remote/target_client.hpp @@ -52,7 +52,8 @@ using serve_target_result_t = /// src/buildtool/serve_api/serve_service/just_serve.proto class TargetClient { public: - explicit TargetClient(ServerAddress const& address) noexcept; + explicit TargetClient(ServerAddress const& address, + gsl::not_null<ApiBundle const*> const& apis) noexcept; /// \brief Retrieve the pair of TargetCacheEntry and ObjectInfo associated /// to the given key. @@ -86,14 +87,9 @@ class TargetClient { const noexcept -> std::optional<ArtifactDigest>; private: + ApiBundle const& apis_; std::unique_ptr<justbuild::just_serve::Target::Stub> stub_; Logger logger_{"RemoteTargetClient"}; - gsl::not_null<IExecutionApi::Ptr> const remote_api_{ - CreateExecutionApi(RemoteExecutionConfig::RemoteAddress(), - std::nullopt, - "remote-execution")}; - gsl::not_null<IExecutionApi::Ptr> const local_api_{ - CreateExecutionApi(std::nullopt)}; }; #endif // INCLUDED_SRC_BUILDTOOL_SERVE_API_TARGET_CLIENT_HPP diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp index 4b90dd61..47c107f3 100644 --- a/src/other_tools/just_mr/fetch.cpp +++ b/src/other_tools/just_mr/fetch.cpp @@ -408,7 +408,7 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, return kExitConfigError; } - auto serve = ServeApi::Create(*serve_config); + auto serve = ServeApi::Create(*serve_config, &apis); // 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 0900c4fa..8bcefead 100644 --- a/src/other_tools/just_mr/setup.cpp +++ b/src/other_tools/just_mr/setup.cpp @@ -127,7 +127,7 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, return std::nullopt; } - auto serve = ServeApi::Create(*serve_config); + auto serve = ServeApi::Create(*serve_config, &apis); // check configuration of the serve endpoint provided if (serve) { diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index 67f21c0b..c2be76df 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -27,6 +27,7 @@ #include "src/buildtool/build_engine/target_map/target_map.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" +#include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/main/analyse_context.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" @@ -98,7 +99,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") { auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -540,7 +542,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -627,7 +630,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -724,7 +728,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") { auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -931,7 +936,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") { auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -1071,7 +1077,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") { auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -1177,7 +1184,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, @@ -1340,7 +1348,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") { auto serve_config = TestServeConfig::ReadServeConfigFromEnvironment(); REQUIRE(serve_config); - auto serve = ServeApi::Create(*serve_config); + ApiBundle const apis{std::nullopt, RemoteExecutionConfig::RemoteAddress()}; + auto serve = ServeApi::Create(*serve_config, &apis); AnalyseContext ctx{.repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, |