summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/bazel_msg
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2025-02-25 13:42:22 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2025-02-27 09:03:30 +0100
commit461312b57d3b49f92861d2c6c5e8a6b13ffa839b (patch)
treec642cd0d3379e6886d1b3847d38661e249e75d58 /src/buildtool/execution_api/bazel_msg
parenteccc7dcfb22fb9c6c42bbcd5566cd044acd1a2f3 (diff)
downloadjustbuild-461312b57d3b49f92861d2c6c5e8a6b13ffa839b.tar.gz
ArtifactBlob: Use static function for construction
Diffstat (limited to 'src/buildtool/execution_api/bazel_msg')
-rw-r--r--src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp37
1 files changed, 20 insertions, 17 deletions
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 6eb35e4c..ccc0f2d7 100644
--- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
+++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp
@@ -164,13 +164,14 @@ struct DirectoryNodeBundle final {
// SHA256 is used since bazel types are processed here.
HashFunction const hash_function{HashFunction::Type::PlainSHA256};
- auto digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>(
- hash_function, *content);
-
- return DirectoryNodeBundle{
- .message = CreateDirectoryNode(dir_name, digest),
- .blob = ArtifactBlob{
- std::move(digest), std::move(*content), /*is_exec=*/false}};
+ auto blob = ArtifactBlob::FromMemory(
+ hash_function, ObjectType::File, *std::move(content));
+ if (not blob.has_value()) {
+ return std::nullopt;
+ }
+ auto const digest = blob->GetDigest();
+ return DirectoryNodeBundle{.message = CreateDirectoryNode(dir_name, digest),
+ .blob = *std::move(blob)};
}
/// \brief Create bundle for protobuf message Command from args strings.
@@ -201,11 +202,12 @@ struct DirectoryNodeBundle final {
if (not content) {
return std::nullopt;
}
- auto digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>(
- request.hash_function, *content);
- return ArtifactBlob{std::move(digest),
- std::move(*content),
- /*is_exec=*/false};
+ auto blob = ArtifactBlob::FromMemory(
+ request.hash_function, ObjectType::File, *std::move(content));
+ if (not blob.has_value()) {
+ return std::nullopt;
+ }
+ return *std::move(blob);
}
/// \brief Create bundle for protobuf message Action from Command.
@@ -240,11 +242,12 @@ struct DirectoryNodeBundle final {
if (not content) {
return std::nullopt;
}
- auto digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>(
- request.hash_function, *content);
- return ArtifactBlob{std::move(digest),
- std::move(*content),
- /*is_exec=*/false};
+ auto blob = ArtifactBlob::FromMemory(
+ request.hash_function, ObjectType::File, *std::move(content));
+ if (not blob.has_value()) {
+ return std::nullopt;
+ }
+ return *std::move(blob);
}
/// \brief Convert `DirectoryTree` to `DirectoryNodeBundle`.