diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-06-11 13:19:38 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-06-18 12:05:10 +0200 |
commit | 60a056f0b01515ad70ff99d08dd3d2b7475c6c37 (patch) | |
tree | 4fd4de8710e29582f6843e32c703f5451717d572 /src | |
parent | 26fdbae5f7269c06f95d3d087e657bb192b909d1 (diff) | |
download | justbuild-60a056f0b01515ad70ff99d08dd3d2b7475c6c37.tar.gz |
Pass ServeApi as a field of context to the analysis
...instead of using singleton calls.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/target_map/absent_target_map.cpp | 35 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/absent_target_map.hpp | 5 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/export.cpp | 5 | ||||
-rw-r--r-- | src/buildtool/build_engine/target_map/target_map.cpp | 4 | ||||
-rw-r--r-- | src/buildtool/main/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/main/analyse.cpp | 10 | ||||
-rw-r--r-- | src/buildtool/main/analyse_context.hpp | 4 | ||||
-rw-r--r-- | src/buildtool/main/main.cpp | 14 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/TARGETS | 1 | ||||
-rw-r--r-- | src/buildtool/serve_api/serve_service/target.cpp | 7 |
10 files changed, 56 insertions, 31 deletions
diff --git a/src/buildtool/build_engine/target_map/absent_target_map.cpp b/src/buildtool/build_engine/target_map/absent_target_map.cpp index 0b2f3496..18251de3 100644 --- a/src/buildtool/build_engine/target_map/absent_target_map.cpp +++ b/src/buildtool/build_engine/target_map/absent_target_map.cpp @@ -76,7 +76,7 @@ void WithFlexibleVariables( target_cache_value{std::nullopt}; target_cache_value = context->target_cache.Read(*target_cache_key); bool from_just_serve = false; - if (!target_cache_value) { + if (not target_cache_value and context->serve) { auto task = fmt::format("[{},{}]", key.target.ToString(), PruneJson(effective_config.ToJson()).dump()); @@ -86,8 +86,7 @@ void WithFlexibleVariables( task, key.target.ToString()); context->progress->TaskTracker().Start(task); - auto res = - ServeApi::Instance().ServeTarget(*target_cache_key, *repo_key); + auto res = (*context->serve)->ServeTarget(*target_cache_key, *repo_key); // process response from serve endpoint if (not res) { // report target not found @@ -185,10 +184,11 @@ void WithFlexibleVariables( } // namespace -#endif +#endif // BOOTSTRAP_BUILD_TOOL -auto BuildMaps::Target::CreateAbsentTargetVariablesMap(std::size_t jobs) - -> AbsentTargetVariablesMap { +auto BuildMaps::Target::CreateAbsentTargetVariablesMap( + const gsl::not_null<AnalyseContext*>& context, + std::size_t jobs) -> AbsentTargetVariablesMap { #ifdef BOOTSTRAP_BUILD_TOOL auto target_variables = [](auto /*ts*/, auto /*setter*/, @@ -196,21 +196,26 @@ auto BuildMaps::Target::CreateAbsentTargetVariablesMap(std::size_t jobs) auto /*subcaller*/, auto /*key*/) {}; #else - auto target_variables = [](auto /*ts*/, - auto setter, - auto logger, - auto /*subcaller*/, - auto key) { - auto flexible_vars_opt = ServeApi::Instance().ServeTargetVariables( - key.target_root_id, key.target_file, key.target); - if (!flexible_vars_opt) { + auto target_variables = [context](auto /*ts*/, + auto setter, + auto logger, + auto /*subcaller*/, + auto key) { + std::optional<std::vector<std::string>> vars; + if (context->serve) { + vars = (*context->serve) + ->ServeTargetVariables( + key.target_root_id, key.target_file, key.target); + } + + if (not vars) { (*logger)(fmt::format("Failed to obtain flexible config variables " "for absent target {}", key.target), /*fatal=*/true); return; } - (*setter)(std::move(flexible_vars_opt.value())); + (*setter)(std::move(vars.value())); }; #endif return AbsentTargetVariablesMap{target_variables, jobs}; diff --git a/src/buildtool/build_engine/target_map/absent_target_map.hpp b/src/buildtool/build_engine/target_map/absent_target_map.hpp index 3c580336..7d04f5f4 100644 --- a/src/buildtool/build_engine/target_map/absent_target_map.hpp +++ b/src/buildtool/build_engine/target_map/absent_target_map.hpp @@ -48,8 +48,9 @@ using AbsentTargetVariablesMap = using ServeFailureLogReporter = std::function<void(ConfiguredTarget, std::string)>; -auto CreateAbsentTargetVariablesMap(std::size_t jobs = 0) - -> AbsentTargetVariablesMap; +auto CreateAbsentTargetVariablesMap( + const gsl::not_null<AnalyseContext*>& context, + std::size_t jobs = 0) -> AbsentTargetVariablesMap; auto CreateAbsentTargetMap(const gsl::not_null<AnalyseContext*>&, const gsl::not_null<ResultTargetMap*>&, diff --git a/src/buildtool/build_engine/target_map/export.cpp b/src/buildtool/build_engine/target_map/export.cpp index b908e60f..ea600fc7 100644 --- a/src/buildtool/build_engine/target_map/export.cpp +++ b/src/buildtool/build_engine/target_map/export.cpp @@ -142,8 +142,7 @@ void ExportRule( #ifndef BOOTSTRAP_BUILD_TOOL // if not found locally, try the serve endpoint - if (not target_cache_value and - RemoteServeConfig::Instance().RemoteAddress()) { + if (not target_cache_value and context->serve) { Logger::Log(LogLevel::Debug, "Querying serve endpoint for export target {}", key.target.ToString()); @@ -153,7 +152,7 @@ void ExportRule( PruneJson(effective_config.ToJson()).dump()); context->progress->TaskTracker().Start(task); auto res = - ServeApi::Instance().ServeTarget(*target_cache_key, *repo_key); + (*context->serve)->ServeTarget(*target_cache_key, *repo_key); // process response from serve endpoint if (not res) { // target not found: log to performance, and continue diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp index 0170f3f5..8df7abbf 100644 --- a/src/buildtool/build_engine/target_map/target_map.cpp +++ b/src/buildtool/build_engine/target_map/target_map.cpp @@ -1905,7 +1905,7 @@ auto CreateTargetMap( else if (context->repo_config ->TargetRoot(key.target.ToModule().repository) ->IsAbsent()) { - if (not RemoteServeConfig::Instance().RemoteAddress()) { + if (not context->serve) { (*logger)( fmt::format("Root for target {} is absent, but no serve " "endpoint was configured. Please provide " @@ -1914,7 +1914,7 @@ auto CreateTargetMap( /*is_fatal=*/true); return; } - if (not ServeApi::Instance().CheckServeRemoteExecution()) { + if (not(*context->serve)->CheckServeRemoteExecution()) { (*logger)( "Inconsistent remote execution endpoint and serve endpoint" "configuration detected.", diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS index 6fba9d29..b92d4738 100644 --- a/src/buildtool/main/TARGETS +++ b/src/buildtool/main/TARGETS @@ -32,6 +32,7 @@ , ["src/buildtool/serve_api/remote", "config"] , ["src/buildtool/serve_api/serve_service", "serve_server_implementation"] , ["src/buildtool/storage", "file_chunker"] + , ["src/buildtool/serve_api/remote", "serve_api"] , "common" , "cli" , "version" @@ -200,6 +201,7 @@ , ["src/buildtool/progress_reporting", "exports_progress_reporter"] , ["src/buildtool/progress_reporting", "progress"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/serve_api/remote", "serve_api"] ] , "stage": ["src", "buildtool", "main"] } diff --git a/src/buildtool/main/analyse.cpp b/src/buildtool/main/analyse.cpp index 22ad8586..13214463 100644 --- a/src/buildtool/main/analyse.cpp +++ b/src/buildtool/main/analyse.cpp @@ -116,7 +116,7 @@ namespace Target = BuildMaps::Target; auto source_targets = Base::CreateSourceTargetMap( &directory_entries, context->repo_config, jobs); auto absent_target_variables_map = - Target::CreateAbsentTargetVariablesMap(jobs); + Target::CreateAbsentTargetVariablesMap(context, jobs); auto absent_target_map = Target::CreateAbsentTargetMap( context, result_map, &absent_target_variables_map, jobs, serve_log); @@ -134,13 +134,7 @@ namespace Target = BuildMaps::Target; AnalysedTargetPtr target{}; // we should only report served export targets if a serve endpoint exists - bool has_serve{false}; -#ifndef BOOTSTRAP_BUILD_TOOL - if (RemoteServeConfig::Instance().RemoteAddress()) { - has_serve = true; - } -#endif // BOOTSTRAP_BUILD_TOOL - + bool has_serve = context->serve.has_value(); std::atomic<bool> done{false}; std::condition_variable cv{}; auto reporter = ExportsProgressReporter::Reporter( diff --git a/src/buildtool/main/analyse_context.hpp b/src/buildtool/main/analyse_context.hpp index 3897d84c..0702410c 100644 --- a/src/buildtool/main/analyse_context.hpp +++ b/src/buildtool/main/analyse_context.hpp @@ -15,10 +15,13 @@ #ifndef INCLUDED_SRC_BUILDOOL_MAIN_ANALYSE_CONTEXT_HPP #define INCLUDED_SRC_BUILDOOL_MAIN_ANALYSE_CONTEXT_HPP +#include <optional> + #include "gsl/gsl" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/progress_reporting/progress.hpp" +#include "src/buildtool/serve_api/remote/serve_api.hpp" #include "src/buildtool/storage/target_cache.hpp" struct AnalyseContext final { @@ -26,6 +29,7 @@ struct AnalyseContext final { ActiveTargetCache const& target_cache; gsl::not_null<Statistics*> statistics; gsl::not_null<Progress*> progress; + std::optional<gsl::not_null<const ServeApi*>> serve; }; #endif // INCLUDED_SRC_BUILDOOL_MAIN_ANALYSE_CONTEXT_HPP diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 92f64891..7ae42622 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -56,6 +56,7 @@ #include "src/buildtool/multithreading/async_map_consumer.hpp" #include "src/buildtool/multithreading/task_system.hpp" #include "src/buildtool/progress_reporting/progress.hpp" +#include "src/buildtool/serve_api/remote/serve_api.hpp" #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/file_chunker.hpp" #include "src/buildtool/storage/garbage_collector.hpp" @@ -948,6 +949,15 @@ auto main(int argc, char* argv[]) -> int { DetermineRoots(&repo_config, arguments.common, arguments.analysis); #ifndef BOOTSTRAP_BUILD_TOOL + std::optional<gsl::not_null<const ServeApi*>> serve; + if (RemoteServeConfig::Instance().RemoteAddress()) { + serve = &ServeApi::Instance(); + } +#else + std::optional<gsl::not_null<const ServeApi*>> serve; +#endif // BOOTSTRAP_BUILD_TOOL + +#ifndef BOOTSTRAP_BUILD_TOOL auto lock = GarbageCollector::SharedLock(); if (not lock) { return kExitFailure; @@ -1019,7 +1029,9 @@ auto main(int argc, char* argv[]) -> int { .repo_config = &repo_config, .target_cache = Storage::Instance().TargetCache(), .statistics = &stats, - .progress = &exports_progress}; + .progress = &exports_progress, + .serve = serve}; + auto result = AnalyseTarget(&analyse_ctx, id, &result_map, diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS index 008a76a4..1be5da66 100644 --- a/src/buildtool/serve_api/serve_service/TARGETS +++ b/src/buildtool/serve_api/serve_service/TARGETS @@ -109,6 +109,7 @@ , ["src/buildtool/progress_reporting", "progress"] , ["src/buildtool/main", "analyse_context"] , ["src/buildtool/common", "config"] + , ["src/buildtool/serve_api/remote", "serve_api"] ] } , "configuration_service": diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp index 5f6f038f..afa98b24 100644 --- a/src/buildtool/serve_api/serve_service/target.cpp +++ b/src/buildtool/serve_api/serve_service/target.cpp @@ -39,6 +39,7 @@ #include "src/buildtool/progress_reporting/progress.hpp" #include "src/buildtool/progress_reporting/progress_reporter.hpp" #include "src/buildtool/serve_api/remote/config.hpp" +#include "src/buildtool/serve_api/remote/serve_api.hpp" #include "src/buildtool/serve_api/serve_service/target_utils.hpp" #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" @@ -453,6 +454,12 @@ auto TargetService::ServeTarget( .statistics = &stats, .progress = &progress}; +#ifndef BOOTSTRAP_BUILD_TOOL + if (RemoteServeConfig::Instance().RemoteAddress()) { + analyse_ctx.serve = &ServeApi::Instance(); + } +#endif // BOOTSTRAP_BUILD_TOOL + // analyse the configured target auto result = AnalyseTarget(&analyse_ctx, configured_target, |