summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-05-27 14:57:15 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-05-28 16:19:19 +0200
commitfd8ad0f561dd253bf7399ce9a4594242e918ca25 (patch)
treed72aa981cafc03d0f1aded827cb621fabe541fff /src
parent9bdd30f307b83a3901250a51780f308f5c4a0065 (diff)
downloadjustbuild-fd8ad0f561dd253bf7399ce9a4594242e918ca25.tar.gz
Use ArtifactBlobContainer in IExecutionApi
...instead of BazelBlobContainer to not bring bazel_re::Digest to IExecutionApi.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/common/TARGETS2
-rw-r--r--src/buildtool/execution_api/common/artifact_blob_container.hpp1
-rw-r--r--src/buildtool/execution_api/common/common_api.cpp20
-rw-r--r--src/buildtool/execution_api/common/execution_api.cpp6
-rw-r--r--src/buildtool/execution_api/common/execution_api.hpp4
-rw-r--r--src/buildtool/execution_api/git/git_api.hpp34
-rw-r--r--src/buildtool/execution_api/local/local_api.hpp25
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_api.cpp27
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_api.hpp2
-rw-r--r--src/buildtool/execution_engine/executor/executor.hpp29
-rw-r--r--src/buildtool/graph_traverser/graph_traverser.hpp6
11 files changed, 84 insertions, 72 deletions
diff --git a/src/buildtool/execution_api/common/TARGETS b/src/buildtool/execution_api/common/TARGETS
index 1ce6a1da..956fb3a3 100644
--- a/src/buildtool/execution_api/common/TARGETS
+++ b/src/buildtool/execution_api/common/TARGETS
@@ -16,7 +16,6 @@
, ["@", "gsl", "", "gsl"]
, ["src/buildtool/common", "common"]
, ["src/buildtool/crypto", "hash_function"]
- , ["src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["src/buildtool/execution_api/bazel_msg", "bazel_msg_factory"]
, ["src/buildtool/file_system", "file_system_manager"]
, ["src/buildtool/file_system", "object_type"]
@@ -25,6 +24,7 @@
, ["src/utils/cpp", "gsl"]
, ["src/utils/cpp", "hex_string"]
, ["src/buildtool/file_system", "git_repo"]
+ , ["src/buildtool/execution_engine/dag", "dag"]
]
, "stage": ["src", "buildtool", "execution_api", "common"]
}
diff --git a/src/buildtool/execution_api/common/artifact_blob_container.hpp b/src/buildtool/execution_api/common/artifact_blob_container.hpp
index 7aea21ab..32f3fc38 100644
--- a/src/buildtool/execution_api/common/artifact_blob_container.hpp
+++ b/src/buildtool/execution_api/common/artifact_blob_container.hpp
@@ -19,5 +19,6 @@
#include "src/buildtool/execution_api/common/content_blob_container.hpp"
using ArtifactBlob = ContentBlob<ArtifactDigest>;
+using ArtifactBlobContainer = ContentBlobContainer<ArtifactDigest>;
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_ARTIFACT_BLOB_CONTAINER_HPP
diff --git a/src/buildtool/execution_api/common/common_api.cpp b/src/buildtool/execution_api/common/common_api.cpp
index eac0a1f8..b14c81dc 100644
--- a/src/buildtool/execution_api/common/common_api.cpp
+++ b/src/buildtool/execution_api/common/common_api.cpp
@@ -99,7 +99,7 @@ auto CommonUploadBlobTree(BlobTreePtr const& blob_tree,
}
// Process missing blobs.
- BazelBlobContainer container;
+ ArtifactBlobContainer container;
for (auto const& digest : missing_blobs_info->digests) {
if (auto it = missing_blobs_info->back_map.find(digest);
it != missing_blobs_info->back_map.end()) {
@@ -112,17 +112,14 @@ auto CommonUploadBlobTree(BlobTreePtr const& blob_tree,
}
// Store blob.
try {
- BazelBlob bazel_blob{node->Blob().digest,
- node->Blob().data,
- node->Blob().is_exec};
- container.Emplace(std::move(bazel_blob));
+ container.Emplace(node->Blob());
} catch (...) {
return false;
}
}
}
- return api->Upload(container, /*skip_find_missing=*/true);
+ return api->Upload(std::move(container), /*skip_find_missing=*/true);
}
auto CommonUploadTreeCompatible(
@@ -130,10 +127,11 @@ auto CommonUploadTreeCompatible(
DirectoryTreePtr const& build_root,
BazelMsgFactory::LinkDigestResolveFunc const& resolve_links) noexcept
-> std::optional<ArtifactDigest> {
- BazelBlobContainer blobs{};
+ ArtifactBlobContainer blobs{};
auto digest = BazelMsgFactory::CreateDirectoryDigestFromTree(
build_root, resolve_links, [&blobs](BazelBlob&& blob) {
- blobs.Emplace(std::move(blob));
+ blobs.Emplace(ArtifactBlob{
+ ArtifactDigest{blob.digest}, blob.data, blob.is_exec});
});
if (not digest) {
Logger::Log(LogLevel::Debug, "failed to create digest for build root.");
@@ -145,7 +143,7 @@ auto CommonUploadTreeCompatible(
oss << fmt::format(" - root digest: {}", digest->hash()) << std::endl;
return oss.str();
});
- if (not api->Upload(blobs, /*skip_find_missing=*/false)) {
+ if (not api->Upload(std::move(blobs), /*skip_find_missing=*/false)) {
Logger::Log(LogLevel::Debug, "failed to upload blobs for build root.");
return std::nullopt;
}
@@ -170,9 +168,7 @@ auto CommonUploadTreeNative(gsl::not_null<IExecutionApi*> const& api,
"failed to upload blob tree for build root.");
return std::nullopt;
}
- BazelBlob bazel_blob{
- tree_blob.digest, tree_blob.data, tree_blob.is_exec};
- if (not api->Upload(BazelBlobContainer{{bazel_blob}},
+ if (not api->Upload(ArtifactBlobContainer{{tree_blob}},
/*skip_find_missing=*/true)) {
Logger::Log(LogLevel::Debug,
"failed to upload tree blob for build root.");
diff --git a/src/buildtool/execution_api/common/execution_api.cpp b/src/buildtool/execution_api/common/execution_api.cpp
index b6b16a0f..d3fcb36f 100644
--- a/src/buildtool/execution_api/common/execution_api.cpp
+++ b/src/buildtool/execution_api/common/execution_api.cpp
@@ -43,13 +43,13 @@
Ensures(false); // unreachable
return false;
}
- BazelBlobContainer container{};
+ ArtifactBlobContainer container{};
try {
auto exec = IsExecutableObject(type);
- container.Emplace(BazelBlob{digest, *data, exec});
+ container.Emplace(ArtifactBlob{digest, *data, exec});
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error, "failed to emplace blob: ", ex.what());
return false;
}
- return Upload(container);
+ return Upload(std::move(container));
}
diff --git a/src/buildtool/execution_api/common/execution_api.hpp b/src/buildtool/execution_api/common/execution_api.hpp
index c4b51780..42554a48 100644
--- a/src/buildtool/execution_api/common/execution_api.hpp
+++ b/src/buildtool/execution_api/common/execution_api.hpp
@@ -26,7 +26,7 @@
#include "gsl/gsl"
#include "src/buildtool/common/artifact.hpp" // Artifact::ObjectInfo
#include "src/buildtool/common/artifact_digest.hpp"
-#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
+#include "src/buildtool/execution_api/common/artifact_blob_container.hpp"
#include "src/buildtool/execution_api/common/execution_action.hpp"
#include "src/buildtool/execution_engine/dag/dag.hpp"
#include "src/buildtool/file_system/object_type.hpp"
@@ -116,7 +116,7 @@ class IExecutionApi {
/// \param blobs Container of blobs to upload.
/// \param skip_find_missing Skip finding missing blobs, just upload all.
/// NOLINTNEXTLINE(google-default-arguments)
- [[nodiscard]] virtual auto Upload(BazelBlobContainer const& blobs,
+ [[nodiscard]] virtual auto Upload(ArtifactBlobContainer&& blobs,
bool skip_find_missing = false) noexcept
-> bool = 0;
diff --git a/src/buildtool/execution_api/git/git_api.hpp b/src/buildtool/execution_api/git/git_api.hpp
index b26654f5..914d4c19 100644
--- a/src/buildtool/execution_api/git/git_api.hpp
+++ b/src/buildtool/execution_api/git/git_api.hpp
@@ -194,7 +194,7 @@ class GitApi final : public IExecutionApi {
// Collect blobs of missing artifacts from local CAS. Trees are
// processed recursively before any blob is uploaded.
- BazelBlobContainer container{};
+ ArtifactBlobContainer container{};
for (auto const& dgst : missing_artifacts_info->digests) {
auto const& info = missing_artifacts_info->back_map[dgst];
std::optional<std::string> content;
@@ -205,7 +205,7 @@ class GitApi final : public IExecutionApi {
if (not tree) {
return false;
}
- BazelBlobContainer tree_deps_only_blobs{};
+ ArtifactBlobContainer tree_deps_only_blobs{};
for (auto const& [path, entry] : *tree) {
if (entry->IsTree()) {
if (not RetrieveToCas(
@@ -227,10 +227,10 @@ class GitApi final : public IExecutionApi {
auto digest =
ArtifactDigest::Create<ObjectType::File>(*content);
try {
- tree_deps_only_blobs.Emplace(
- BazelBlob{digest,
- *content,
- IsExecutableObject(entry->Type())});
+ tree_deps_only_blobs.Emplace(ArtifactBlob{
+ digest,
+ *content,
+ IsExecutableObject(entry->Type())});
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error,
"failed to emplace blob: ",
@@ -239,7 +239,7 @@ class GitApi final : public IExecutionApi {
}
}
}
- if (not api->Upload(tree_deps_only_blobs)) {
+ if (not api->Upload(std::move(tree_deps_only_blobs))) {
return false;
}
content = tree->RawData();
@@ -251,17 +251,15 @@ class GitApi final : public IExecutionApi {
return false;
}
- ArtifactDigest digest;
- if (IsTreeObject(info.type)) {
- digest = ArtifactDigest::Create<ObjectType::Tree>(*content);
- }
- else {
- digest = ArtifactDigest::Create<ObjectType::File>(*content);
- }
+ ArtifactDigest digest =
+ IsTreeObject(info.type)
+ ? ArtifactDigest::Create<ObjectType::Tree>(*content)
+ : ArtifactDigest::Create<ObjectType::File>(*content);
try {
- container.Emplace(
- BazelBlob{digest, *content, IsExecutableObject(info.type)});
+ container.Emplace(ArtifactBlob{std::move(digest),
+ *content,
+ IsExecutableObject(info.type)});
} catch (std::exception const& ex) {
Logger::Log(
LogLevel::Error, "failed to emplace blob: ", ex.what());
@@ -270,7 +268,7 @@ class GitApi final : public IExecutionApi {
}
// Upload blobs to remote CAS.
- return api->Upload(container, /*skip_find_missing=*/true);
+ return api->Upload(std::move(container), /*skip_find_missing=*/true);
}
[[nodiscard]] auto RetrieveToMemory(
@@ -280,7 +278,7 @@ class GitApi final : public IExecutionApi {
}
/// NOLINTNEXTLINE(google-default-arguments)
- [[nodiscard]] auto Upload(BazelBlobContainer const& /*blobs*/,
+ [[nodiscard]] auto Upload(ArtifactBlobContainer&& /*blobs*/,
bool /*skip_find_missing*/ = false) noexcept
-> bool override {
// Upload to git cas not supported
diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp
index 978d3968..153f9971 100644
--- a/src/buildtool/execution_api/local/local_api.hpp
+++ b/src/buildtool/execution_api/local/local_api.hpp
@@ -191,7 +191,7 @@ class LocalApi final : public IExecutionApi {
// Collect blobs of missing artifacts from local CAS. Trees are
// processed recursively before any blob is uploaded.
- BazelBlobContainer container{};
+ ArtifactBlobContainer container{};
for (auto const& dgst : missing_artifacts_info->digests) {
auto const& info = missing_artifacts_info->back_map[dgst];
// Recursively process trees.
@@ -222,18 +222,16 @@ class LocalApi final : public IExecutionApi {
// Regenerate digest since object infos read by
// storage_->ReadTreeInfos() will contain 0 as size.
- ArtifactDigest digest;
- if (IsTreeObject(info.type)) {
- digest = ArtifactDigest::Create<ObjectType::Tree>(*content);
- }
- else {
- digest = ArtifactDigest::Create<ObjectType::File>(*content);
- }
+ ArtifactDigest digest =
+ IsTreeObject(info.type)
+ ? ArtifactDigest::Create<ObjectType::Tree>(*content)
+ : ArtifactDigest::Create<ObjectType::File>(*content);
// Collect blob.
try {
- container.Emplace(
- BazelBlob{digest, *content, IsExecutableObject(info.type)});
+ container.Emplace(ArtifactBlob{std::move(digest),
+ *content,
+ IsExecutableObject(info.type)});
} catch (std::exception const& ex) {
Logger::Log(
LogLevel::Error, "failed to emplace blob: ", ex.what());
@@ -242,7 +240,7 @@ class LocalApi final : public IExecutionApi {
}
// Upload blobs to remote CAS.
- return api->Upload(container, /*skip_find_missing=*/true);
+ return api->Upload(std::move(container), /*skip_find_missing=*/true);
}
[[nodiscard]] auto RetrieveToMemory(
@@ -267,11 +265,12 @@ class LocalApi final : public IExecutionApi {
return content;
}
- [[nodiscard]] auto Upload(BazelBlobContainer const& blobs,
+ [[nodiscard]] auto Upload(ArtifactBlobContainer&& blobs,
bool /*skip_find_missing*/) noexcept
-> bool final {
for (auto const& blob : blobs.Blobs()) {
- auto const is_tree = NativeSupport::IsTree(blob.digest.hash());
+ auto const is_tree = NativeSupport::IsTree(
+ static_cast<bazel_re::Digest>(blob.digest).hash());
auto cas_digest =
is_tree ? storage_->CAS().StoreTree(blob.data)
: storage_->CAS().StoreBlob(blob.data, blob.is_exec);
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp
index 33561e91..e56228eb 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp
@@ -60,7 +60,7 @@ namespace {
auto reader = network->ReadBlobs(digests);
auto blobs = reader.Next();
std::size_t count{};
- BazelBlobContainer container{};
+ ArtifactBlobContainer container{};
while (not blobs.empty()) {
if (count + blobs.size() > size) {
Logger::Log(LogLevel::Warning,
@@ -73,7 +73,7 @@ namespace {
auto exec = info_map.contains(digest)
? IsExecutableObject(info_map.at(digest).type)
: false;
- container.Emplace(BazelBlob{blob.digest, blob.data, exec});
+ container.Emplace(ArtifactBlob{digest, blob.data, exec});
} catch (std::exception const& ex) {
Logger::Log(
LogLevel::Warning, "failed to emplace blob: ", ex.what());
@@ -90,7 +90,7 @@ namespace {
}
// Upload blobs to other CAS.
- return api->Upload(container, /*skip_find_missing=*/true);
+ return api->Upload(std::move(container), /*skip_find_missing=*/true);
}
[[nodiscard]] auto RetrieveToCasSplitted(
@@ -166,6 +166,21 @@ namespace {
return true;
}
+[[nodiscard]] auto ConvertToBazelBlobContainer(
+ ArtifactBlobContainer&& container) noexcept
+ -> std::optional<BazelBlobContainer> {
+ std::vector<BazelBlob> blobs;
+ try {
+ blobs.reserve(container.Size());
+ for (const auto& blob : container.Blobs()) {
+ blobs.emplace_back(blob.digest, blob.data, blob.is_exec);
+ }
+ } catch (...) {
+ return std::nullopt;
+ }
+ return BazelBlobContainer{std::move(blobs)};
+};
+
} // namespace
BazelApi::BazelApi(std::string const& instance_name,
@@ -422,9 +437,11 @@ auto BazelApi::CreateAction(
return std::nullopt;
}
-[[nodiscard]] auto BazelApi::Upload(BazelBlobContainer const& blobs,
+[[nodiscard]] auto BazelApi::Upload(ArtifactBlobContainer&& blobs,
bool skip_find_missing) noexcept -> bool {
- return network_->UploadBlobs(blobs, skip_find_missing);
+ auto bazel_blobs = ConvertToBazelBlobContainer(std::move(blobs));
+ return bazel_blobs ? network_->UploadBlobs(*bazel_blobs, skip_find_missing)
+ : false;
}
[[nodiscard]] auto BazelApi::UploadTree(
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp
index b96148b1..9d6f2964 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp
@@ -80,7 +80,7 @@ class BazelApi final : public IExecutionApi {
std::vector<Artifact::ObjectInfo> const& artifacts_info,
gsl::not_null<IExecutionApi*> const& api) noexcept -> bool final;
- [[nodiscard]] auto Upload(BazelBlobContainer const& blobs,
+ [[nodiscard]] auto Upload(ArtifactBlobContainer&& blobs,
bool skip_find_missing) noexcept -> bool final;
[[nodiscard]] auto UploadTree(
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp
index 7f931cbd..2f14446a 100644
--- a/src/buildtool/execution_engine/executor/executor.hpp
+++ b/src/buildtool/execution_engine/executor/executor.hpp
@@ -295,7 +295,7 @@ class ExecutorImpl {
}
// upload missing entries (blobs or trees)
- BazelBlobContainer container;
+ ArtifactBlobContainer container;
for (auto const& digest : missing_digests) {
if (auto it = entry_map.find(digest); it != entry_map.end()) {
auto const& entry = it->second;
@@ -304,10 +304,10 @@ class ExecutorImpl {
return false;
}
try {
- container.Emplace(std::move(
- BazelBlob{digest,
- std::move(*content),
- IsExecutableObject(entry->Type())}));
+ container.Emplace(
+ ArtifactBlob{digest,
+ std::move(*content),
+ IsExecutableObject(entry->Type())});
} catch (std::exception const& ex) {
Logger::Log(LogLevel::Error,
"failed to create blob with: ",
@@ -317,7 +317,7 @@ class ExecutorImpl {
}
}
- return api->Upload(container, /*skip_find_missing=*/true);
+ return api->Upload(std::move(container), /*skip_find_missing=*/true);
}
/// \brief Lookup blob via digest in local git repositories and upload.
@@ -360,10 +360,11 @@ class ExecutorImpl {
return false;
}
- // upload artifact content
- auto container = BazelBlobContainer{{BazelBlob{
- info.digest, std::move(*content), IsExecutableObject(info.type)}}};
- return api->Upload(container, /*skip_find_missing=*/true);
+ return api->Upload(ArtifactBlobContainer{{ArtifactBlob{
+ info.digest,
+ std::move(*content),
+ IsExecutableObject(info.type)}}},
+ /*skip_find_missing=*/true);
}
[[nodiscard]] static auto ReadGitBlob(
@@ -447,10 +448,10 @@ class ExecutorImpl {
return std::nullopt;
}
auto digest = ArtifactDigest::Create<ObjectType::File>(*content);
- if (not api->Upload(BazelBlobContainer{
- {BazelBlob{digest,
- std::move(*content),
- IsExecutableObject(*object_type)}}})) {
+ if (not api->Upload(ArtifactBlobContainer{
+ {ArtifactBlob{digest,
+ std::move(*content),
+ IsExecutableObject(*object_type)}}})) {
return std::nullopt;
}
return Artifact::ObjectInfo{.digest = std::move(digest),
diff --git a/src/buildtool/graph_traverser/graph_traverser.hpp b/src/buildtool/graph_traverser/graph_traverser.hpp
index 3f86568f..f10f96d5 100644
--- a/src/buildtool/graph_traverser/graph_traverser.hpp
+++ b/src/buildtool/graph_traverser/graph_traverser.hpp
@@ -322,7 +322,7 @@ class GraphTraverser {
/// \param[in] blobs blobs to be uploaded
[[nodiscard]] auto UploadBlobs(
std::vector<std::string> const& blobs) const noexcept -> bool {
- BazelBlobContainer container;
+ ArtifactBlobContainer container;
for (auto const& blob : blobs) {
auto digest = ArtifactDigest::Create<ObjectType::File>(blob);
Logger::Log(logger_, LogLevel::Trace, [&]() {
@@ -334,7 +334,7 @@ class GraphTraverser {
});
try {
container.Emplace(
- BazelBlob{std::move(digest), blob, /*is_exec=*/false});
+ ArtifactBlob{std::move(digest), blob, /*is_exec=*/false});
} catch (std::exception const& ex) {
Logger::Log(logger_,
LogLevel::Error,
@@ -343,7 +343,7 @@ class GraphTraverser {
return false;
}
}
- return remote_api_->Upload(container);
+ return remote_api_->Upload(std::move(container));
}
/// \brief Adds the artifacts to be retrieved to the graph