summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-11 15:19:34 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-13 14:41:00 +0200
commit0b3c77edde2b3497e3d943d1433d704453eabd19 (patch)
tree94b83d991320297feffeb9930b05e1e0fc35100e
parentddf48a60029bed958fb2cf0238dbb0bca0b770fb (diff)
downloadjustbuild-0b3c77edde2b3497e3d943d1433d704453eabd19.tar.gz
Check compatibility in readers based on the hash type
-rw-r--r--src/buildtool/execution_api/common/stream_dumper.hpp2
-rw-r--r--src/buildtool/execution_api/common/tree_reader.hpp4
-rw-r--r--src/buildtool/execution_api/local/local_cas_reader.cpp4
-rw-r--r--src/buildtool/execution_api/local/local_cas_reader.hpp2
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp10
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp2
6 files changed, 18 insertions, 6 deletions
diff --git a/src/buildtool/execution_api/common/stream_dumper.hpp b/src/buildtool/execution_api/common/stream_dumper.hpp
index ea0a323d..c1d99588 100644
--- a/src/buildtool/execution_api/common/stream_dumper.hpp
+++ b/src/buildtool/execution_api/common/stream_dumper.hpp
@@ -65,7 +65,7 @@ class StreamDumper final {
[[nodiscard]] auto DumpTree(
Artifact::ObjectInfo const& info,
gsl::not_null<FILE*> const& stream) const noexcept -> bool {
- if (ProtocolTraits::Instance().IsCompatible()) {
+ if (not impl_.IsNativeProtocol()) {
auto directory = impl_.ReadDirectory(info.digest);
auto data = directory
? TreeReaderUtils::DirectoryToString(*directory)
diff --git a/src/buildtool/execution_api/common/tree_reader.hpp b/src/buildtool/execution_api/common/tree_reader.hpp
index 18e94fe8..de1e2edf 100644
--- a/src/buildtool/execution_api/common/tree_reader.hpp
+++ b/src/buildtool/execution_api/common/tree_reader.hpp
@@ -59,7 +59,7 @@ class TreeReader final {
return true;
};
- if (ProtocolTraits::Instance().IsCompatible()) {
+ if (not impl_.IsNativeProtocol()) {
auto tree = impl_.ReadDirectory(digest);
if (tree and
not TreeReaderUtils::ReadObjectInfos(*tree, store_info)) {
@@ -132,7 +132,7 @@ class TreeReader final {
: store(parent / path, info);
};
- if (ProtocolTraits::Instance().IsCompatible()) {
+ if (not impl_.IsNativeProtocol()) {
if (auto tree = impl_.ReadDirectory(digest)) {
if (include_trees and IsDirectoryEmpty(*tree)) {
if (not store(parent, {digest, ObjectType::Tree})) {
diff --git a/src/buildtool/execution_api/local/local_cas_reader.cpp b/src/buildtool/execution_api/local/local_cas_reader.cpp
index 2da3bc00..bac7ee71 100644
--- a/src/buildtool/execution_api/local/local_cas_reader.cpp
+++ b/src/buildtool/execution_api/local/local_cas_reader.cpp
@@ -164,6 +164,10 @@ auto LocalCasReader::DumpRaw(std::filesystem::path const& path,
return true;
}
+auto LocalCasReader::IsNativeProtocol() const noexcept -> bool {
+ return ProtocolTraits::IsNative(cas_.GetHashFunction().GetType());
+}
+
namespace {
[[nodiscard]] auto AssembleTree(
bazel_re::Directory root,
diff --git a/src/buildtool/execution_api/local/local_cas_reader.hpp b/src/buildtool/execution_api/local/local_cas_reader.hpp
index b989ec09..8fe9afd4 100644
--- a/src/buildtool/execution_api/local/local_cas_reader.hpp
+++ b/src/buildtool/execution_api/local/local_cas_reader.hpp
@@ -52,6 +52,8 @@ class LocalCasReader final {
DumpCallback const& dumper) const noexcept
-> bool;
+ [[nodiscard]] auto IsNativeProtocol() const noexcept -> bool;
+
private:
LocalCAS<true> const& cas_;
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp
index d78a63de..5dac053b 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp
@@ -41,7 +41,7 @@ BazelNetworkReader::BazelNetworkReader(
: instance_name_{other.instance_name_},
cas_{other.cas_},
hash_function_{other.hash_function_} {
- if (ProtocolTraits::Instance().IsCompatible() and request_remote_tree) {
+ if (not IsNativeProtocol() and request_remote_tree) {
// Query full tree from remote CAS. Note that this is currently not
// supported by Buildbarn revision c3c06bbe2a.
auto full_tree =
@@ -72,7 +72,7 @@ auto BazelNetworkReader::ReadDirectory(ArtifactDigest const& digest)
auto BazelNetworkReader::ReadGitTree(ArtifactDigest const& digest)
const noexcept -> std::optional<GitRepo::tree_entries_t> {
- ExpectsAudit(ProtocolTraits::IsNative(hash_function_.GetType()));
+ ExpectsAudit(IsNativeProtocol());
auto read_blob = ReadSingleBlob(digest);
if (not read_blob) {
@@ -143,10 +143,14 @@ auto BazelNetworkReader::DumpBlob(Artifact::ObjectInfo const& info,
return data.has_value();
}
+auto BazelNetworkReader::IsNativeProtocol() const noexcept -> bool {
+ return ProtocolTraits::IsNative(hash_function_.GetType());
+}
+
auto BazelNetworkReader::MakeAuxiliaryMap(
std::vector<bazel_re::Directory>&& full_tree) const noexcept
-> std::optional<DirectoryMap> {
- ExpectsAudit(not ProtocolTraits::IsNative(hash_function_.GetType()));
+ ExpectsAudit(not IsNativeProtocol());
DirectoryMap result;
result.reserve(full_tree.size());
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp
index 2acd10c7..5c6cdbf9 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp
@@ -63,6 +63,8 @@ class BazelNetworkReader final {
DumpCallback const& dumper) const noexcept
-> bool;
+ [[nodiscard]] auto IsNativeProtocol() const noexcept -> bool;
+
[[nodiscard]] auto ReadSingleBlob(bazel_re::Digest const& digest)
const noexcept -> std::optional<ArtifactBlob>;