diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-12-05 14:41:11 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-12-05 16:25:07 +0100 |
commit | 17be89e34ce5b1160af90430be8e0b32acbf6efc (patch) | |
tree | 417f877c51816ac865b54e5043a6966d5757f634 /src/buildtool/execution_api/remote/bazel/bazel_api.cpp | |
parent | d40eb82b519fb17819c8e8f0827f7338bed02bf7 (diff) | |
download | justbuild-17be89e34ce5b1160af90430be8e0b32acbf6efc.tar.gz |
While there, also avoid unnecessary indirection in RertrieveToPaths.
Diffstat (limited to 'src/buildtool/execution_api/remote/bazel/bazel_api.cpp')
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.cpp | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index 0b05dd19..6aa8b938 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -246,7 +246,8 @@ auto BazelApi::CreateAction( std::vector<std::size_t> artifact_pos{}; for (std::size_t i{}; i < artifacts_info.size(); ++i) { auto const& info = artifacts_info[i]; - if (alternative != nullptr and alternative->IsAvailable(info.digest)) { + if (alternative != nullptr and alternative != this and + alternative->IsAvailable(info.digest)) { if (not alternative->RetrieveToPaths({info}, {output_paths[i]})) { return false; } @@ -312,17 +313,51 @@ auto BazelApi::CreateAction( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<int> const& fds, bool raw_tree, - IExecutionApi const* /*alternative*/) const noexcept -> bool { - auto dumper = StreamDumper<BazelNetworkReader>{network_->CreateReader()}; - return CommonRetrieveToFds( - artifacts_info, - fds, - [&dumper, &raw_tree](Artifact::ObjectInfo const& info, - gsl::not_null<FILE*> const& out) { - return dumper.DumpToStream(info, out, raw_tree); - }, - std::nullopt // remote can't fallback to Git - ); + IExecutionApi const* alternative) const noexcept -> bool { + if (alternative == nullptr or alternative == this) { + auto dumper = + StreamDumper<BazelNetworkReader>{network_->CreateReader()}; + return CommonRetrieveToFds( + artifacts_info, + fds, + [&dumper, &raw_tree](Artifact::ObjectInfo const& info, + gsl::not_null<FILE*> const& out) { + return dumper.DumpToStream(info, out, raw_tree); + }, + std::nullopt // no fallback + ); + } + + // We have an alternative, and, in fact, preferred API. So go + // through the artifacts one by one and first try the the preferred one, + // then fall back to retrieving ourselves. + if (artifacts_info.size() != fds.size()) { + Logger::Log(LogLevel::Error, + "different number of digests and file descriptors."); + return false; + } + for (std::size_t i{}; i < artifacts_info.size(); ++i) { + auto fd = fds[i]; + auto const& info = artifacts_info[i]; + if (alternative->IsAvailable(info.digest)) { + if (not alternative->RetrieveToFds( + std::vector<Artifact::ObjectInfo>{info}, + std::vector<int>{fd}, + raw_tree, + nullptr)) { + return false; + } + } + else { + if (not RetrieveToFds(std::vector<Artifact::ObjectInfo>{info}, + std::vector<int>{fd}, + raw_tree, + nullptr)) { + return false; + } + } + } + return true; } [[nodiscard]] auto BazelApi::RetrieveToCas( |