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 /src | |
parent | 74498f0633d9039bbb7971efa33d4242cd724812 (diff) | |
download | justbuild-0be15127f1ecbd4010c657e908e62ed5f4b737dc.tar.gz |
Pass HashFunction::Type to SourceTargetMap
...that is to be used by FileRoot::ToArtifactDescription.
Diffstat (limited to 'src')
-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 |
6 files changed, 52 insertions, 38 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); |