diff options
-rw-r--r-- | src/buildtool/common/artifact_digest.hpp | 15 | ||||
-rw-r--r-- | src/buildtool/file_system/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/file_system/object_cas.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/storage/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/storage/compactifier.cpp | 5 | ||||
-rw-r--r-- | src/buildtool/storage/local_cas.tpp | 3 | ||||
-rw-r--r-- | test/buildtool/storage/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/storage/local_cas.test.cpp | 5 |
8 files changed, 14 insertions, 21 deletions
diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp index ebd01ceb..24097776 100644 --- a/src/buildtool/common/artifact_digest.hpp +++ b/src/buildtool/common/artifact_digest.hpp @@ -96,21 +96,6 @@ class ArtifactDigest final { } } - template <ObjectType kType> - [[nodiscard]] static auto CreateFromFile( - HashFunction hash_function, - std::filesystem::path const& path) noexcept - -> std::optional<ArtifactDigest> { - static constexpr bool kIsTree = IsTreeObject(kType); - auto const hash = kIsTree ? hash_function.HashTreeFile(path) - : hash_function.HashBlobFile(path); - if (hash) { - return ArtifactDigest{ - hash->first.HexString(), hash->second, kIsTree}; - } - return std::nullopt; - } - private: std::size_t size_{}; std::string hash_{}; diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index ef5abada..9d70f7d8 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -26,6 +26,7 @@ [ "file_storage" , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/common", "common"] + , ["src/buildtool/common", "artifact_digest_factory"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/crypto", "hash_function"] diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp index d8ea71a2..79ba70da 100644 --- a/src/buildtool/file_system/object_cas.hpp +++ b/src/buildtool/file_system/object_cas.hpp @@ -23,6 +23,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_storage.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -129,7 +130,8 @@ class ObjectCAS { [[nodiscard]] auto CreateDigest(std::filesystem::path const& file_path) const noexcept -> std::optional<ArtifactDigest> { - return ArtifactDigest::CreateFromFile<kType>(hash_function_, file_path); + return ArtifactDigestFactory::HashFileAs<kType>(hash_function_, + file_path); } [[nodiscard]] auto IsAvailable( diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS index c4377581..7ca3f6be 100644 --- a/src/buildtool/storage/TARGETS +++ b/src/buildtool/storage/TARGETS @@ -63,6 +63,7 @@ [ "config" , "file_chunker" , ["src/buildtool/common", "common"] + , ["src/buildtool/common", "artifact_digest_factory"] , ["src/buildtool/file_system", "file_storage"] , ["src/buildtool/file_system", "object_cas"] , ["src/buildtool/execution_api/common", "common"] diff --git a/src/buildtool/storage/compactifier.cpp b/src/buildtool/storage/compactifier.cpp index 1e6033ed..2a6368ca 100644 --- a/src/buildtool/storage/compactifier.cpp +++ b/src/buildtool/storage/compactifier.cpp @@ -22,6 +22,7 @@ #include <vector> #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/crypto/hasher.hpp" @@ -272,8 +273,8 @@ template <ObjectType kType> } // Calculate the digest for the entry: - auto const digest = - ArtifactDigest::CreateFromFile<kType>(task.cas.GetHashFunction(), path); + auto const digest = ArtifactDigestFactory::HashFileAs<kType>( + task.cas.GetHashFunction(), path); if (not digest) { task.Log(LogLevel::Error, "Failed to calculate digest for {}", diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index e2a77e87..d43bd18b 100644 --- a/src/buildtool/storage/local_cas.tpp +++ b/src/buildtool/storage/local_cas.tpp @@ -19,6 +19,7 @@ #include <utility> // std::move #include "fmt/core.h" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/storage/local_cas.hpp" @@ -359,7 +360,7 @@ auto LocalCAS<kDoGlobalUplink>::Splice(ArtifactDigest const& digest, // calculation is done instead. auto const& file_path = large_object.GetPath(); auto spliced_digest = - ArtifactDigest::CreateFromFile<kType>(hash_function_, file_path); + ArtifactDigestFactory::HashFileAs<kType>(hash_function_, file_path); if (not spliced_digest) { return unexpected{LargeObjectError{LargeObjectErrorCode::Internal, "could not calculate digest"}}; diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS index c61cde66..b5d88715 100644 --- a/test/buildtool/storage/TARGETS +++ b/test/buildtool/storage/TARGETS @@ -18,6 +18,7 @@ , ["", "catch-main"] , ["utils", "test_storage_config"] , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp index 4b7c844a..44371fea 100644 --- a/test/buildtool/storage/local_cas.test.cpp +++ b/test/buildtool/storage/local_cas.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -82,7 +83,7 @@ TEST_CASE("LocalCAS: Add blob to storage from non-executable file", std::filesystem::path non_exec_file{ "test/buildtool/storage/data/non_executable_file"}; - auto test_blob = ArtifactDigest::CreateFromFile<ObjectType::File>( + auto test_blob = ArtifactDigestFactory::HashFileAs<ObjectType::File>( storage_config.Get().hash_function, non_exec_file); REQUIRE(test_blob); @@ -133,7 +134,7 @@ TEST_CASE("LocalCAS: Add blob to storage from executable file", "[storage]") { std::filesystem::path exec_file{ "test/buildtool/storage/data/executable_file"}; - auto test_blob = ArtifactDigest::CreateFromFile<ObjectType::File>( + auto test_blob = ArtifactDigestFactory::HashFileAs<ObjectType::File>( storage_config.Get().hash_function, exec_file); REQUIRE(test_blob); |