summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/common/TARGETS5
-rw-r--r--src/buildtool/execution_api/common/artifact_blob_container.hpp23
-rw-r--r--src/buildtool/execution_api/common/blob_tree.cpp19
-rw-r--r--src/buildtool/execution_api/common/blob_tree.hpp11
-rw-r--r--src/buildtool/execution_api/common/common_api.cpp13
5 files changed, 48 insertions, 23 deletions
diff --git a/src/buildtool/execution_api/common/TARGETS b/src/buildtool/execution_api/common/TARGETS
index 0eac0c15..1ce6a1da 100644
--- a/src/buildtool/execution_api/common/TARGETS
+++ b/src/buildtool/execution_api/common/TARGETS
@@ -8,10 +8,12 @@
, "execution_response.hpp"
, "tree_reader.hpp"
, "stream_dumper.hpp"
+ , "artifact_blob_container.hpp"
]
, "srcs": ["execution_api.cpp"]
, "deps":
- [ ["@", "gsl", "", "gsl"]
+ [ "content_blob_container"
+ , ["@", "gsl", "", "gsl"]
, ["src/buildtool/common", "common"]
, ["src/buildtool/crypto", "hash_function"]
, ["src/buildtool/execution_api/bazel_msg", "bazel_msg"]
@@ -78,7 +80,6 @@
, "srcs": ["blob_tree.cpp"]
, "deps":
[ "common"
- , ["src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["src/buildtool/execution_api/bazel_msg", "directory_tree"]
, ["@", "gsl", "", "gsl"]
, ["src/buildtool/compatibility", "compatibility"]
diff --git a/src/buildtool/execution_api/common/artifact_blob_container.hpp b/src/buildtool/execution_api/common/artifact_blob_container.hpp
new file mode 100644
index 00000000..7aea21ab
--- /dev/null
+++ b/src/buildtool/execution_api/common/artifact_blob_container.hpp
@@ -0,0 +1,23 @@
+// 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_EXECUTION_API_COMMON_ARTIFACT_BLOB_CONTAINER_HPP
+#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_ARTIFACT_BLOB_CONTAINER_HPP
+
+#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/execution_api/common/content_blob_container.hpp"
+
+using ArtifactBlob = ContentBlob<ArtifactDigest>;
+
+#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_ARTIFACT_BLOB_CONTAINER_HPP
diff --git a/src/buildtool/execution_api/common/blob_tree.cpp b/src/buildtool/execution_api/common/blob_tree.cpp
index 0954220e..6e04d55f 100644
--- a/src/buildtool/execution_api/common/blob_tree.cpp
+++ b/src/buildtool/execution_api/common/blob_tree.cpp
@@ -18,8 +18,6 @@
#include <variant>
#include "src/buildtool/common/artifact.hpp"
-#include "src/buildtool/common/bazel_types.hpp"
-#include "src/buildtool/compatibility/native_support.hpp"
#include "src/buildtool/file_system/git_repo.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/utils/cpp/hex_string.hpp"
@@ -39,8 +37,7 @@ auto BlobTree::FromDirectoryTree(DirectoryTreePtr const& tree,
if (not blob_tree) {
return std::nullopt;
}
- auto raw_id = FromHexString(NativeSupport::Unprefix(
- (*blob_tree)->Blob().digest.hash()));
+ auto raw_id = FromHexString((*blob_tree)->Blob().digest.hash());
if (not raw_id) {
return std::nullopt;
}
@@ -64,14 +61,12 @@ auto BlobTree::FromDirectoryTree(DirectoryTreePtr const& tree,
}
}
if (auto git_tree = GitRepo::CreateShallowTree(entries)) {
- bazel_re::Digest digest{};
- digest.set_hash(NativeSupport::Prefix(ToHexString(git_tree->first),
- /*is_tree=*/true));
- digest.set_size_bytes(
- gsl::narrow<google::protobuf::int64>(git_tree->second.size()));
- return std::make_shared<BlobTree>(BazelBlob{digest,
- git_tree->second,
- /*is_exec=*/false},
+ ArtifactDigest digest{ToHexString(git_tree->first),
+ git_tree->second.size(),
+ /*is_tree=*/true};
+ return std::make_shared<BlobTree>(ArtifactBlob{std::move(digest),
+ git_tree->second,
+ /*is_exec=*/false},
nodes);
}
} catch (...) {
diff --git a/src/buildtool/execution_api/common/blob_tree.hpp b/src/buildtool/execution_api/common/blob_tree.hpp
index 59e58410..ad462aab 100644
--- a/src/buildtool/execution_api/common/blob_tree.hpp
+++ b/src/buildtool/execution_api/common/blob_tree.hpp
@@ -23,8 +23,8 @@
#include "gsl/gsl"
#include "src/buildtool/compatibility/native_support.hpp"
-#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
#include "src/buildtool/execution_api/bazel_msg/directory_tree.hpp"
+#include "src/buildtool/execution_api/common/artifact_blob_container.hpp"
class BlobTree;
using BlobTreePtr = gsl::not_null<std::shared_ptr<BlobTree>>;
@@ -33,12 +33,13 @@ using BlobTreePtr = gsl::not_null<std::shared_ptr<BlobTree>>;
/// upload.
class BlobTree {
public:
- BlobTree(BazelBlob blob, std::vector<BlobTreePtr> nodes)
+ BlobTree(ArtifactBlob blob, std::vector<BlobTreePtr> nodes)
: blob_{std::move(blob)}, nodes_{std::move(nodes)} {}
- [[nodiscard]] auto Blob() const noexcept -> BazelBlob { return blob_; }
+ [[nodiscard]] auto Blob() const noexcept -> ArtifactBlob { return blob_; }
[[nodiscard]] auto IsTree() const noexcept -> bool {
- return NativeSupport::IsTree(blob_.digest.hash());
+ return NativeSupport::IsTree(
+ static_cast<bazel_re::Digest>(blob_.digest).hash());
}
/// \brief Create a `BlobTree` from a `DirectoryTree`.
@@ -52,7 +53,7 @@ class BlobTree {
[[nodiscard]] auto size() const noexcept { return nodes_.size(); }
private:
- BazelBlob blob_;
+ ArtifactBlob blob_;
std::vector<BlobTreePtr> nodes_;
};
diff --git a/src/buildtool/execution_api/common/common_api.cpp b/src/buildtool/execution_api/common/common_api.cpp
index c3a13fd8..eac0a1f8 100644
--- a/src/buildtool/execution_api/common/common_api.cpp
+++ b/src/buildtool/execution_api/common/common_api.cpp
@@ -112,7 +112,10 @@ auto CommonUploadBlobTree(BlobTreePtr const& blob_tree,
}
// Store blob.
try {
- container.Emplace(node->Blob());
+ BazelBlob bazel_blob{node->Blob().digest,
+ node->Blob().data,
+ node->Blob().is_exec};
+ container.Emplace(std::move(bazel_blob));
} catch (...) {
return false;
}
@@ -161,18 +164,20 @@ auto CommonUploadTreeNative(gsl::not_null<IExecutionApi*> const& api,
auto tree_blob = (*blob_tree)->Blob();
// Upload blob tree if tree is not available at the remote side (content
// first).
- if (not api->IsAvailable(ArtifactDigest{tree_blob.digest})) {
+ if (not api->IsAvailable(tree_blob.digest)) {
if (not CommonUploadBlobTree(*blob_tree, api)) {
Logger::Log(LogLevel::Debug,
"failed to upload blob tree for build root.");
return std::nullopt;
}
- if (not api->Upload(BazelBlobContainer{{tree_blob}},
+ BazelBlob bazel_blob{
+ tree_blob.digest, tree_blob.data, tree_blob.is_exec};
+ if (not api->Upload(BazelBlobContainer{{bazel_blob}},
/*skip_find_missing=*/true)) {
Logger::Log(LogLevel::Debug,
"failed to upload tree blob for build root.");
return std::nullopt;
}
}
- return ArtifactDigest{tree_blob.digest};
+ return tree_blob.digest;
}