summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-06-26 09:09:03 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-06-27 11:24:20 +0200
commit0ca3aecffb8c3c8162ba7b8cf4d16a2e34a7ac3e (patch)
treeca66a26560338633b39ccd371838fcf97a9e8613
parent3f75861a2d60fc5a2fd9c9894267f1df72f66c47 (diff)
downloadjustbuild-0ca3aecffb8c3c8162ba7b8cf4d16a2e34a7ac3e.tar.gz
Capture TargetCache by pointer in AnalyseContext
-rw-r--r--src/buildtool/build_engine/target_map/absent_target_map.cpp4
-rw-r--r--src/buildtool/build_engine/target_map/export.cpp5
-rw-r--r--src/buildtool/main/analyse_context.hpp8
-rw-r--r--src/buildtool/main/main.cpp2
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp2
-rw-r--r--test/buildtool/build_engine/target_map/target_map.test.cpp16
6 files changed, 19 insertions, 18 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 b21f426c..fd786539 100644
--- a/src/buildtool/build_engine/target_map/absent_target_map.cpp
+++ b/src/buildtool/build_engine/target_map/absent_target_map.cpp
@@ -64,7 +64,7 @@ void WithFlexibleVariables(
/*fatal=*/true);
return;
}
- auto target_cache_key = context->target_cache.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 {}",
@@ -74,7 +74,7 @@ void WithFlexibleVariables(
}
std::optional<std::pair<TargetCacheEntry, Artifact::ObjectInfo>>
target_cache_value{std::nullopt};
- target_cache_value = context->target_cache.Read(*target_cache_key);
+ target_cache_value = context->target_cache->Read(*target_cache_key);
bool from_just_serve = false;
if (not target_cache_value and context->serve) {
auto task = fmt::format("[{},{}]",
diff --git a/src/buildtool/build_engine/target_map/export.cpp b/src/buildtool/build_engine/target_map/export.cpp
index 23a70cd4..f3f4e97a 100644
--- a/src/buildtool/build_engine/target_map/export.cpp
+++ b/src/buildtool/build_engine/target_map/export.cpp
@@ -131,13 +131,14 @@ void ExportRule(
auto const& target_name = key.target.GetNamedTarget();
auto repo_key = context->repo_config->RepositoryKey(target_name.repository);
auto target_cache_key = repo_key
- ? context->target_cache.ComputeKey(
+ ? 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 = context->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
diff --git a/src/buildtool/main/analyse_context.hpp b/src/buildtool/main/analyse_context.hpp
index d5022d4b..de3b4980 100644
--- a/src/buildtool/main/analyse_context.hpp
+++ b/src/buildtool/main/analyse_context.hpp
@@ -25,10 +25,10 @@
#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;
+ gsl::not_null<RepositoryConfig const*> const repo_config;
+ gsl::not_null<ActiveTargetCache const*> const target_cache;
+ gsl::not_null<Statistics*> const statistics;
+ gsl::not_null<Progress*> const progress;
std::optional<ServeApi> const& serve;
};
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 457bfcd1..1e956cc8 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -1007,7 +1007,7 @@ auto main(int argc, char* argv[]) -> int {
Progress exports_progress{};
AnalyseContext analyse_ctx{
.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index a87648dc..d7e48402 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -451,7 +451,7 @@ auto TargetService::ServeTarget(
Logger logger{"serve-target", {LogSinkFile::CreateFactory(tmp_log)}};
AnalyseContext analyse_ctx{.repo_config = &repository_config,
- .target_cache = tc,
+ .target_cache = &tc,
.statistics = &stats,
.progress = &progress,
.serve = serve_};
diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp
index fa9e2890..fb75188f 100644
--- a/test/buildtool/build_engine/target_map/target_map.test.cpp
+++ b/test/buildtool/build_engine/target_map/target_map.test.cpp
@@ -102,7 +102,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") {
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -545,7 +545,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -633,7 +633,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -731,7 +731,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") {
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -939,7 +939,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") {
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -1080,7 +1080,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") {
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -1187,7 +1187,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};
@@ -1351,7 +1351,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") {
ApiBundle const apis{nullptr, RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = Storage::Instance().TargetCache(),
+ .target_cache = &Storage::Instance().TargetCache(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve};