summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/common
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-12-17 18:27:37 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2024-12-19 16:37:59 +0100
commitb3c863abc09f9f81150e21af2cc89d75bee98db2 (patch)
tree7159690d103f3fd4e2d95ba077fe0b6d1e33793e /src/buildtool/execution_api/common
parentbd410a2557b6127d47396cd0740347e4af0766df (diff)
downloadjustbuild-b3c863abc09f9f81150e21af2cc89d75bee98db2.tar.gz
Move functionality for staging from CAS to output paths to TreeReader
...and employ it in LocalApi.
Diffstat (limited to 'src/buildtool/execution_api/common')
-rw-r--r--src/buildtool/execution_api/common/tree_reader.hpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/buildtool/execution_api/common/tree_reader.hpp b/src/buildtool/execution_api/common/tree_reader.hpp
index 7ec66163..42bf20e6 100644
--- a/src/buildtool/execution_api/common/tree_reader.hpp
+++ b/src/buildtool/execution_api/common/tree_reader.hpp
@@ -15,6 +15,7 @@
#ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_TREE_READER_HPP
#define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_COMMON_TREE_READER_HPP
+#include <cstddef>
#include <filesystem>
#include <optional>
#include <utility>
@@ -107,6 +108,32 @@ class TreeReader final {
}
}
+ /// \brief Traverse a tree recursively and stage all artifacts to paths.
+ /// \param infos Infos to be staged
+ /// \param outputs Paths to be used for staging
+ /// \return True if outputs contain corresponding infos.
+ [[nodiscard]] auto StageTo(std::vector<Artifact::ObjectInfo> const& infos,
+ std::vector<std::filesystem::path> const&
+ outputs) const noexcept -> bool {
+ if (infos.size() != outputs.size()) {
+ return false;
+ }
+
+ for (std::size_t i = 0; i < infos.size(); ++i) {
+ auto const& info = infos[i];
+ if (IsTreeObject(info.type)) {
+ auto result = RecursivelyReadTreeLeafs(info.digest, outputs[i]);
+ if (not result or not StageTo(result->infos, result->paths)) {
+ return false;
+ }
+ }
+ else if (not impl_.StageBlobTo(info, outputs[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private:
TImpl impl_;