summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/build_engine/target_map/TARGETS14
-rw-r--r--src/buildtool/build_engine/target_map/absent_target_map.cpp139
-rw-r--r--src/buildtool/build_engine/target_map/absent_target_map.hpp19
-rw-r--r--src/buildtool/build_engine/target_map/built_in_rules.cpp77
-rw-r--r--src/buildtool/build_engine/target_map/built_in_rules.hpp10
-rw-r--r--src/buildtool/build_engine/target_map/export.cpp38
-rw-r--r--src/buildtool/build_engine/target_map/export.hpp23
-rw-r--r--src/buildtool/build_engine/target_map/target_map.cpp70
-rw-r--r--src/buildtool/build_engine/target_map/target_map.hpp10
-rw-r--r--src/buildtool/main/TARGETS24
-rw-r--r--src/buildtool/main/analyse.cpp50
-rw-r--r--src/buildtool/main/analyse.hpp8
-rw-r--r--src/buildtool/main/analyse_context.hpp31
-rw-r--r--src/buildtool/main/main.cpp15
-rw-r--r--src/buildtool/serve_api/serve_service/TARGETS4
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp15
16 files changed, 259 insertions, 288 deletions
diff --git a/src/buildtool/build_engine/target_map/TARGETS b/src/buildtool/build_engine/target_map/TARGETS
index 3693049c..6768abe3 100644
--- a/src/buildtool/build_engine/target_map/TARGETS
+++ b/src/buildtool/build_engine/target_map/TARGETS
@@ -47,11 +47,9 @@
, ["src/buildtool/build_engine/base_maps", "rule_map"]
, ["src/buildtool/build_engine/base_maps", "source_map"]
, ["src/buildtool/build_engine/base_maps", "targets_file_map"]
- , ["src/buildtool/common", "common"]
- , ["src/buildtool/common", "config"]
, ["src/buildtool/multithreading", "async_map_consumer"]
- , ["src/buildtool/progress_reporting", "progress"]
, ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/main", "analyse_context"]
, ["@", "gsl", "", "gsl"]
, ["@", "json", "", "json"]
]
@@ -73,6 +71,9 @@
, ["src/utils/cpp", "vector"]
, ["src/buildtool/serve_api/remote", "serve_api"]
, ["src/buildtool/serve_api/remote", "config"]
+ , ["src/buildtool/common", "common"]
+ , ["src/buildtool/common", "config"]
+ , ["src/buildtool/progress_reporting", "progress"]
]
}
, "target_map_testable_internals":
@@ -102,11 +103,9 @@
[ "configured_target"
, "result_map"
, ["src/buildtool/build_engine/analysed_target", "target"]
- , ["src/buildtool/common", "common"]
- , ["src/buildtool/common", "config"]
, ["src/buildtool/multithreading", "async_map_consumer"]
- , ["src/buildtool/progress_reporting", "progress"]
, ["src/utils/cpp", "hash_combine"]
+ , ["src/buildtool/main", "analyse_context"]
, ["@", "gsl", "", "gsl"]
]
, "stage": ["src", "buildtool", "build_engine", "target_map"]
@@ -117,6 +116,9 @@
, ["src/buildtool/serve_api/remote", "serve_api"]
, ["src/utils/cpp", "json"]
, ["@", "json", "", "json"]
+ , ["src/buildtool/common", "common"]
+ , ["src/buildtool/common", "config"]
+ , ["src/buildtool/progress_reporting", "progress"]
]
}
}
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 fca75194..0b2f3496 100644
--- a/src/buildtool/build_engine/target_map/absent_target_map.cpp
+++ b/src/buildtool/build_engine/target_map/absent_target_map.cpp
@@ -18,9 +18,13 @@
#include <utility> // std::move
#include "nlohmann/json.hpp"
+#include "src/buildtool/common/repository_config.hpp"
+#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/buildtool/serve_api/remote/serve_api.hpp"
+#include "src/buildtool/storage/target_cache.hpp"
#include "src/buildtool/storage/target_cache_key.hpp"
#include "src/utils/cpp/json.hpp"
#endif
@@ -29,15 +33,13 @@
namespace {
void WithFlexibleVariables(
+ const gsl::not_null<AnalyseContext*>& context,
const BuildMaps::Target::ConfiguredTarget& key,
std::vector<std::string> flexible_vars,
- gsl::not_null<const RepositoryConfig*> const& repo_config,
const BuildMaps::Target::AbsentTargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::AbsentTargetMap::SetterPtr& setter,
const BuildMaps::Target::AbsentTargetMap::LoggerPtr& logger,
const gsl::not_null<BuildMaps::Target::ResultTargetMap*> result_map,
- gsl::not_null<Statistics*> const& stats,
- gsl::not_null<Progress*> const& exports_progress,
BuildMaps::Target::ServeFailureLogReporter* serve_failure_reporter) {
auto effective_config = key.config.Prune(flexible_vars);
if (key.config != effective_config) {
@@ -53,16 +55,16 @@ void WithFlexibleVariables(
}
// TODO(asartori): avoid code duplication in export.cpp
- stats->IncrementExportsFoundCounter();
+ context->statistics->IncrementExportsFoundCounter();
auto target_name = key.target.GetNamedTarget();
- auto repo_key = repo_config->RepositoryKey(target_name.repository);
+ auto repo_key = context->repo_config->RepositoryKey(target_name.repository);
if (!repo_key) {
(*logger)(fmt::format("Failed to obtain repository key for repo \"{}\"",
target_name.repository),
/*fatal=*/true);
return;
}
- auto target_cache_key = Storage::Instance().TargetCache().ComputeKey(
+ auto target_cache_key = context->target_cache.ComputeKey(
*repo_key, target_name, effective_config);
if (not target_cache_key) {
(*logger)(fmt::format("Could not produce cache key for target {}",
@@ -72,8 +74,7 @@ void WithFlexibleVariables(
}
std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>>
target_cache_value{std::nullopt};
- target_cache_value =
- Storage::Instance().TargetCache().Read(*target_cache_key);
+ target_cache_value = context->target_cache.Read(*target_cache_key);
bool from_just_serve = false;
if (!target_cache_value) {
auto task = fmt::format("[{},{}]",
@@ -84,7 +85,7 @@ void WithFlexibleVariables(
"Querying serve endpoint for absent export target {} with key {}",
task,
key.target.ToString());
- exports_progress->TaskTracker().Start(task);
+ context->progress->TaskTracker().Start(task);
auto res =
ServeApi::Instance().ServeTarget(*target_cache_key, *repo_key);
// process response from serve endpoint
@@ -125,7 +126,7 @@ void WithFlexibleVariables(
default: {
// index == 3
target_cache_value = std::get<3>(*res);
- exports_progress->TaskTracker().Stop(task);
+ context->progress->TaskTracker().Stop(task);
from_just_serve = true;
}
}
@@ -170,10 +171,10 @@ void WithFlexibleVariables(
(*setter)(std::move(analysis_result));
if (from_just_serve) {
- stats->IncrementExportsServedCounter();
+ context->statistics->IncrementExportsServedCounter();
}
else {
- stats->IncrementExportsCachedCounter();
+ context->statistics->IncrementExportsCachedCounter();
}
return;
}
@@ -216,75 +217,63 @@ auto BuildMaps::Target::CreateAbsentTargetVariablesMap(std::size_t jobs)
}
auto BuildMaps::Target::CreateAbsentTargetMap(
+ const gsl::not_null<AnalyseContext*>& context,
const gsl::not_null<ResultTargetMap*>& result_map,
const gsl::not_null<AbsentTargetVariablesMap*>& absent_variables,
- gsl::not_null<const RepositoryConfig*> const& repo_config,
- gsl::not_null<Statistics*> const& stats,
- gsl::not_null<Progress*> const& exports_progress,
std::size_t jobs,
BuildMaps::Target::ServeFailureLogReporter* serve_failure_reporter)
-> AbsentTargetMap {
#ifndef BOOTSTRAP_BUILD_TOOL
- auto target_reader = [result_map,
- repo_config,
- stats,
- exports_progress,
- absent_variables,
- serve_failure_reporter](auto ts,
- auto setter,
- auto logger,
- auto subcaller,
- auto key) {
- // assumptions:
- // - target with absent targets file requested
- // - ServeApi correctly configured
- auto const& repo_name = key.target.ToModule().repository;
- auto target_root_id =
- repo_config->TargetRoot(repo_name)->GetAbsentTreeId();
- if (!target_root_id) {
- (*logger)(fmt::format("Failed to get the target root id for "
- "repository \"{}\"",
- repo_name),
- /*fatal=*/true);
- return;
- }
- std::filesystem::path module{key.target.ToModule().module};
- auto vars_request = AbsentTargetDescription{
- .target_root_id = *target_root_id,
- .target_file =
- (module / *(repo_config->TargetFileName(repo_name))).string(),
- .target = key.target.GetNamedTarget().name};
- absent_variables->ConsumeAfterKeysReady(
- ts,
- {vars_request},
- [key,
- setter,
- repo_config,
- logger,
- serve_failure_reporter,
- result_map,
- stats,
- exports_progress,
- subcaller](auto const& values) {
- WithFlexibleVariables(key,
- *(values[0]),
- repo_config,
- subcaller,
- setter,
- logger,
- result_map,
- stats,
- exports_progress,
- serve_failure_reporter);
- },
- [logger, target = key.target](auto const& msg, auto fatal) {
- (*logger)(fmt::format("While requested the flexible "
- "variables of {}:\n{}",
- target.ToString(),
- msg),
- fatal);
- });
- };
+ auto target_reader =
+ [context, result_map, absent_variables, serve_failure_reporter](
+ auto ts, auto setter, auto logger, auto subcaller, auto key) {
+ // assumptions:
+ // - target with absent targets file requested
+ // - ServeApi correctly configured
+ auto const& repo_name = key.target.ToModule().repository;
+ auto target_root_id =
+ context->repo_config->TargetRoot(repo_name)->GetAbsentTreeId();
+ if (!target_root_id) {
+ (*logger)(fmt::format("Failed to get the target root id for "
+ "repository \"{}\"",
+ repo_name),
+ /*fatal=*/true);
+ return;
+ }
+ std::filesystem::path module{key.target.ToModule().module};
+ auto vars_request = AbsentTargetDescription{
+ .target_root_id = *target_root_id,
+ .target_file = (module / *(context->repo_config->TargetFileName(
+ repo_name)))
+ .string(),
+ .target = key.target.GetNamedTarget().name};
+ absent_variables->ConsumeAfterKeysReady(
+ ts,
+ {vars_request},
+ [context,
+ key,
+ setter,
+ logger,
+ serve_failure_reporter,
+ result_map,
+ subcaller](auto const& values) {
+ WithFlexibleVariables(context,
+ key,
+ *(values[0]),
+ subcaller,
+ setter,
+ logger,
+ result_map,
+ serve_failure_reporter);
+ },
+ [logger, target = key.target](auto const& msg, auto fatal) {
+ (*logger)(fmt::format("While requested the flexible "
+ "variables of {}:\n{}",
+ target.ToString(),
+ msg),
+ fatal);
+ });
+ };
#else
auto target_reader = [](auto /*ts*/,
auto /*setter*/,
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 65416e68..3c580336 100644
--- a/src/buildtool/build_engine/target_map/absent_target_map.hpp
+++ b/src/buildtool/build_engine/target_map/absent_target_map.hpp
@@ -24,10 +24,8 @@
#include "src/buildtool/build_engine/analysed_target/analysed_target.hpp"
#include "src/buildtool/build_engine/target_map/configured_target.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
-#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/common/statistics.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
#include "src/buildtool/multithreading/async_map_consumer.hpp"
-#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/utils/cpp/hash_combine.hpp"
namespace BuildMaps::Target {
@@ -53,15 +51,12 @@ using ServeFailureLogReporter =
auto CreateAbsentTargetVariablesMap(std::size_t jobs = 0)
-> AbsentTargetVariablesMap;
-auto CreateAbsentTargetMap(
- const gsl::not_null<ResultTargetMap*>&,
- const gsl::not_null<AbsentTargetVariablesMap*>&,
- gsl::not_null<const RepositoryConfig*> const& repo_config,
- gsl::not_null<Statistics*> const& stats,
- gsl::not_null<Progress*> const& exports_progress,
- std::size_t jobs = 0,
- ServeFailureLogReporter* serve_failure_reporter = nullptr)
- -> AbsentTargetMap;
+auto CreateAbsentTargetMap(const gsl::not_null<AnalyseContext*>&,
+ const gsl::not_null<ResultTargetMap*>&,
+ const gsl::not_null<AbsentTargetVariablesMap*>&,
+ std::size_t jobs = 0,
+ ServeFailureLogReporter* serve_failure_reporter =
+ nullptr) -> AbsentTargetMap;
} // namespace BuildMaps::Target
diff --git a/src/buildtool/build_engine/target_map/built_in_rules.cpp b/src/buildtool/build_engine/target_map/built_in_rules.cpp
index 21292b3f..7d858840 100644
--- a/src/buildtool/build_engine/target_map/built_in_rules.cpp
+++ b/src/buildtool/build_engine/target_map/built_in_rules.cpp
@@ -32,6 +32,7 @@
#include "src/buildtool/build_engine/expression/expression_ptr.hpp"
#include "src/buildtool/build_engine/target_map/export.hpp"
#include "src/buildtool/build_engine/target_map/utils.hpp"
+#include "src/buildtool/common/repository_config.hpp"
#include "src/utils/cpp/path.hpp"
#include "src/utils/cpp/vector.hpp"
@@ -376,19 +377,16 @@ void BlobGenRule(
}
void FileGenRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- [[maybe_unused]] const ActiveTargetCache& /*target_cache*/,
- [[maybe_unused]] const gsl::not_null<Statistics*>& /*stats*/,
- [[maybe_unused]] const gsl::not_null<Progress*>& /*exports_progress*/,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
const gsl::not_null<BuildMaps::Target::ResultTargetMap*>& result_map) {
BlobGenRule(desc_json,
key,
- repo_config,
+ context->repo_config,
subcaller,
setter,
logger,
@@ -397,19 +395,16 @@ void FileGenRule(
}
void SymlinkRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- [[maybe_unused]] const ActiveTargetCache& /*target_cache*/,
- [[maybe_unused]] const gsl::not_null<Statistics*>& /*stats*/,
- [[maybe_unused]] const gsl::not_null<Progress*>& /*exports_progress*/,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
const gsl::not_null<BuildMaps::Target::ResultTargetMap*>& result_map) {
BlobGenRule(desc_json,
key,
- repo_config,
+ context->repo_config,
subcaller,
setter,
logger,
@@ -535,12 +530,9 @@ void TreeRuleWithDeps(
}
void TreeRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- [[maybe_unused]] const ActiveTargetCache& /*target_cache*/,
- [[maybe_unused]] const gsl::not_null<Statistics*>& /*stats*/,
- [[maybe_unused]] const gsl::not_null<Progress*>& /*exports_progress*/,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
@@ -579,7 +571,7 @@ void TreeRule(
auto dep_target = BuildMaps::Base::ParseEntityNameFromExpression(
dep_name,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &dep_name](std::string const& parse_err) {
(*logger)(fmt::format("Parsing dep entry {} failed with:\n{}",
dep_name->ToString(),
@@ -797,12 +789,9 @@ void InstallRuleWithDeps(
}
void InstallRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- [[maybe_unused]] const ActiveTargetCache& /*target_cache*/,
- [[maybe_unused]] const gsl::not_null<Statistics*>& /*stats*/,
- [[maybe_unused]] const gsl::not_null<Progress*>& /*exports_progress*/,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
@@ -843,7 +832,7 @@ void InstallRule(
auto dep_target = BuildMaps::Base::ParseEntityNameFromExpression(
dep_name,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &dep_name](std::string const& parse_err) {
(*logger)(fmt::format("Parsing dep entry {} failed with:\n{}",
dep_name->ToString(),
@@ -888,7 +877,7 @@ void InstallRule(
auto dep_target = BuildMaps::Base::ParseEntityNameFromExpression(
dep_name,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &dep_name, &path = path](std::string const& parse_err) {
(*logger)(fmt::format("Parsing file entry {} for key {} failed "
"with:\n{}",
@@ -939,7 +928,7 @@ void InstallRule(
auto dep_target = BuildMaps::Base::ParseEntityNameFromExpression(
entry->List()[0],
key.target,
- repo_config,
+ context->repo_config,
[&logger, &entry](std::string const& parse_err) {
(*logger)(fmt::format("Parsing dir entry {} for path {} failed "
"with:\n{}",
@@ -1385,16 +1374,13 @@ void GenericRuleWithDeps(
}
void GenericRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- [[maybe_unused]] const ActiveTargetCache& /*target_cache*/,
- [[maybe_unused]] const gsl::not_null<Statistics*>& /*stats*/,
- [[maybe_unused]] const gsl::not_null<Progress*>& /*exports_progress*/,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
- const gsl::not_null<BuildMaps::Target::ResultTargetMap*> result_map) {
+ const gsl::not_null<BuildMaps::Target::ResultTargetMap*>& result_map) {
auto desc = BuildMaps::Base::FieldReader::CreatePtr(
desc_json, key.target, "generic target", logger);
desc->ExpectFields(kGenericRuleFields);
@@ -1428,7 +1414,7 @@ void GenericRule(
auto dep_target = BuildMaps::Base::ParseEntityNameFromExpression(
dep_name,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &dep_name](std::string const& parse_err) {
(*logger)(fmt::format("Parsing dep entry {} failed with:\n{}",
dep_name->ToString(),
@@ -1450,13 +1436,13 @@ void GenericRule(
setter,
logger,
key,
- repo_config,
+ context,
result_map](auto const& values) {
GenericRuleWithDeps(transition_keys,
values,
desc,
key,
- repo_config,
+ context->repo_config,
setter,
logger,
result_map);
@@ -1465,12 +1451,9 @@ void GenericRule(
}
void ConfigureRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- [[maybe_unused]] const ActiveTargetCache& /*target_cache*/,
- [[maybe_unused]] const gsl::not_null<Statistics*>& /*stats*/,
- [[maybe_unused]] const gsl::not_null<Progress*>& /*exports_progress*/,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
@@ -1500,7 +1483,7 @@ void ConfigureRule(
auto configured_target = BuildMaps::Base::ParseEntityNameFromExpression(
configured_target_name,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &configured_target_name](std::string const& parse_err) {
(*logger)(fmt::format("Parsing target name {} failed with:\n{}",
configured_target_name->ToString(),
@@ -1608,16 +1591,13 @@ void ConfigureRule(
auto const kBuiltIns = std::unordered_map<
std::string,
std::function<void(
+ const gsl::not_null<AnalyseContext*>&,
const nlohmann::json&,
const BuildMaps::Target::ConfiguredTarget&,
- const gsl::not_null<const RepositoryConfig*>&,
- const ActiveTargetCache&,
- const gsl::not_null<Statistics*>&,
- const gsl::not_null<Progress*>&,
const BuildMaps::Target::TargetMap::SubCallerPtr&,
const BuildMaps::Target::TargetMap::SetterPtr&,
const BuildMaps::Target::TargetMap::LoggerPtr&,
- const gsl::not_null<BuildMaps::Target::ResultTargetMap*>)>>{
+ const gsl::not_null<BuildMaps::Target::ResultTargetMap*>&)>>{
{"export", ExportRule},
{"file_gen", FileGenRule},
{"tree", TreeRule},
@@ -1640,13 +1620,10 @@ auto IsBuiltInRule(nlohmann::json const& rule_type) -> bool {
}
auto HandleBuiltin(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& rule_type,
const nlohmann::json& desc,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- const ActiveTargetCache& target_cache,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
@@ -1669,16 +1646,8 @@ auto HandleBuiltin(
msg),
fatal);
});
- (it->second)(desc,
- key,
- repo_config,
- target_cache,
- stats,
- exports_progress,
- subcaller,
- setter,
- target_logger,
- result_map);
+ (it->second)(
+ context, desc, key, subcaller, setter, target_logger, result_map);
return true;
}
} // namespace BuildMaps::Target
diff --git a/src/buildtool/build_engine/target_map/built_in_rules.hpp b/src/buildtool/build_engine/target_map/built_in_rules.hpp
index 2df85bc0..6790148a 100644
--- a/src/buildtool/build_engine/target_map/built_in_rules.hpp
+++ b/src/buildtool/build_engine/target_map/built_in_rules.hpp
@@ -20,20 +20,14 @@
#include "src/buildtool/build_engine/target_map/configured_target.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
#include "src/buildtool/build_engine/target_map/target_map.hpp"
-#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/common/statistics.hpp"
-#include "src/buildtool/progress_reporting/progress.hpp"
-#include "src/buildtool/storage/target_cache.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
namespace BuildMaps::Target {
auto HandleBuiltin(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& rule_type,
const nlohmann::json& desc,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- const ActiveTargetCache& target_cache,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
diff --git a/src/buildtool/build_engine/target_map/export.cpp b/src/buildtool/build_engine/target_map/export.cpp
index 3e309280..b908e60f 100644
--- a/src/buildtool/build_engine/target_map/export.cpp
+++ b/src/buildtool/build_engine/target_map/export.cpp
@@ -20,10 +20,13 @@
#include "nlohmann/json.hpp"
#include "src/buildtool/build_engine/base_maps/field_reader.hpp"
#include "src/buildtool/build_engine/expression/configuration.hpp"
+#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/progress_reporting/progress.hpp"
#include "src/buildtool/storage/storage.hpp"
+#include "src/buildtool/storage/target_cache.hpp"
#include "src/utils/cpp/json.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
#include "src/buildtool/serve_api/remote/config.hpp"
@@ -99,16 +102,13 @@ void FinalizeExport(
} // namespace
void ExportRule(
+ const gsl::not_null<AnalyseContext*>& context,
const nlohmann::json& desc_json,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- const ActiveTargetCache& target_cache,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
const BuildMaps::Target::TargetMap::SetterPtr& setter,
const BuildMaps::Target::TargetMap::LoggerPtr& logger,
- const gsl::not_null<BuildMaps::Target::ResultTargetMap*> result_map) {
+ const gsl::not_null<BuildMaps::Target::ResultTargetMap*>& result_map) {
auto desc = BuildMaps::Base::FieldReader::CreatePtr(
desc_json, key.target, "export target", logger);
auto flexible_vars = desc->ReadStringList("flexible_config");
@@ -127,17 +127,17 @@ void ExportRule(
logger);
return;
}
- stats->IncrementExportsFoundCounter();
+ context->statistics->IncrementExportsFoundCounter();
auto const& target_name = key.target.GetNamedTarget();
- auto repo_key = repo_config->RepositoryKey(target_name.repository);
- auto target_cache_key =
- repo_key
- ? target_cache.ComputeKey(*repo_key, target_name, effective_config)
- : std::nullopt;
+ auto repo_key = context->repo_config->RepositoryKey(target_name.repository);
+ auto target_cache_key = repo_key
+ ? context->target_cache.ComputeKey(
+ *repo_key, target_name, effective_config)
+ : std::nullopt;
if (target_cache_key) {
// first try to get value from local target cache
- auto target_cache_value = target_cache.Read(*target_cache_key);
+ auto target_cache_value = context->target_cache.Read(*target_cache_key);
bool from_just_serve{false};
#ifndef BOOTSTRAP_BUILD_TOOL
@@ -151,7 +151,7 @@ void ExportRule(
fmt::format("[{},{}]",
key.target.ToString(),
PruneJson(effective_config.ToJson()).dump());
- exports_progress->TaskTracker().Start(task);
+ context->progress->TaskTracker().Start(task);
auto res =
ServeApi::Instance().ServeTarget(*target_cache_key, *repo_key);
// process response from serve endpoint
@@ -202,12 +202,12 @@ void ExportRule(
}
}
}
- exports_progress->TaskTracker().Stop(task);
+ context->progress->TaskTracker().Stop(task);
}
#endif // BOOTSTRAP_BUILD_TOOL
if (not target_cache_value) {
- stats->IncrementExportsUncachedCounter();
+ context->statistics->IncrementExportsUncachedCounter();
Logger::Log(LogLevel::Performance,
"Export target {} registered for caching: {}",
key.target.ToString(),
@@ -250,10 +250,10 @@ void ExportRule(
(*setter)(std::move(analysis_result));
if (from_just_serve) {
- stats->IncrementExportsServedCounter();
+ context->statistics->IncrementExportsServedCounter();
}
else {
- stats->IncrementExportsCachedCounter();
+ context->statistics->IncrementExportsCachedCounter();
}
return;
}
@@ -263,7 +263,7 @@ void ExportRule(
}
}
else {
- stats->IncrementExportsNotEligibleCounter();
+ context->statistics->IncrementExportsNotEligibleCounter();
Logger::Log(LogLevel::Performance,
"Export target {} is not eligible for target caching",
key.target.ToString());
@@ -277,7 +277,7 @@ void ExportRule(
auto exported_target = BuildMaps::Base::ParseEntityNameFromExpression(
exported_target_name,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &exported_target_name](std::string const& parse_err) {
(*logger)(fmt::format("Parsing target name {} failed with:\n{}",
exported_target_name->ToString(),
diff --git a/src/buildtool/build_engine/target_map/export.hpp b/src/buildtool/build_engine/target_map/export.hpp
index 1af92b6b..e0e6e568 100644
--- a/src/buildtool/build_engine/target_map/export.hpp
+++ b/src/buildtool/build_engine/target_map/export.hpp
@@ -20,20 +20,15 @@
#include "src/buildtool/build_engine/target_map/configured_target.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
#include "src/buildtool/build_engine/target_map/target_map.hpp"
-#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/common/statistics.hpp"
-#include "src/buildtool/progress_reporting/progress.hpp"
-#include "src/buildtool/storage/target_cache.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
-void ExportRule(const nlohmann::json& desc_json,
- const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- const ActiveTargetCache& target_cache,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
- const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
- const BuildMaps::Target::TargetMap::SetterPtr& setter,
- const BuildMaps::Target::TargetMap::LoggerPtr& logger,
- gsl::not_null<BuildMaps::Target::ResultTargetMap*> result_map);
+void ExportRule(
+ const gsl::not_null<AnalyseContext*>& context,
+ const nlohmann::json& desc_json,
+ const BuildMaps::Target::ConfiguredTarget& key,
+ const BuildMaps::Target::TargetMap::SubCallerPtr& subcaller,
+ const BuildMaps::Target::TargetMap::SetterPtr& setter,
+ const BuildMaps::Target::TargetMap::LoggerPtr& logger,
+ const gsl::not_null<BuildMaps::Target::ResultTargetMap*>& result_map);
#endif
diff --git a/src/buildtool/build_engine/target_map/target_map.cpp b/src/buildtool/build_engine/target_map/target_map.cpp
index fc19a6c6..0170f3f5 100644
--- a/src/buildtool/build_engine/target_map/target_map.cpp
+++ b/src/buildtool/build_engine/target_map/target_map.cpp
@@ -37,6 +37,8 @@
#include "src/buildtool/build_engine/expression/function_map.hpp"
#include "src/buildtool/build_engine/target_map/built_in_rules.hpp"
#include "src/buildtool/build_engine/target_map/utils.hpp"
+#include "src/buildtool/common/repository_config.hpp"
+#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/gsl.hpp"
@@ -1370,11 +1372,8 @@ void withRuleDefinition(
}
void withTargetsFile(
+ const gsl::not_null<AnalyseContext*>& context,
const BuildMaps::Target::ConfiguredTarget& key,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- const ActiveTargetCache& target_cache,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
const nlohmann::json& targets_file,
const gsl::not_null<BuildMaps::Base::SourceTargetMap*>& source_target,
const gsl::not_null<BuildMaps::Base::UserRuleMap*>& rule_map,
@@ -1409,18 +1408,14 @@ void withTargetsFile(
return;
}
// Handle built-in rule, if it is
- auto handled_as_builtin =
- BuildMaps::Target::HandleBuiltin(*rule_it,
- desc,
- key,
- repo_config,
- target_cache,
- stats,
- exports_progress,
- subcaller,
- setter,
- logger,
- result_map);
+ auto handled_as_builtin = BuildMaps::Target::HandleBuiltin(context,
+ *rule_it,
+ desc,
+ key,
+ subcaller,
+ setter,
+ logger,
+ result_map);
if (handled_as_builtin) {
return;
}
@@ -1429,7 +1424,7 @@ void withTargetsFile(
auto rule_name = BuildMaps::Base::ParseEntityNameFromJson(
*rule_it,
key.target,
- repo_config,
+ context->repo_config,
[&logger, &rule_it, &key](std::string const& parse_err) {
(*logger)(fmt::format("Parsing rule name {} for target {} "
"failed with:\n{}",
@@ -1457,7 +1452,7 @@ void withTargetsFile(
setter,
logger,
key,
- repo_config,
+ context,
result_map,
rn = *rule_name](auto values) {
auto data = TargetData::FromFieldReader(*values[0], desc);
@@ -1473,7 +1468,7 @@ void withTargetsFile(
*values[0],
data,
key,
- repo_config,
+ context->repo_config,
subcaller,
setter,
std::make_shared<AsyncMapConsumerLogger>(
@@ -1791,6 +1786,7 @@ void GlobTargetWithDirEntry(
namespace BuildMaps::Target {
auto CreateTargetMap(
+ const gsl::not_null<AnalyseContext*>& context,
const gsl::not_null<BuildMaps::Base::SourceTargetMap*>& source_target_map,
const gsl::not_null<BuildMaps::Base::TargetsFileMap*>& targets_file_map,
const gsl::not_null<BuildMaps::Base::UserRuleMap*>& rule_map,
@@ -1798,10 +1794,6 @@ auto CreateTargetMap(
directory_entries_map,
const gsl::not_null<AbsentTargetMap*>& absent_target_map,
const gsl::not_null<ResultTargetMap*>& result_map,
- const gsl::not_null<const RepositoryConfig*>& repo_config,
- const ActiveTargetCache& target_cache,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
std::size_t jobs) -> TargetMap {
auto target_reader = [source_target_map,
targets_file_map,
@@ -1809,17 +1801,14 @@ auto CreateTargetMap(
directory_entries_map,
absent_target_map,
result_map,
- repo_config,
- target_cache,
- stats,
- exports_progress](auto ts,
- auto setter,
- auto logger,
- auto subcaller,
- auto key) {
+ context](auto ts,
+ auto setter,
+ auto logger,
+ auto subcaller,
+ auto key) {
if (key.target.IsAnonymousTarget()) {
withTargetNode(key,
- repo_config,
+ context->repo_config,
rule_map,
ts,
subcaller,
@@ -1845,7 +1834,7 @@ auto CreateTargetMap(
wrapped_logger,
result_map,
directory_entries_map,
- stats);
+ context->statistics);
}
else if (key.target.GetNamedTarget().reference_t ==
BuildMaps::Base::ReferenceType::kFile) {
@@ -1913,7 +1902,8 @@ auto CreateTargetMap(
);
}
#ifndef BOOTSTRAP_BUILD_TOOL
- else if (repo_config->TargetRoot(key.target.ToModule().repository)
+ else if (context->repo_config
+ ->TargetRoot(key.target.ToModule().repository)
->IsAbsent()) {
if (not RemoteServeConfig::Instance().RemoteAddress()) {
(*logger)(
@@ -1951,10 +1941,7 @@ auto CreateTargetMap(
ts,
{key.target.ToModule()},
[key,
- repo_config,
- target_cache,
- stats,
- exports_progress,
+ context,
source_target_map,
rule_map,
ts,
@@ -1962,11 +1949,8 @@ auto CreateTargetMap(
setter = std::move(setter),
logger,
result_map](auto values) {
- withTargetsFile(key,
- repo_config,
- target_cache,
- stats,
- exports_progress,
+ withTargetsFile(context,
+ key,
*values[0],
source_target_map,
rule_map,
diff --git a/src/buildtool/build_engine/target_map/target_map.hpp b/src/buildtool/build_engine/target_map/target_map.hpp
index 0898a0c8..11273ad0 100644
--- a/src/buildtool/build_engine/target_map/target_map.hpp
+++ b/src/buildtool/build_engine/target_map/target_map.hpp
@@ -28,27 +28,21 @@
#include "src/buildtool/build_engine/target_map/absent_target_map.hpp"
#include "src/buildtool/build_engine/target_map/configured_target.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
-#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/common/statistics.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
#include "src/buildtool/multithreading/async_map_consumer.hpp"
-#include "src/buildtool/progress_reporting/progress.hpp"
-#include "src/buildtool/storage/target_cache.hpp"
namespace BuildMaps::Target {
using TargetMap = AsyncMapConsumer<ConfiguredTarget, AnalysedTargetPtr>;
auto CreateTargetMap(
+ const gsl::not_null<AnalyseContext*>&,
const gsl::not_null<BuildMaps::Base::SourceTargetMap*>&,
const gsl::not_null<BuildMaps::Base::TargetsFileMap*>&,
const gsl::not_null<BuildMaps::Base::UserRuleMap*>&,
const gsl::not_null<BuildMaps::Base::DirectoryEntriesMap*>&,
const gsl::not_null<AbsentTargetMap*>&,
const gsl::not_null<ResultTargetMap*>&,
- const gsl::not_null<const RepositoryConfig*>&,
- const ActiveTargetCache&,
- const gsl::not_null<Statistics*>& stats,
- const gsl::not_null<Progress*>& exports_progress,
std::size_t jobs = 0) -> TargetMap;
// use explicit cast to std::function to allow template deduction when used
diff --git a/src/buildtool/main/TARGETS b/src/buildtool/main/TARGETS
index 91f711ac..6fba9d29 100644
--- a/src/buildtool/main/TARGETS
+++ b/src/buildtool/main/TARGETS
@@ -36,6 +36,7 @@
, "cli"
, "version"
, "analyse"
+ , "analyse_context"
, "add_to_cas"
, "install_cas"
, "describe"
@@ -158,16 +159,14 @@
, "hdrs": ["analyse.hpp"]
, "srcs": ["analyse.cpp"]
, "deps":
- [ ["@", "gsl", "", "gsl"]
+ [ "analyse_context"
+ , ["@", "gsl", "", "gsl"]
, ["src/buildtool/common", "cli"]
- , ["src/buildtool/common", "common"]
, ["src/buildtool/build_engine/target_map", "absent_target_map"]
, ["src/buildtool/build_engine/target_map", "configured_target"]
, ["src/buildtool/build_engine/target_map", "result_map"]
, ["src/buildtool/build_engine/analysed_target", "target"]
- , ["src/buildtool/common", "config"]
, ["src/buildtool/logging", "logging"]
- , ["src/buildtool/storage", "storage"]
]
, "stage": ["src", "buildtool", "main"]
, "private-deps":
@@ -185,8 +184,25 @@
, ["src/buildtool/progress_reporting", "exports_progress_reporter"]
, ["src/buildtool/progress_reporting", "progress"]
, ["src/buildtool/serve_api/remote", "config"]
+ , ["src/buildtool/common", "common"]
+ , ["src/buildtool/common", "config"]
+ , ["src/buildtool/storage", "storage"]
]
}
+, "analyse_context":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["analyse_context"]
+ , "hdrs": ["analyse_context.hpp"]
+ , "deps":
+ [ ["@", "gsl", "", "gsl"]
+ , ["src/buildtool/common", "common"]
+ , ["src/buildtool/common", "config"]
+ , ["src/buildtool/progress_reporting", "exports_progress_reporter"]
+ , ["src/buildtool/progress_reporting", "progress"]
+ , ["src/buildtool/storage", "storage"]
+ ]
+ , "stage": ["src", "buildtool", "main"]
+ }
, "diagnose":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["diagnose"]
diff --git a/src/buildtool/main/analyse.cpp b/src/buildtool/main/analyse.cpp
index 7acb33b6..22ad8586 100644
--- a/src/buildtool/main/analyse.cpp
+++ b/src/buildtool/main/analyse.cpp
@@ -31,7 +31,6 @@
#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/progress_reporting/progress.hpp"
#ifndef BOOTSTRAP_BUILD_TOOL
#include "src/buildtool/serve_api/remote/config.hpp"
#endif // BOOTSTRAP_BUILD_TOOL
@@ -94,50 +93,41 @@ namespace Target = BuildMaps::Target;
} // namespace
[[nodiscard]] auto AnalyseTarget(
+ gsl::not_null<AnalyseContext*> const& context,
const Target::ConfiguredTarget& id,
gsl::not_null<Target::ResultTargetMap*> const& result_map,
- gsl::not_null<const RepositoryConfig*> const& repo_config,
- ActiveTargetCache const& target_cache,
- gsl::not_null<Statistics*> const& stats,
std::size_t jobs,
std::optional<std::string> const& request_action_input,
Logger const* logger,
BuildMaps::Target::ServeFailureLogReporter* serve_log)
-> std::optional<AnalysisResult> {
- // create progress tracker for export targets
- Progress exports_progress{};
// create async maps
- auto directory_entries = Base::CreateDirectoryEntriesMap(repo_config, jobs);
+ auto directory_entries =
+ Base::CreateDirectoryEntriesMap(context->repo_config, jobs);
auto expressions_file_map =
- Base::CreateExpressionFileMap(repo_config, jobs);
- auto rule_file_map = Base::CreateRuleFileMap(repo_config, jobs);
- auto targets_file_map = Base::CreateTargetsFileMap(repo_config, jobs);
- auto expr_map =
- Base::CreateExpressionMap(&expressions_file_map, repo_config, jobs);
- auto rule_map =
- Base::CreateRuleMap(&rule_file_map, &expr_map, repo_config, jobs);
- auto source_targets =
- Base::CreateSourceTargetMap(&directory_entries, repo_config, jobs);
+ Base::CreateExpressionFileMap(context->repo_config, jobs);
+ auto rule_file_map = Base::CreateRuleFileMap(context->repo_config, jobs);
+ auto targets_file_map =
+ Base::CreateTargetsFileMap(context->repo_config, jobs);
+ auto expr_map = Base::CreateExpressionMap(
+ &expressions_file_map, context->repo_config, jobs);
+ 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);
auto absent_target_variables_map =
Target::CreateAbsentTargetVariablesMap(jobs);
- auto absent_target_map =
- Target::CreateAbsentTargetMap(result_map,
- &absent_target_variables_map,
- repo_config,
- stats,
- &exports_progress,
- jobs,
- serve_log);
- auto target_map = Target::CreateTargetMap(&source_targets,
+
+ auto absent_target_map = Target::CreateAbsentTargetMap(
+ context, result_map, &absent_target_variables_map, jobs, serve_log);
+
+ auto target_map = Target::CreateTargetMap(context,
+ &source_targets,
&targets_file_map,
&rule_map,
&directory_entries,
&absent_target_map,
result_map,
- repo_config,
- target_cache,
- stats,
- &exports_progress,
jobs);
Logger::Log(
logger, LogLevel::Info, "Requested target is {}", id.ToString());
@@ -154,7 +144,7 @@ namespace Target = BuildMaps::Target;
std::atomic<bool> done{false};
std::condition_variable cv{};
auto reporter = ExportsProgressReporter::Reporter(
- stats, &exports_progress, has_serve, logger);
+ context->statistics, context->progress, has_serve, logger);
auto observer =
std::thread([reporter, &done, &cv]() { reporter(&done, &cv); });
diff --git a/src/buildtool/main/analyse.hpp b/src/buildtool/main/analyse.hpp
index 7c0bbf1f..0c637a0e 100644
--- a/src/buildtool/main/analyse.hpp
+++ b/src/buildtool/main/analyse.hpp
@@ -25,10 +25,8 @@
#include "src/buildtool/build_engine/target_map/configured_target.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
#include "src/buildtool/common/cli.hpp"
-#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/logging/logger.hpp"
-#include "src/buildtool/storage/target_cache.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
struct AnalysisResult {
BuildMaps::Target::ConfiguredTarget id;
@@ -37,11 +35,9 @@ struct AnalysisResult {
};
[[nodiscard]] auto AnalyseTarget(
+ gsl::not_null<AnalyseContext*> const& context,
const BuildMaps::Target::ConfiguredTarget& id,
gsl::not_null<BuildMaps::Target::ResultTargetMap*> const& result_map,
- gsl::not_null<const RepositoryConfig*> const& repo_config,
- ActiveTargetCache const& target_cache,
- gsl::not_null<Statistics*> const& stats,
std::size_t jobs,
std::optional<std::string> const& request_action_input,
Logger const* logger = nullptr,
diff --git a/src/buildtool/main/analyse_context.hpp b/src/buildtool/main/analyse_context.hpp
new file mode 100644
index 00000000..3897d84c
--- /dev/null
+++ b/src/buildtool/main/analyse_context.hpp
@@ -0,0 +1,31 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_BUILDOOL_MAIN_ANALYSE_CONTEXT_HPP
+#define INCLUDED_SRC_BUILDOOL_MAIN_ANALYSE_CONTEXT_HPP
+
+#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/storage/target_cache.hpp"
+
+struct AnalyseContext final {
+ gsl::not_null<const RepositoryConfig*> repo_config;
+ ActiveTargetCache const& target_cache;
+ gsl::not_null<Statistics*> statistics;
+ gsl::not_null<Progress*> progress;
+};
+
+#endif // INCLUDED_SRC_BUILDOOL_MAIN_ANALYSE_CONTEXT_HPP
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index ae533515..92f64891 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -43,6 +43,7 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/main/add_to_cas.hpp"
#include "src/buildtool/main/analyse.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
#include "src/buildtool/main/build_utils.hpp"
#include "src/buildtool/main/cli.hpp"
#include "src/buildtool/main/constants.hpp"
@@ -1011,11 +1012,17 @@ auto main(int argc, char* argv[]) -> int {
entry.push_back(blob);
serve_errors.push_back(entry);
};
- auto result = AnalyseTarget(id,
+
+ // create progress tracker for export targets
+ Progress exports_progress{};
+ AnalyseContext analyse_ctx{
+ .repo_config = &repo_config,
+ .target_cache = Storage::Instance().TargetCache(),
+ .statistics = &stats,
+ .progress = &exports_progress};
+ auto result = AnalyseTarget(&analyse_ctx,
+ id,
&result_map,
- &repo_config,
- Storage::Instance().TargetCache(),
- &stats,
arguments.common.jobs,
arguments.analysis.request_action_input,
/*logger=*/nullptr,
diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS
index 1235d1ac..008a76a4 100644
--- a/src/buildtool/serve_api/serve_service/TARGETS
+++ b/src/buildtool/serve_api/serve_service/TARGETS
@@ -76,7 +76,6 @@
, "deps":
[ ["src/buildtool/logging", "logging"]
, ["@", "gsl", "", "gsl"]
- , ["src/buildtool/common", "common"]
, ["src/buildtool/common/remote", "remote_common"]
, ["src/buildtool/execution_api/remote", "config"]
, ["src/buildtool/execution_api/common", "create_execution_api"]
@@ -107,6 +106,9 @@
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/storage", "storage"]
, ["src/utils/cpp", "verify_hash"]
+ , ["src/buildtool/progress_reporting", "progress"]
+ , ["src/buildtool/main", "analyse_context"]
+ , ["src/buildtool/common", "config"]
]
}
, "configuration_service":
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index e91d6dbf..dbcae8aa 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -23,14 +23,18 @@
#include "src/buildtool/build_engine/target_map/configured_target.hpp"
#include "src/buildtool/build_engine/target_map/result_map.hpp"
#include "src/buildtool/common/artifact.hpp"
+#include "src/buildtool/common/repository_config.hpp"
+#include "src/buildtool/common/statistics.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/graph_traverser/graph_traverser.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/log_sink_file.hpp"
#include "src/buildtool/main/analyse.hpp"
+#include "src/buildtool/main/analyse_context.hpp"
#include "src/buildtool/main/build_utils.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
+#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/serve_service/target_utils.hpp"
@@ -442,12 +446,15 @@ auto TargetService::ServeTarget(
std::filesystem::path tmp_log{tmp_dir->GetPath() / "log"};
Logger logger{"serve-target", {LogSinkFile::CreateFactory(tmp_log)}};
+ AnalyseContext analyse_ctx{.repo_config = &repository_config,
+ .target_cache = tc,
+ .statistics = &stats,
+ .progress = &progress};
+
// analyse the configured target
- auto result = AnalyseTarget(configured_target,
+ auto result = AnalyseTarget(&analyse_ctx,
+ configured_target,
&result_map,
- &repository_config,
- tc,
- &stats,
RemoteServeConfig::Instance().Jobs(),
std::nullopt /*request_action_input*/,
&logger);