diff options
Diffstat (limited to 'src/buildtool/execution_api')
-rw-r--r-- | src/buildtool/execution_api/common/common_api.cpp | 27 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/common_api.hpp | 14 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/execution_api.hpp | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/git/git_api.hpp | 20 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.hpp | 20 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.cpp | 38 | ||||
-rw-r--r-- | src/buildtool/execution_api/remote/bazel/bazel_api.hpp | 6 |
7 files changed, 64 insertions, 67 deletions
diff --git a/src/buildtool/execution_api/common/common_api.cpp b/src/buildtool/execution_api/common/common_api.cpp index ce124a67..74e52c19 100644 --- a/src/buildtool/execution_api/common/common_api.cpp +++ b/src/buildtool/execution_api/common/common_api.cpp @@ -82,9 +82,8 @@ auto CommonRetrieveToFds( } /// NOLINTNEXTLINE(misc-no-recursion) -auto CommonUploadBlobTree( - BlobTreePtr const& blob_tree, - gsl::not_null<const IExecutionApi*> const& api) noexcept -> bool { +auto CommonUploadBlobTree(BlobTreePtr const& blob_tree, + IExecutionApi const& api) noexcept -> bool { // Create digest list from blobs for batch availability check. auto missing_blobs_info = GetMissingArtifactsInfo<BlobTreePtr>( api, blob_tree->begin(), blob_tree->end(), [](BlobTreePtr const& node) { @@ -115,19 +114,19 @@ auto CommonUploadBlobTree( std::move(node->Blob()), /*exception_is_fatal=*/false, [&api](ArtifactBlobContainer&& blobs) -> bool { - return api->Upload(std::move(blobs), - /*skip_find_missing=*/true); + return api.Upload(std::move(blobs), + /*skip_find_missing=*/true); })) { return false; } } } // Transfer any remaining blobs. - return api->Upload(std::move(container), /*skip_find_missing=*/true); + return api.Upload(std::move(container), /*skip_find_missing=*/true); } auto CommonUploadTreeCompatible( - gsl::not_null<const IExecutionApi*> const& api, + IExecutionApi const& api, DirectoryTreePtr const& build_root, BazelMsgFactory::LinkDigestResolveFunc const& resolve_links) noexcept -> std::optional<ArtifactDigest> { @@ -141,8 +140,8 @@ auto CommonUploadTreeCompatible( ArtifactDigest{blob.digest}, blob.data, blob.is_exec}), /*exception_is_fatal=*/false, [&api](ArtifactBlobContainer&& container) -> bool { - return api->Upload(std::move(container), - /*skip_find_missing=*/false); + return api.Upload(std::move(container), + /*skip_find_missing=*/false); }); }); if (not digest) { @@ -156,14 +155,14 @@ auto CommonUploadTreeCompatible( return oss.str(); }); // Upload remaining blobs. - if (not api->Upload(std::move(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; } return ArtifactDigest{*digest}; } -auto CommonUploadTreeNative(gsl::not_null<const IExecutionApi*> const& api, +auto CommonUploadTreeNative(IExecutionApi const& api, DirectoryTreePtr const& build_root) noexcept -> std::optional<ArtifactDigest> { auto blob_tree = BlobTree::FromDirectoryTree(build_root); @@ -175,14 +174,14 @@ auto CommonUploadTreeNative(gsl::not_null<const 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(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(ArtifactBlobContainer{{tree_blob}}, - /*skip_find_missing=*/true)) { + if (not api.Upload(ArtifactBlobContainer{{tree_blob}}, + /*skip_find_missing=*/true)) { Logger::Log(LogLevel::Debug, "failed to upload tree blob for build root."); return std::nullopt; diff --git a/src/buildtool/execution_api/common/common_api.hpp b/src/buildtool/execution_api/common/common_api.hpp index e35be206..c11180da 100644 --- a/src/buildtool/execution_api/common/common_api.hpp +++ b/src/buildtool/execution_api/common/common_api.hpp @@ -61,7 +61,7 @@ struct MissingArtifactsInfo { /// original given type, or nullopt in case of exceptions. template <typename T> [[nodiscard]] auto GetMissingArtifactsInfo( - gsl::not_null<const IExecutionApi*> const& api, + IExecutionApi const& api, typename std::vector<T>::const_iterator const& begin, typename std::vector<T>::const_iterator const& end, typename std::function<ArtifactDigest(T const&)> const& converter) noexcept @@ -78,25 +78,25 @@ template <typename T> return std::nullopt; } } - res.digests = api->IsAvailable(digests); + res.digests = api.IsAvailable(digests); return res; } /// \brief Upload missing blobs from a given BlobTree. -[[nodiscard]] auto CommonUploadBlobTree( - BlobTreePtr const& blob_tree, - gsl::not_null<const IExecutionApi*> const& api) noexcept -> bool; +[[nodiscard]] auto CommonUploadBlobTree(BlobTreePtr const& blob_tree, + IExecutionApi const& api) noexcept + -> bool; /// \brief Runs the compatible branch of local/bazel UploadTree API. [[nodiscard]] auto CommonUploadTreeCompatible( - gsl::not_null<const IExecutionApi*> const& api, + IExecutionApi const& api, DirectoryTreePtr const& build_root, BazelMsgFactory::LinkDigestResolveFunc const& resolve_links) noexcept -> std::optional<ArtifactDigest>; /// \brief Runs the native branch of local/bazel UploadTree API. [[nodiscard]] auto CommonUploadTreeNative( - gsl::not_null<const IExecutionApi*> const& api, + IExecutionApi const& api, DirectoryTreePtr const& build_root) noexcept -> std::optional<ArtifactDigest>; diff --git a/src/buildtool/execution_api/common/execution_api.hpp b/src/buildtool/execution_api/common/execution_api.hpp index 1a8ee578..5b6743e3 100644 --- a/src/buildtool/execution_api/common/execution_api.hpp +++ b/src/buildtool/execution_api/common/execution_api.hpp @@ -70,7 +70,7 @@ class IExecutionApi { [[nodiscard]] virtual auto RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<std::filesystem::path> const& output_paths, - std::optional<gsl::not_null<IExecutionApi*>> const& alternative = + std::optional<gsl::not_null<const IExecutionApi*>> const& alternative = std::nullopt) const noexcept -> bool = 0; /// \brief Retrieve artifacts from CAS and write to file descriptors. @@ -88,7 +88,7 @@ class IExecutionApi { /// resolved and its containing file artifacts are recursively retrieved. [[nodiscard]] virtual auto RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api) const noexcept -> bool = 0; + IExecutionApi const& api) const noexcept -> bool = 0; /// \brief A variant of RetrieveToCas that is allowed to internally use /// the specified number of threads to carry out the task in parallel. @@ -98,7 +98,7 @@ class IExecutionApi { /// the remote blobs. [[nodiscard]] virtual auto ParallelRetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api, + IExecutionApi const& api, std::size_t /* jobs */, bool /* use_blob_splitting */) const noexcept -> bool { return RetrieveToCas(artifacts_info, api); diff --git a/src/buildtool/execution_api/git/git_api.hpp b/src/buildtool/execution_api/git/git_api.hpp index 2b29fa40..53184988 100644 --- a/src/buildtool/execution_api/git/git_api.hpp +++ b/src/buildtool/execution_api/git/git_api.hpp @@ -54,8 +54,9 @@ class GitApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<std::filesystem::path> const& output_paths, - std::optional<gsl::not_null<IExecutionApi*>> const& /*alternative*/ = - std::nullopt) const noexcept -> bool override { + std::optional< + gsl::not_null<const IExecutionApi*>> const& /*alternative*/ + = std::nullopt) const noexcept -> bool override { if (artifacts_info.size() != output_paths.size()) { Logger::Log(LogLevel::Error, "different number of digests and output paths."); @@ -175,10 +176,9 @@ class GitApi final : public IExecutionApi { // NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api) const noexcept - -> bool override { + IExecutionApi const& api) const noexcept -> bool override { // Return immediately if target CAS is this CAS - if (this == api) { + if (this == &api) { return true; } @@ -238,14 +238,14 @@ class GitApi final : public IExecutionApi { IsExecutableObject(entry->Type())}, /*exception_is_fatal=*/true, [&api](ArtifactBlobContainer&& blobs) -> bool { - return api->Upload(std::move(blobs)); + return api.Upload(std::move(blobs)); })) { return false; } } } // Upload remaining blobs. - if (not api->Upload(std::move(tree_deps_only_blobs))) { + if (not api.Upload(std::move(tree_deps_only_blobs))) { return false; } content = tree->RawData(); @@ -270,15 +270,15 @@ class GitApi final : public IExecutionApi { IsExecutableObject(info.type)}, /*exception_is_fatal=*/true, [&api](ArtifactBlobContainer&& blobs) { - return api->Upload(std::move(blobs), - /*skip_find_missing=*/true); + return api.Upload(std::move(blobs), + /*skip_find_missing=*/true); })) { return false; } } // Upload remaining blobs to remote CAS. - return api->Upload(std::move(container), /*skip_find_missing=*/true); + return api.Upload(std::move(container), /*skip_find_missing=*/true); } [[nodiscard]] auto RetrieveToMemory( diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index fc64e842..928fb5b8 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -78,8 +78,9 @@ class LocalApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<std::filesystem::path> const& output_paths, - std::optional<gsl::not_null<IExecutionApi*>> const& /*alternative*/ = - std::nullopt) const noexcept -> bool final { + std::optional< + gsl::not_null<const IExecutionApi*>> const& /*alternative*/ + = std::nullopt) const noexcept -> bool final { if (artifacts_info.size() != output_paths.size()) { Logger::Log(LogLevel::Error, "different number of digests and output paths."); @@ -171,10 +172,9 @@ class LocalApi final : public IExecutionApi { // NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api) const noexcept -> bool final { - + IExecutionApi const& api) const noexcept -> bool final { // Return immediately if target CAS is this CAS - if (this == api) { + if (this == &api) { return true; } @@ -237,15 +237,15 @@ class LocalApi final : public IExecutionApi { IsExecutableObject(info.type)}, /*exception_is_fatal=*/true, [&api](ArtifactBlobContainer&& blobs) { - return api->Upload(std::move(blobs), - /*skip_find_missing=*/true); + return api.Upload(std::move(blobs), + /*skip_find_missing=*/true); })) { return false; } } // Upload remaining blobs to remote CAS. - return api->Upload(std::move(container), /*skip_find_missing=*/true); + return api.Upload(std::move(container), /*skip_find_missing=*/true); } [[nodiscard]] auto RetrieveToMemory( @@ -299,7 +299,7 @@ class LocalApi final : public IExecutionApi { if (Compatibility::IsCompatible()) { return CommonUploadTreeCompatible( - this, + *this, *build_root, [&cas = storage_->CAS()]( std::vector<bazel_re::Digest> const& digests, @@ -313,7 +313,7 @@ class LocalApi final : public IExecutionApi { }); } - return CommonUploadTreeNative(this, *build_root); + return CommonUploadTreeNative(*this, *build_root); } [[nodiscard]] auto IsAvailable(ArtifactDigest const& digest) const noexcept diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index 04cae278..b475dfe8 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -51,7 +51,7 @@ namespace { [[nodiscard]] auto RetrieveToCas( std::vector<bazel_re::Digest> const& digests, - gsl::not_null<const IExecutionApi*> const& api, + IExecutionApi const& api, std::shared_ptr<BazelNetwork> const& network, std::unordered_map<ArtifactDigest, Artifact::ObjectInfo> const& info_map) noexcept -> bool { @@ -78,8 +78,8 @@ namespace { std::move(blob), /*exception_is_fatal=*/true, [&api](ArtifactBlobContainer&& blobs) { - return api->Upload(std::move(blobs), - /*skip_find_missing=*/true); + return api.Upload(std::move(blobs), + /*skip_find_missing=*/true); })) { return false; } @@ -93,19 +93,19 @@ namespace { } // Upload remaining blobs to other CAS. - return api->Upload(std::move(container), /*skip_find_missing=*/true); + return api.Upload(std::move(container), /*skip_find_missing=*/true); } [[nodiscard]] auto RetrieveToCasSplitted( Artifact::ObjectInfo const& artifact_info, - gsl::not_null<const IExecutionApi*> const& this_api, - gsl::not_null<const IExecutionApi*> const& other_api, + IExecutionApi const& this_api, + IExecutionApi const& other_api, std::shared_ptr<BazelNetwork> const& network, std::unordered_map<ArtifactDigest, Artifact::ObjectInfo> const& info_map) noexcept -> bool { // Split blob into chunks at the remote side and retrieve chunk digests. - auto chunk_digests = this_api->SplitBlob(artifact_info.digest); + auto chunk_digests = this_api.SplitBlob(artifact_info.digest); if (not chunk_digests) { // If blob splitting failed, fall back to regular fetching. return ::RetrieveToCas( @@ -118,7 +118,7 @@ namespace { auto unique_digests = std::vector<ArtifactDigest>{digest_set.begin(), digest_set.end()}; - auto missing_artifact_digests = other_api->IsAvailable(unique_digests); + auto missing_artifact_digests = other_api.IsAvailable(unique_digests); auto missing_digests = std::vector<bazel_re::Digest>{}; missing_digests.reserve(digest_set.size()); @@ -133,7 +133,7 @@ namespace { } // Assemble blob from chunks. - auto digest = other_api->SpliceBlob(artifact_info.digest, *chunk_digests); + auto digest = other_api.SpliceBlob(artifact_info.digest, *chunk_digests); if (not digest) { // If blob splicing failed, fall back to regular fetching. return ::RetrieveToCas( @@ -221,7 +221,7 @@ auto BazelApi::CreateAction( [[nodiscard]] auto BazelApi::RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<std::filesystem::path> const& output_paths, - std::optional<gsl::not_null<IExecutionApi*>> const& alternative) + std::optional<gsl::not_null<const IExecutionApi*>> const& alternative) const noexcept -> bool { if (artifacts_info.size() != output_paths.size()) { Logger::Log(LogLevel::Warning, @@ -315,10 +315,9 @@ auto BazelApi::CreateAction( // NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto BazelApi::RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api) const noexcept -> bool { - + IExecutionApi const& api) const noexcept -> bool { // Return immediately if target CAS is this CAS - if (this == api) { + if (this == &api) { return true; } @@ -361,12 +360,11 @@ auto BazelApi::CreateAction( /// NOLINTNEXTLINE(misc-no-recursion) [[nodiscard]] auto BazelApi::ParallelRetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api, + IExecutionApi const& api, std::size_t jobs, bool use_blob_splitting) const noexcept -> bool { - // Return immediately if target CAS is this CAS - if (this == api) { + if (this == &api) { return true; } @@ -410,9 +408,9 @@ auto BazelApi::CreateAction( &info_map = missing_artifacts_info->back_map, use_blob_splitting]() { if (use_blob_splitting and network_->BlobSplitSupport() and - api->BlobSpliceSupport() + api.BlobSpliceSupport() ? ::RetrieveToCasSplitted( - info, this, api, network_, info_map) + info, *this, api, network_, info_map) : ::RetrieveToCas( {info.digest}, api, network_, info_map)) { return; @@ -461,7 +459,7 @@ auto BazelApi::CreateAction( if (Compatibility::IsCompatible()) { return CommonUploadTreeCompatible( - this, + *this, *build_root, [&network = network_](std::vector<bazel_re::Digest> const& digests, std::vector<std::string>* targets) { @@ -475,7 +473,7 @@ auto BazelApi::CreateAction( }); } - return CommonUploadTreeNative(this, *build_root); + return CommonUploadTreeNative(*this, *build_root); } [[nodiscard]] auto BazelApi::IsAvailable( diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp index 62080bf1..a9149450 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.hpp @@ -62,7 +62,7 @@ class BazelApi final : public IExecutionApi { [[nodiscard]] auto RetrieveToPaths( std::vector<Artifact::ObjectInfo> const& artifacts_info, std::vector<std::filesystem::path> const& output_paths, - std::optional<gsl::not_null<IExecutionApi*>> const& alternative = + std::optional<gsl::not_null<const IExecutionApi*>> const& alternative = std::nullopt) const noexcept -> bool final; [[nodiscard]] auto RetrieveToFds( @@ -72,13 +72,13 @@ class BazelApi final : public IExecutionApi { [[nodiscard]] auto ParallelRetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api, + IExecutionApi const& api, std::size_t jobs, bool use_blob_splitting) const noexcept -> bool final; [[nodiscard]] auto RetrieveToCas( std::vector<Artifact::ObjectInfo> const& artifacts_info, - gsl::not_null<IExecutionApi*> const& api) const noexcept -> bool final; + IExecutionApi const& api) const noexcept -> bool final; [[nodiscard]] auto Upload(ArtifactBlobContainer&& blobs, bool skip_find_missing) const noexcept |