diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-12-17 16:26:01 +0100 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-12-19 16:37:59 +0100 |
commit | 75abf567afd7a130e9fbc90c6b7ac03ac40651c1 (patch) | |
tree | 0331c8ff237524b6e1cfd32fe88e82e138b13f7e /src | |
parent | bd606d1355afe1276675ac1c0077d44bb484b363 (diff) | |
download | justbuild-75abf567afd7a130e9fbc90c6b7ac03ac40651c1.tar.gz |
Use PrecomputedRoots during evaluation
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/computed_roots/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/computed_roots/evaluate.cpp | 87 | ||||
-rw-r--r-- | src/buildtool/computed_roots/evaluate.hpp | 2 | ||||
-rw-r--r-- | src/buildtool/file_system/file_root.hpp | 30 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 16 |
5 files changed, 66 insertions, 70 deletions
diff --git a/src/buildtool/computed_roots/TARGETS b/src/buildtool/computed_roots/TARGETS index 825198ce..c90ecfd3 100644 --- a/src/buildtool/computed_roots/TARGETS +++ b/src/buildtool/computed_roots/TARGETS @@ -82,6 +82,7 @@ , ["src/buildtool/file_system", "git_cas"] , ["src/buildtool/file_system", "git_repo"] , ["src/buildtool/file_system", "object_type"] + , ["src/buildtool/file_system", "precomputed_root"] , ["src/buildtool/logging", "log_level"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/main", "analyse_context"] diff --git a/src/buildtool/computed_roots/evaluate.cpp b/src/buildtool/computed_roots/evaluate.cpp index 3a8940a4..161e8144 100644 --- a/src/buildtool/computed_roots/evaluate.cpp +++ b/src/buildtool/computed_roots/evaluate.cpp @@ -50,6 +50,7 @@ #include "src/buildtool/file_system/git_cas.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/buildtool/file_system/precomputed_root.hpp" #include "src/buildtool/graph_traverser/graph_traverser.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/log_sink.hpp" @@ -69,12 +70,11 @@ namespace { // Add the description of a computed root to a vector, if the given // root is computed. -void AddDescriptionIfComputed( +void AddDescriptionIfPrecomputed( FileRoot const& root, - gsl::not_null<std::vector<FileRoot::ComputedRoot>*> croots) { - auto desc = root.GetComputedDescription(); - if (desc) { - croots->emplace_back(*desc); + gsl::not_null<std::vector<PrecomputedRoot>*> croots) { + if (auto desc = root.GetPrecomputedDescription()) { + croots->emplace_back(*std::move(desc)); } } @@ -83,7 +83,7 @@ void AddDescriptionIfComputed( void TraverseRepoForComputedRoots( std::string const& name, gsl::not_null<RepositoryConfig*> const& repository_config, - gsl::not_null<std::vector<FileRoot::ComputedRoot>*> croots, + gsl::not_null<std::vector<PrecomputedRoot>*> roots, gsl::not_null<std::set<std::string>*> seen) { if (seen->contains(name)) { return; @@ -97,12 +97,12 @@ void TraverseRepoForComputedRoots( nlohmann::json(name).dump()); return; } - AddDescriptionIfComputed(info->workspace_root, croots); - AddDescriptionIfComputed(info->target_root, croots); - AddDescriptionIfComputed(info->rule_root, croots); - AddDescriptionIfComputed(info->expression_root, croots); + AddDescriptionIfPrecomputed(info->workspace_root, roots); + AddDescriptionIfPrecomputed(info->target_root, roots); + AddDescriptionIfPrecomputed(info->rule_root, roots); + AddDescriptionIfPrecomputed(info->expression_root, roots); for (auto const& [k, v] : info->name_mapping) { - TraverseRepoForComputedRoots(v, repository_config, croots, seen); + TraverseRepoForComputedRoots(v, repository_config, roots, seen); } } @@ -110,8 +110,8 @@ void TraverseRepoForComputedRoots( // upon auto GetRootDeps(std::string const& name, gsl::not_null<RepositoryConfig*> const& repository_config) - -> std::vector<FileRoot::ComputedRoot> { - std::vector<FileRoot::ComputedRoot> result{}; + -> std::vector<PrecomputedRoot> { + std::vector<PrecomputedRoot> result{}; std::set<std::string> seen{}; TraverseRepoForComputedRoots(name, repository_config, &result, &seen); sort_and_deduplicate(&result); @@ -130,9 +130,9 @@ auto GetRootDeps(std::string const& name, // For each computed root, we have to determine the git tree identifier; it has // to be given as string, as this is the format needed to update a repository // root. -using RootMap = AsyncMapConsumer<FileRoot::ComputedRoot, std::string>; +using RootMap = AsyncMapConsumer<PrecomputedRoot, std::string>; -auto WhileHandling(FileRoot::ComputedRoot const& root, +auto WhileHandling(PrecomputedRoot const& root, AsyncMapConsumerLoggerPtr const& logger) -> AsyncMapConsumerLoggerPtr { return std::make_shared<AsyncMapConsumerLogger>( @@ -266,7 +266,7 @@ auto IsTreePresent(std::string const& tree_id, } void ComputeAndFill( - FileRoot::ComputedRoot const& key, + ComputedRoot const& key, gsl::not_null<RepositoryConfig*> const& repository_config, gsl::not_null<const GraphTraverser::CommandLineArguments*> const& traverser_args, @@ -356,7 +356,8 @@ void ComputeAndFill( } { std::unique_lock setting{*config_lock}; - repository_config->SetComputedRoot(key, *root_result); + repository_config->SetPrecomputedRoot(PrecomputedRoot{key}, + *root_result); } (*setter)(std::move(root)); return; @@ -422,7 +423,8 @@ void ComputeAndFill( // For setting, we need an exclusiver lock; so get one after we // dropped the shared one std::unique_lock setting{*config_lock}; - repository_config->SetComputedRoot(key, *root_result); + repository_config->SetPrecomputedRoot(PrecomputedRoot{key}, + *root_result); } (*setter)(std::move(*result)); } @@ -446,17 +448,17 @@ auto FillRoots( context, config_lock, git_lock, - jobs]( - auto /*ts*/, - auto setter, - auto logger, - auto subcaller, - FileRoot::ComputedRoot const& key) { + jobs](auto /*ts*/, + auto setter, + auto logger, + auto subcaller, + PrecomputedRoot const& key) { auto annotated_logger = WhileHandling(key, logger); - std::vector<FileRoot::ComputedRoot> roots{}; + std::vector<PrecomputedRoot> roots{}; { std::shared_lock reading{*config_lock}; - roots = GetRootDeps(key.repository, repository_config); + roots = + GetRootDeps(key.GetReferencedRepository(), repository_config); } (*subcaller)( roots, @@ -472,18 +474,20 @@ auto FillRoots( jobs, logger = annotated_logger, setter](auto /*values*/) { - ComputeAndFill(key, - repository_config, - traverser_args, - serve, - context, - storage_config, - rehash, - config_lock, - git_lock, - jobs, - logger, - setter); + if (auto const computed = key.AsComputed()) { + ComputeAndFill(*computed, + repository_config, + traverser_args, + serve, + context, + storage_config, + rehash, + config_lock, + git_lock, + jobs, + logger, + setter); + } }, annotated_logger); }; @@ -492,7 +496,7 @@ auto FillRoots( } // namespace -auto EvaluateComputedRoots( +auto EvaluatePrecomputedRoots( gsl::not_null<RepositoryConfig*> const& repository_config, std::string const& main_repo, ServeApi const* serve, @@ -585,9 +589,8 @@ auto EvaluateComputedRoots( return false; } if (not done) { - const std::function<std::string(FileRoot::ComputedRoot const&)> - k_root_printer = - [](FileRoot::ComputedRoot const& x) -> std::string { + const std::function k_root_printer = + [](PrecomputedRoot const& x) -> std::string { return x.ToString(); }; diff --git a/src/buildtool/computed_roots/evaluate.hpp b/src/buildtool/computed_roots/evaluate.hpp index 8f726fcd..e90db25b 100644 --- a/src/buildtool/computed_roots/evaluate.hpp +++ b/src/buildtool/computed_roots/evaluate.hpp @@ -26,7 +26,7 @@ #include "src/buildtool/serve_api/remote/serve_api.hpp" #include "src/buildtool/storage/config.hpp" -auto EvaluateComputedRoots( +auto EvaluatePrecomputedRoots( gsl::not_null<RepositoryConfig*> const& repository_config, std::string const& main_repo, ServeApi const* serve, diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index ce92ab1e..e47b68f5 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -827,25 +827,17 @@ class FileRoot { FileRoot{std::string{root[1]}, /*ignore_special=*/true}, std::nullopt}; } - if (root[0] == FileRoot::kComputedMarker) { - // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers) - if (root.size() != 5 or (not root[1].is_string()) or - (not root[2].is_string()) or (not root[3].is_string()) or - (not root[4].is_object())) { - return unexpected{fmt::format( - "{} scheme requires, in this order, the arugments root, " - "module, name, config. However found {} for {} of " - "repository {}", - kComputedMarker, - root.dump(), - keyword, - repo)}; - } - return ResultType{FileRoot{std::string{root[1]}, - std::string{root[2]}, - std::string{root[3]}, - root[4]}, - std::nullopt}; + if (PrecomputedRoot::IsPrecomputedMarker(root[0])) { + auto precomputed = PrecomputedRoot::Parse(root); + if (not precomputed) { + return unexpected{ + fmt::format("While parsing {} for {} of repository{}:\n{}", + root.dump(), + keyword, + repo, + std::move(precomputed).error())}; + } + return ResultType{FileRoot{*std::move(precomputed)}, std::nullopt}; } return unexpected{fmt::format( "Unknown scheme in the specification {} of {} of repository {}", diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index a7bd14f8..42a36391 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -1047,14 +1047,14 @@ auto main(int argc, char* argv[]) -> int { } std::optional<ServeApi> serve = ServeApi::Create( *serve_config, &local_context, &remote_context, &main_apis); - if (not EvaluateComputedRoots(&repo_config, - main_repo, - serve ? &*serve : nullptr, - *storage_config, - git_storage_config, - traverse_args, - &exec_context, - eval_root_jobs)) { + if (not EvaluatePrecomputedRoots(&repo_config, + main_repo, + serve ? &*serve : nullptr, + *storage_config, + git_storage_config, + traverse_args, + &exec_context, + eval_root_jobs)) { return kExitFailure; } #else |