diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-12 11:52:55 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-13 14:41:00 +0200 |
commit | 0be15127f1ecbd4010c657e908e62ed5f4b737dc (patch) | |
tree | 1e2897dc587018f4903e3e0c0783ffee0a158ac4 | |
parent | 74498f0633d9039bbb7971efa33d4242cd724812 (diff) | |
download | justbuild-0be15127f1ecbd4010c657e908e62ed5f4b737dc.tar.gz |
Pass HashFunction::Type to SourceTargetMap
...that is to be used by FileRoot::ToArtifactDescription.
-rw-r--r-- | src/buildtool/build_engine/base_maps/TARGETS | 3 | ||||
-rw-r--r-- | src/buildtool/build_engine/base_maps/source_map.cpp | 54 | ||||
-rw-r--r-- | src/buildtool/build_engine/base_maps/source_map.hpp | 2 | ||||
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 23 | ||||
-rw-r--r-- | src/buildtool/main/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/main/analyse.cpp | 7 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/source_map.test.cpp | 52 | ||||
-rw-r--r-- | test/buildtool/build_engine/target_map/target_map.test.cpp | 48 | ||||
-rw-r--r-- | test/buildtool/file_system/file_root.test.cpp | 77 |
10 files changed, 163 insertions, 105 deletions
diff --git a/src/buildtool/build_engine/base_maps/TARGETS b/src/buildtool/build_engine/base_maps/TARGETS index 5a54ea54..5080b5bc 100644 --- a/src/buildtool/build_engine/base_maps/TARGETS +++ b/src/buildtool/build_engine/base_maps/TARGETS @@ -90,7 +90,8 @@ , ["src/buildtool/multithreading", "task_system"] ] , "stage": ["src", "buildtool", "build_engine", "base_maps"] - , "private-deps": [["src/utils/cpp", "json"]] + , "private-deps": + [["src/utils/cpp", "json"], ["src/buildtool/crypto", "hash_function"]] } , "field_reader": { "type": ["@", "rules", "CC", "library"] diff --git a/src/buildtool/build_engine/base_maps/source_map.cpp b/src/buildtool/build_engine/base_maps/source_map.cpp index e47c59b1..8c716ac7 100644 --- a/src/buildtool/build_engine/base_maps/source_map.cpp +++ b/src/buildtool/build_engine/base_maps/source_map.cpp @@ -49,12 +49,13 @@ auto as_target(const BuildMaps::Base::EntityName& key, auto CreateSourceTargetMap( const gsl::not_null<DirectoryEntriesMap*>& dirs, gsl::not_null<const RepositoryConfig*> const& repo_config, + HashFunction::Type hash_type, std::size_t jobs) -> SourceTargetMap { - auto src_target_reader = [dirs, repo_config](auto ts, - auto setter, - auto logger, - auto /* unused */, - auto const& key) { + auto src_target_reader = [dirs, repo_config, hash_type](auto ts, + auto setter, + auto logger, + auto /* unused */, + auto const& key) { using std::filesystem::path; const auto& target = key.GetNamedTarget(); auto name = path(target.name).lexically_normal(); @@ -68,27 +69,30 @@ auto CreateSourceTargetMap( auto dir = (path(target.module) / name).parent_path(); auto const* ws_root = repo_config->WorkspaceRoot(target.repository); - auto src_file_reader = [key, name, setter, logger, dir, ws_root]( - bool exists_in_ws_root) { - if (ws_root != nullptr and exists_in_ws_root) { - if (auto desc = ws_root->ToArtifactDescription( - path(key.GetNamedTarget().module) / name, - key.GetNamedTarget().repository)) { - (*setter)(as_target(key, ExpressionPtr{std::move(*desc)})); - return; + auto src_file_reader = + [key, name, setter, logger, dir, ws_root, hash_type]( + bool exists_in_ws_root) { + if (ws_root != nullptr and exists_in_ws_root) { + if (auto desc = ws_root->ToArtifactDescription( + hash_type, + path(key.GetNamedTarget().module) / name, + key.GetNamedTarget().repository)) { + (*setter)( + as_target(key, ExpressionPtr{std::move(*desc)})); + return; + } } - } - (*logger)( - fmt::format( - "Cannot determine source file {} in directory {} of " - "repository {}", - nlohmann::json( - path(key.GetNamedTarget().name).filename().string()) - .dump(), - nlohmann::json(dir.string()).dump(), - nlohmann::json(key.GetNamedTarget().repository).dump()), - true); - }; + (*logger)( + fmt::format( + "Cannot determine source file {} in directory {} of " + "repository {}", + nlohmann::json( + path(key.GetNamedTarget().name).filename().string()) + .dump(), + nlohmann::json(dir.string()).dump(), + nlohmann::json(key.GetNamedTarget().repository).dump()), + true); + }; if (ws_root != nullptr and ws_root->HasFastDirectoryLookup()) { // by-pass directory map and directly attempt to read from ws_root diff --git a/src/buildtool/build_engine/base_maps/source_map.hpp b/src/buildtool/build_engine/base_maps/source_map.hpp index 97088d9d..fa18190b 100644 --- a/src/buildtool/build_engine/base_maps/source_map.hpp +++ b/src/buildtool/build_engine/base_maps/source_map.hpp @@ -25,6 +25,7 @@ #include "src/buildtool/build_engine/base_maps/entity_name.hpp" #include "src/buildtool/build_engine/expression/expression.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" @@ -35,6 +36,7 @@ using SourceTargetMap = AsyncMapConsumer<EntityName, AnalysedTargetPtr>; auto CreateSourceTargetMap( const gsl::not_null<DirectoryEntriesMap*>& dirs, gsl::not_null<const RepositoryConfig*> const& repo_config, + HashFunction::Type hash_type, std::size_t jobs = 0) -> SourceTargetMap; } // namespace BuildMaps::Base diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index 798d8341..50065bfd 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -576,6 +576,7 @@ class FileRoot { // Create LOCAL or KNOWN artifact. Does not check existence for LOCAL. // `file_path` must reference a blob. [[nodiscard]] auto ToArtifactDescription( + HashFunction::Type hash_type, std::filesystem::path const& file_path, std::string const& repository) const noexcept -> std::optional<ArtifactDescription> { @@ -584,26 +585,26 @@ class FileRoot { std::get<git_root_t>(root_).tree->LookupEntryByPath( file_path)) { if (entry->IsBlob()) { - if (ProtocolTraits::Instance().IsCompatible()) { + if (not ProtocolTraits::IsNative(hash_type)) { auto compatible_hash = GitHashesConverter::Instance().RegisterGitEntry( entry->Hash(), *entry->Blob(), repository); - auto digest = ArtifactDigestFactory::Create( - HashFunction::Type::PlainSHA256, - compatible_hash, - *entry->Size(), - /*is_tree=*/false); + auto digest = + ArtifactDigestFactory::Create(hash_type, + compatible_hash, + *entry->Size(), + /*is_tree=*/false); if (not digest) { return std::nullopt; } return ArtifactDescription::CreateKnown( *std::move(digest), entry->Type()); } - auto digest = ArtifactDigestFactory::Create( - HashFunction::Type::GitSHA1, - entry->Hash(), - *entry->Size(), - /*is_tree=*/false); + auto digest = + ArtifactDigestFactory::Create(hash_type, + entry->Hash(), + *entry->Size(), + /*is_tree=*/false); if (not digest) { return std::nullopt; } diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS index 0a31325e..f3e1db5b 100644 --- a/src/buildtool/main/TARGETS +++ b/src/buildtool/main/TARGETS @@ -199,6 +199,7 @@ , ["src/buildtool/common", "common"] , ["src/buildtool/common", "config"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/crypto", "hash_function"] ] } , "analyse_context": diff --git a/src/buildtool/main/analyse.cpp b/src/buildtool/main/analyse.cpp index c9d61872..fa332b9b 100644 --- a/src/buildtool/main/analyse.cpp +++ b/src/buildtool/main/analyse.cpp @@ -26,11 +26,13 @@ #include "src/buildtool/build_engine/base_maps/targets_file_map.hpp" #include "src/buildtool/build_engine/target_map/absent_target_map.hpp" #include "src/buildtool/build_engine/target_map/target_map.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/async_map_utils.hpp" #include "src/buildtool/multithreading/task_system.hpp" #include "src/buildtool/progress_reporting/exports_progress_reporter.hpp" +#include "src/buildtool/storage/storage.hpp" #ifndef BOOTSTRAP_BUILD_TOOL #include "src/buildtool/serve_api/remote/config.hpp" #endif // BOOTSTRAP_BUILD_TOOL @@ -127,7 +129,10 @@ namespace Target = BuildMaps::Target; auto rule_map = Base::CreateRuleMap( &rule_file_map, &expr_map, context->repo_config, jobs); auto source_targets = Base::CreateSourceTargetMap( - &directory_entries, context->repo_config, jobs); + &directory_entries, + context->repo_config, + context->storage->GetHashFunction().GetType(), + jobs); auto absent_target_variables_map = Target::CreateAbsentTargetVariablesMap(context, jobs); diff --git a/test/buildtool/build_engine/base_maps/TARGETS b/test/buildtool/build_engine/base_maps/TARGETS index 2c5f4029..bb145bac 100644 --- a/test/buildtool/build_engine/base_maps/TARGETS +++ b/test/buildtool/build_engine/base_maps/TARGETS @@ -68,6 +68,7 @@ , ["@", "src", "src/buildtool/build_engine/base_maps", "source_map"] , ["@", "src", "src/buildtool/build_engine/base_maps", "entity_name_data"] , ["@", "src", "src/buildtool/file_system", "file_root"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp index b6c7f1c1..bd1e71ba 100644 --- a/test/buildtool/build_engine/base_maps/source_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp @@ -27,6 +27,7 @@ #include "src/buildtool/build_engine/base_maps/entity_name_data.hpp" #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/repository_config.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" @@ -60,13 +61,14 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadSourceTarget(EntityName const& id, SourceTargetMap::Consumer consumer, + HashFunction::Type hash_type, bool use_git = false, std::optional<SourceTargetMap::FailureFunction> fail_func = std::nullopt) -> bool { auto repo_config = SetupConfig(use_git); auto directory_entries = CreateDirectoryEntriesMap(&repo_config); auto source_artifacts = - CreateSourceTargetMap(&directory_entries, &repo_config); + CreateSourceTargetMap(&directory_entries, &repo_config, hash_type); std::string error_msg; bool success{true}; { @@ -93,14 +95,18 @@ TEST_CASE("from file") { artifacts = (*values[0])->Artifacts()->ToJson(); }; + auto const hash_type = ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/false)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["file"]["type"] == "LOCAL"); CHECK(artifacts["file"]["data"]["path"] == "file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["file"]["type"] == "KNOWN"); CHECK(artifacts["file"]["data"]["id"] == (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256 @@ -116,16 +122,20 @@ TEST_CASE("not present at all") { auto consumer = [&consumed](auto /*unused*/) { consumed = true; }; auto fail_func = [&failure_called]() { failure_called = true; }; + auto const hash_type = ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + SECTION("via file") { - CHECK_FALSE( - ReadSourceTarget(name, consumer, /*use_git=*/false, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE( - ReadSourceTarget(name, consumer, /*use_git=*/true, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/true, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -138,16 +148,20 @@ TEST_CASE("malformed entry") { auto consumer = [&consumed](auto /*unused*/) { consumed = true; }; auto fail_func = [&failure_called]() { failure_called = true; }; + auto const hash_type = ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + SECTION("via git tree") { - CHECK_FALSE( - ReadSourceTarget(name, consumer, /*use_git=*/false, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE( - ReadSourceTarget(name, consumer, /*use_git=*/true, fail_func)); + CHECK_FALSE(ReadSourceTarget( + name, consumer, hash_type, /*use_git=*/true, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -160,14 +174,18 @@ TEST_CASE("subdir file") { artifacts = (*values[0])->Artifacts()->ToJson(); }; + auto const hash_type = ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/false)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["bar/file"]["type"] == "LOCAL"); CHECK(artifacts["bar/file"]["data"]["path"] == "foo/bar/file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["bar/file"]["type"] == "KNOWN"); CHECK(artifacts["bar/file"]["data"]["id"] == (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256 @@ -183,14 +201,18 @@ TEST_CASE("subdir symlink") { artifacts = (*values[0])->Artifacts()->ToJson(); }; + auto const hash_type = ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/false)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); CHECK(artifacts["link"]["type"] == "LOCAL"); CHECK(artifacts["link"]["data"]["path"] == "foo/link"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, /*use_git=*/true)); + CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); CHECK(artifacts["link"]["type"] == "KNOWN"); CHECK(artifacts["link"]["data"]["id"] == (ProtocolTraits::Instance().IsCompatible() ? kSrcLinkIdSha256 diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index cb8aa230..99fe1d4e 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -93,8 +93,10 @@ TEST_CASE("simple targets", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -720,8 +722,10 @@ TEST_CASE("configuration deduplication", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -830,8 +834,10 @@ TEST_CASE("generator functions in string arguments", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -952,8 +958,10 @@ TEST_CASE("built-in rules", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1186,8 +1194,10 @@ TEST_CASE("target reference", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1351,8 +1361,10 @@ TEST_CASE("trees", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1480,8 +1492,10 @@ TEST_CASE("RESULT error reporting", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); @@ -1668,8 +1682,10 @@ TEST_CASE("wrong arguments", "[target_map]") { auto repo_config = SetupConfig(); auto directory_entries = BuildMaps::Base::CreateDirectoryEntriesMap(&repo_config); - auto source = BuildMaps::Base::CreateSourceTargetMap(&directory_entries, - &repo_config); + auto source = BuildMaps::Base::CreateSourceTargetMap( + &directory_entries, + &repo_config, + storage_config.Get().hash_function.GetType()); auto targets_file_map = BuildMaps::Base::CreateTargetsFileMap(&repo_config, 0); auto rule_file_map = BuildMaps::Base::CreateRuleFileMap(&repo_config, 0); diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index 1e7b9e7b..1a27dd1b 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -374,89 +374,94 @@ TEST_CASE("Reading blob type", "[file_root]") { } } -static void CheckLocalRoot(bool ignore_special) noexcept; -static void CheckGitRoot(bool ignore_special) noexcept; +static void CheckLocalRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept; +static void CheckGitRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept; TEST_CASE("Creating artifact descriptions", "[file_root]") { + auto const hash_type = ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + SECTION("local root") { - CheckLocalRoot(/*ignore_special=*/false); + CheckLocalRoot(hash_type, /*ignore_special=*/false); } SECTION("git root") { - CheckGitRoot(/*ignore_special=*/false); + CheckGitRoot(hash_type, /*ignore_special=*/false); } SECTION("local root ignore-special") { - CheckLocalRoot(/*ignore_special=*/true); + CheckLocalRoot(hash_type, /*ignore_special=*/true); } SECTION("git root ignore-special") { - CheckGitRoot(/*ignore_special=*/true); + CheckGitRoot(hash_type, /*ignore_special=*/true); } } -static void CheckLocalRoot(bool ignore_special) noexcept { +static void CheckLocalRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept { auto const root_path = CreateTestRepoSymlinks(true); REQUIRE(root_path); auto const root = FileRoot{*root_path, ignore_special}; - auto const desc = root.ToArtifactDescription("baz/foo", "repo"); + auto const desc = root.ToArtifactDescription(hash_type, "baz/foo", "repo"); REQUIRE(desc); CHECK(*desc == ArtifactDescription::CreateLocal( std::filesystem::path{"baz/foo"}, "repo")); - CHECK(root.ToArtifactDescription("does_not_exist", "repo")); + CHECK(root.ToArtifactDescription(hash_type, "does_not_exist", "repo")); } -static void CheckGitRoot(bool ignore_special) noexcept { +static void CheckGitRoot(HashFunction::Type hash_type, + bool ignore_special) noexcept { auto const repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); auto const root = FileRoot::FromGit(*repo_path, kTreeSymId, ignore_special); REQUIRE(root); - auto const foo = root->ToArtifactDescription("baz/foo", "repo"); + auto const foo = root->ToArtifactDescription(hash_type, "baz/foo", "repo"); REQUIRE(foo); - if (ProtocolTraits::Instance().IsCompatible()) { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::PlainSHA256, - kFooIdSha256, - kFooContentLength, - /*is_tree=*/false); + if (not ProtocolTraits::IsNative(hash_type)) { + auto const digest = ArtifactDigestFactory::Create(hash_type, + kFooIdSha256, + kFooContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*foo == ArtifactDescription::CreateKnown(*digest, ObjectType::File)); } else { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::GitSHA1, - kFooIdGitSha1, - kFooContentLength, - /*is_tree=*/false); + auto const digest = ArtifactDigestFactory::Create(hash_type, + kFooIdGitSha1, + kFooContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*foo == ArtifactDescription::CreateKnown( *digest, ObjectType::File, "repo")); } - auto const bar = root->ToArtifactDescription("baz/bar", "repo"); + auto const bar = root->ToArtifactDescription(hash_type, "baz/bar", "repo"); REQUIRE(bar); - if (ProtocolTraits::Instance().IsCompatible()) { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::PlainSHA256, - kBarIdSha256, - kBarContentLength, - /*is_tree=*/false); + if (not ProtocolTraits::IsNative(hash_type)) { + auto const digest = ArtifactDigestFactory::Create(hash_type, + kBarIdSha256, + kBarContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*bar == ArtifactDescription::CreateKnown(*digest, ObjectType::Executable)); } else { - auto const digest = - ArtifactDigestFactory::Create(HashFunction::Type::GitSHA1, - kBarIdGitSha1, - kBarContentLength, - /*is_tree=*/false); + auto const digest = ArtifactDigestFactory::Create(hash_type, + kBarIdGitSha1, + kBarContentLength, + /*is_tree=*/false); REQUIRE(digest); CHECK(*bar == ArtifactDescription::CreateKnown( *digest, ObjectType::Executable, "repo")); } - CHECK_FALSE(root->ToArtifactDescription("baz", "repo")); - CHECK_FALSE(root->ToArtifactDescription("does_not_exist", "repo")); + CHECK_FALSE(root->ToArtifactDescription(hash_type, "baz", "repo")); + CHECK_FALSE( + root->ToArtifactDescription(hash_type, "does_not_exist", "repo")); } |