summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_engine/executor/executor.hpp
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2025-04-04 10:05:54 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2025-04-07 17:42:26 +0200
commit0ce050714843dec41f2dc097a2236ab00f85ccce (patch)
tree65a0b6dc9c345dc8d1546df447148ec49053a923 /src/buildtool/execution_engine/executor/executor.hpp
parentab7d432e72a6c97b7ad9dcfe45b530cd626e4b58 (diff)
downloadjustbuild-0ce050714843dec41f2dc097a2236ab00f85ccce.tar.gz
executor: also handle tree-overlay actions
Diffstat (limited to 'src/buildtool/execution_engine/executor/executor.hpp')
-rw-r--r--src/buildtool/execution_engine/executor/executor.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp
index 41870df2..d274655a 100644
--- a/src/buildtool/execution_engine/executor/executor.hpp
+++ b/src/buildtool/execution_engine/executor/executor.hpp
@@ -18,6 +18,7 @@
#include <algorithm>
#include <chrono>
#include <cmath>
+#include <compare>
#include <exception>
#include <filesystem>
#include <functional>
@@ -59,6 +60,7 @@
#include "src/buildtool/execution_api/remote/context.hpp"
#include "src/buildtool/execution_engine/dag/dag.hpp"
#include "src/buildtool/execution_engine/executor/context.hpp"
+#include "src/buildtool/execution_engine/tree_operations/tree_operations_utils.hpp"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/file_system/git_tree.hpp"
#include "src/buildtool/file_system/object_type.hpp"
@@ -77,6 +79,54 @@
/// \brief Implementations for executing actions and uploading artifacts.
class ExecutorImpl {
public:
+ /// \brief Computes the result of a tree-overlay action.
+ /// \returns std::nullopt on success, nullptr on error.
+ [[nodiscard]] static auto ExecuteTreeOverlayAction(
+ Logger const& logger,
+ gsl::not_null<DependencyGraph::ActionNode const*> const& action,
+ IExecutionApi const& api) -> std::optional<IExecutionResponse::Ptr> {
+ std::vector<DependencyGraph::NamedArtifactNodePtr> inputs =
+ action->Dependencies();
+ std::sort(inputs.begin(), inputs.end(), [](auto a, auto b) {
+ return a.path < b.path;
+ });
+ logger.Emit(LogLevel::Debug, [&]() {
+ std::ostringstream oss{};
+ oss << "Requested tree-overlay action is " << action->Content().Id()
+ << "\n";
+ oss << "Trees to overlay:";
+ for (auto const& input : inputs) {
+ oss << "\n - " << input.node->Content().Info()->digest.hash()
+ << ":" << input.node->Content().Info()->digest.size() << ":"
+ << ToChar(input.node->Content().Info()->type);
+ }
+ return oss.str();
+ });
+ auto tree = *inputs[0].node->Content().Info();
+ for (auto const& overlay : inputs) {
+ auto computed_overlay = TreeOperationsUtils::ComputeTreeOverlay(
+ api,
+ tree,
+ *overlay.node->Content().Info(),
+ action->Content().IsOverlayDisjoint());
+ if (not computed_overlay) {
+ logger.Emit(LogLevel::Error,
+ "Tree-overlay computation failed: {}",
+ computed_overlay.error());
+ return nullptr;
+ }
+ tree = computed_overlay.value();
+ }
+ auto const& tree_artifact = action->OutputDirs()[0].node->Content();
+ bool failed_inputs = false;
+ for (auto const& [local_path, artifact] : inputs) {
+ failed_inputs |= artifact->Content().Info()->failed;
+ }
+ tree_artifact.SetObjectInfo(
+ tree.digest, ObjectType::Tree, failed_inputs);
+ return std::nullopt;
+ }
+
/// \brief Execute action and obtain response.
/// \returns std::nullopt for actions without response (e.g., tree actions).
/// \returns nullptr on error.
@@ -91,6 +141,9 @@ class ExecutorImpl {
gsl::not_null<Statistics*> const& stats,
gsl::not_null<Progress*> const& progress)
-> std::optional<IExecutionResponse::Ptr> {
+ if (action->Content().IsTreeOverlayAction()) {
+ return ExecuteTreeOverlayAction(logger, action, api);
+ }
auto const& inputs = action->Dependencies();
auto const tree_action = action->Content().IsTreeAction();