summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/local/local_api.hpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-06-27 13:27:06 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-05 13:32:39 +0200
commit9f5dcef077a3db2f6c791e403e5036f6464c9576 (patch)
tree5e14f016207af83a8d0458a7ffe960ecba56280d /src/buildtool/execution_api/local/local_api.hpp
parent0d8a4ad15b93283cc31787b039051b9e9a285ba8 (diff)
downloadjustbuild-9f5dcef077a3db2f6c791e403e5036f6464c9576.tar.gz
Pass StorageConfig and Storage to LocalApi
Diffstat (limited to 'src/buildtool/execution_api/local/local_api.hpp')
-rw-r--r--src/buildtool/execution_api/local/local_api.hpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp
index f9eefb64..6f43dd44 100644
--- a/src/buildtool/execution_api/local/local_api.hpp
+++ b/src/buildtool/execution_api/local/local_api.hpp
@@ -48,13 +48,18 @@
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
/// \brief API for local execution.
class LocalApi final : public IExecutionApi {
public:
- explicit LocalApi(RepositoryConfig const* repo_config = nullptr) noexcept
- : repo_config_{repo_config} {}
+ explicit LocalApi(gsl::not_null<StorageConfig const*> const& storage_config,
+ gsl::not_null<Storage const*> const& storage,
+ RepositoryConfig const* repo_config = nullptr) noexcept
+ : storage_config_{*storage_config},
+ storage_{*storage},
+ repo_config_{repo_config} {}
[[nodiscard]] auto CreateAction(
ArtifactDigest const& root_digest,
@@ -64,7 +69,8 @@ class LocalApi final : public IExecutionApi {
std::map<std::string, std::string> const& env_vars,
std::map<std::string, std::string> const& properties) const noexcept
-> IExecutionAction::Ptr final {
- return IExecutionAction::Ptr{new LocalAction{storage_,
+ return IExecutionAction::Ptr{new LocalAction{&storage_config_,
+ &storage_,
root_digest,
command,
output_files,
@@ -89,7 +95,7 @@ class LocalApi final : public IExecutionApi {
auto const& info = artifacts_info[i];
if (IsTreeObject(info.type)) {
// read object infos from sub tree and call retrieve recursively
- auto reader = TreeReader<LocalCasReader>{storage_->CAS()};
+ auto reader = TreeReader<LocalCasReader>{storage_.CAS()};
auto const result = reader.RecursivelyReadTreeLeafs(
info.digest, output_paths[i]);
if (not result) {
@@ -109,7 +115,7 @@ class LocalApi final : public IExecutionApi {
}
}
else {
- auto const blob_path = storage_->CAS().BlobPath(
+ auto const blob_path = storage_.CAS().BlobPath(
info.digest, IsExecutableObject(info.type));
if (not blob_path) {
if (Compatibility::IsCompatible()) {
@@ -143,7 +149,7 @@ class LocalApi final : public IExecutionApi {
std::vector<Artifact::ObjectInfo> const& artifacts_info,
std::vector<int> const& fds,
bool raw_tree) const noexcept -> bool final {
- auto dumper = StreamDumper<LocalCasReader>{storage_->CAS()};
+ auto dumper = StreamDumper<LocalCasReader>{storage_.CAS()};
return CommonRetrieveToFds(
artifacts_info,
fds,
@@ -196,7 +202,7 @@ class LocalApi final : public IExecutionApi {
auto const& info = missing_artifacts_info->back_map[dgst];
// Recursively process trees.
if (IsTreeObject(info.type)) {
- auto reader = TreeReader<LocalCasReader>{storage_->CAS()};
+ auto reader = TreeReader<LocalCasReader>{storage_.CAS()};
auto const& result = reader.ReadDirectTreeEntries(
info.digest, std::filesystem::path{});
if (not result or not RetrieveToCas(result->infos, api)) {
@@ -207,9 +213,9 @@ class LocalApi final : public IExecutionApi {
// Determine artifact path.
auto const& path =
IsTreeObject(info.type)
- ? storage_->CAS().TreePath(info.digest)
- : storage_->CAS().BlobPath(info.digest,
- IsExecutableObject(info.type));
+ ? storage_.CAS().TreePath(info.digest)
+ : storage_.CAS().BlobPath(info.digest,
+ IsExecutableObject(info.type));
if (not path) {
return false;
}
@@ -221,7 +227,7 @@ class LocalApi final : public IExecutionApi {
}
// Regenerate digest since object infos read by
- // storage_->ReadTreeInfos() will contain 0 as size.
+ // storage_.ReadTreeInfos() will contain 0 as size.
ArtifactDigest digest =
IsTreeObject(info.type)
? ArtifactDigest::Create<ObjectType::Tree>(*content)
@@ -251,10 +257,10 @@ class LocalApi final : public IExecutionApi {
-> std::optional<std::string> override {
std::optional<std::filesystem::path> location{};
if (IsTreeObject(artifact_info.type)) {
- location = storage_->CAS().TreePath(artifact_info.digest);
+ location = storage_.CAS().TreePath(artifact_info.digest);
}
else {
- location = storage_->CAS().BlobPath(
+ location = storage_.CAS().BlobPath(
artifact_info.digest, IsExecutableObject(artifact_info.type));
}
std::optional<std::string> content = std::nullopt;
@@ -274,8 +280,8 @@ class LocalApi final : public IExecutionApi {
auto const is_tree = NativeSupport::IsTree(
static_cast<bazel_re::Digest>(blob.digest).hash());
auto cas_digest =
- is_tree ? storage_->CAS().StoreTree(*blob.data)
- : storage_->CAS().StoreBlob(*blob.data, blob.is_exec);
+ is_tree ? storage_.CAS().StoreTree(*blob.data)
+ : storage_.CAS().StoreBlob(*blob.data, blob.is_exec);
if (not cas_digest or not std::equal_to<bazel_re::Digest>{}(
*cas_digest, blob.digest)) {
return false;
@@ -298,7 +304,7 @@ class LocalApi final : public IExecutionApi {
return CommonUploadTreeCompatible(
*this,
*build_root,
- [&cas = storage_->CAS()](
+ [&cas = storage_.CAS()](
std::vector<bazel_re::Digest> const& digests,
std::vector<std::string>* targets) {
targets->reserve(digests.size());
@@ -317,8 +323,8 @@ class LocalApi final : public IExecutionApi {
-> bool final {
return static_cast<bool>(
NativeSupport::IsTree(static_cast<bazel_re::Digest>(digest).hash())
- ? storage_->CAS().TreePath(digest)
- : storage_->CAS().BlobPath(digest, false));
+ ? storage_.CAS().TreePath(digest)
+ : storage_.CAS().BlobPath(digest, false));
}
[[nodiscard]] auto IsAvailable(std::vector<ArtifactDigest> const& digests)
@@ -327,8 +333,8 @@ class LocalApi final : public IExecutionApi {
for (auto const& digest : digests) {
auto const& path = NativeSupport::IsTree(
static_cast<bazel_re::Digest>(digest).hash())
- ? storage_->CAS().TreePath(digest)
- : storage_->CAS().BlobPath(digest, false);
+ ? storage_.CAS().TreePath(digest)
+ : storage_.CAS().BlobPath(digest, false);
if (not path) {
result.push_back(digest);
}
@@ -340,7 +346,7 @@ class LocalApi final : public IExecutionApi {
const noexcept -> std::optional<std::vector<ArtifactDigest>> final {
Logger::Log(LogLevel::Debug, "SplitBlob({})", blob_digest.hash());
auto split_result = CASUtils::SplitBlobFastCDC(
- static_cast<bazel_re::Digest>(blob_digest), *storage_);
+ static_cast<bazel_re::Digest>(blob_digest), storage_);
if (not split_result) {
Logger::Log(LogLevel::Error, split_result.error().error_message());
return std::nullopt;
@@ -390,7 +396,7 @@ class LocalApi final : public IExecutionApi {
return static_cast<bazel_re::Digest>(artifact_digest);
});
auto splice_result = CASUtils::SpliceBlob(
- static_cast<bazel_re::Digest>(blob_digest), digests, *storage_);
+ static_cast<bazel_re::Digest>(blob_digest), digests, storage_);
if (not splice_result) {
Logger::Log(LogLevel::Error, splice_result.error().error_message());
return std::nullopt;
@@ -403,8 +409,9 @@ class LocalApi final : public IExecutionApi {
}
private:
+ StorageConfig const& storage_config_;
+ Storage const& storage_;
RepositoryConfig const* const repo_config_ = nullptr;
- gsl::not_null<Storage const*> storage_ = &Storage::Instance();
};
#endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_API_HPP