summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/main.cpp13
-rw-r--r--src/buildtool/serve_api/remote/TARGETS1
-rw-r--r--src/buildtool/serve_api/remote/serve_api.hpp9
-rw-r--r--src/buildtool/serve_api/remote/target_client.cpp7
-rw-r--r--src/buildtool/serve_api/remote/target_client.hpp3
-rw-r--r--src/buildtool/serve_api/serve_service/TARGETS14
-rw-r--r--src/buildtool/serve_api/serve_service/serve_server_implementation.cpp20
-rw-r--r--src/buildtool/serve_api/serve_service/serve_server_implementation.hpp10
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp159
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.hpp11
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp37
-rw-r--r--src/buildtool/serve_api/serve_service/target.hpp12
-rw-r--r--src/buildtool/serve_api/serve_service/target_utils.cpp13
-rw-r--r--src/buildtool/serve_api/serve_service/target_utils.hpp3
-rw-r--r--src/other_tools/just_mr/TARGETS1
-rw-r--r--src/other_tools/just_mr/fetch.cpp3
-rw-r--r--src/other_tools/just_mr/setup.cpp3
17 files changed, 174 insertions, 145 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 3be560bb..39806c68 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -814,10 +814,15 @@ auto main(int argc, char* argv[]) -> int {
/*repo_config=*/nullptr,
&*auth_config,
RemoteExecutionConfig::RemoteAddress()};
- auto serve = ServeApi::Create(*serve_config, &serve_apis);
+ auto serve = ServeApi::Create(
+ *serve_config, &Storage::Instance(), &serve_apis);
bool with_execute = not RemoteExecutionConfig::RemoteAddress();
- return serve_server->Run(
- *serve_config, serve, serve_apis, with_execute)
+ return serve_server->Run(*serve_config,
+ StorageConfig::Instance(),
+ Storage::Instance(),
+ serve,
+ serve_apis,
+ with_execute)
? kExitSuccess
: kExitFailure;
}
@@ -903,7 +908,7 @@ auto main(int argc, char* argv[]) -> int {
#ifndef BOOTSTRAP_BUILD_TOOL
std::optional<ServeApi> serve =
- ServeApi::Create(*serve_config, &main_apis);
+ ServeApi::Create(*serve_config, &Storage::Instance(), &main_apis);
#else
std::optional<ServeApi> serve;
#endif // BOOTSTRAP_BUILD_TOOL
diff --git a/src/buildtool/serve_api/remote/TARGETS b/src/buildtool/serve_api/remote/TARGETS
index 4af6387f..a1f65ba0 100644
--- a/src/buildtool/serve_api/remote/TARGETS
+++ b/src/buildtool/serve_api/remote/TARGETS
@@ -44,6 +44,7 @@
, ["src/buildtool/file_system/symlinks_map", "pragma_special"]
, ["src/buildtool/execution_api/common", "api_bundle"]
, ["src/utils/cpp", "expected"]
+ , ["src/buildtool/storage", "storage"]
, "source_tree_client"
, "target_client"
, "configuration_client"
diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp
index 3374e6aa..fd455037 100644
--- a/src/buildtool/serve_api/remote/serve_api.hpp
+++ b/src/buildtool/serve_api/remote/serve_api.hpp
@@ -36,14 +36,16 @@ class ServeApi final {};
#include "src/buildtool/serve_api/remote/configuration_client.hpp"
#include "src/buildtool/serve_api/remote/source_tree_client.hpp"
#include "src/buildtool/serve_api/remote/target_client.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "src/utils/cpp/expected.hpp"
class ServeApi final {
public:
explicit ServeApi(ServerAddress const& address,
+ gsl::not_null<Storage const*> const& storage,
gsl::not_null<ApiBundle const*> const& apis) noexcept
: stc_{address, &apis->auth},
- tc_{address, apis},
+ tc_{address, storage, apis},
cc_{address, &apis->auth} {}
~ServeApi() noexcept = default;
@@ -54,11 +56,12 @@ class ServeApi final {
[[nodiscard]] static auto Create(
RemoteServeConfig const& serve_config,
+ gsl::not_null<Storage const*> const& storage,
gsl::not_null<ApiBundle const*> const& apis) noexcept
-> std::optional<ServeApi> {
if (serve_config.remote_address) {
- return std::make_optional<ServeApi>(*serve_config.remote_address,
- apis);
+ return std::make_optional<ServeApi>(
+ *serve_config.remote_address, storage, apis);
}
return std::nullopt;
}
diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp
index 526121ab..fd886254 100644
--- a/src/buildtool/serve_api/remote/target_client.cpp
+++ b/src/buildtool/serve_api/remote/target_client.cpp
@@ -25,11 +25,11 @@
#include "src/buildtool/common/remote/client_common.hpp"
#include "src/buildtool/execution_api/remote/config.hpp"
#include "src/buildtool/logging/log_level.hpp"
-#include "src/buildtool/storage/storage.hpp"
TargetClient::TargetClient(ServerAddress const& address,
+ gsl::not_null<Storage const*> const& storage,
gsl::not_null<ApiBundle const*> const& apis) noexcept
- : apis_{*apis} {
+ : storage_{*storage}, apis_{*apis} {
stub_ = justbuild::just_serve::Target::NewStub(
CreateChannelWithCredentials(address.host, address.port, &apis->auth));
}
@@ -84,8 +84,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key,
ex.what())};
}
- auto dispatch_dgst =
- Storage::Instance().CAS().StoreBlob(dispatch_list.dump(2));
+ auto dispatch_dgst = storage_.CAS().StoreBlob(dispatch_list.dump(2));
if (not dispatch_dgst) {
return serve_target_result_t{
std::in_place_index<1>,
diff --git a/src/buildtool/serve_api/remote/target_client.hpp b/src/buildtool/serve_api/remote/target_client.hpp
index 35bb2d29..f8f51987 100644
--- a/src/buildtool/serve_api/remote/target_client.hpp
+++ b/src/buildtool/serve_api/remote/target_client.hpp
@@ -30,6 +30,7 @@
#include "src/buildtool/common/remote/remote_common.hpp"
#include "src/buildtool/execution_api/common/api_bundle.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "src/buildtool/storage/target_cache_entry.hpp"
#include "src/buildtool/storage/target_cache_key.hpp"
@@ -53,6 +54,7 @@ using serve_target_result_t =
class TargetClient {
public:
explicit TargetClient(ServerAddress const& address,
+ gsl::not_null<Storage const*> const& storage,
gsl::not_null<ApiBundle const*> const& apis) noexcept;
/// \brief Retrieve the pair of TargetCacheEntry and ObjectInfo associated
@@ -87,6 +89,7 @@ class TargetClient {
const noexcept -> std::optional<ArtifactDigest>;
private:
+ Storage const& storage_;
ApiBundle const& apis_;
std::unique_ptr<justbuild::just_serve::Target::Stub> stub_;
Logger logger_{"RemoteTargetClient"};
diff --git a/src/buildtool/serve_api/serve_service/TARGETS b/src/buildtool/serve_api/serve_service/TARGETS
index 54148ee3..625039cf 100644
--- a/src/buildtool/serve_api/serve_service/TARGETS
+++ b/src/buildtool/serve_api/serve_service/TARGETS
@@ -24,6 +24,8 @@
, ["src/buildtool/file_system/symlinks_map", "resolve_symlinks_map"]
, ["src/buildtool/serve_api/remote", "config"]
, ["src/utils/cpp", "expected"]
+ , ["src/buildtool/storage", "config"]
+ , ["src/buildtool/storage", "storage"]
]
, "stage": ["src", "buildtool", "serve_api", "serve_service"]
, "private-deps":
@@ -33,9 +35,7 @@
, ["src/buildtool/file_system", "git_repo"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/multithreading", "async_map_utils"]
- , ["src/buildtool/storage", "config"]
, ["src/buildtool/storage", "fs_utils"]
- , ["src/buildtool/storage", "storage"]
, ["src/utils/archive", "archive_ops"]
, ["src/buildtool/execution_api/git", "git"]
]
@@ -50,6 +50,8 @@
, ["src/buildtool/serve_api/remote", "config"]
, ["src/buildtool/serve_api/remote", "serve_api"]
, ["src/buildtool/execution_api/common", "api_bundle"]
+ , ["src/buildtool/storage", "config"]
+ , ["src/buildtool/storage", "storage"]
]
, "stage": ["src", "buildtool", "serve_api", "serve_service"]
, "private-deps":
@@ -62,7 +64,6 @@
, ["src/buildtool/common/remote", "port"]
, ["src/buildtool/compatibility", "compatibility"]
, ["src/buildtool/logging", "log_level"]
- , ["src/buildtool/storage", "config"]
, ["src/buildtool/execution_api/execution_service", "execution_server"]
, ["src/buildtool/execution_api/execution_service", "ac_server"]
, ["src/buildtool/execution_api/execution_service", "cas_server"]
@@ -86,6 +87,8 @@
, ["src/buildtool/execution_api/common", "common"]
, ["src/buildtool/serve_api/remote", "config"]
, ["src/utils/cpp", "expected"]
+ , ["src/buildtool/storage", "config"]
+ , ["src/buildtool/storage", "storage"]
]
, "stage": ["src", "buildtool", "serve_api", "serve_service"]
, "private-deps":
@@ -106,10 +109,8 @@
, ["src/buildtool/main", "build_utils"]
, ["src/buildtool/multithreading", "task_system"]
, ["src/buildtool/progress_reporting", "progress_reporter"]
- , ["src/buildtool/storage", "config"]
, ["src/buildtool/common", "common"]
, ["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"]
@@ -140,6 +141,7 @@
, ["src/buildtool/common", "config"]
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/serve_api/remote", "config"]
+ , ["src/buildtool/storage", "config"]
]
, "stage": ["src", "buildtool", "serve_api", "serve_service"]
, "private-deps":
@@ -150,8 +152,6 @@
, ["src/buildtool/file_system", "git_repo"]
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/logging", "log_level"]
- , ["src/buildtool/storage", "config"]
- , ["src/buildtool/storage", "storage"]
]
}
}
diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp
index 9016fd82..a6754c74 100644
--- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp
+++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp
@@ -43,7 +43,6 @@
#include "src/buildtool/serve_api/serve_service/configuration.hpp"
#include "src/buildtool/serve_api/serve_service/source_tree.hpp"
#include "src/buildtool/serve_api/serve_service/target.hpp"
-#include "src/buildtool/storage/config.hpp"
namespace {
template <typename T>
@@ -89,26 +88,31 @@ auto ServeServerImpl::Create(std::optional<std::string> interface,
}
auto ServeServerImpl::Run(RemoteServeConfig const& serve_config,
+ StorageConfig const& storage_config,
+ Storage const& storage,
std::optional<ServeApi> const& serve,
ApiBundle const& apis,
bool with_execute) -> bool {
// make sure the git root directory is properly initialized
- if (not FileSystemManager::CreateDirectory(
- StorageConfig::Instance().GitRoot())) {
+ if (not FileSystemManager::CreateDirectory(storage_config.GitRoot())) {
Logger::Log(LogLevel::Error,
"Could not create directory {}. Aborting",
- StorageConfig::Instance().GitRoot().string());
+ storage_config.GitRoot().string());
return false;
}
- if (not GitRepo::InitAndOpen(StorageConfig::Instance().GitRoot(), true)) {
+ if (not GitRepo::InitAndOpen(storage_config.GitRoot(), true)) {
Logger::Log(LogLevel::Error,
fmt::format("could not initialize bare git repository {}",
- StorageConfig::Instance().GitRoot().string()));
+ storage_config.GitRoot().string()));
return false;
}
- SourceTreeService sts{&serve_config, &apis};
- TargetService ts{&serve_config, &apis, serve ? &*serve : nullptr};
+ SourceTreeService sts{&serve_config, &storage_config, &storage, &apis};
+ TargetService ts{&serve_config,
+ &storage_config,
+ &storage,
+ &apis,
+ serve ? &*serve : nullptr};
ConfigurationService cs{};
grpc::ServerBuilder builder;
diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp
index a4dfbd65..d30c77f9 100644
--- a/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp
+++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.hpp
@@ -22,6 +22,8 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/buildtool/serve_api/remote/serve_api.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/buildtool/storage/storage.hpp"
class ServeServerImpl {
public:
@@ -41,11 +43,15 @@ class ServeServerImpl {
auto operator=(ServeServerImpl&&) noexcept -> ServeServerImpl& = default;
/// \brief Start the serve service.
- /// \param serve_config RemoteServeConfig to be used.
- /// \param serve ServeApi to be used.
+ /// \param serve_config RemoteServeConfig to be used.
+ /// \param storage_config StorageConfig to be used.
+ /// \param storage Storage to be used.
+ /// \param serve ServeApi to be used.
/// \param with_execute Flag specifying if just serve should act also as
/// just execute (i.e., start remote execution services with same interface)
auto Run(RemoteServeConfig const& serve_config,
+ StorageConfig const& storage_config,
+ Storage const& storage,
std::optional<ServeApi> const& serve,
ApiBundle const& apis,
bool with_execute) -> bool;
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp
index 0abfef83..74edaca8 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.cpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.cpp
@@ -30,10 +30,8 @@
#include "src/buildtool/file_system/git_repo.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/multithreading/async_map_utils.hpp"
-#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/fs_utils.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
-#include "src/buildtool/storage/storage.hpp"
#include "src/utils/archive/archive_ops.hpp"
namespace {
@@ -203,7 +201,7 @@ auto SourceTreeService::ServeCommitTree(
auto const& subdir{request->subdir()};
// try in local build root Git cache
auto res = GetSubtreeFromCommit(
- StorageConfig::Instance().GitRoot(), commit, subdir, logger_);
+ storage_config_.GitRoot(), commit, subdir, logger_);
if (res) {
auto tree_id = *std::move(res);
if (request->sync_tree()) {
@@ -219,10 +217,10 @@ auto SourceTreeService::ServeCommitTree(
}
auto digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true};
auto repo = RepositoryConfig{};
- if (not repo.SetGitCAS(StorageConfig::Instance().GitRoot())) {
+ if (not repo.SetGitCAS(storage_config_.GitRoot())) {
logger_->Emit(LogLevel::Error,
"Failed to SetGitCAS at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeCommitTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -251,7 +249,7 @@ auto SourceTreeService::ServeCommitTree(
"repository {}",
subdir,
commit,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeCommitTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -375,7 +373,7 @@ auto SourceTreeService::ResolveContentTree(
if (resolve_special) {
// get the resolved tree
auto tree_id_file = StorageUtils::GetResolvedTreeIDFile(
- StorageConfig::Instance(), tree_id, *resolve_special);
+ storage_config_, tree_id, *resolve_special);
if (FileSystemManager::Exists(tree_id_file)) {
// read resolved tree id
auto resolved_tree_id = FileSystemManager::ReadFile(tree_id_file);
@@ -390,11 +388,11 @@ auto SourceTreeService::ResolveContentTree(
*resolved_tree_id, repo_path, sync_tree, response);
}
// resolve tree; target repository is always the Git cache
- auto target_cas = GitCAS::Open(StorageConfig::Instance().GitRoot());
+ auto target_cas = GitCAS::Open(storage_config_.GitRoot());
if (not target_cas) {
logger_->Emit(LogLevel::Error,
"Failed to open Git ODB at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -451,12 +449,14 @@ auto SourceTreeService::ResolveContentTree(
}
// keep tree alive in the Git cache via a tagged commit
auto wrapped_logger = std::make_shared<GitRepo::anon_logger_t>(
- [logger = logger_, resolved_tree](auto const& msg, bool fatal) {
+ [logger = logger_,
+ storage_config = &storage_config_,
+ resolved_tree](auto const& msg, bool fatal) {
if (fatal) {
logger->Emit(LogLevel::Error,
"While keeping tree {} in repository {}:\n{}",
resolved_tree.id,
- StorageConfig::Instance().GitRoot().string(),
+ storage_config->GitRoot().string(),
msg);
}
});
@@ -464,11 +464,11 @@ auto SourceTreeService::ResolveContentTree(
// this is a non-thread-safe Git operation, so it must be guarded!
std::shared_lock slock{mutex_};
// open real repository at Git CAS location
- auto git_repo = GitRepo::Open(StorageConfig::Instance().GitRoot());
+ auto git_repo = GitRepo::Open(storage_config_.GitRoot());
if (not git_repo) {
logger_->Emit(LogLevel::Error,
"Failed to open Git CAS repository {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeArchiveTreeResponse::RESOLVE_ERROR);
return ::grpc::Status::OK;
}
@@ -522,31 +522,29 @@ auto SourceTreeService::CommonImportToGit(
return unexpected{err};
}
// open the Git CAS repo
- auto just_git_cas = GitCAS::Open(StorageConfig::Instance().GitRoot());
+ auto just_git_cas = GitCAS::Open(storage_config_.GitRoot());
if (not just_git_cas) {
- return unexpected{
- fmt::format("Failed to open Git ODB at {}",
- StorageConfig::Instance().GitRoot().string())};
+ return unexpected{fmt::format("Failed to open Git ODB at {}",
+ storage_config_.GitRoot().string())};
}
auto just_git_repo = GitRepo::Open(just_git_cas);
if (not just_git_repo) {
- return unexpected{
- fmt::format("Failed to open Git repository {}",
- StorageConfig::Instance().GitRoot().string())};
+ return unexpected{fmt::format("Failed to open Git repository {}",
+ storage_config_.GitRoot().string())};
}
// wrap logger for GitRepo call
err.clear();
wrapped_logger = std::make_shared<GitRepo::anon_logger_t>(
- [&err](auto const& msg, bool fatal) {
+ [&err, storage_config = &storage_config_](auto const& msg, bool fatal) {
if (fatal) {
err = fmt::format("While fetching in repository {}:\n{}",
- StorageConfig::Instance().GitRoot().string(),
+ storage_config->GitRoot().string(),
msg);
}
});
// fetch the new commit into the Git CAS via tmp directory; the call is
// thread-safe, so it needs no guarding
- if (not just_git_repo->LocalFetchViaTmpRepo(StorageConfig::Instance(),
+ if (not just_git_repo->LocalFetchViaTmpRepo(storage_config_,
root_path.string(),
/*branch=*/std::nullopt,
wrapped_logger)) {
@@ -555,12 +553,13 @@ auto SourceTreeService::CommonImportToGit(
// wrap logger for GitRepo call
err.clear();
wrapped_logger = std::make_shared<GitRepo::anon_logger_t>(
- [commit_hash, &err](auto const& msg, bool fatal) {
+ [commit_hash, storage_config = &storage_config_, &err](auto const& msg,
+ bool fatal) {
if (fatal) {
err =
fmt::format("While tagging commit {} in repository {}:\n{}",
*commit_hash,
- StorageConfig::Instance().GitRoot().string(),
+ storage_config->GitRoot().string(),
msg);
}
});
@@ -569,11 +568,11 @@ auto SourceTreeService::CommonImportToGit(
// this is a non-thread-safe Git operation, so it must be guarded!
std::shared_lock slock{mutex_};
// open real repository at Git CAS location
- auto git_repo = GitRepo::Open(StorageConfig::Instance().GitRoot());
+ auto git_repo = GitRepo::Open(storage_config_.GitRoot());
if (not git_repo) {
return unexpected{
fmt::format("Failed to open Git CAS repository {}",
- StorageConfig::Instance().GitRoot().string())};
+ storage_config_.GitRoot().string())};
}
// Important: message must be consistent with just-mr!
if (not git_repo->KeepTag(*commit_hash,
@@ -631,11 +630,11 @@ auto SourceTreeService::ArchiveImportToGit(
return ::grpc::Status::OK;
}
// open the Git CAS repo
- auto just_git_cas = GitCAS::Open(StorageConfig::Instance().GitRoot());
+ auto just_git_cas = GitCAS::Open(storage_config_.GitRoot());
if (not just_git_cas) {
logger_->Emit(LogLevel::Error,
"Failed to open Git ODB at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -643,7 +642,7 @@ auto SourceTreeService::ArchiveImportToGit(
if (not just_git_repo) {
logger_->Emit(LogLevel::Error,
"Failed to open Git repository {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -667,7 +666,7 @@ auto SourceTreeService::ArchiveImportToGit(
return ::grpc::Status::OK;
}
return ResolveContentTree(*subtree_id,
- StorageConfig::Instance().GitRoot(),
+ storage_config_.GitRoot(),
/*repo_is_git_cache=*/true,
resolve_special,
sync_tree,
@@ -713,7 +712,7 @@ auto SourceTreeService::ServeArchiveTree(
// check for archive_tree_id_file
auto archive_tree_id_file = StorageUtils::GetArchiveTreeIDFile(
- StorageConfig::Instance(), archive_type, content);
+ storage_config_, archive_type, content);
if (FileSystemManager::Exists(archive_tree_id_file)) {
// read archive_tree_id from file tree_id_file
auto archive_tree_id =
@@ -726,13 +725,11 @@ auto SourceTreeService::ServeArchiveTree(
return ::grpc::Status::OK;
}
// check local build root Git cache
- auto res = GetSubtreeFromTree(StorageConfig::Instance().GitRoot(),
- *archive_tree_id,
- subdir,
- logger_);
+ auto res = GetSubtreeFromTree(
+ storage_config_.GitRoot(), *archive_tree_id, subdir, logger_);
if (res) {
return ResolveContentTree(*res, // tree_id
- StorageConfig::Instance().GitRoot(),
+ storage_config_.GitRoot(),
/*repo_is_git_cache=*/true,
resolve_special,
request->sync_tree(),
@@ -742,7 +739,7 @@ auto SourceTreeService::ServeArchiveTree(
if (res.error() == GitLookupError::Fatal) {
logger_->Emit(LogLevel::Error,
"Failed to open repository {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -776,7 +773,7 @@ auto SourceTreeService::ServeArchiveTree(
return ::grpc::Status::OK;
}
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
@@ -784,24 +781,22 @@ auto SourceTreeService::ServeArchiveTree(
}
// check if content is in local CAS already
auto digest = ArtifactDigest(content, 0, false);
- auto const& cas = Storage::Instance().CAS();
+ auto const& cas = storage_.CAS();
std::optional<std::filesystem::path> content_cas_path{std::nullopt};
if (content_cas_path = cas.BlobPath(digest, /*is_executable=*/false);
not content_cas_path) {
// check if content blob is in Git cache
- auto res = GetBlobFromRepo(
- StorageConfig::Instance().GitRoot(), content, logger_);
+ auto res = GetBlobFromRepo(storage_config_.GitRoot(), content, logger_);
if (res) {
// add to CAS
- content_cas_path =
- StorageUtils::AddToCAS(Storage::Instance(), *res);
+ content_cas_path = StorageUtils::AddToCAS(storage_, *res);
}
if (res.error() == GitLookupError::Fatal) {
logger_->Emit(
LogLevel::Error,
"Failed while trying to retrieve content {} from repository {}",
content,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -812,8 +807,7 @@ auto SourceTreeService::ServeArchiveTree(
auto res = GetBlobFromRepo(path, content, logger_);
if (res) {
// add to CAS
- content_cas_path =
- StorageUtils::AddToCAS(Storage::Instance(), *res);
+ content_cas_path = StorageUtils::AddToCAS(storage_, *res);
if (content_cas_path) {
break;
}
@@ -851,7 +845,7 @@ auto SourceTreeService::ServeArchiveTree(
}
}
// extract archive
- auto tmp_dir = StorageConfig::Instance().CreateTypedTmpDir(archive_type);
+ auto tmp_dir = storage_config_.CreateTypedTmpDir(archive_type);
if (not tmp_dir) {
logger_->Emit(
LogLevel::Error,
@@ -890,8 +884,7 @@ auto SourceTreeService::DistdirImportToGit(
bool sync_tree,
ServeDistdirTreeResponse* response) -> ::grpc::Status {
// create tmp directory for the distdir
- auto distdir_tmp_dir =
- StorageConfig::Instance().CreateTypedTmpDir("distdir");
+ auto distdir_tmp_dir = storage_config_.CreateTypedTmpDir("distdir");
if (not distdir_tmp_dir) {
logger_->Emit(LogLevel::Error,
"Failed to create tmp path for distdir target {}",
@@ -901,7 +894,7 @@ auto SourceTreeService::DistdirImportToGit(
}
auto const& tmp_path = distdir_tmp_dir->GetPath();
// link the CAS blobs into the tmp dir
- auto const& cas = Storage::Instance().CAS();
+ auto const& cas = storage_.CAS();
if (not std::all_of(content_list.begin(),
content_list.end(),
[&cas, tmp_path](auto const& kv) {
@@ -957,10 +950,10 @@ auto SourceTreeService::DistdirImportToGit(
}
auto digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true};
auto repo = RepositoryConfig{};
- if (not repo.SetGitCAS(StorageConfig::Instance().GitRoot())) {
+ if (not repo.SetGitCAS(storage_config_.GitRoot())) {
logger_->Emit(LogLevel::Error,
"Failed to SetGitCAS at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeDistdirTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -988,7 +981,7 @@ auto SourceTreeService::ServeDistdirTree(
const ::justbuild::just_serve::ServeDistdirTreeRequest* request,
ServeDistdirTreeResponse* response) -> ::grpc::Status {
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeDistdirTreeResponse::INTERNAL_ERROR);
@@ -998,7 +991,7 @@ auto SourceTreeService::ServeDistdirTree(
GitRepo::tree_entries_t entries{};
entries.reserve(request->distfiles().size());
- auto const& cas = Storage::Instance().CAS();
+ auto const& cas = storage_.CAS();
std::unordered_map<std::string, std::pair<std::string, bool>>
content_list{};
content_list.reserve(request->distfiles().size());
@@ -1024,8 +1017,8 @@ auto SourceTreeService::ServeDistdirTree(
}
else {
// check local Git cache
- auto res = GetBlobFromRepo(
- StorageConfig::Instance().GitRoot(), content, logger_);
+ auto res =
+ GetBlobFromRepo(storage_config_.GitRoot(), content, logger_);
if (res) {
// add content to local CAS
auto stored_blob = cas.StoreBlob(*res, kv.executable());
@@ -1047,7 +1040,7 @@ auto SourceTreeService::ServeDistdirTree(
"Failed while trying to retrieve content {} "
"from repository {}",
content,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(
ServeDistdirTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
@@ -1165,13 +1158,12 @@ auto SourceTreeService::ServeDistdirTree(
return ::grpc::Status::OK;
}
// check if tree is already in Git cache
- auto has_tree =
- IsTreeInRepo(tree_id, StorageConfig::Instance().GitRoot(), logger_);
+ auto has_tree = IsTreeInRepo(tree_id, storage_config_.GitRoot(), logger_);
if (not has_tree) {
logger_->Emit(LogLevel::Error,
"Failed while checking for tree {} in repository {}",
tree_id,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeDistdirTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1190,10 +1182,10 @@ auto SourceTreeService::ServeDistdirTree(
}
auto digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true};
auto repo = RepositoryConfig{};
- if (not repo.SetGitCAS(StorageConfig::Instance().GitRoot())) {
+ if (not repo.SetGitCAS(storage_config_.GitRoot())) {
logger_->Emit(LogLevel::Error,
"Failed to SetGitCAS at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeDistdirTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1279,7 +1271,7 @@ auto SourceTreeService::ServeContent(
ServeContentResponse* response) -> ::grpc::Status {
auto const& content{request->content()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeContentResponse::INTERNAL_ERROR);
@@ -1287,15 +1279,14 @@ auto SourceTreeService::ServeContent(
}
auto const digest = ArtifactDigest{content, 0, /*is_tree=*/false};
// check if content blob is in Git cache
- auto res =
- GetBlobFromRepo(StorageConfig::Instance().GitRoot(), content, logger_);
+ auto res = GetBlobFromRepo(storage_config_.GitRoot(), content, logger_);
if (res) {
// upload blob to remote CAS
auto repo = RepositoryConfig{};
- if (not repo.SetGitCAS(StorageConfig::Instance().GitRoot())) {
+ if (not repo.SetGitCAS(storage_config_.GitRoot())) {
logger_->Emit(LogLevel::Error,
"Failed to SetGitCAS at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeContentResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1318,7 +1309,7 @@ auto SourceTreeService::ServeContent(
logger_->Emit(LogLevel::Error,
"Failed while checking for content {} in repository {}",
content,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeContentResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1389,7 +1380,7 @@ auto SourceTreeService::ServeTree(
ServeTreeResponse* response) -> ::grpc::Status {
auto const& tree_id{request->tree()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeTreeResponse::INTERNAL_ERROR);
@@ -1397,13 +1388,12 @@ auto SourceTreeService::ServeTree(
}
auto digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true};
// check if tree is in Git cache
- auto has_tree =
- IsTreeInRepo(tree_id, StorageConfig::Instance().GitRoot(), logger_);
+ auto has_tree = IsTreeInRepo(tree_id, storage_config_.GitRoot(), logger_);
if (not has_tree) {
logger_->Emit(LogLevel::Error,
"Failed while checking for tree {} in repository {}",
tree_id,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1418,10 +1408,10 @@ auto SourceTreeService::ServeTree(
return ::grpc::Status::OK;
}
auto repo = RepositoryConfig{};
- if (not repo.SetGitCAS(StorageConfig::Instance().GitRoot())) {
+ if (not repo.SetGitCAS(storage_config_.GitRoot())) {
logger_->Emit(LogLevel::Error,
"Failed to SetGitCAS at {}",
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(ServeTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1523,20 +1513,19 @@ auto SourceTreeService::CheckRootTree(
CheckRootTreeResponse* response) -> ::grpc::Status {
auto const& tree_id{request->tree()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(CheckRootTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
// check first in the Git cache
- auto has_tree =
- IsTreeInRepo(tree_id, StorageConfig::Instance().GitRoot(), logger_);
+ auto has_tree = IsTreeInRepo(tree_id, storage_config_.GitRoot(), logger_);
if (not has_tree) {
logger_->Emit(LogLevel::Error,
"Failed while checking for tree {} in repository {}",
tree_id,
- StorageConfig::Instance().GitRoot().string());
+ storage_config_.GitRoot().string());
response->set_status(CheckRootTreeResponse::INTERNAL_ERROR);
return ::grpc::Status::OK;
}
@@ -1564,11 +1553,11 @@ auto SourceTreeService::CheckRootTree(
}
// now check in the local CAS
auto digest = ArtifactDigest{tree_id, 0, /*is_tree=*/true};
- if (auto path = Storage::Instance().CAS().TreePath(digest)) {
+ if (auto path = storage_.CAS().TreePath(digest)) {
// As we currently build only against roots in Git repositories, we need
// to move the tree from CAS to local Git storage
- auto tmp_dir = StorageConfig::Instance().CreateTypedTmpDir(
- "source-tree-check-root-tree");
+ auto tmp_dir =
+ storage_config_.CreateTypedTmpDir("source-tree-check-root-tree");
if (not tmp_dir) {
logger_->Emit(LogLevel::Error,
"Failed to create tmp directory for copying git-tree "
@@ -1625,7 +1614,7 @@ auto SourceTreeService::GetRemoteTree(
GetRemoteTreeResponse* response) -> ::grpc::Status {
auto const& tree_id{request->tree()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(GetRemoteTreeResponse::INTERNAL_ERROR);
@@ -1640,8 +1629,8 @@ auto SourceTreeService::GetRemoteTree(
response->set_status(GetRemoteTreeResponse::FAILED_PRECONDITION);
return ::grpc::Status::OK;
}
- auto tmp_dir = StorageConfig::Instance().CreateTypedTmpDir(
- "source-tree-get-remote-tree");
+ auto tmp_dir =
+ storage_config_.CreateTypedTmpDir("source-tree-get-remote-tree");
if (not tmp_dir) {
logger_->Emit(LogLevel::Error,
"Failed to create tmp directory for copying git-tree {} "
diff --git a/src/buildtool/serve_api/serve_service/source_tree.hpp b/src/buildtool/serve_api/serve_service/source_tree.hpp
index a21eb23e..2f6d649c 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.hpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.hpp
@@ -35,6 +35,8 @@
#include "src/buildtool/file_system/symlinks_map/resolve_symlinks_map.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "src/utils/cpp/expected.hpp"
// Service for improved interaction with the target-level cache.
@@ -59,8 +61,13 @@ class SourceTreeService final
explicit SourceTreeService(
gsl::not_null<RemoteServeConfig const*> const& serve_config,
+ gsl::not_null<StorageConfig const*> const& storage_config,
+ gsl::not_null<Storage const*> const& storage,
gsl::not_null<ApiBundle const*> const& apis) noexcept
- : serve_config_{*serve_config}, apis_{*apis} {}
+ : serve_config_{*serve_config},
+ storage_{*storage},
+ storage_config_{*storage_config},
+ apis_{*apis} {}
// Retrieve the Git-subtree identifier from a given Git commit.
//
@@ -127,6 +134,8 @@ class SourceTreeService final
private:
RemoteServeConfig const& serve_config_;
+ StorageConfig const& storage_config_;
+ Storage const& storage_;
ApiBundle const& apis_;
mutable std::shared_mutex mutex_;
std::shared_ptr<Logger> logger_{std::make_shared<Logger>("serve-service")};
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index cc21a7be..6afea7e0 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -39,8 +39,6 @@
#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/config.hpp"
-#include "src/buildtool/storage/storage.hpp"
#include "src/buildtool/storage/target_cache_key.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -91,7 +89,7 @@ auto TargetService::HandleFailureLog(
logfile.string());
});
// ...but try to give the client the proper log
- auto const& cas = Storage::Instance().CAS();
+ auto const& cas = storage_.CAS();
auto digest = cas.StoreBlob(logfile, /*is_executable=*/false);
if (not digest) {
auto msg = fmt::format("Failed to store log of failed {} to local CAS",
@@ -129,7 +127,7 @@ auto TargetService::ServeTarget(
ArtifactDigest{request->target_cache_key_id()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
auto msg = std::string("Could not acquire gc SharedLock");
logger_->Emit(LogLevel::Error, msg);
@@ -198,8 +196,7 @@ auto TargetService::ServeTarget(
logger_->Emit(LogLevel::Error, err);
return ::grpc::Status{::grpc::StatusCode::INTERNAL, err};
}
- auto execution_backend_dgst =
- Storage::Instance().CAS().StoreBlob(description_str);
+ auto execution_backend_dgst = storage_.CAS().StoreBlob(description_str);
if (not execution_backend_dgst) {
std::string err{
"Failed to store execution backend description in local CAS"};
@@ -212,7 +209,7 @@ auto TargetService::ServeTarget(
address
? std::make_optional(ArtifactDigest(*execution_backend_dgst).hash())
: std::nullopt;
- auto const& tc = Storage::Instance().TargetCache().WithShard(shard);
+ auto const& tc = storage_.TargetCache().WithShard(shard);
auto const& tc_key =
TargetCacheKey{{target_cache_key_digest, ObjectType::File}};
@@ -336,8 +333,8 @@ auto TargetService::ServeTarget(
logger_->Emit(LogLevel::Error, "{}", msg);
return ::grpc::Status{::grpc::StatusCode::FAILED_PRECONDITION, msg};
}
- auto repo_config_path = Storage::Instance().CAS().BlobPath(
- repo_key_dgst, /*is_executable=*/false);
+ auto repo_config_path =
+ storage_.CAS().BlobPath(repo_key_dgst, /*is_executable=*/false);
if (not repo_config_path) {
// This should not fail unless something went really bad...
auto msg = fmt::format(
@@ -351,6 +348,7 @@ auto TargetService::ServeTarget(
RepositoryConfig repository_config{};
std::string const main_repo{"0"}; // known predefined main repository name
if (auto msg = DetermineRoots(serve_config_,
+ storage_config_,
main_repo,
*repo_config_path,
&repository_config,
@@ -435,7 +433,7 @@ auto TargetService::ServeTarget(
Progress progress{};
// setup logging for analysis and build; write into a temporary file
- auto tmp_dir = StorageConfig::Instance().CreateTypedTmpDir("serve-target");
+ auto tmp_dir = storage_config_.CreateTypedTmpDir("serve-target");
if (!tmp_dir) {
auto msg = std::string("Could not create TmpDir");
logger_->Emit(LogLevel::Error, msg);
@@ -592,10 +590,8 @@ auto TargetService::ServeTargetVariables(
std::optional<std::string> target_file_content{std::nullopt};
bool tree_found{false};
// try in local build root Git cache
- if (auto res = GetBlobContent(StorageConfig::Instance().GitRoot(),
- root_tree,
- target_file,
- logger_)) {
+ if (auto res = GetBlobContent(
+ storage_config_.GitRoot(), root_tree, target_file, logger_)) {
tree_found = true;
if (res->first) {
if (not res->second) {
@@ -748,10 +744,8 @@ auto TargetService::ServeTargetDescription(
std::optional<std::string> target_file_content{std::nullopt};
bool tree_found{false};
// try in local build root Git cache
- if (auto res = GetBlobContent(StorageConfig::Instance().GitRoot(),
- root_tree,
- target_file,
- logger_)) {
+ if (auto res = GetBlobContent(
+ storage_config_.GitRoot(), root_tree, target_file, logger_)) {
tree_found = true;
if (res->first) {
if (not res->second) {
@@ -880,7 +874,7 @@ auto TargetService::ServeTargetDescription(
}
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
+ auto lock = GarbageCollector::SharedLock(storage_config_);
if (!lock) {
auto error_msg = fmt::format("Could not acquire gc SharedLock");
logger_->Emit(LogLevel::Error, error_msg);
@@ -901,9 +895,8 @@ auto TargetService::ServeTargetDescription(
logger_->Emit(LogLevel::Error, err);
return ::grpc::Status{::grpc::StatusCode::INTERNAL, err};
}
- if (auto dgst =
- Storage::Instance().CAS().StoreBlob(description_str,
- /*is_executable=*/false)) {
+ if (auto dgst = storage_.CAS().StoreBlob(description_str,
+ /*is_executable=*/false)) {
auto const& artifact_dgst = ArtifactDigest{*dgst};
if (not apis_.local->RetrieveToCas(
{Artifact::ObjectInfo{.digest = artifact_dgst,
diff --git a/src/buildtool/serve_api/serve_service/target.hpp b/src/buildtool/serve_api/serve_service/target.hpp
index 5301b82c..9488e19c 100644
--- a/src/buildtool/serve_api/serve_service/target.hpp
+++ b/src/buildtool/serve_api/serve_service/target.hpp
@@ -34,6 +34,8 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/buildtool/serve_api/remote/serve_api.hpp"
+#include "src/buildtool/storage/config.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "src/utils/cpp/expected.hpp"
// The target-level cache service.
@@ -41,9 +43,15 @@ class TargetService final : public justbuild::just_serve::Target::Service {
public:
explicit TargetService(
gsl::not_null<RemoteServeConfig const*> const& serve_config,
+ gsl::not_null<StorageConfig const*> const& storage_config,
+ gsl::not_null<Storage const*> const& storage,
gsl::not_null<ApiBundle const*> const& apis,
ServeApi const* serve = nullptr) noexcept
- : serve_config_{*serve_config}, apis_{*apis}, serve_{serve} {}
+ : serve_config_{*serve_config},
+ storage_config_{*storage_config},
+ storage_{*storage},
+ apis_{*apis},
+ serve_{serve} {}
// Given a target-level caching key, returns the computed value. In doing
// so, it can build on the associated endpoint passing the
@@ -122,6 +130,8 @@ class TargetService final : public justbuild::just_serve::Target::Service {
private:
RemoteServeConfig const& serve_config_;
+ StorageConfig const& storage_config_;
+ Storage const& storage_;
ApiBundle const& apis_;
ServeApi const* const serve_ = nullptr;
std::shared_ptr<Logger> logger_{std::make_shared<Logger>("target-service")};
diff --git a/src/buildtool/serve_api/serve_service/target_utils.cpp b/src/buildtool/serve_api/serve_service/target_utils.cpp
index c2dd0422..a6463c37 100644
--- a/src/buildtool/serve_api/serve_service/target_utils.cpp
+++ b/src/buildtool/serve_api/serve_service/target_utils.cpp
@@ -25,8 +25,6 @@
#include "src/buildtool/file_system/git_repo.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/logging/log_level.hpp"
-#include "src/buildtool/storage/config.hpp"
-#include "src/buildtool/storage/storage.hpp"
auto IsTreeInRepo(std::string const& tree_id,
std::filesystem::path const& repo_path,
@@ -54,12 +52,13 @@ auto IsTreeInRepo(std::string const& tree_id,
}
auto GetServingRepository(RemoteServeConfig const& serve_config,
+ StorageConfig const& storage_config,
std::string const& tree_id,
std::shared_ptr<Logger> const& logger)
-> std::optional<std::filesystem::path> {
// try the Git cache repository
- if (IsTreeInRepo(tree_id, StorageConfig::Instance().GitRoot(), logger)) {
- return StorageConfig::Instance().GitRoot();
+ if (IsTreeInRepo(tree_id, storage_config.GitRoot(), logger)) {
+ return storage_config.GitRoot();
}
// check the known repositories
for (auto const& path : serve_config.known_repositories) {
@@ -71,6 +70,7 @@ auto GetServingRepository(RemoteServeConfig const& serve_config,
}
auto DetermineRoots(RemoteServeConfig const& serve_config,
+ StorageConfig const& storage_config,
std::string const& main_repo,
std::filesystem::path const& repo_config_path,
gsl::not_null<RepositoryConfig*> const& repository_config,
@@ -103,6 +103,7 @@ auto DetermineRoots(RemoteServeConfig const& serve_config,
// root parser
auto parse_keyword_root =
[&serve_config,
+ &storage_config,
&desc = desc,
&repo = repo,
&error_msg = error_msg,
@@ -122,8 +123,8 @@ auto DetermineRoots(RemoteServeConfig const& serve_config,
}
// find the serving repository for the root tree
auto tree_id = *parsed_root->first.GetAbsentTreeId();
- auto repo_path =
- GetServingRepository(serve_config, tree_id, logger);
+ auto repo_path = GetServingRepository(
+ serve_config, storage_config, tree_id, logger);
if (not repo_path) {
error_msg = fmt::format(
"{} tree {} is not known", keyword, tree_id);
diff --git a/src/buildtool/serve_api/serve_service/target_utils.hpp b/src/buildtool/serve_api/serve_service/target_utils.hpp
index 504113e4..e35e9142 100644
--- a/src/buildtool/serve_api/serve_service/target_utils.hpp
+++ b/src/buildtool/serve_api/serve_service/target_utils.hpp
@@ -26,6 +26,7 @@
#include "src/buildtool/common/repository_config.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
+#include "src/buildtool/storage/config.hpp"
// Methods used by ServeTarget remote service
@@ -36,6 +37,7 @@
/// \brief For a given tree id, find the known repository that can serve it.
[[nodiscard]] auto GetServingRepository(RemoteServeConfig const& serve_config,
+ StorageConfig const& storage_config,
std::string const& tree_id,
std::shared_ptr<Logger> const& logger)
-> std::optional<std::filesystem::path>;
@@ -45,6 +47,7 @@
/// \returns nullopt on success, error message as a string otherwise.
[[nodiscard]] auto DetermineRoots(
RemoteServeConfig const& serve_config,
+ StorageConfig const& storage_config,
std::string const& main_repo,
std::filesystem::path const& repo_config_path,
gsl::not_null<RepositoryConfig*> const& repository_config,
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index 8f265405..791c2dc5 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -126,6 +126,7 @@
, ["src/buildtool/execution_api/common", "api_bundle"]
, ["src/buildtool/serve_api/remote", "config"]
, ["src/buildtool/serve_api/remote", "serve_api"]
+ , ["src/buildtool/storage", "storage"]
]
}
, "update":
diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp
index 07a03f3d..0e2d3e60 100644
--- a/src/other_tools/just_mr/fetch.cpp
+++ b/src/other_tools/just_mr/fetch.cpp
@@ -28,6 +28,7 @@
#include "src/buildtool/multithreading/task_system.hpp"
#include "src/buildtool/serve_api/remote/config.hpp"
#include "src/buildtool/serve_api/remote/serve_api.hpp"
+#include "src/buildtool/storage/storage.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress_reporter.hpp"
@@ -417,7 +418,7 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config,
return kExitConfigError;
}
- auto serve = ServeApi::Create(*serve_config, &apis);
+ auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
// check configuration of the serve endpoint provided
if (serve) {
// if we have a remote endpoint explicitly given by the user, it must
diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp
index 5094c3aa..c96af8b1 100644
--- a/src/other_tools/just_mr/setup.cpp
+++ b/src/other_tools/just_mr/setup.cpp
@@ -137,7 +137,8 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config,
return std::nullopt;
}
- auto serve = ServeApi::Create(*serve_config, &apis);
+ auto serve = ServeApi::Create(*serve_config, &Storage::Instance(), &apis);
+
// check configuration of the serve endpoint provided
if (serve) {
// if we have a remote endpoint explicitly given by the user, it must