From 398894b85672f5197b5fc3eeae3fa2ec32f03908 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 25 Aug 2024 13:41:56 +0200 Subject: [PATCH] libstore: make Goal::ex a shared_ptr this makes WorkResult copyable, and just all around easier to deal with. in the future we'll need this to let Goal::work() return a promise for a WorkResult (or even just a Finished) that can be awaited by other goals. Change-Id: Ic5a1ce04c5a0f8e683bd00a2ed2b77a2e28989c1 --- src/libstore/build/derivation-goal.cc | 2 +- src/libstore/build/entry-points.cc | 4 ++-- src/libstore/build/goal.hh | 4 ++-- src/libstore/build/worker.cc | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 2638d7395..f2c8ccc5f 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -1545,7 +1545,7 @@ Goal::Finished DerivationGoal::done( return Finished{ .result = buildResult.success() ? ecSuccess : ecFailed, - .ex = ex ? std::make_unique(std::move(*ex)) : nullptr, + .ex = ex ? std::make_shared(std::move(*ex)) : nullptr, .permanentFailure = buildResult.status == BuildResult::PermanentFailure, .timedOut = buildResult.status == BuildResult::TimedOut, .hashMismatch = anyHashMismatchSeen, diff --git a/src/libstore/build/entry-points.cc b/src/libstore/build/entry-points.cc index c6955600e..f52f2876f 100644 --- a/src/libstore/build/entry-points.cc +++ b/src/libstore/build/entry-points.cc @@ -16,13 +16,13 @@ void Store::buildPaths(const std::vector & reqs, BuildMode buildMod worker.run(goals); StringSet failed; - std::optional ex; + std::shared_ptr ex; for (auto & i : goals) { if (i->ex) { if (ex) logError(i->ex->info()); else - ex = std::move(*i->ex); + ex = i->ex; } if (i->exitCode != Goal::ecSuccess) { if (auto i2 = dynamic_cast(i.get())) diff --git a/src/libstore/build/goal.hh b/src/libstore/build/goal.hh index 4ff4a14f8..1bfea8231 100644 --- a/src/libstore/build/goal.hh +++ b/src/libstore/build/goal.hh @@ -118,7 +118,7 @@ public: }; struct [[nodiscard]] Finished { ExitCode result; - std::unique_ptr ex; + std::shared_ptr ex; bool permanentFailure = false; bool timedOut = false; bool hashMismatch = false; @@ -141,7 +141,7 @@ public: /** * Exception containing an error message, if any. */ - std::unique_ptr ex; + std::shared_ptr ex; explicit Goal(Worker & worker) : worker(worker) diff --git a/src/libstore/build/worker.cc b/src/libstore/build/worker.cc index 4a70b272a..1b4633e64 100644 --- a/src/libstore/build/worker.cc +++ b/src/libstore/build/worker.cc @@ -150,7 +150,7 @@ void Worker::goalFinished(GoalPtr goal, Goal::Finished & f) if (!goal->waiters.empty()) logError(f.ex->info()); else - goal->ex = std::move(f.ex); + goal->ex = f.ex; } for (auto & i : goal->waiters) {