diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-03 13:20:22 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-09 13:07:13 +0200 |
commit | 4cecbc2873cd4ce464a8bf3b3c529830fcd29d0d (patch) | |
tree | 1061aeb5c73f18331ff0817b30da9cb0f2d5667b /src/buildtool/execution_api/common/tree_reader_utils.cpp | |
parent | c04a25e02be349d36d95edb9df2bed390c352a7d (diff) | |
download | justbuild-4cecbc2873cd4ce464a8bf3b3c529830fcd29d0d.tar.gz |
Use ArtifactDigestFactory casts in readers
Diffstat (limited to 'src/buildtool/execution_api/common/tree_reader_utils.cpp')
-rw-r--r-- | src/buildtool/execution_api/common/tree_reader_utils.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/buildtool/execution_api/common/tree_reader_utils.cpp b/src/buildtool/execution_api/common/tree_reader_utils.cpp index 151594d0..250d8245 100644 --- a/src/buildtool/execution_api/common/tree_reader_utils.cpp +++ b/src/buildtool/execution_api/common/tree_reader_utils.cpp @@ -27,24 +27,35 @@ #include "src/utils/cpp/hex_string.hpp" namespace { -[[nodiscard]] auto CreateObjectInfo(bazel_re::DirectoryNode const& node) - -> Artifact::ObjectInfo { - return Artifact::ObjectInfo{.digest = ArtifactDigest{node.digest()}, +[[nodiscard]] auto CreateObjectInfo(HashFunction hash_function, + bazel_re::DirectoryNode const& node) + -> std::optional<Artifact::ObjectInfo> { + auto digest = ArtifactDigestFactory::FromBazel(hash_function.GetType(), + node.digest()); + if (not digest) { + return std::nullopt; + } + return Artifact::ObjectInfo{.digest = *std::move(digest), .type = ObjectType::Tree}; } -[[nodiscard]] auto CreateObjectInfo(bazel_re::FileNode const& node) - -> Artifact::ObjectInfo { - return Artifact::ObjectInfo{.digest = ArtifactDigest{node.digest()}, +[[nodiscard]] auto CreateObjectInfo(HashFunction hash_function, + bazel_re::FileNode const& node) + -> std::optional<Artifact::ObjectInfo> { + auto digest = ArtifactDigestFactory::FromBazel(hash_function.GetType(), + node.digest()); + if (not digest) { + return std::nullopt; + } + return Artifact::ObjectInfo{.digest = *std::move(digest), .type = node.is_executable() ? ObjectType::Executable : ObjectType::File}; } -[[nodiscard]] auto CreateObjectInfo(bazel_re::SymlinkNode const& node, - HashFunction hash_function) +[[nodiscard]] auto CreateObjectInfo(HashFunction hash_function, + bazel_re::SymlinkNode const& node) -> Artifact::ObjectInfo { - return Artifact::ObjectInfo{ .digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( hash_function, node.target()), @@ -84,22 +95,24 @@ template <typename TTree> auto TreeReaderUtils::ReadObjectInfos(bazel_re::Directory const& dir, InfoStoreFunc const& store_info) noexcept -> bool { + // SHA256 is used since bazel types are processed here. + HashFunction const hash_function{HashFunction::Type::PlainSHA256}; try { for (auto const& f : dir.files()) { - if (not store_info(f.name(), CreateObjectInfo(f))) { + auto const info = CreateObjectInfo(hash_function, f); + if (not info or not store_info(f.name(), *info)) { return false; } } - // SHA256 is used since bazel types are processed here. - HashFunction const hash_function{HashFunction::Type::PlainSHA256}; for (auto const& l : dir.symlinks()) { - if (not store_info(l.name(), CreateObjectInfo(l, hash_function))) { + if (not store_info(l.name(), CreateObjectInfo(hash_function, l))) { return false; } } for (auto const& d : dir.directories()) { - if (not store_info(d.name(), CreateObjectInfo(d))) { + auto const info = CreateObjectInfo(hash_function, d); + if (not store_info(d.name(), *info)) { return false; } } |