summaryrefslogtreecommitdiff
path: root/src/buildtool/common/artifact_digest.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/buildtool/common/artifact_digest.hpp')
-rw-r--r--src/buildtool/common/artifact_digest.hpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp
index 2ad94c27..8cbf6ccc 100644
--- a/src/buildtool/common/artifact_digest.hpp
+++ b/src/buildtool/common/artifact_digest.hpp
@@ -90,6 +90,19 @@ class ArtifactDigest {
}
}
+ template <ObjectType kType>
+ [[nodiscard]] static auto CreateFromFile(
+ std::filesystem::path const& path) noexcept
+ -> std::optional<ArtifactDigest> {
+ static constexpr bool kIsTree = IsTreeObject(kType);
+ auto hash = HashFunction::ComputeHashFile(path, kIsTree);
+ if (hash) {
+ return ArtifactDigest{
+ hash->first.HexString(), hash->second, kIsTree};
+ }
+ return std::nullopt;
+ }
+
[[nodiscard]] auto operator<(ArtifactDigest const& other) const -> bool {
return (hash_ < other.hash_) or
((hash_ == other.hash_) and (static_cast<int>(is_tree_) <