diff options
Diffstat (limited to 'src')
6 files changed, 91 insertions, 3 deletions
diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 13bcb7e3..dd3bc4a0 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -134,7 +134,7 @@ class LocalApi final : public IExecutionApi { for (auto const& info : missing_artifacts_info) { // Recursively process trees. if (IsTreeObject(info.type)) { - auto const& infos = storage_->ReadTreeInfos( + auto const& infos = storage_->ReadTreeInfosDirect( info.digest, std::filesystem::path{}); if (not infos or not RetrieveToCas(infos->second, api)) { return false; diff --git a/src/buildtool/execution_api/local/local_storage.cpp b/src/buildtool/execution_api/local/local_storage.cpp index b8e8401c..2734577b 100644 --- a/src/buildtool/execution_api/local/local_storage.cpp +++ b/src/buildtool/execution_api/local/local_storage.cpp @@ -108,6 +108,43 @@ auto LocalStorage::ReadTreeInfos( return std::nullopt; } +auto LocalStorage::ReadTreeInfosDirect( + bazel_re::Digest const& tree_digest, + std::filesystem::path const& parent) const noexcept + -> std::optional<std::pair<std::vector<std::filesystem::path>, + std::vector<Artifact::ObjectInfo>>> { + std::vector<std::filesystem::path> paths{}; + std::vector<Artifact::ObjectInfo> infos{}; + + auto store_info = [&paths, &infos](auto path, auto info) { + paths.emplace_back(path); + infos.emplace_back(info); + return true; + }; + + if (Compatibility::IsCompatible()) { + if (auto dir = ReadDirectory(this, tree_digest)) { + if (not BazelMsgFactory::ReadObjectInfosFromDirectory( + *dir, [&store_info, &parent](auto path, auto info) { + return store_info(parent / path, info); + })) { + return std::nullopt; + } + } + } + else { + if (auto entries = ReadGitTree(this, tree_digest)) { + if (not BazelMsgFactory::ReadObjectInfosFromGitTree( + *entries, [&store_info, &parent](auto path, auto info) { + return store_info(parent / path, info); + })) { + return std::nullopt; + } + } + } + return std::make_pair(std::move(paths), std::move(infos)); +} + // NOLINTNEXTLINE(misc-no-recursion) auto LocalStorage::ReadObjectInfosRecursively( BazelMsgFactory::InfoStoreFunc const& store_info, diff --git a/src/buildtool/execution_api/local/local_storage.hpp b/src/buildtool/execution_api/local/local_storage.hpp index 5ad7f142..888f39c8 100644 --- a/src/buildtool/execution_api/local/local_storage.hpp +++ b/src/buildtool/execution_api/local/local_storage.hpp @@ -75,6 +75,12 @@ class LocalStorage { -> std::optional<std::pair<std::vector<std::filesystem::path>, std::vector<Artifact::ObjectInfo>>>; + [[nodiscard]] auto ReadTreeInfosDirect( + bazel_re::Digest const& tree_digest, + std::filesystem::path const& parent) const noexcept + -> std::optional<std::pair<std::vector<std::filesystem::path>, + std::vector<Artifact::ObjectInfo>>>; + [[nodiscard]] auto DumpToStream(Artifact::ObjectInfo const& info, gsl::not_null<FILE*> const& stream, bool raw_tree) const noexcept -> bool; diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index d1de9a68..34cb129e 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -170,8 +170,8 @@ auto BazelApi::CreateAction( std::vector<bazel_re::Digest> blob_digests{}; for (auto const& info : missing_artifacts_info) { if (IsTreeObject(info.type)) { - auto const infos = - network_->ReadTreeInfos(info.digest, std::filesystem::path{}); + auto const infos = network_->ReadTreeInfosDirect( + info.digest, std::filesystem::path{}); if (not infos or not RetrieveToCas(infos->second, api)) { return false; } diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp index e4205d25..4fb9398b 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp @@ -279,6 +279,45 @@ auto BazelNetwork::ReadTreeInfos(bazel_re::Digest const& tree_digest, return std::nullopt; } +auto BazelNetwork::ReadTreeInfosDirect( + bazel_re::Digest const& tree_digest, + std::filesystem::path const& parent) const noexcept + -> std::optional<std::pair<std::vector<std::filesystem::path>, + std::vector<Artifact::ObjectInfo>>> { + std::vector<std::filesystem::path> paths{}; + std::vector<Artifact::ObjectInfo> infos{}; + + auto store_info = [&paths, &infos](auto path, auto info) { + paths.emplace_back(path); + infos.emplace_back(info); + return true; + }; + + if (Compatibility::IsCompatible()) { + // read from CAS + if (auto dir = ReadDirectory(this, tree_digest)) { + if (not BazelMsgFactory::ReadObjectInfosFromDirectory( + *dir, [&store_info, &parent](auto path, auto info) { + return store_info(parent / path, info); + })) { + return std::nullopt; + } + } + } + else { + if (auto entries = ReadGitTree(this, tree_digest)) { + if (not BazelMsgFactory::ReadObjectInfosFromGitTree( + *entries, [&store_info, &parent](auto path, auto info) { + return store_info(parent / path, info); + })) { + return std::nullopt; + } + } + } + + return std::make_pair(std::move(paths), std::move(infos)); +} + // NOLINTNEXTLINE(misc-no-recursion) auto BazelNetwork::ReadObjectInfosRecursively( std::optional<DirectoryMap> const& dir_map, diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp index a323e00b..7b0d69ae 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network.hpp @@ -85,6 +85,12 @@ class BazelNetwork { -> std::optional<std::pair<std::vector<std::filesystem::path>, std::vector<Artifact::ObjectInfo>>>; + [[nodiscard]] auto ReadTreeInfosDirect( + bazel_re::Digest const& tree_digest, + std::filesystem::path const& parent) const noexcept + -> std::optional<std::pair<std::vector<std::filesystem::path>, + std::vector<Artifact::ObjectInfo>>>; + [[nodiscard]] auto DumpToStream( Artifact::ObjectInfo const& info, gsl::not_null<FILE*> const& stream) const noexcept -> bool; |