summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-08-29 17:29:49 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-08-30 17:17:09 +0200
commit013d83eed166049be110d47f00feb4c6af1315af (patch)
treed792e9f6a180337365f639a17c0e07b52b480b37
parent576e31959bb7550bdd2b348f5d096f4926e859c6 (diff)
downloadjustbuild-013d83eed166049be110d47f00feb4c6af1315af.tar.gz
Use BazelDigestFactory to create bazel_re::Digest directly if needed
...bypassing ArtifactDigest functionality.
-rw-r--r--src/buildtool/common/TARGETS12
-rw-r--r--src/buildtool/common/bazel_digest_factory.hpp63
-rw-r--r--src/buildtool/execution_api/bazel_msg/TARGETS1
-rw-r--r--src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp13
-rw-r--r--src/buildtool/execution_api/remote/TARGETS1
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp14
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_response.cpp8
-rw-r--r--test/buildtool/execution_api/bazel/TARGETS8
-rw-r--r--test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp6
-rw-r--r--test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp10
-rw-r--r--test/buildtool/execution_api/bazel/bazel_network.test.cpp42
-rw-r--r--test/buildtool/execution_api/bazel/bytestream_client.test.cpp51
-rw-r--r--test/buildtool/execution_api/execution_service/TARGETS1
-rw-r--r--test/buildtool/execution_api/execution_service/cas_server.test.cpp5
-rw-r--r--test/utils/TARGETS1
-rw-r--r--test/utils/remote_execution/bazel_action_creator.hpp13
16 files changed, 168 insertions, 81 deletions
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index df3c0e33..e2db528c 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -39,6 +39,18 @@
, "proto": [["@", "bazel_remote_apis", "", "remote_execution_proto"]]
, "stage": ["src", "buildtool", "common"]
}
+, "bazel_digest_factory":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["bazel_digest_factory"]
+ , "hdrs": ["bazel_digest_factory.hpp"]
+ , "deps":
+ [ "bazel_types"
+ , ["src/buildtool/crypto", "hash_function"]
+ , ["src/buildtool/file_system", "object_type"]
+ , ["src/utils/cpp", "gsl"]
+ ]
+ , "stage": ["src", "buildtool", "common"]
+ }
, "common":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["common"]
diff --git a/src/buildtool/common/bazel_digest_factory.hpp b/src/buildtool/common/bazel_digest_factory.hpp
new file mode 100644
index 00000000..e08eabb7
--- /dev/null
+++ b/src/buildtool/common/bazel_digest_factory.hpp
@@ -0,0 +1,63 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_BUILDTOOL_COMMON_BAZEL_DIGEST_FACTORY_HPP
+#define INCLUDED_SRC_BUILDTOOL_COMMON_BAZEL_DIGEST_FACTORY_HPP
+
+#include <cstddef>
+#include <cstdint>
+#include <string>
+
+#include "gsl/gsl"
+#include "src/buildtool/common/bazel_types.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
+#include "src/buildtool/file_system/object_type.hpp"
+
+class BazelDigestFactory final {
+ static constexpr auto kBlobTag = "62";
+ static constexpr auto kTreeTag = "74";
+
+ public:
+ /// \brief Hash content using hash function and return a valid
+ /// bazel_re::Digest
+ /// \tparam kType Type of the hashing algorithm to be used
+ /// \param hash_function Hash function to be used for hashing
+ /// \param content Content to be hashed
+ /// \return The digest of the content
+ template <ObjectType kType>
+ [[nodiscard]] static auto HashDataAs(HashFunction hash_function,
+ std::string const& content)
+ -> bazel_re::Digest {
+ static constexpr bool kIsTree = IsTreeObject(kType);
+ auto const hash_digest = kIsTree ? hash_function.HashTreeData(content)
+ : hash_function.HashBlobData(content);
+
+ auto hash = hash_function.GetType() == HashFunction::Type::GitSHA1
+ ? Prefix(hash_digest.HexString(), kIsTree)
+ : hash_digest.HexString();
+
+ bazel_re::Digest digest{};
+ digest.set_hash(std::move(hash));
+ digest.set_size_bytes(gsl::narrow<std::int64_t>(content.size()));
+ return digest;
+ }
+
+ private:
+ [[nodiscard]] static auto Prefix(std::string const& hash,
+ bool is_tree) noexcept -> std::string {
+ return (is_tree ? kTreeTag : kBlobTag) + hash;
+ }
+};
+
+#endif // INCLUDED_SRC_BUILDTOOL_COMMON_BAZEL_DIGEST_FACTORY_HPP
diff --git a/src/buildtool/execution_api/bazel_msg/TARGETS b/src/buildtool/execution_api/bazel_msg/TARGETS
index f5e06ab1..f434f816 100644
--- a/src/buildtool/execution_api/bazel_msg/TARGETS
+++ b/src/buildtool/execution_api/bazel_msg/TARGETS
@@ -37,6 +37,7 @@
, ["src/utils/cpp", "hex_string"]
, ["src/buildtool/file_system", "file_system_manager"]
, ["src/buildtool/file_system", "git_repo"]
+ , ["src/buildtool/common", "bazel_digest_factory"]
]
, "stage": ["src", "buildtool", "execution_api", "bazel_msg"]
}
diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
index 532910fb..f4c7baad 100644
--- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
+++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
@@ -25,6 +25,7 @@
#include <utility> // std::move
#include <vector>
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/compatibility/native_support.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
@@ -185,9 +186,11 @@ struct DirectoryNodeBundle final {
if (not content) {
return std::nullopt;
}
- auto digest = ArtifactDigest::Create<ObjectType::File>(
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
request.hash_function, *content);
- return BazelBlob{digest, std::move(*content), /*is_exec=*/false};
+ return BazelBlob{std::move(digest),
+ std::move(*content),
+ /*is_exec=*/false};
}
/// \brief Create bundle for protobuf message Action from Command.
@@ -222,9 +225,11 @@ struct DirectoryNodeBundle final {
if (not content) {
return std::nullopt;
}
- auto digest = ArtifactDigest::Create<ObjectType::File>(
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
request.hash_function, *content);
- return BazelBlob{digest, std::move(*content), /*is_exec=*/false};
+ return BazelBlob{std::move(digest),
+ std::move(*content),
+ /*is_exec=*/false};
}
/// \brief Convert `DirectoryTree` to `DirectoryNodeBundle`.
diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS
index c87bdbb9..8d057783 100644
--- a/src/buildtool/execution_api/remote/TARGETS
+++ b/src/buildtool/execution_api/remote/TARGETS
@@ -47,6 +47,7 @@
, "stage": ["src", "buildtool", "execution_api", "remote"]
, "private-deps":
[ ["src/buildtool/common", "common"]
+ , ["src/buildtool/common", "bazel_digest_factory"]
, ["src/buildtool/file_system", "file_system_manager"]
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/compatibility", "compatibility"]
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
index aac7f2a5..4a8f7ab9 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
@@ -22,6 +22,7 @@
#include "grpcpp/grpcpp.h"
#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/common/remote/client_common.hpp"
#include "src/buildtool/common/remote/retry.hpp"
@@ -31,6 +32,7 @@
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/common/execution_common.hpp"
#include "src/buildtool/execution_api/common/message_limits.hpp"
+#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/log_level.hpp"
namespace {
@@ -56,10 +58,8 @@ namespace {
HashFunction const hash_function{Compatibility::IsCompatible()
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- std::string hash = hash_function.HashBlobData(empty_str).HexString();
- bazel_re::Digest digest{};
- digest.set_hash(NativeSupport::Prefix(hash, false));
- digest.set_size_bytes(empty_str.size());
+ auto const digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, empty_str);
// Upload empty blob.
grpc::ClientContext update_context{};
@@ -124,10 +124,8 @@ namespace {
HashFunction const hash_function{Compatibility::IsCompatible()
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- std::string hash = hash_function.HashBlobData(empty_str).HexString();
- bazel_re::Digest digest{};
- digest.set_hash(NativeSupport::Prefix(hash, false));
- digest.set_size_bytes(empty_str.size());
+ auto const digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, empty_str);
// Upload empty blob.
grpc::ClientContext update_context{};
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp
index f56f9992..aa4a64b6 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp
@@ -17,6 +17,7 @@
#include <cstddef>
#include "gsl/gsl"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/compatibility/native_support.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
@@ -32,8 +33,11 @@ auto ProcessDirectoryMessage(HashFunction hash_function,
bazel_re::Directory const& dir) noexcept
-> std::optional<BazelBlob> {
auto data = dir.SerializeAsString();
- auto digest = ArtifactDigest::Create<ObjectType::File>(hash_function, data);
- return BazelBlob{std::move(digest), std::move(data), /*is_exec=*/false};
+ auto digest =
+ BazelDigestFactory::HashDataAs<ObjectType::File>(hash_function, data);
+ return BazelBlob{std::move(digest),
+ std::move(data),
+ /*is_exec=*/false};
}
} // namespace
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS
index 18a9e012..9d9aa5d8 100644
--- a/test/buildtool/execution_api/bazel/TARGETS
+++ b/test/buildtool/execution_api/bazel/TARGETS
@@ -8,7 +8,7 @@
, ["utils", "catch-main-remote-execution"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
@@ -28,7 +28,7 @@
, ["utils", "execution_bazel"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
@@ -48,7 +48,7 @@
, ["utils", "execution_bazel"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
@@ -68,7 +68,7 @@
, ["utils", "execution_bazel"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, ["@", "src", "src/buildtool/compatibility", "compatibility"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
diff --git a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
index bd005497..e4772f7d 100644
--- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
@@ -20,7 +20,7 @@
#include "catch2/catch_test_macros.hpp"
#include "gsl/gsl"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
@@ -52,8 +52,8 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") {
HashFunction const hash_function{Compatibility::IsCompatible()
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- auto digest =
- ArtifactDigest::Create<ObjectType::File>(hash_function, content);
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
// Valid blob
BazelBlob blob{digest, content, /*is_exec=*/false};
diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
index 093c4eb1..c354316c 100644
--- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
@@ -17,7 +17,7 @@
#include <string>
#include "catch2/catch_test_macros.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
@@ -35,8 +35,8 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") {
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- auto test_digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
auto auth_config = TestAuthConfig::ReadFromEnvironment();
REQUIRE(auth_config);
@@ -119,8 +119,8 @@ TEST_CASE("Bazel internals: Execution Client using env variables",
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- auto test_digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
auto auth_config = TestAuthConfig::ReadFromEnvironment();
REQUIRE(auth_config);
diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp
index edc35ea7..01c5aea9 100644
--- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp
@@ -21,7 +21,7 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/auth/authentication.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
@@ -62,18 +62,18 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") {
std::string content_bar("bar");
std::string content_baz(kLargeSize, 'x'); // single larger blob
- BazelBlob foo{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_foo),
- content_foo,
- /*is_exec=*/false};
- BazelBlob bar{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_bar),
- content_bar,
- /*is_exec=*/false};
- BazelBlob baz{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_baz),
- content_baz,
- /*is_exec=*/false};
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_foo),
+ content_foo,
+ /*is_exec=*/false};
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_bar),
+ content_bar,
+ /*is_exec=*/false};
+ BazelBlob baz{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_baz),
+ content_baz,
+ /*is_exec=*/false};
// Search blobs via digest
REQUIRE(network.UploadBlobs(BazelBlobContainer{{foo, bar, baz}}));
@@ -128,14 +128,14 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") {
std::string content_foo("foo");
std::string content_bar(kLargeSize, 'x'); // single larger blob
- BazelBlob foo{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_foo),
- content_foo,
- /*is_exec=*/false};
- BazelBlob bar{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_bar),
- content_bar,
- /*is_exec=*/false};
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_foo),
+ content_foo,
+ /*is_exec=*/false};
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_bar),
+ content_bar,
+ /*is_exec=*/false};
// Upload blobs
REQUIRE(network.UploadBlobs(BazelBlobContainer{{foo, bar}}));
diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
index 10fe0c83..731073e5 100644
--- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
@@ -20,7 +20,7 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/auth/authentication.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
@@ -54,8 +54,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
std::string content("foobar");
// digest of "foobar"
- auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -80,9 +80,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
std::string other_content("This is a differnt string");
// Valid digest, but for a different string
- auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function,
- other_content));
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, other_content);
CHECK(not stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -101,8 +100,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
}
// digest of "instance_nameinstance_nameinstance_..."
- auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -160,18 +159,18 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") {
SECTION("Upload small blobs") {
std::string instance_name{"remote-execution"};
- BazelBlob foo{
- ArtifactDigest::Create<ObjectType::File>(hash_function, "foo"),
- "foo",
- /*is_exec=*/false};
- BazelBlob bar{
- ArtifactDigest::Create<ObjectType::File>(hash_function, "bar"),
- "bar",
- /*is_exec=*/false};
- BazelBlob baz{
- ArtifactDigest::Create<ObjectType::File>(hash_function, "baz"),
- "baz",
- /*is_exec=*/false};
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, "foo"),
+ "foo",
+ /*is_exec=*/false};
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, "bar"),
+ "bar",
+ /*is_exec=*/false};
+ BazelBlob baz{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, "baz"),
+ "baz",
+ /*is_exec=*/false};
CHECK(stream.WriteMany<BazelBlob>(
{foo, bar, baz},
@@ -216,16 +215,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") {
content_baz[i] = instance_name[(i + 2) % instance_name.size()];
}
- BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(hash_function,
- content_foo),
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_foo),
content_foo,
/*is_exec=*/false};
- BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(hash_function,
- content_bar),
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_bar),
content_bar,
/*is_exec=*/false};
- BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(hash_function,
- content_baz),
+ BazelBlob baz{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_baz),
content_baz,
/*is_exec=*/false};
diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS
index 0e32c4ad..a2c1e9dd 100644
--- a/test/buildtool/execution_api/execution_service/TARGETS
+++ b/test/buildtool/execution_api/execution_service/TARGETS
@@ -16,6 +16,7 @@
, ["@", "src", "src/buildtool/file_system", "git_repo"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/storage", "config"]
, ["@", "src", "src/buildtool/storage", "storage"]
, ["@", "gsl", "", "gsl"]
diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp
index 4bc90546..ca88b17b 100644
--- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp
+++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp
@@ -19,6 +19,7 @@
#include "catch2/catch_test_macros.hpp"
#include "gsl/gsl"
#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
#include "src/buildtool/execution_api/local/context.hpp"
#include "src/buildtool/file_system/git_repo.hpp"
@@ -66,7 +67,7 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") {
auto empty_entries = GitRepo::tree_entries_t{};
auto empty_tree = GitRepo::CreateShallowTree(empty_entries);
REQUIRE(empty_tree);
- auto empty_tree_digest = ArtifactDigest::Create<ObjectType::Tree>(
+ auto empty_tree_digest = BazelDigestFactory::HashDataAs<ObjectType::Tree>(
storage_config.Get().hash_function, empty_tree->second);
// Create a tree containing the empty tree.
@@ -74,7 +75,7 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") {
entries[empty_tree->first].emplace_back("empty_tree", ObjectType::Tree);
auto tree = GitRepo::CreateShallowTree(entries);
REQUIRE(tree);
- auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>(
+ auto tree_digest = BazelDigestFactory::HashDataAs<ObjectType::Tree>(
storage_config.Get().hash_function, tree->second);
// Upload tree. The tree invariant is violated, thus, a negative answer is
diff --git a/test/utils/TARGETS b/test/utils/TARGETS
index 18bda841..9daecce8 100644
--- a/test/utils/TARGETS
+++ b/test/utils/TARGETS
@@ -13,6 +13,7 @@
[ ["@", "gsl", "", "gsl"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
, ["@", "src", "src/buildtool/common", "bazel_types"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, "test_env"
, "test_auth_config"
diff --git a/test/utils/remote_execution/bazel_action_creator.hpp b/test/utils/remote_execution/bazel_action_creator.hpp
index 7b92428d..ad9b3fbc 100644
--- a/test/utils/remote_execution/bazel_action_creator.hpp
+++ b/test/utils/remote_execution/bazel_action_creator.hpp
@@ -24,6 +24,7 @@
#include "gsl/gsl"
#include "src/buildtool/auth/authentication.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
@@ -64,14 +65,14 @@
});
auto cmd_data = cmd.SerializeAsString();
- auto cmd_id =
- ArtifactDigest::Create<ObjectType::File>(hash_function, cmd_data);
+ auto cmd_id = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, cmd_data);
blobs.emplace_back(cmd_id, cmd_data, /*is_exec=*/false);
bazel_re::Directory empty_dir;
auto dir_data = empty_dir.SerializeAsString();
- auto dir_id =
- ArtifactDigest::Create<ObjectType::Tree>(hash_function, dir_data);
+ auto dir_id = BazelDigestFactory::HashDataAs<ObjectType::Tree>(
+ hash_function, dir_data);
blobs.emplace_back(dir_id, dir_data, /*is_exec=*/false);
bazel_re::Action action;
@@ -82,8 +83,8 @@
gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{dir_id}});
auto action_data = action.SerializeAsString();
- auto action_id =
- ArtifactDigest::Create<ObjectType::File>(hash_function, action_data);
+ auto action_id = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, action_data);
blobs.emplace_back(action_id, action_data, /*is_exec=*/false);
auto auth_config = TestAuthConfig::ReadFromEnvironment();