summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buildtool/build_engine/target_map/absent_target_map.cpp9
-rw-r--r--src/buildtool/build_engine/target_map/export.cpp7
-rw-r--r--src/buildtool/common/TARGETS6
-rw-r--r--src/buildtool/common/repository_config.cpp8
-rw-r--r--src/buildtool/common/repository_config.hpp4
-rw-r--r--src/buildtool/main/analyse_context.hpp4
-rw-r--r--src/buildtool/main/main.cpp11
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp3
-rw-r--r--test/buildtool/build_engine/target_map/target_map.test.cpp16
-rw-r--r--test/buildtool/common/repository_config.test.cpp36
10 files changed, 54 insertions, 50 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 017d25c5..3c886586 100644
--- a/src/buildtool/build_engine/target_map/absent_target_map.cpp
+++ b/src/buildtool/build_engine/target_map/absent_target_map.cpp
@@ -24,6 +24,7 @@
#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/storage.hpp"
#include "src/buildtool/storage/target_cache.hpp"
#include "src/buildtool/storage/target_cache_key.hpp"
#include "src/utils/cpp/json.hpp"
@@ -57,14 +58,15 @@ void WithFlexibleVariables(
// TODO(asartori): avoid code duplication in export.cpp
context->statistics->IncrementExportsFoundCounter();
auto target_name = key.target.GetNamedTarget();
- auto repo_key = context->repo_config->RepositoryKey(target_name.repository);
+ auto repo_key = context->repo_config->RepositoryKey(*context->storage,
+ 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 = context->target_cache->ComputeKey(
+ auto target_cache_key = context->storage->TargetCache().ComputeKey(
*repo_key, target_name, effective_config);
if (not target_cache_key) {
(*logger)(fmt::format("Could not produce cache key for target {}",
@@ -74,7 +76,8 @@ 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->storage->TargetCache().Read(*target_cache_key);
bool from_just_serve = false;
if (not target_cache_value and context->serve != nullptr) {
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 2d92bed6..23ffe641 100644
--- a/src/buildtool/build_engine/target_map/export.cpp
+++ b/src/buildtool/build_engine/target_map/export.cpp
@@ -129,16 +129,17 @@ void ExportRule(
}
context->statistics->IncrementExportsFoundCounter();
auto const& target_name = key.target.GetNamedTarget();
- auto repo_key = context->repo_config->RepositoryKey(target_name.repository);
+ auto repo_key = context->repo_config->RepositoryKey(*context->storage,
+ target_name.repository);
auto target_cache_key = repo_key
- ? context->target_cache->ComputeKey(
+ ? context->storage->TargetCache().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);
+ context->storage->TargetCache().Read(*target_cache_key);
bool from_just_serve{false};
#ifndef BOOTSTRAP_BUILD_TOOL
diff --git a/src/buildtool/common/TARGETS b/src/buildtool/common/TARGETS
index be4246f0..d8f48a8e 100644
--- a/src/buildtool/common/TARGETS
+++ b/src/buildtool/common/TARGETS
@@ -127,12 +127,10 @@
, ["src/buildtool/file_system", "file_root"]
, ["src/buildtool/file_system", "git_cas"]
, ["src/buildtool/multithreading", "atomic_value"]
- ]
- , "stage": ["src", "buildtool", "common"]
- , "private-deps":
- [ ["src/utils/automata", "dfa_minimizer"]
, ["src/buildtool/storage", "storage"]
]
+ , "stage": ["src", "buildtool", "common"]
+ , "private-deps": [["src/utils/automata", "dfa_minimizer"]]
}
, "user_structs":
{ "type": ["@", "rules", "CC", "library"]
diff --git a/src/buildtool/common/repository_config.cpp b/src/buildtool/common/repository_config.cpp
index a3b81de1..d26ba55b 100644
--- a/src/buildtool/common/repository_config.cpp
+++ b/src/buildtool/common/repository_config.cpp
@@ -14,7 +14,6 @@
#include "src/buildtool/common/repository_config.hpp"
-#include "src/buildtool/storage/storage.hpp"
#include "src/utils/automata/dfa_minimizer.hpp"
auto RepositoryConfig::RepositoryInfo::BaseContentDescription() const
@@ -35,15 +34,16 @@ auto RepositoryConfig::RepositoryInfo::BaseContentDescription() const
return std::nullopt;
}
-auto RepositoryConfig::RepositoryKey(std::string const& repo) const noexcept
+auto RepositoryConfig::RepositoryKey(Storage const& storage,
+ std::string const& repo) const noexcept
-> std::optional<std::string> {
auto const& unique = DeduplicateRepo(repo);
if (auto const* data = Data(unique)) {
// compute key only once (thread-safe)
return data->key.SetOnceAndGet(
- [this, &unique]() -> std::optional<std::string> {
+ [this, &storage, &unique]() -> std::optional<std::string> {
if (auto graph = BuildGraphForRepository(unique)) {
- auto const& cas = Storage::Instance().CAS();
+ auto const& cas = storage.CAS();
if (auto digest = cas.StoreBlob(graph->dump(2))) {
return ArtifactDigest{*digest}.hash();
}
diff --git a/src/buildtool/common/repository_config.hpp b/src/buildtool/common/repository_config.hpp
index ea463d43..8c5c29a5 100644
--- a/src/buildtool/common/repository_config.hpp
+++ b/src/buildtool/common/repository_config.hpp
@@ -28,6 +28,7 @@
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/file_system/git_cas.hpp"
#include "src/buildtool/multithreading/atomic_value.hpp"
+#include "src/buildtool/storage/storage.hpp"
class RepositoryConfig {
@@ -136,7 +137,8 @@ class RepositoryConfig {
// Obtain repository's cache key if the repository is content fixed or
// std::nullopt otherwise.
- [[nodiscard]] auto RepositoryKey(std::string const& repo) const noexcept
+ [[nodiscard]] auto RepositoryKey(Storage const& storage,
+ std::string const& repo) const noexcept
-> std::optional<std::string>;
// used for testing
diff --git a/src/buildtool/main/analyse_context.hpp b/src/buildtool/main/analyse_context.hpp
index 9999ae43..4fe7381e 100644
--- a/src/buildtool/main/analyse_context.hpp
+++ b/src/buildtool/main/analyse_context.hpp
@@ -20,11 +20,11 @@
#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"
+#include "src/buildtool/storage/storage.hpp"
struct AnalyseContext final {
gsl::not_null<RepositoryConfig const*> const repo_config;
- gsl::not_null<ActiveTargetCache const*> const target_cache;
+ gsl::not_null<Storage const*> const storage;
gsl::not_null<Statistics*> const statistics;
gsl::not_null<Progress*> const progress;
ServeApi const* const serve = nullptr;
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 878cfc50..293c8002 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -991,12 +991,11 @@ auto main(int argc, char* argv[]) -> int {
// 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,
- .serve = serve ? &*serve : nullptr};
+ AnalyseContext analyse_ctx{.repo_config = &repo_config,
+ .storage = &Storage::Instance(),
+ .statistics = &stats,
+ .progress = &exports_progress,
+ .serve = serve ? &*serve : nullptr};
auto result = AnalyseTarget(&analyse_ctx,
id,
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index 727751f4..ec86bf47 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/serve_service/target_utils.hpp"
+#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/buildtool/storage/target_cache_key.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -443,7 +444,7 @@ auto TargetService::ServeTarget(
Logger logger{"serve-target", {LogSinkFile::CreateFactory(tmp_log)}};
AnalyseContext analyse_ctx{.repo_config = &repository_config,
- .target_cache = &tc,
+ .storage = &storage_,
.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 a3e1d350..bb15a544 100644
--- a/test/buildtool/build_engine/target_map/target_map.test.cpp
+++ b/test/buildtool/build_engine/target_map/target_map.test.cpp
@@ -109,7 +109,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "simple targets", "[target_map]") {
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -557,7 +557,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -650,7 +650,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -753,7 +753,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "built-in rules", "[target_map]") {
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -966,7 +966,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "target reference", "[target_map]") {
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -1112,7 +1112,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "trees", "[target_map]") {
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -1224,7 +1224,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
@@ -1393,7 +1393,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "wrong arguments", "[target_map]") {
RemoteExecutionConfig::RemoteAddress()};
auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
AnalyseContext ctx{.repo_config = &repo_config,
- .target_cache = &Storage::Instance().TargetCache(),
+ .storage = &Storage::Instance(),
.statistics = &stats,
.progress = &exports_progress,
.serve = serve ? &*serve : nullptr};
diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp
index e4b4fd8d..56100643 100644
--- a/test/buildtool/common/repository_config.test.cpp
+++ b/test/buildtool/common/repository_config.test.cpp
@@ -120,7 +120,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
RepositoryConfig config{};
CHECK(config.Info("missing") == nullptr);
- CHECK_FALSE(config.RepositoryKey("missing"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "missing"));
}
TEST_CASE_METHOD(HermeticLocalTestFixture,
@@ -130,7 +130,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
SECTION("for single fixed repository") {
config.SetInfo("foo", CreateFixedRepoInfo());
- auto key = config.RepositoryKey("foo");
+ auto key = config.RepositoryKey(Storage::Instance(), "foo");
REQUIRE(key);
// verify created graph from CAS
@@ -140,15 +140,15 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
SECTION("for fixed repositories with same missing dependency") {
config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz"}}));
config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz"}}));
- CHECK_FALSE(config.RepositoryKey("foo"));
- CHECK_FALSE(config.RepositoryKey("bar"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "foo"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "bar"));
}
SECTION("for fixed repositories with different missing dependency") {
config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz0"}}));
config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz1"}}));
- CHECK_FALSE(config.RepositoryKey("foo"));
- CHECK_FALSE(config.RepositoryKey("bar"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "foo"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "bar"));
}
}
@@ -159,14 +159,14 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
SECTION("for single file repository") {
config.SetInfo("foo", CreateFileRepoInfo());
- CHECK_FALSE(config.RepositoryKey("foo"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "foo"));
}
SECTION("for graph with leaf dependency as file") {
config.SetInfo("foo", CreateFixedRepoInfo({{"bar", "bar"}}));
config.SetInfo("bar", CreateFixedRepoInfo({{"baz", "baz"}}));
config.SetInfo("baz", CreateFileRepoInfo());
- CHECK_FALSE(config.RepositoryKey("foo"));
+ CHECK_FALSE(config.RepositoryKey(Storage::Instance(), "foo"));
}
}
@@ -186,8 +186,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
config.SetInfo("baz1", Copy(baz));
// check if computed key is same
- auto foo_key = config.RepositoryKey("foo");
- auto bar_key = config.RepositoryKey("bar");
+ auto foo_key = config.RepositoryKey(Storage::Instance(), "foo");
+ auto bar_key = config.RepositoryKey(Storage::Instance(), "bar");
REQUIRE(foo_key);
REQUIRE(bar_key);
CHECK(*foo_key == *bar_key);
@@ -205,8 +205,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
config.SetInfo("baz1", Copy(baz));
// check if computed key is same
- auto foo_key = config.RepositoryKey("foo");
- auto bar_key = config.RepositoryKey("bar");
+ auto foo_key = config.RepositoryKey(Storage::Instance(), "foo");
+ auto bar_key = config.RepositoryKey(Storage::Instance(), "bar");
REQUIRE(foo_key);
REQUIRE(bar_key);
CHECK(*foo_key == *bar_key);
@@ -223,8 +223,8 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
config.SetInfo("baz1", CreateFixedRepoInfo({{"dep", "bar"}}));
// check if computed key is same
- auto foo_key = config.RepositoryKey("foo");
- auto bar_key = config.RepositoryKey("bar");
+ auto foo_key = config.RepositoryKey(Storage::Instance(), "foo");
+ auto bar_key = config.RepositoryKey(Storage::Instance(), "bar");
REQUIRE(foo_key);
REQUIRE(bar_key);
CHECK(*foo_key == *bar_key);
@@ -239,10 +239,10 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
config.SetInfo("baz1", CreateFixedRepoInfo({{"dep", "baz1"}}));
// check if computed key is same
- auto foo_key = config.RepositoryKey("foo");
- auto bar_key = config.RepositoryKey("bar");
- auto baz0_key = config.RepositoryKey("baz0");
- auto baz1_key = config.RepositoryKey("baz1");
+ auto foo_key = config.RepositoryKey(Storage::Instance(), "foo");
+ auto bar_key = config.RepositoryKey(Storage::Instance(), "bar");
+ auto baz0_key = config.RepositoryKey(Storage::Instance(), "baz0");
+ auto baz1_key = config.RepositoryKey(Storage::Instance(), "baz1");
CHECK(foo_key);
CHECK(bar_key);
CHECK(baz0_key);