diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-29 11:35:37 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-30 17:17:09 +0200 |
commit | d551ef4acdf1732a145724b70f65be5fbe4052b0 (patch) | |
tree | 0cd3d2da73907d5d142b6b8c6b92304ed0a9a17e | |
parent | 8520a8fe2b2fc20940ed6457971a8de179343449 (diff) | |
download | justbuild-d551ef4acdf1732a145724b70f65be5fbe4052b0.tar.gz |
Replace bazel_re::Digest in LocalCAS::{...}Path
...with ArtifactDigest.
-rw-r--r-- | src/buildtool/execution_api/execution_service/bytestream_server.cpp | 5 | ||||
-rw-r--r-- | src/buildtool/execution_api/execution_service/cas_utils.cpp | 8 | ||||
-rw-r--r-- | src/buildtool/execution_api/execution_service/execution_server.cpp | 14 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_response.hpp | 10 | ||||
-rw-r--r-- | src/buildtool/storage/local_ac.tpp | 2 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.hpp | 16 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.tpp | 10 | ||||
-rw-r--r-- | test/buildtool/storage/large_object_cas.test.cpp | 35 |
9 files changed, 59 insertions, 45 deletions
diff --git a/src/buildtool/execution_api/execution_service/bytestream_server.cpp b/src/buildtool/execution_api/execution_service/bytestream_server.cpp index 32adba91..0f77542d 100644 --- a/src/buildtool/execution_api/execution_service/bytestream_server.cpp +++ b/src/buildtool/execution_api/execution_service/bytestream_server.cpp @@ -73,12 +73,11 @@ auto BytestreamServiceImpl::Read( if (NativeSupport::IsTree(*hash)) { ArtifactDigest dgst{NativeSupport::Unprefix(*hash), 0, true}; - path = storage_.CAS().TreePath(static_cast<bazel_re::Digest>(dgst)); + path = storage_.CAS().TreePath(dgst); } else { ArtifactDigest dgst{NativeSupport::Unprefix(*hash), 0, false}; - path = - storage_.CAS().BlobPath(static_cast<bazel_re::Digest>(dgst), false); + path = storage_.CAS().BlobPath(dgst, false); } if (not path) { auto str = fmt::format("could not find {}", *hash); diff --git a/src/buildtool/execution_api/execution_service/cas_utils.cpp b/src/buildtool/execution_api/execution_service/cas_utils.cpp index 592cd6ce..e92a2239 100644 --- a/src/buildtool/execution_api/execution_service/cas_utils.cpp +++ b/src/buildtool/execution_api/execution_service/cas_utils.cpp @@ -50,9 +50,11 @@ auto CASUtils::SplitBlobIdentity(bazel_re::Digest const& blob_digest, -> expected<std::vector<bazel_re::Digest>, grpc::Status> { // Check blob existence. - auto path = NativeSupport::IsTree(blob_digest.hash()) - ? storage.CAS().TreePath(blob_digest) - : storage.CAS().BlobPath(blob_digest, false); + auto path = + NativeSupport::IsTree(blob_digest.hash()) + ? storage.CAS().TreePath(static_cast<ArtifactDigest>(blob_digest)) + : storage.CAS().BlobPath(static_cast<ArtifactDigest>(blob_digest), + false); if (not path) { return unexpected{ grpc::Status{grpc::StatusCode::NOT_FOUND, diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp index 16202975..b862a03d 100644 --- a/src/buildtool/execution_api/execution_service/execution_server.cpp +++ b/src/buildtool/execution_api/execution_service/execution_server.cpp @@ -378,8 +378,8 @@ namespace { if (auto error_msg = IsAHash(request.action_digest().hash())) { return unexpected{std::move(*error_msg)}; } - auto const action_path = - storage.CAS().BlobPath(request.action_digest(), false); + auto const action_path = storage.CAS().BlobPath( + static_cast<ArtifactDigest>(request.action_digest()), false); if (not action_path) { return unexpected{fmt::format("could not retrieve blob {} from cas", request.action_digest().hash())}; @@ -395,8 +395,11 @@ namespace { } auto const input_root_path = Compatibility::IsCompatible() - ? storage.CAS().BlobPath(action.input_root_digest(), false) - : storage.CAS().TreePath(action.input_root_digest()); + ? storage.CAS().BlobPath( + static_cast<ArtifactDigest>(action.input_root_digest()), + false) + : storage.CAS().TreePath( + static_cast<ArtifactDigest>(action.input_root_digest())); if (not input_root_path) { return unexpected{ @@ -412,7 +415,8 @@ namespace { if (auto error_msg = IsAHash(action.command_digest().hash())) { return unexpected{*std::move(error_msg)}; } - auto path = storage.CAS().BlobPath(action.command_digest(), false); + auto path = storage.CAS().BlobPath( + static_cast<ArtifactDigest>(action.command_digest()), false); if (not path) { return unexpected{fmt::format("Could not retrieve blob {} from cas", action.command_digest().hash())}; diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 59dc1880..35b7b768 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -293,7 +293,9 @@ class LocalApi final : public IExecutionApi { std::vector<std::string>* targets) { targets->reserve(digests.size()); for (auto const& digest : digests) { - auto p = cas.BlobPath(digest, /*is_executable=*/false); + auto p = + cas.BlobPath(static_cast<ArtifactDigest>(digest), + /*is_executable=*/false); auto content = FileSystemManager::ReadFile(*p); targets->emplace_back(*content); } diff --git a/src/buildtool/execution_api/local/local_response.hpp b/src/buildtool/execution_api/local/local_response.hpp index 21dd5952..68ab0bcc 100644 --- a/src/buildtool/execution_api/local/local_response.hpp +++ b/src/buildtool/execution_api/local/local_response.hpp @@ -43,8 +43,9 @@ class LocalResponse final : public IExecutionResponse { return (output_.action.stdout_digest().size_bytes() != 0); } auto StdErr() noexcept -> std::string final { - if (auto path = storage_.CAS().BlobPath(output_.action.stderr_digest(), - /*is_executable=*/false)) { + if (auto path = storage_.CAS().BlobPath( + static_cast<ArtifactDigest>(output_.action.stderr_digest()), + /*is_executable=*/false)) { if (auto content = FileSystemManager::ReadFile(*path)) { return std::move(*content); } @@ -53,8 +54,9 @@ class LocalResponse final : public IExecutionResponse { return {}; } auto StdOut() noexcept -> std::string final { - if (auto path = storage_.CAS().BlobPath(output_.action.stdout_digest(), - /*is_executable=*/false)) { + if (auto path = storage_.CAS().BlobPath( + static_cast<ArtifactDigest>(output_.action.stdout_digest()), + /*is_executable=*/false)) { if (auto content = FileSystemManager::ReadFile(*path)) { return std::move(*content); } diff --git a/src/buildtool/storage/local_ac.tpp b/src/buildtool/storage/local_ac.tpp index 8ed930c4..4bd63b5c 100644 --- a/src/buildtool/storage/local_ac.tpp +++ b/src/buildtool/storage/local_ac.tpp @@ -169,7 +169,7 @@ auto LocalAC<kDoGlobalUplink>::WriteAction(bazel_re::ActionResult const& action) template <bool kDoGlobalUplink> auto LocalAC<kDoGlobalUplink>::ReadAction(bazel_re::Digest const& cas_key) const noexcept -> std::optional<bazel_re::ActionResult> { - auto const action_path = cas_.BlobPath(cas_key, + auto const action_path = cas_.BlobPath(static_cast<ArtifactDigest>(cas_key), /*is_executable=*/false); if (not action_path) { return std::nullopt; diff --git a/src/buildtool/storage/local_cas.hpp b/src/buildtool/storage/local_cas.hpp index 1b9bed48..6f3bbec1 100644 --- a/src/buildtool/storage/local_cas.hpp +++ b/src/buildtool/storage/local_cas.hpp @@ -134,7 +134,7 @@ class LocalCAS { /// \param digest Digest of the blob to lookup. /// \param is_executable Lookup blob with executable permissions. /// \returns Path to the blob if found or nullopt otherwise. - [[nodiscard]] auto BlobPath(bazel_re::Digest const& digest, + [[nodiscard]] auto BlobPath(ArtifactDigest const& digest, bool is_executable) const noexcept -> std::optional<std::filesystem::path> { auto const path = BlobPathNoSync(digest, is_executable); @@ -146,12 +146,11 @@ class LocalCAS { /// \param digest Digest of the blob to lookup. /// \param is_executable Lookup blob with executable permissions. /// \returns Path to the blob if found or nullopt otherwise. - [[nodiscard]] auto BlobPathNoSync(bazel_re::Digest const& digest, + [[nodiscard]] auto BlobPathNoSync(ArtifactDigest const& digest, bool is_executable) const noexcept -> std::optional<std::filesystem::path> { - auto const a_digest = static_cast<ArtifactDigest>(digest); - return is_executable ? cas_exec_.BlobPath(a_digest) - : cas_file_.BlobPath(a_digest); + return is_executable ? cas_exec_.BlobPath(digest) + : cas_file_.BlobPath(digest); } /// \brief Split a blob into chunks. @@ -204,10 +203,9 @@ class LocalCAS { /// \brief Obtain tree path from digest. /// \param digest Digest of the tree to lookup. /// \returns Path to the tree if found or nullopt otherwise. - [[nodiscard]] auto TreePath(bazel_re::Digest const& digest) const noexcept + [[nodiscard]] auto TreePath(ArtifactDigest const& digest) const noexcept -> std::optional<std::filesystem::path> { - auto const a_digest = static_cast<ArtifactDigest>(digest); - return cas_tree_.BlobPath(a_digest); + return cas_tree_.BlobPath(digest); } /// \brief Split a tree into chunks. @@ -350,7 +348,7 @@ class LocalCAS { /// \param digest Blob digest. /// \param to_executable Sync direction. /// \returns Path to blob in target CAS. - [[nodiscard]] auto TrySyncBlob(bazel_re::Digest const& digest, + [[nodiscard]] auto TrySyncBlob(ArtifactDigest const& digest, bool to_executable) const noexcept -> std::optional<std::filesystem::path> { auto const src_blob = BlobPathNoSync(digest, not to_executable); diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index bf208ca9..221470d7 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -48,19 +48,19 @@ auto LocalCAS<kDoGlobalUplink>::LocalUplinkBlob( bool is_executable, bool skip_sync, bool splice_result) const noexcept -> bool { + auto const a_digest = static_cast<ArtifactDigest>(digest); // Determine blob path in latest generation. - auto blob_path_latest = latest.BlobPathNoSync(digest, is_executable); + auto blob_path_latest = latest.BlobPathNoSync(a_digest, is_executable); if (blob_path_latest) { return true; } // Determine blob path of given generation. - auto blob_path = skip_sync ? BlobPathNoSync(digest, is_executable) - : BlobPath(digest, is_executable); + auto blob_path = skip_sync ? BlobPathNoSync(a_digest, is_executable) + : BlobPath(a_digest, is_executable); std::optional<LargeObject> spliced; if (not blob_path) { - spliced = - TrySplice<ObjectType::File>(static_cast<ArtifactDigest>(digest)); + spliced = TrySplice<ObjectType::File>(a_digest); blob_path = spliced ? std::optional{spliced->GetPath()} : std::nullopt; } if (not blob_path) { diff --git a/test/buildtool/storage/large_object_cas.test.cpp b/test/buildtool/storage/large_object_cas.test.cpp index 7d191629..2b993b04 100644 --- a/test/buildtool/storage/large_object_cas.test.cpp +++ b/test/buildtool/storage/large_object_cas.test.cpp @@ -58,7 +58,7 @@ class Blob final { LocalCAS<kDefaultDoGlobalUplink> const& cas, std::string const& id, std::uintmax_t size) noexcept - -> std::optional<std::pair<bazel_re::Digest, std::filesystem::path>>; + -> std::optional<std::pair<ArtifactDigest, std::filesystem::path>>; [[nodiscard]] static auto Generate(std::string const& id, std::uintmax_t size) noexcept @@ -82,7 +82,7 @@ class Tree final { LocalCAS<kDefaultDoGlobalUplink> const& cas, std::string const& id, std::uintmax_t entries_count) noexcept - -> std::optional<std::pair<bazel_re::Digest, std::filesystem::path>>; + -> std::optional<std::pair<ArtifactDigest, std::filesystem::path>>; [[nodiscard]] static auto Generate(std::string const& id, std::uintmax_t entries_count) noexcept @@ -91,7 +91,7 @@ class Tree final { [[nodiscard]] static auto StoreRaw( LocalCAS<kDefaultDoGlobalUplink> const& cas, std::filesystem::path const& directory) noexcept - -> std::optional<bazel_re::Digest>; + -> std::optional<ArtifactDigest>; }; } // namespace LargeTestUtils @@ -243,7 +243,8 @@ static void TestSmall(Storage const& storage) noexcept { // The part of a small executable is the same file but without the // execution permission. It must be deleted too. if constexpr (kIsExec) { - auto part_path = cas.BlobPath(pack_1->front(), false); + auto part_path = cas.BlobPath( + static_cast<ArtifactDigest>(pack_1->front()), false); CHECK(part_path); CHECK(FileSystemManager::RemoveFile(*part_path)); } @@ -352,7 +353,8 @@ static void TestExternal(StorageConfig const& storage_config, REQUIRE(GarbageCollector::TriggerGarbageCollection(storage_config)); for (auto const& part : *pack_1) { static constexpr bool is_executable = false; - REQUIRE(cas.BlobPath(part, is_executable)); + REQUIRE( + cas.BlobPath(static_cast<ArtifactDigest>(part), is_executable)); } auto const youngest = ::Generation::Create(&storage_config); @@ -467,7 +469,7 @@ static void TestCompactification(StorageConfig const& storage_config, REQUIRE(FileSystemManager::Rename(invalid_path, *unique_path)); // Ensure all entries are in the storage: - auto get_path = [](auto const& cas, bazel_re::Digest const& digest) { + auto get_path = [](auto const& cas, ArtifactDigest const& digest) { return kIsTree ? cas.TreePath(digest) : cas.BlobPath(digest, kIsExec); }; @@ -651,7 +653,7 @@ template <bool IsExecutable> auto Blob<IsExecutable>::Create(LocalCAS<kDefaultDoGlobalUplink> const& cas, std::string const& id, std::uintmax_t size) noexcept - -> std::optional<std::pair<bazel_re::Digest, std::filesystem::path>> { + -> std::optional<std::pair<ArtifactDigest, std::filesystem::path>> { auto path = Generate(id, size); auto digest = path ? cas.StoreBlob(*path, IsExecutable) : std::nullopt; auto blob_path = @@ -678,7 +680,7 @@ auto Blob<IsExecutable>::Generate(std::string const& id, auto Tree::Create(LocalCAS<kDefaultDoGlobalUplink> const& cas, std::string const& id, std::uintmax_t entries_count) noexcept - -> std::optional<std::pair<bazel_re::Digest, std::filesystem::path>> { + -> std::optional<std::pair<ArtifactDigest, std::filesystem::path>> { auto path = Generate(id, entries_count); auto digest = path ? StoreRaw(cas, *path) : std::nullopt; auto cas_path = digest ? cas.TreePath(*digest) : std::nullopt; @@ -702,7 +704,7 @@ auto Tree::Generate(std::string const& id, auto Tree::StoreRaw(LocalCAS<kDefaultDoGlobalUplink> const& cas, std::filesystem::path const& directory) noexcept - -> std::optional<bazel_re::Digest> { + -> std::optional<ArtifactDigest> { if (not FileSystemManager::IsDirectory(directory)) { return std::nullopt; } @@ -720,11 +722,16 @@ auto Tree::StoreRaw(LocalCAS<kDefaultDoGlobalUplink> const& cas, return cas.StoreBlob(content); }; - return Compatibility::IsCompatible() - ? BazelMsgFactory::CreateDirectoryDigestFromLocalTree( - directory, store_blob, store_tree, store_symlink) - : BazelMsgFactory::CreateGitTreeDigestFromLocalTree( - directory, store_blob, store_tree, store_symlink); + auto bazel_digest = + Compatibility::IsCompatible() + ? BazelMsgFactory::CreateDirectoryDigestFromLocalTree( + directory, store_blob, store_tree, store_symlink) + : BazelMsgFactory::CreateGitTreeDigestFromLocalTree( + directory, store_blob, store_tree, store_symlink); + if (bazel_digest.has_value()) { + return static_cast<ArtifactDigest>(*bazel_digest); + } + return std::nullopt; } } // namespace LargeTestUtils |