diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-10-07 16:26:51 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2022-10-07 16:34:56 +0200 |
commit | 149fe52517653a3a5c2ef5f2be2ab09415eedba4 (patch) | |
tree | 5e223a08dee78bec91eaf4e6f94be653ca846f2a | |
parent | 947a1e16e8079592773c055e86d9c4cbb8c305a8 (diff) | |
download | justbuild-149fe52517653a3a5c2ef5f2be2ab09415eedba4.tar.gz |
Fix upload of known source trees
When a tree is taken from a git root, it is not necessarily known on
the remote site. So, as any missing artifact it has to be uploaded,
recursively uploading the parts to keep the tree invariant. The
function RetrieveToCas was doing the correct recursiv pattern, however
inspecting trees incorrectly using the function ReadTreeInfos; the
latter function, however, was obtaining all the leafs of the tree
as is needed for a compatible action-input description. Add and
use a function that reads the direct contents of a tree.
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; |