diff options
44 files changed, 212 insertions, 106 deletions
diff --git a/src/buildtool/build_engine/target_map/built_in_rules.cpp b/src/buildtool/build_engine/target_map/built_in_rules.cpp index abcc9d40..538f1940 100644 --- a/src/buildtool/build_engine/target_map/built_in_rules.cpp +++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp @@ -34,6 +34,7 @@ #include "src/buildtool/build_engine/target_map/utils.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/utils/cpp/path.hpp" #include "src/utils/cpp/vector.hpp" @@ -267,11 +268,12 @@ void BlobGenRuleWithDeps( return; } - auto stage = ExpressionPtr{Expression::map_t{ - name_val->String(), - ExpressionPtr{ArtifactDescription::CreateKnown( - ArtifactDigest::Create<ObjectType::File>(data_val->String()), - blob_type)}}}; + auto stage = ExpressionPtr{ + Expression::map_t{name_val->String(), + ExpressionPtr{ArtifactDescription::CreateKnown( + ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), data_val->String()), + blob_type)}}}; auto analysis_result = std::make_shared<AnalysedTarget const>( TargetResult{.artifact_stage = stage, diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp index 1c8d3743..0c970636 100644 --- a/src/buildtool/build_engine/target_map/target_map.cpp +++ b/src/buildtool/build_engine/target_map/target_map.cpp @@ -40,6 +40,7 @@ #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/utils/cpp/gsl.hpp" @@ -731,7 +732,8 @@ void withDependencies( } blobs.emplace_back(data->String()); return ExpressionPtr{ArtifactDescription::CreateKnown( - ArtifactDigest::Create<ObjectType::File>(data->String()), + ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), data->String()), ObjectType::File)}; }}, @@ -751,7 +753,8 @@ void withDependencies( blobs.emplace_back(data->String()); return ExpressionPtr{ArtifactDescription::CreateKnown( - ArtifactDigest::Create<ObjectType::Symlink>(data->String()), + ArtifactDigest::Create<ObjectType::Symlink>( + HashFunction::Instance(), data->String()), ObjectType::Symlink)}; }}, diff --git a/src/buildtool/common/artifact_digest.hpp b/src/buildtool/common/artifact_digest.hpp index 59299232..686a6fa5 100644 --- a/src/buildtool/common/artifact_digest.hpp +++ b/src/buildtool/common/artifact_digest.hpp @@ -74,17 +74,18 @@ class ArtifactDigest { } template <ObjectType kType> - [[nodiscard]] static auto Create(std::string const& content) noexcept + [[nodiscard]] static auto Create(HashFunction hash_function, + std::string const& content) noexcept -> ArtifactDigest { if constexpr (kType == ObjectType::Tree) { return ArtifactDigest{ - HashFunction::Instance().ComputeTreeHash(content).HexString(), + hash_function.ComputeTreeHash(content).HexString(), content.size(), /*is_tree=*/true}; } else { return ArtifactDigest{ - HashFunction::Instance().ComputeBlobHash(content).HexString(), + hash_function.ComputeBlobHash(content).HexString(), content.size(), /*is_tree=*/false}; } @@ -92,10 +93,11 @@ class ArtifactDigest { 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 hash = HashFunction::Instance().ComputeHashFile(path, kIsTree); + auto hash = hash_function.ComputeHashFile(path, kIsTree); if (hash) { return ArtifactDigest{ hash->first.HexString(), hash->second, kIsTree}; diff --git a/src/buildtool/execution_api/bazel_msg/TARGETS b/src/buildtool/execution_api/bazel_msg/TARGETS index cc14a0df..db495aa5 100644 --- a/src/buildtool/execution_api/bazel_msg/TARGETS +++ b/src/buildtool/execution_api/bazel_msg/TARGETS @@ -34,6 +34,7 @@ [ ["src/buildtool/compatibility", "compatibility"] , ["src/utils/cpp", "hex_string"] , ["src/buildtool/file_system", "file_system_manager"] + , ["src/buildtool/crypto", "hash_function"] , ["src/buildtool/file_system", "git_repo"] ] , "stage": ["src", "buildtool", "execution_api", "bazel_msg"] diff --git a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp index 48c8b062..155067fd 100644 --- a/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp +++ b/src/buildtool/execution_api/bazel_msg/bazel_msg_factory.cpp @@ -27,6 +27,7 @@ #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/compatibility/native_support.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/utils/cpp/hex_string.hpp" @@ -184,7 +185,8 @@ template <class T> if (not content) { return std::nullopt; } - auto digest = ArtifactDigest::Create<ObjectType::File>(*content); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *content); auto msg = CreateDirectoryNode(dir_name); msg.set_allocated_digest( @@ -223,7 +225,8 @@ template <class T> if (not content) { return std::nullopt; } - auto digest = ArtifactDigest::Create<ObjectType::File>(*content); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *content); return BazelBlob{digest, std::move(*content), /*is_exec=*/false}; } @@ -259,7 +262,8 @@ template <class T> if (not content) { return std::nullopt; } - auto digest = ArtifactDigest::Create<ObjectType::File>(*content); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *content); return BazelBlob{digest, std::move(*content), /*is_exec=*/false}; } diff --git a/src/buildtool/execution_api/common/tree_reader_utils.cpp b/src/buildtool/execution_api/common/tree_reader_utils.cpp index 1ec7edc0..874d1884 100644 --- a/src/buildtool/execution_api/common/tree_reader_utils.cpp +++ b/src/buildtool/execution_api/common/tree_reader_utils.cpp @@ -19,6 +19,7 @@ #include "nlohmann/json.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" @@ -42,7 +43,8 @@ namespace { [[nodiscard]] auto CreateObjectInfo(bazel_re::SymlinkNode const& node) -> Artifact::ObjectInfo { return Artifact::ObjectInfo{ - .digest = ArtifactDigest::Create<ObjectType::File>(node.target()), + .digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), node.target()), .type = ObjectType::Symlink}; } diff --git a/src/buildtool/execution_api/git/TARGETS b/src/buildtool/execution_api/git/TARGETS index df3dfcdc..2c614f08 100644 --- a/src/buildtool/execution_api/git/TARGETS +++ b/src/buildtool/execution_api/git/TARGETS @@ -11,6 +11,7 @@ , ["src/buildtool/execution_api/common", "common_api"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "execution_api", "git"] } diff --git a/src/buildtool/execution_api/git/git_api.hpp b/src/buildtool/execution_api/git/git_api.hpp index a18bd71b..b6a30a9b 100644 --- a/src/buildtool/execution_api/git/git_api.hpp +++ b/src/buildtool/execution_api/git/git_api.hpp @@ -25,6 +25,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" #include "src/buildtool/execution_api/common/artifact_blob_container.hpp" #include "src/buildtool/execution_api/common/common_api.hpp" @@ -227,7 +228,7 @@ class GitApi final : public IExecutionApi { return false; } auto digest = ArtifactDigest::Create<ObjectType::File>( - *entry_content); + HashFunction::Instance(), *entry_content); // Collect blob and upload to remote CAS if transfer // size reached. if (not UpdateContainerAndUpload<ArtifactDigest>( @@ -258,8 +259,10 @@ class GitApi final : public IExecutionApi { ArtifactDigest digest = IsTreeObject(info.type) - ? ArtifactDigest::Create<ObjectType::Tree>(*content) - : ArtifactDigest::Create<ObjectType::File>(*content); + ? ArtifactDigest::Create<ObjectType::Tree>( + HashFunction::Instance(), *content) + : ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *content); // Collect blob and upload to remote CAS if transfer size reached. if (not UpdateContainerAndUpload<ArtifactDigest>( diff --git a/src/buildtool/execution_api/local/TARGETS b/src/buildtool/execution_api/local/TARGETS index 53b7f717..682c8624 100644 --- a/src/buildtool/execution_api/local/TARGETS +++ b/src/buildtool/execution_api/local/TARGETS @@ -42,6 +42,7 @@ , ["src/buildtool/execution_api/execution_service", "cas_utils"] , ["src/buildtool/file_system", "git_repo"] , ["src/utils/cpp", "tmp_dir"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "execution_api", "local"] , "private-deps": diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 5f8fb6a4..e8ba0831 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -34,6 +34,7 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/compatibility/native_support.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/common/artifact_blob_container.hpp" #include "src/buildtool/execution_api/common/blob_tree.hpp" @@ -214,8 +215,10 @@ class LocalApi final : public IExecutionApi { // storage_.ReadTreeInfos() will contain 0 as size. ArtifactDigest digest = IsTreeObject(info.type) - ? ArtifactDigest::Create<ObjectType::Tree>(*content) - : ArtifactDigest::Create<ObjectType::File>(*content); + ? ArtifactDigest::Create<ObjectType::Tree>( + HashFunction::Instance(), *content) + : ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *content); // Collect blob and upload to remote CAS if transfer size reached. if (not UpdateContainerAndUpload<ArtifactDigest>( diff --git a/src/buildtool/execution_api/local/local_response.hpp b/src/buildtool/execution_api/local/local_response.hpp index 30d47ca7..c6214320 100644 --- a/src/buildtool/execution_api/local/local_response.hpp +++ b/src/buildtool/execution_api/local/local_response.hpp @@ -20,6 +20,7 @@ #include <utility> #include "gsl/gsl" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/execution_response.hpp" #include "src/buildtool/execution_api/local/local_action.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -139,7 +140,7 @@ class LocalResponse final : public IExecutionResponse { link.path(), Artifact::ObjectInfo{ .digest = ArtifactDigest::Create<ObjectType::File>( - link.target()), + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); } catch (...) { return false; @@ -151,7 +152,7 @@ class LocalResponse final : public IExecutionResponse { link.path(), Artifact::ObjectInfo{ .digest = ArtifactDigest::Create<ObjectType::File>( - link.target()), + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); dir_symlinks.emplace(link.path()); // add it to set } catch (...) { @@ -166,7 +167,7 @@ class LocalResponse final : public IExecutionResponse { link.path(), Artifact::ObjectInfo{ .digest = ArtifactDigest::Create<ObjectType::File>( - link.target()), + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); } catch (...) { return false; @@ -178,7 +179,7 @@ class LocalResponse final : public IExecutionResponse { link.path(), Artifact::ObjectInfo{ .digest = ArtifactDigest::Create<ObjectType::File>( - link.target()), + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); } catch (...) { return false; diff --git a/src/buildtool/execution_api/remote/TARGETS b/src/buildtool/execution_api/remote/TARGETS index ad4093f3..e45af2f1 100644 --- a/src/buildtool/execution_api/remote/TARGETS +++ b/src/buildtool/execution_api/remote/TARGETS @@ -56,7 +56,6 @@ , ["@", "grpc", "", "grpc++"] , ["src/buildtool/common/remote", "retry"] , ["src/buildtool/execution_api/common", "message_limits"] - , ["src/buildtool/crypto", "hash_function"] , ["src/utils/cpp", "path"] ] } diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp index 4547ff8c..135cfd52 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp @@ -138,9 +138,10 @@ auto BazelNetworkReader::MakeAuxiliaryMap( result.reserve(full_tree.size()); for (auto& dir : full_tree) { try { - result.emplace(ArtifactDigest::Create<ObjectType::File>( - dir.SerializeAsString()), - std::move(dir)); + result.emplace( + ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), dir.SerializeAsString()), + std::move(dir)); } catch (...) { return std::nullopt; } @@ -191,8 +192,10 @@ auto BazelNetworkReader::BatchReadBlobs( auto BazelNetworkReader::Validate(BazelBlob const& blob) noexcept -> bool { ArtifactDigest const rehashed_digest = NativeSupport::IsTree(blob.digest.hash()) - ? ArtifactDigest::Create<ObjectType::Tree>(*blob.data) - : ArtifactDigest::Create<ObjectType::File>(*blob.data); + ? ArtifactDigest::Create<ObjectType::Tree>(HashFunction::Instance(), + *blob.data) + : ArtifactDigest::Create<ObjectType::File>(HashFunction::Instance(), + *blob.data); if (rehashed_digest == ArtifactDigest{blob.digest}) { return true; } diff --git a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp index 1b7682bd..0cb860a3 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_response.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_response.cpp @@ -18,6 +18,7 @@ #include "gsl/gsl" #include "src/buildtool/compatibility/native_support.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/common/common_api.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp" @@ -30,7 +31,8 @@ namespace { auto ProcessDirectoryMessage(bazel_re::Directory const& dir) noexcept -> std::optional<BazelBlob> { auto data = dir.SerializeAsString(); - auto digest = ArtifactDigest::Create<ObjectType::File>(data); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), data); return BazelBlob{std::move(digest), std::move(data), /*is_exec=*/false}; } @@ -99,8 +101,8 @@ auto BazelResponse::Populate() noexcept -> bool { artifacts.emplace( link.path(), Artifact::ObjectInfo{ - .digest = - ArtifactDigest::Create<ObjectType::File>(link.target()), + .digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); } catch (...) { return false; @@ -111,8 +113,8 @@ auto BazelResponse::Populate() noexcept -> bool { artifacts.emplace( link.path(), Artifact::ObjectInfo{ - .digest = - ArtifactDigest::Create<ObjectType::File>(link.target()), + .digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); dir_symlinks.emplace(link.path()); // add it to set } catch (...) { @@ -126,8 +128,8 @@ auto BazelResponse::Populate() noexcept -> bool { artifacts.emplace( link.path(), Artifact::ObjectInfo{ - .digest = - ArtifactDigest::Create<ObjectType::File>(link.target()), + .digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); } catch (...) { return false; @@ -138,8 +140,8 @@ auto BazelResponse::Populate() noexcept -> bool { artifacts.emplace( link.path(), Artifact::ObjectInfo{ - .digest = - ArtifactDigest::Create<ObjectType::File>(link.target()), + .digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), link.target()), .type = ObjectType::Symlink}); } catch (...) { return false; diff --git a/src/buildtool/execution_engine/executor/TARGETS b/src/buildtool/execution_engine/executor/TARGETS index 2956b33f..ecba14f0 100644 --- a/src/buildtool/execution_engine/executor/TARGETS +++ b/src/buildtool/execution_engine/executor/TARGETS @@ -22,6 +22,7 @@ , ["@", "gsl", "", "gsl"] , ["src/buildtool/common", "common"] , ["src/buildtool/common/remote", "remote_common"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "execution_engine", "executor"] } diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index 0f0a09ec..d4d1f928 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -36,6 +36,7 @@ #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/common/tree.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/artifact_blob_container.hpp" #include "src/buildtool/execution_api/common/common_api.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" @@ -456,7 +457,8 @@ class ExecutorImpl { if (not content.has_value()) { return std::nullopt; } - auto digest = ArtifactDigest::Create<ObjectType::File>(*content); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *content); if (not api.Upload(ArtifactBlobContainer{ {ArtifactBlob{digest, std::move(*content), diff --git a/src/buildtool/file_system/TARGETS b/src/buildtool/file_system/TARGETS index 2d3198c5..b67ac0cf 100644 --- a/src/buildtool/file_system/TARGETS +++ b/src/buildtool/file_system/TARGETS @@ -28,6 +28,7 @@ , ["src/buildtool/common", "common"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "file_system"] } diff --git a/src/buildtool/file_system/object_cas.hpp b/src/buildtool/file_system/object_cas.hpp index aa521e07..122778b5 100644 --- a/src/buildtool/file_system/object_cas.hpp +++ b/src/buildtool/file_system/object_cas.hpp @@ -22,6 +22,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/bazel_types.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" #include "src/buildtool/logging/log_level.hpp" @@ -116,13 +117,14 @@ class ObjectCAS { [[nodiscard]] static auto CreateDigest(std::string const& bytes) noexcept -> std::optional<bazel_re::Digest> { - return ArtifactDigest::Create<kType>(bytes); + return ArtifactDigest::Create<kType>(HashFunction::Instance(), bytes); } [[nodiscard]] static auto CreateDigest( std::filesystem::path const& file_path) noexcept -> std::optional<bazel_re::Digest> { - return ArtifactDigest::CreateFromFile<kType>(file_path); + return ArtifactDigest::CreateFromFile<kType>(HashFunction::Instance(), + file_path); } [[nodiscard]] auto IsAvailable( diff --git a/src/buildtool/graph_traverser/TARGETS b/src/buildtool/graph_traverser/TARGETS index 0bb9a8e8..189159f2 100644 --- a/src/buildtool/graph_traverser/TARGETS +++ b/src/buildtool/graph_traverser/TARGETS @@ -25,6 +25,7 @@ , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/progress_reporting", "base_progress_reporter"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "graph_traverser"] } diff --git a/src/buildtool/graph_traverser/graph_traverser.hpp b/src/buildtool/graph_traverser/graph_traverser.hpp index 9c2a2175..ae154c6a 100644 --- a/src/buildtool/graph_traverser/graph_traverser.hpp +++ b/src/buildtool/graph_traverser/graph_traverser.hpp @@ -37,6 +37,7 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/common/tree.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/execution_api/common/artifact_blob_container.hpp" #include "src/buildtool/execution_api/common/common_api.hpp" @@ -292,7 +293,8 @@ class GraphTraverser { std::vector<std::string> const& blobs) const noexcept -> bool { ArtifactBlobContainer container; for (auto const& blob : blobs) { - auto digest = ArtifactDigest::Create<ObjectType::File>(blob); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), blob); Logger::Log(logger_, LogLevel::Trace, [&]() { return fmt::format( "Uploaded blob {}, its digest has id {} and size {}.", diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS index 0b264aab..c5d1fb9c 100644 --- a/src/buildtool/storage/TARGETS +++ b/src/buildtool/storage/TARGETS @@ -15,6 +15,7 @@ , ["src/utils/cpp", "gsl"] , ["src/utils/cpp", "tmp_dir"] , ["src/utils/cpp", "expected"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "storage"] } @@ -81,6 +82,7 @@ , ["src/buildtool/file_system", "git_repo"] , ["src/buildtool/common", "artifact_description"] , ["src/buildtool/compatibility", "compatibility"] + , ["src/buildtool/crypto", "hash_function"] ] , "stage": ["src", "buildtool", "storage"] , "private-deps": diff --git a/src/buildtool/storage/compactifier.cpp b/src/buildtool/storage/compactifier.cpp index 34f17b67..916a131a 100644 --- a/src/buildtool/storage/compactifier.cpp +++ b/src/buildtool/storage/compactifier.cpp @@ -271,7 +271,8 @@ template <ObjectType kType> } // Calculate the digest for the entry: - auto const digest = ArtifactDigest::CreateFromFile<kType>(path); + auto const digest = + ArtifactDigest::CreateFromFile<kType>(HashFunction::Instance(), path); if (not digest) { task.Log(LogLevel::Error, "Failed to calculate digest for {}", diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp index 4bc8911c..a6213074 100644 --- a/src/buildtool/storage/config.hpp +++ b/src/buildtool/storage/config.hpp @@ -27,6 +27,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/remote_common.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -157,6 +158,7 @@ struct StorageConfig final { -> std::string { try { return ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), DescribeBackend(std::nullopt, {}, {}).value()) .hash(); } catch (...) { @@ -219,8 +221,9 @@ class StorageConfig::Builder final { auto desc = DescribeBackend( remote_address_, remote_platform_properties_, remote_dispatch_); if (desc) { - backend_description_id = - ArtifactDigest::Create<ObjectType::File>(*desc).hash(); + backend_description_id = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), *desc) + .hash(); } else { return unexpected{desc.error()}; diff --git a/src/buildtool/storage/local_ac.tpp b/src/buildtool/storage/local_ac.tpp index 559346f5..c60e8751 100644 --- a/src/buildtool/storage/local_ac.tpp +++ b/src/buildtool/storage/local_ac.tpp @@ -18,6 +18,7 @@ #include <tuple> //std::ignore #include "src/buildtool/common/bazel_types.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/storage/local_ac.hpp" @@ -104,8 +105,8 @@ requires(kIsLocalGeneration) auto LocalAC<kDoGlobalUplink>::LocalUplinkEntry( for (auto const& link : result->output_file_symlinks()) { if (not cas_.LocalUplinkBlob( latest.cas_, - bazel_re::Digest( - ArtifactDigest::Create<ObjectType::File>(link.target())), + bazel_re::Digest(ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), link.target())), /*is_executable=*/false)) { return false; } @@ -113,8 +114,8 @@ requires(kIsLocalGeneration) auto LocalAC<kDoGlobalUplink>::LocalUplinkEntry( for (auto const& link : result->output_directory_symlinks()) { if (not cas_.LocalUplinkBlob( latest.cas_, - bazel_re::Digest( - ArtifactDigest::Create<ObjectType::File>(link.target())), + bazel_re::Digest(ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), link.target())), /*is_executable=*/false)) { return false; } diff --git a/src/buildtool/storage/local_cas.tpp b/src/buildtool/storage/local_cas.tpp index 8bb04049..54807580 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/crypto/hash_function.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/storage/local_cas.hpp" @@ -374,7 +375,8 @@ auto LocalCAS<kDoGlobalUplink>::Splice( // methods can refer to a file that existed before. The direct hash // calculation is done instead. auto const& file_path = large_object.GetPath(); - auto spliced_digest = ArtifactDigest::CreateFromFile<kType>(file_path); + auto spliced_digest = ArtifactDigest::CreateFromFile<kType>( + HashFunction::Instance(), file_path); if (not spliced_digest) { return unexpected{LargeObjectError{LargeObjectErrorCode::Internal, "could not calculate digest"}}; diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index eb888328..4bb08931 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -14,6 +14,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -32,6 +33,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -50,6 +52,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -70,6 +73,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -89,6 +93,7 @@ ] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["utils", "blob_creator"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } diff --git a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp index 5c906b44..498b0492 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -20,6 +20,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/retry_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" @@ -47,7 +48,8 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { SECTION("Valid digest and blob") { // digest of "test" - auto digest = ArtifactDigest::Create<ObjectType::File>(content); + auto digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content); // Valid blob BazelBlob blob{digest, content, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp index 57967957..00da3636 100755..100644 --- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/retry_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -27,8 +28,9 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { std::string instance_name{"remote-execution"}; std::string content("test"); - auto test_digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + auto test_digest = + static_cast<bazel_re::Digest>(ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content)); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -48,11 +50,11 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { config.skip_cache_lookup = false; SECTION("Immediate execution and response") { - auto action_immediate = - CreateAction(instance_name, - {"echo", "-n", content}, - {}, - remote_config->platform_properties); + auto action_immediate = CreateAction(instance_name, + {"echo", "-n", content}, + {}, + remote_config->platform_properties, + HashFunction::Instance()); REQUIRE(action_immediate); auto response = execution_client.Execute( @@ -71,7 +73,8 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { CreateAction(instance_name, {"sh", "-c", "sleep 1s; echo -n test"}, {}, - remote_config->platform_properties); + remote_config->platform_properties, + HashFunction::Instance()); SECTION("Blocking, immediately obtain result") { auto response = execution_client.Execute( @@ -105,8 +108,9 @@ TEST_CASE("Bazel internals: Execution Client using env variables", "[execution_api]") { std::string instance_name{"remote-execution"}; std::string content("contents of env variable"); - auto test_digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + auto test_digest = + static_cast<bazel_re::Digest>(ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content)); auto auth_config = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth_config); @@ -128,7 +132,8 @@ TEST_CASE("Bazel internals: Execution Client using env variables", CreateAction(instance_name, {"/bin/sh", "-c", "set -e\necho -n ${MYTESTVAR}"}, {{"MYTESTVAR", content}}, - remote_config->platform_properties); + remote_config->platform_properties, + HashFunction::Instance()); REQUIRE(action); auto response = diff --git a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp index b56021c8..233621e9 100644 --- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -36,9 +37,9 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") { REQUIRE(FileSystemManager::CreateSymlink("file1", link)); // create the corresponding blobs - auto file1_blob = CreateBlobFromPath(file1); - auto file2_blob = CreateBlobFromPath(file2); - auto link_blob = CreateBlobFromPath(link); + auto file1_blob = CreateBlobFromPath(file1, HashFunction::Instance()); + auto file2_blob = CreateBlobFromPath(file2, HashFunction::Instance()); + auto link_blob = CreateBlobFromPath(link, HashFunction::Instance()); CHECK(file1_blob); CHECK(file2_blob); diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index d60af9fc..ff05eefb 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -22,6 +22,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_network.hpp" @@ -55,13 +56,16 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { std::string content_bar("bar"); std::string content_baz(kLargeSize, 'x'); // single larger blob - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(content_foo), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(content_bar), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_bar), content_bar, /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(content_baz), + BazelBlob baz{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_baz), content_baz, /*is_exec=*/false}; @@ -113,10 +117,12 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { std::string content_foo("foo"); std::string content_bar(kLargeSize, 'x'); // single larger blob - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(content_foo), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(content_bar), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_bar), content_bar, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 293d2c45..fda769e1 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -19,6 +19,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/common/execution_common.hpp" #include "src/buildtool/execution_api/remote/bazel/bytestream_client.hpp" @@ -48,7 +49,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { // digest of "foobar" auto digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + ArtifactDigest::Create<ObjectType::File>(HashFunction::Instance(), + content)); CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -77,7 +79,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { // digest of "instance_nameinstance_nameinstance_..." auto digest = static_cast<bazel_re::Digest>( - ArtifactDigest::Create<ObjectType::File>(content)); + ArtifactDigest::Create<ObjectType::File>(HashFunction::Instance(), + content)); CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}", instance_name, @@ -131,13 +134,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { SECTION("Upload small blobs") { std::string instance_name{"remote-execution"}; - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>("foo"), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "foo"), "foo", /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>("bar"), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "bar"), "bar", /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create<ObjectType::File>("baz"), + BazelBlob baz{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "baz"), "baz", /*is_exec=*/false}; @@ -184,13 +190,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { content_baz[i] = instance_name[(i + 2) % instance_name.size()]; } - BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(content_foo), + BazelBlob foo{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_foo), content_foo, /*is_exec=*/false}; - BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(content_bar), + BazelBlob bar{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_bar), content_bar, /*is_exec=*/false}; - BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(content_baz), + BazelBlob baz{ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), content_baz), content_baz, /*is_exec=*/false}; diff --git a/test/buildtool/execution_api/common/TARGETS b/test/buildtool/execution_api/common/TARGETS index b4e2c4a9..89da6ab8 100644 --- a/test/buildtool/execution_api/common/TARGETS +++ b/test/buildtool/execution_api/common/TARGETS @@ -10,6 +10,7 @@ , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/logging", "log_level"] , ["@", "src", "src/buildtool/logging", "logging"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "common"] } diff --git a/test/buildtool/execution_api/common/api_test.hpp b/test/buildtool/execution_api/common/api_test.hpp index e2d8a17d..e00a3b32 100644 --- a/test/buildtool/execution_api/common/api_test.hpp +++ b/test/buildtool/execution_api/common/api_test.hpp @@ -21,6 +21,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/execution_action.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/common/execution_response.hpp" @@ -128,7 +129,8 @@ using ExecProps = std::map<std::string, std::string>; ExecProps const& props, bool is_hermetic = false) { std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); std::string output_path{"output_file"}; @@ -205,7 +207,8 @@ using ExecProps = std::map<std::string, std::string>; ExecProps const& props, bool is_hermetic = false) { std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); auto input_artifact_opt = ArtifactDescription::CreateKnown(test_digest, ObjectType::File) @@ -289,7 +292,8 @@ using ExecProps = std::map<std::string, std::string>; ApiFactory const& api_factory, ExecProps const& props) { std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); std::string output_path{"output_file"}; diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS index 754615d5..f50057c7 100644 --- a/test/buildtool/execution_api/execution_service/TARGETS +++ b/test/buildtool/execution_api/execution_service/TARGETS @@ -17,6 +17,7 @@ , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "gsl", "", "gsl"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "execution_service"] } diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp index f0fcf949..845d94aa 100644 --- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp +++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp @@ -17,6 +17,7 @@ #include "catch2/catch_test_macros.hpp" #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/execution_service/cas_server.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/file_system/object_type.hpp" @@ -57,15 +58,16 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") { auto empty_entries = GitRepo::tree_entries_t{}; auto empty_tree = GitRepo::CreateShallowTree(empty_entries); REQUIRE(empty_tree); - auto empty_tree_digest = - ArtifactDigest::Create<ObjectType::Tree>(empty_tree->second); + auto empty_tree_digest = ArtifactDigest::Create<ObjectType::Tree>( + HashFunction::Instance(), empty_tree->second); // Create a tree containing the empty tree. auto entries = GitRepo::tree_entries_t{}; entries[empty_tree->first].emplace_back("empty_tree", ObjectType::Tree); auto tree = GitRepo::CreateShallowTree(entries); REQUIRE(tree); - auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>(tree->second); + auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>( + HashFunction::Instance(), tree->second); // Upload tree. The tree invariant is violated, thus, a negative answer is // expected. diff --git a/test/buildtool/execution_api/local/TARGETS b/test/buildtool/execution_api/local/TARGETS index 41870428..212bf0b6 100644 --- a/test/buildtool/execution_api/local/TARGETS +++ b/test/buildtool/execution_api/local/TARGETS @@ -15,6 +15,7 @@ , ["utils", "test_storage_config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "execution_api", "local"] } diff --git a/test/buildtool/execution_api/local/local_execution.test.cpp b/test/buildtool/execution_api/local/local_execution.test.cpp index 72db2800..cac83b2a 100644 --- a/test/buildtool/execution_api/local/local_execution.test.cpp +++ b/test/buildtool/execution_api/local/local_execution.test.cpp @@ -21,6 +21,7 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/local/config.hpp" #include "src/buildtool/execution_api/local/local_api.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -172,7 +173,8 @@ TEST_CASE("LocalExecution: No input, create output", "[execution_api]") { &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); std::string output_path{"output_file"}; std::vector<std::string> const cmdline = { @@ -231,7 +233,8 @@ TEST_CASE("LocalExecution: One input copied to output", "[execution_api]") { &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); REQUIRE(api.Upload(ArtifactBlobContainer{{ArtifactBlob{ test_digest, test_content, /*is_exec=*/false}}}, false)); diff --git a/test/buildtool/file_system/object_cas.test.cpp b/test/buildtool/file_system/object_cas.test.cpp index be9ba709..df72d038 100644 --- a/test/buildtool/file_system/object_cas.test.cpp +++ b/test/buildtool/file_system/object_cas.test.cpp @@ -30,7 +30,8 @@ TEST_CASE("ObjectCAS", "[file_system]") { auto gen_config = storage_config.Get().CreateGenerationConfig(0); std::string test_content{"test"}; - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_content); SECTION("CAS for files") { ObjectCAS<ObjectType::File> cas{gen_config.cas_f}; diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS index 4a2881c3..a2b0b0d2 100644 --- a/test/buildtool/storage/TARGETS +++ b/test/buildtool/storage/TARGETS @@ -24,6 +24,7 @@ , ["utils", "blob_creator"] , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "storage"] } @@ -41,6 +42,7 @@ , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "src", "src/buildtool/storage", "config"] , ["utils", "test_storage_config"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "storage"] } diff --git a/test/buildtool/storage/local_ac.test.cpp b/test/buildtool/storage/local_ac.test.cpp index fdd8eec6..b3a4fcd1 100644 --- a/test/buildtool/storage/local_ac.test.cpp +++ b/test/buildtool/storage/local_ac.test.cpp @@ -18,6 +18,7 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/common/bazel_types.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/storage/config.hpp" @@ -36,7 +37,8 @@ TEST_CASE("LocalAC: Single action, single result", "[storage]") { auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id = ArtifactDigest::Create<ObjectType::File>("action"); + auto action_id = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action"); CHECK(not ac.CachedResult(action_id)); CHECK(RunDummyExecution(&ac, &cas, action_id, "result")); auto ac_result = ac.CachedResult(action_id); @@ -50,8 +52,10 @@ TEST_CASE("LocalAC: Two different actions, two different results", auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1"); - auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2"); + auto action_id1 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action1"); + auto action_id2 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action2"); CHECK(not ac.CachedResult(action_id1)); CHECK(not ac.CachedResult(action_id2)); @@ -79,8 +83,10 @@ TEST_CASE("LocalAC: Two different actions, same two results", "[storage]") { auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id1 = ArtifactDigest::Create<ObjectType::File>("action1"); - auto action_id2 = ArtifactDigest::Create<ObjectType::File>("action2"); + auto action_id1 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action1"); + auto action_id2 = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "action2"); CHECK(not ac.CachedResult(action_id1)); CHECK(not ac.CachedResult(action_id2)); @@ -108,7 +114,8 @@ TEST_CASE("LocalAC: Same two actions, two different results", "[storage]") { auto const& ac = storage.ActionCache(); auto const& cas = storage.CAS(); - auto action_id = ArtifactDigest::Create<ObjectType::File>("same action"); + auto action_id = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), "same action"); CHECK(not ac.CachedResult(action_id)); std::string result_content1{}; diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp index ef77a6a1..c1d65b8e 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/crypto/hash_function.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" @@ -32,7 +33,8 @@ TEST_CASE("LocalCAS: Add blob to storage from bytes", "[storage]") { std::string test_bytes("test"); - auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_bytes); + auto test_digest = ArtifactDigest::Create<ObjectType::File>( + HashFunction::Instance(), test_bytes); // check blob not in storage CHECK(not cas.BlobPath(test_digest, true)); @@ -82,7 +84,8 @@ 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 = CreateBlobFromPath(non_exec_file); + auto test_blob = + CreateBlobFromPath(non_exec_file, HashFunction::Instance()); REQUIRE(test_blob); // check blob not in storage @@ -132,7 +135,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 = CreateBlobFromPath(exec_file); + auto test_blob = CreateBlobFromPath(exec_file, HashFunction::Instance()); REQUIRE(test_blob); // check blob not in storage diff --git a/test/utils/TARGETS b/test/utils/TARGETS index b7a4db53..13ad7626 100644 --- a/test/utils/TARGETS +++ b/test/utils/TARGETS @@ -17,6 +17,7 @@ , "test_env" , "test_auth_config" , "test_remote_config" + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "utils"] } @@ -167,6 +168,7 @@ , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] } , "TESTS": diff --git a/test/utils/blob_creator.hpp b/test/utils/blob_creator.hpp index baa7cc86..944fb9d2 100644 --- a/test/utils/blob_creator.hpp +++ b/test/utils/blob_creator.hpp @@ -20,6 +20,7 @@ #include <string> #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/crypto/hash_function.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" @@ -27,7 +28,8 @@ /// \brief Create a blob from the content found in file or symlink pointed to by /// given path. [[nodiscard]] static inline auto CreateBlobFromPath( - std::filesystem::path const& fpath) noexcept -> std::optional<BazelBlob> { + std::filesystem::path const& fpath, + HashFunction hash_function) noexcept -> std::optional<BazelBlob> { auto const type = FileSystemManager::Type(fpath, /*allow_upwards=*/true); if (not type) { return std::nullopt; @@ -36,9 +38,10 @@ if (not content.has_value()) { return std::nullopt; } - return BazelBlob{ArtifactDigest::Create<ObjectType::File>(*content), - *content, - IsExecutableObject(*type)}; + return BazelBlob{ + ArtifactDigest::Create<ObjectType::File>(hash_function, *content), + *content, + IsExecutableObject(*type)}; } #endif // INCLUDED_SRC_TEST_UTILS_BLOB_CREATOR_HPP diff --git a/test/utils/remote_execution/bazel_action_creator.hpp b/test/utils/remote_execution/bazel_action_creator.hpp index d915cda1..7b92428d 100644 --- a/test/utils/remote_execution/bazel_action_creator.hpp +++ b/test/utils/remote_execution/bazel_action_creator.hpp @@ -36,8 +36,8 @@ std::string const& instance_name, std::vector<std::string> const& args, std::map<std::string, std::string> const& env_vars, - std::map<std::string, std::string> const& properties) noexcept - -> std::unique_ptr<bazel_re::Digest> { + std::map<std::string, std::string> const& properties, + HashFunction hash_function) noexcept -> std::unique_ptr<bazel_re::Digest> { auto platform = std::make_unique<bazel_re::Platform>(); for (auto const& [name, value] : properties) { bazel_re::Platform_Property property; @@ -64,12 +64,14 @@ }); auto cmd_data = cmd.SerializeAsString(); - auto cmd_id = ArtifactDigest::Create<ObjectType::File>(cmd_data); + auto cmd_id = + ArtifactDigest::Create<ObjectType::File>(hash_function, cmd_data); blobs.emplace_back(cmd_id, cmd_data, /*is_exec=*/false); bazel_re::Directory empty_dir; auto dir_data = empty_dir.SerializeAsString(); - auto dir_id = ArtifactDigest::Create<ObjectType::Tree>(dir_data); + auto dir_id = + ArtifactDigest::Create<ObjectType::Tree>(hash_function, dir_data); blobs.emplace_back(dir_id, dir_data, /*is_exec=*/false); bazel_re::Action action; @@ -80,7 +82,8 @@ gsl::owner<bazel_re::Digest*>{new bazel_re::Digest{dir_id}}); auto action_data = action.SerializeAsString(); - auto action_id = ArtifactDigest::Create<ObjectType::File>(action_data); + auto action_id = + ArtifactDigest::Create<ObjectType::File>(hash_function, action_data); blobs.emplace_back(action_id, action_data, /*is_exec=*/false); auto auth_config = TestAuthConfig::ReadFromEnvironment(); |