diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-06 10:34:26 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 14:52:07 +0200 |
commit | 60be90f22c17ff113339bae5915c372ac26348ba (patch) | |
tree | c74425aa31ac6680db6bf53bd24d69a7450eba6b /src | |
parent | ca959f6e3f5fcaca9fb53f0b1065cdceab180924 (diff) | |
download | justbuild-60be90f22c17ff113339bae5915c372ac26348ba.tar.gz |
Create ArtifactDigest from a plain hash in ArtifactDigestFactory
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/common/artifact_digest_factory.cpp | 14 | ||||
-rw-r--r-- | src/buildtool/common/artifact_digest_factory.hpp | 13 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/buildtool/common/artifact_digest_factory.cpp b/src/buildtool/common/artifact_digest_factory.cpp index 05bfd031..0f95f444 100644 --- a/src/buildtool/common/artifact_digest_factory.cpp +++ b/src/buildtool/common/artifact_digest_factory.cpp @@ -19,6 +19,20 @@ #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +auto ArtifactDigestFactory::Create(HashFunction::Type hash_type, + std::string hash, + std::size_t size, + bool is_tree) noexcept + -> expected<ArtifactDigest, std::string> { + const bool kTreesAllowed = hash_type == HashFunction::Type::GitSHA1; + auto hash_info = + HashInfo::Create(hash_type, std::move(hash), kTreesAllowed and is_tree); + if (not hash_info) { + return unexpected{std::move(hash_info).error()}; + } + return ArtifactDigest{*hash_info, size}; +} + auto ArtifactDigestFactory::FromBazel(HashFunction::Type hash_type, bazel_re::Digest const& digest) noexcept -> expected<ArtifactDigest, std::string> { diff --git a/src/buildtool/common/artifact_digest_factory.hpp b/src/buildtool/common/artifact_digest_factory.hpp index 09c0b478..8e28ae83 100644 --- a/src/buildtool/common/artifact_digest_factory.hpp +++ b/src/buildtool/common/artifact_digest_factory.hpp @@ -34,6 +34,19 @@ namespace bazel_re = build::bazel::remote::execution::v2; class ArtifactDigestFactory final { public: + /// \brief Create ArtifactDigest from plain hash. + /// \param hash_type Type of the hash function that was used for creation + /// of the hash + /// \param hash Hexadecimal plain hash + /// \param size Size of the content + /// \return A valid ArtifactDigest on success or an error message if + /// validation fails. + [[nodiscard]] static auto Create(HashFunction::Type hash_type, + std::string hash, + std::size_t size, + bool is_tree) noexcept + -> expected<ArtifactDigest, std::string>; + /// \brief Create ArtifactDigest from bazel_re::Digest /// \param hash_type Type of the hash function that was used for creation of /// the hash |