diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-07-26 14:43:52 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-07-26 15:35:19 +0200 |
commit | 57d3222a4ff1ab3cc64e0d33d721a30827b684e3 (patch) | |
tree | ad85c523bc482f0799e5cdaba92f435e007a0713 | |
parent | 46046066c6004c6cca363c1c11e13de650e9e101 (diff) | |
download | justbuild-57d3222a4ff1ab3cc64e0d33d721a30827b684e3.tar.gz |
remote api: honor the --raw-tree option
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_network.cpp | 26 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_network.hpp | 6 |
4 files changed, 27 insertions, 11 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 761fe55c..97b2f730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ A feature release on top of `1.1.0`, backwards compatible. if `gitignore` files were present. - Temporary files generated by `just execute` are now created inside the local build root. +- `just install-cas` now correctly handles `--raw-tree` also for + remote-execution endpoints. ## Release `1.1.0` (2023-05-19) diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index f4fd3b1f..c4f170a3 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -142,7 +142,7 @@ auto BazelApi::CreateAction( [[nodiscard]] auto BazelApi::RetrieveToFds( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<int> const& fds, - bool /*raw_tree*/) noexcept -> bool { + bool raw_tree) noexcept -> bool { if (artifacts_info.size() != fds.size()) { Logger::Log(LogLevel::Error, "different number of digests and file descriptors."); @@ -154,7 +154,7 @@ auto BazelApi::CreateAction( auto const& info = artifacts_info[i]; if (gsl::owner<FILE*> out = fdopen(fd, "wb")) { // NOLINT - auto const success = network_->DumpToStream(info, out); + auto const success = network_->DumpToStream(info, out, raw_tree); std::fclose(out); if (not success) { Logger::Log(LogLevel::Error, diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp index 60ed22e1..538f2633 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp @@ -79,7 +79,20 @@ namespace { [[nodiscard]] auto TreeToStream( gsl::not_null<BazelNetwork const*> const& network, bazel_re::Digest const& tree_digest, - gsl::not_null<FILE*> const& stream) noexcept -> bool { + gsl::not_null<FILE*> const& stream, + bool raw_tree) noexcept -> bool { + if (raw_tree) { + auto blobs = network->ReadBlobs({tree_digest}).Next(); + if (blobs.size() != 1) { + Logger::Log(LogLevel::Error, + "Object {} not found in CAS", + NativeSupport::Unprefix(tree_digest.hash())); + return false; + } + auto const& str = blobs.at(0).data; + std::fwrite(str.data(), 1, str.size(), stream); + return true; + } if (Compatibility::IsCompatible()) { if (auto dir = ReadDirectory(network, tree_digest)) { if (auto data = BazelMsgFactory::DirectoryToString(*dir)) { @@ -423,9 +436,10 @@ auto BazelNetwork::ReadObjectInfosRecursively( return false; } -auto BazelNetwork::DumpToStream( - Artifact::ObjectInfo const& info, - gsl::not_null<FILE*> const& stream) const noexcept -> bool { - return IsTreeObject(info.type) ? TreeToStream(this, info.digest, stream) - : BlobToStream(this, info.digest, stream); +auto BazelNetwork::DumpToStream(Artifact::ObjectInfo const& info, + gsl::not_null<FILE*> const& stream, + bool raw_tree) const noexcept -> bool { + return IsTreeObject(info.type) + ? TreeToStream(this, info.digest, stream, raw_tree) + : BlobToStream(this, info.digest, stream); } diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp index c1ae34ad..e513b23e 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp @@ -119,9 +119,9 @@ class BazelNetwork { -> std::optional<std::pair<std::vector<std::filesystem::path>, std::vector<Artifact::ObjectInfo>>>; - [[nodiscard]] auto DumpToStream( - Artifact::ObjectInfo const& info, - gsl::not_null<FILE*> const& stream) const noexcept -> bool; + [[nodiscard]] auto DumpToStream(Artifact::ObjectInfo const& info, + gsl::not_null<FILE*> const& stream, + bool raw_tree) const noexcept -> bool; private: using DirectoryMap = |