From 95c577988023d69f5596a8763fae445b21396abb Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 29 Aug 2025 13:52:17 -0400 Subject: [PATCH] `DerivationBuildingGoal::tryToBuild` pull hook waiting out of switch Do this with a new `useHook` boolean we carefully make sure is set in all cases. This change isn't really worthwhile by itself, but it allows us to make further refactors (see later commits) which are well-motivated. --- .../build/derivation-building-goal.cc | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libstore/build/derivation-building-goal.cc b/src/libstore/build/derivation-building-goal.cc index 53343ce84..327955714 100644 --- a/src/libstore/build/derivation-building-goal.cc +++ b/src/libstore/build/derivation-building-goal.cc @@ -470,6 +470,8 @@ void DerivationBuildingGoal::started() Goal::Co DerivationBuildingGoal::tryToBuild() { + bool useHook; + trace("trying to build"); /* Obtain locks on all output paths, if the paths are known a priori. @@ -539,16 +541,15 @@ Goal::Co DerivationBuildingGoal::tryToBuild() bool buildLocally = (buildMode != bmNormal || drvOptions->willBuildLocally(worker.store, *drv)) && settings.maxBuildJobs.get() != 0; - if (!buildLocally) { + if (buildLocally) { + useHook = false; + } else { switch (tryBuildHook()) { case rpAccept: /* Yes, it has started doing so. Wait until we get EOF from the hook. */ - actLock.reset(); - buildResult.startTime = time(0); // inexact - started(); - co_await Suspend{}; - co_return hookDone(); + useHook = true; + break; case rpPostpone: /* Not now; wait until at least one child finishes or the wake-up timeout expires. */ @@ -563,12 +564,20 @@ Goal::Co DerivationBuildingGoal::tryToBuild() co_return tryToBuild(); case rpDecline: /* We should do it ourselves. */ + useHook = false; break; } } actLock.reset(); + if (useHook) { + buildResult.startTime = time(0); // inexact + started(); + co_await Suspend{}; + co_return hookDone(); + } + co_await yield(); if (!dynamic_cast(&worker.store)) {