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
This commit is contained in:
eldritch horrors 2024-08-25 13:41:56 +02:00
parent 30a87b4cd5
commit 398894b856
4 changed files with 6 additions and 6 deletions

View file

@ -1545,7 +1545,7 @@ Goal::Finished DerivationGoal::done(
return Finished{ return Finished{
.result = buildResult.success() ? ecSuccess : ecFailed, .result = buildResult.success() ? ecSuccess : ecFailed,
.ex = ex ? std::make_unique<Error>(std::move(*ex)) : nullptr, .ex = ex ? std::make_shared<Error>(std::move(*ex)) : nullptr,
.permanentFailure = buildResult.status == BuildResult::PermanentFailure, .permanentFailure = buildResult.status == BuildResult::PermanentFailure,
.timedOut = buildResult.status == BuildResult::TimedOut, .timedOut = buildResult.status == BuildResult::TimedOut,
.hashMismatch = anyHashMismatchSeen, .hashMismatch = anyHashMismatchSeen,

View file

@ -16,13 +16,13 @@ void Store::buildPaths(const std::vector<DerivedPath> & reqs, BuildMode buildMod
worker.run(goals); worker.run(goals);
StringSet failed; StringSet failed;
std::optional<Error> ex; std::shared_ptr<Error> ex;
for (auto & i : goals) { for (auto & i : goals) {
if (i->ex) { if (i->ex) {
if (ex) if (ex)
logError(i->ex->info()); logError(i->ex->info());
else else
ex = std::move(*i->ex); ex = i->ex;
} }
if (i->exitCode != Goal::ecSuccess) { if (i->exitCode != Goal::ecSuccess) {
if (auto i2 = dynamic_cast<DerivationGoal *>(i.get())) if (auto i2 = dynamic_cast<DerivationGoal *>(i.get()))

View file

@ -118,7 +118,7 @@ public:
}; };
struct [[nodiscard]] Finished { struct [[nodiscard]] Finished {
ExitCode result; ExitCode result;
std::unique_ptr<Error> ex; std::shared_ptr<Error> ex;
bool permanentFailure = false; bool permanentFailure = false;
bool timedOut = false; bool timedOut = false;
bool hashMismatch = false; bool hashMismatch = false;
@ -141,7 +141,7 @@ public:
/** /**
* Exception containing an error message, if any. * Exception containing an error message, if any.
*/ */
std::unique_ptr<Error> ex; std::shared_ptr<Error> ex;
explicit Goal(Worker & worker) explicit Goal(Worker & worker)
: worker(worker) : worker(worker)

View file

@ -150,7 +150,7 @@ void Worker::goalFinished(GoalPtr goal, Goal::Finished & f)
if (!goal->waiters.empty()) if (!goal->waiters.empty())
logError(f.ex->info()); logError(f.ex->info());
else else
goal->ex = std::move(f.ex); goal->ex = f.ex;
} }
for (auto & i : goal->waiters) { for (auto & i : goal->waiters) {