From 5f6ff55e97104e46c1b5c2c94b39ea0fca35ca7c Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 7 Mar 2024 15:44:28 +0100 Subject: just: Replace singletons for progress tracking and statistics... ...with regular instances that have controlled life-times. This avoids race conditions in tracking and reporting the results of analysis and build, as the serve endpoint can orchestrate multiple builds at the same time asynchronously. As a bonus side-effect this also ensures the correctness of the progress reporting per orchestrated build. --- .../build_engine/target_map/target_map.cpp | 26 ++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/buildtool/build_engine/target_map/target_map.cpp') diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp index 4d28ac6a..aed6d93a 100644 --- a/src/buildtool/build_engine/target_map/target_map.cpp +++ b/src/buildtool/build_engine/target_map/target_map.cpp @@ -1238,6 +1238,7 @@ void withTargetsFile( const BuildMaps::Target::ConfiguredTarget& key, const gsl::not_null& repo_config, const ActiveTargetCache& target_cache, + const gsl::not_null& stats, const nlohmann::json& targets_file, const gsl::not_null& source_target, const gsl::not_null& rule_map, @@ -1277,6 +1278,7 @@ void withTargetsFile( key, repo_config, target_cache, + stats, subcaller, setter, logger, @@ -1457,7 +1459,8 @@ void TreeTarget( const BuildMaps::Target::TargetMap::LoggerPtr& logger, const gsl::not_null& result_map, const gsl::not_null& - directory_entries) { + directory_entries, + const gsl::not_null& stats) { const auto& target = key.target.GetNamedTarget(); const auto dir_name = std::filesystem::path{target.module} / target.name; auto module_ = BuildMaps::Base::ModuleName{target.repository, dir_name}; @@ -1465,7 +1468,7 @@ void TreeTarget( directory_entries->ConsumeAfterKeysReady( ts, {module_}, - [setter, subcaller, target, key, result_map, logger, dir_name]( + [setter, subcaller, target, key, result_map, logger, dir_name, stats]( auto values) { // expected values.size() == 1 const auto& dir_entries = *values[0]; @@ -1495,7 +1498,7 @@ void TreeTarget( "Source tree reference for non-known tree {}", key.target.ToString()); }); - Statistics::Instance().IncrementTreesAnalysedCounter(); + stats->IncrementTreesAnalysedCounter(); using BuildMaps::Target::ConfiguredTarget; @@ -1660,6 +1663,7 @@ auto CreateTargetMap( const gsl::not_null& result_map, const gsl::not_null& repo_config, const ActiveTargetCache& target_cache, + const gsl::not_null& stats, std::size_t jobs) -> TargetMap { auto target_reader = [source_target_map, targets_file_map, @@ -1668,11 +1672,12 @@ auto CreateTargetMap( absent_target_map, result_map, repo_config, - target_cache](auto ts, - auto setter, - auto logger, - auto subcaller, - auto key) { + target_cache, + stats](auto ts, + auto setter, + auto logger, + auto subcaller, + auto key) { if (key.target.IsAnonymousTarget()) { withTargetNode(key, repo_config, @@ -1700,7 +1705,8 @@ auto CreateTargetMap( setter, wrapped_logger, result_map, - directory_entries_map); + directory_entries_map, + stats); } else if (key.target.GetNamedTarget().reference_t == BuildMaps::Base::ReferenceType::kFile) { @@ -1808,6 +1814,7 @@ auto CreateTargetMap( [key, repo_config, target_cache, + stats, source_target_map, rule_map, ts, @@ -1818,6 +1825,7 @@ auto CreateTargetMap( withTargetsFile(key, repo_config, target_cache, + stats, *values[0], source_target_map, rule_map, -- cgit v1.2.3