diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-03 12:11:44 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2025-03-24 09:33:46 +0100 |
commit | f0b76f319e6010118392a100564280fdb69b7837 (patch) | |
tree | 037b68dbf2e06731efdaaddb72c37c0b4525ad85 | |
parent | 5d602f18e81616685c7fd91ac127a8006e631881 (diff) | |
download | justbuild-f0b76f319e6010118392a100564280fdb69b7837.tar.gz |
BazelResponse: Use non-incremental reading
to avoid downloading the same blobs.
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_response.cpp | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp index ffede579..cedc1ff4 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp @@ -234,44 +234,41 @@ auto BazelResponse::Populate() noexcept -> std::optional<std::string> { // collect root digests from trees and store them auto reader = network_->CreateReader(); int pos = 0; - for (auto tree_blobs : reader.ReadIncrementally(&tree_digests)) { - for (auto const& tree_blob : tree_blobs) { - try { - std::optional<bazel_re::Tree> tree; - if (auto const content = tree_blob.ReadContent()) { - tree = BazelMsgFactory::MessageFromString<bazel_re::Tree>( - *content); - } - if (not tree) { - return fmt::format( - "BazelResponse: failed to create Tree for {}", - tree_blob.GetDigest().hash()); - } - - // The server does not store the Directory messages it just - // has sent us as part of the Tree message. If we want to be - // able to use the Directories as inputs for actions, we - // have to upload them manually. - auto root_digest = UploadTreeMessageDirectories(*tree); - if (not root_digest) { - auto error = - fmt::format("BazelResponse: {}", root_digest.error()); - Logger::Log(LogLevel::Trace, error); - return error; - } - artifacts.emplace( - action_result.output_directories(pos).path(), - Artifact::ObjectInfo{.digest = *root_digest, - .type = ObjectType::Tree}); - } catch (std::exception const& ex) { + for (auto const& tree_blob : reader.ReadOrdered(tree_digests)) { + try { + std::optional<bazel_re::Tree> tree; + if (auto const content = tree_blob.ReadContent()) { + tree = BazelMsgFactory::MessageFromString<bazel_re::Tree>( + *content); + } + if (not tree) { return fmt::format( - "BazelResponse: unexpected failure gathering digest for " - "{}:\n{}", - tree_blob.GetDigest().hash(), - ex.what()); + "BazelResponse: failed to create Tree for {}", + tree_blob.GetDigest().hash()); + } + + // The server does not store the Directory messages it just + // has sent us as part of the Tree message. If we want to be + // able to use the Directories as inputs for actions, we + // have to upload them manually. + auto root_digest = UploadTreeMessageDirectories(*tree); + if (not root_digest) { + auto error = + fmt::format("BazelResponse: {}", root_digest.error()); + Logger::Log(LogLevel::Trace, error); + return error; } - ++pos; + artifacts.emplace(action_result.output_directories(pos).path(), + Artifact::ObjectInfo{.digest = *root_digest, + .type = ObjectType::Tree}); + } catch (std::exception const& ex) { + return fmt::format( + "BazelResponse: unexpected failure gathering digest for " + "{}:\n{}", + tree_blob.GetDigest().hash(), + ex.what()); } + ++pos; } artifacts_ = std::move(artifacts); dir_symlinks_ = std::move(dir_symlinks); |