From 4b1753e66164297b4930046200e71e26e4ac2728 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 1 Feb 2025 18:37:54 -0500 Subject: [PATCH 1/2] Move `repairClosure` This is necessary in order to inline `inputsRealised` in the next commit by combing it with its adjacent function (i.e. with a small diff). --- src/libstore/build/derivation-goal.cc | 134 +++++++++++++------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 70d2d30b1..344b2b5a7 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -386,73 +386,6 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution() } -Goal::Co DerivationGoal::repairClosure() -{ - assert(!drv->type().isImpure()); - - /* If we're repairing, we now know that our own outputs are valid. - Now check whether the other paths in the outputs closure are - good. If not, then start derivation goals for the derivations - that produced those outputs. */ - - /* Get the output closure. */ - auto outputs = queryDerivationOutputMap(); - StorePathSet outputClosure; - for (auto & i : outputs) { - if (!wantedOutputs.contains(i.first)) continue; - worker.store.computeFSClosure(i.second, outputClosure); - } - - /* Filter out our own outputs (which we have already checked). */ - for (auto & i : outputs) - outputClosure.erase(i.second); - - /* Get all dependencies of this derivation so that we know which - derivation is responsible for which path in the output - closure. */ - StorePathSet inputClosure; - if (useDerivation) worker.store.computeFSClosure(drvPath, inputClosure); - std::map outputsToDrv; - for (auto & i : inputClosure) - if (i.isDerivation()) { - auto depOutputs = worker.store.queryPartialDerivationOutputMap(i, &worker.evalStore); - for (auto & j : depOutputs) - if (j.second) - outputsToDrv.insert_or_assign(*j.second, i); - } - - /* Check each path (slow!). */ - for (auto & i : outputClosure) { - if (worker.pathContentsGood(i)) continue; - printError( - "found corrupted or missing path '%s' in the output closure of '%s'", - worker.store.printStorePath(i), worker.store.printStorePath(drvPath)); - auto drvPath2 = outputsToDrv.find(i); - if (drvPath2 == outputsToDrv.end()) - addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i, Repair))); - else - addWaitee(worker.makeGoal( - DerivedPath::Built { - .drvPath = makeConstantStorePathRef(drvPath2->second), - .outputs = OutputsSpec::All { }, - }, - bmRepair)); - } - - if (waitees.empty()) { - co_return done(BuildResult::AlreadyValid, assertPathValidity()); - } else { - co_await Suspend{}; - - trace("closure repaired"); - if (nrFailed > 0) - throw Error("some paths in the output closure of derivation '%s' could not be repaired", - worker.store.printStorePath(drvPath)); - co_return done(BuildResult::AlreadyValid, assertPathValidity()); - } -} - - Goal::Co DerivationGoal::inputsRealised() { trace("all inputs realised"); @@ -744,6 +677,73 @@ Goal::Co DerivationGoal::tryLocalBuild() { } +Goal::Co DerivationGoal::repairClosure() +{ + assert(!drv->type().isImpure()); + + /* If we're repairing, we now know that our own outputs are valid. + Now check whether the other paths in the outputs closure are + good. If not, then start derivation goals for the derivations + that produced those outputs. */ + + /* Get the output closure. */ + auto outputs = queryDerivationOutputMap(); + StorePathSet outputClosure; + for (auto & i : outputs) { + if (!wantedOutputs.contains(i.first)) continue; + worker.store.computeFSClosure(i.second, outputClosure); + } + + /* Filter out our own outputs (which we have already checked). */ + for (auto & i : outputs) + outputClosure.erase(i.second); + + /* Get all dependencies of this derivation so that we know which + derivation is responsible for which path in the output + closure. */ + StorePathSet inputClosure; + if (useDerivation) worker.store.computeFSClosure(drvPath, inputClosure); + std::map outputsToDrv; + for (auto & i : inputClosure) + if (i.isDerivation()) { + auto depOutputs = worker.store.queryPartialDerivationOutputMap(i, &worker.evalStore); + for (auto & j : depOutputs) + if (j.second) + outputsToDrv.insert_or_assign(*j.second, i); + } + + /* Check each path (slow!). */ + for (auto & i : outputClosure) { + if (worker.pathContentsGood(i)) continue; + printError( + "found corrupted or missing path '%s' in the output closure of '%s'", + worker.store.printStorePath(i), worker.store.printStorePath(drvPath)); + auto drvPath2 = outputsToDrv.find(i); + if (drvPath2 == outputsToDrv.end()) + addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i, Repair))); + else + addWaitee(worker.makeGoal( + DerivedPath::Built { + .drvPath = makeConstantStorePathRef(drvPath2->second), + .outputs = OutputsSpec::All { }, + }, + bmRepair)); + } + + if (waitees.empty()) { + co_return done(BuildResult::AlreadyValid, assertPathValidity()); + } else { + co_await Suspend{}; + + trace("closure repaired"); + if (nrFailed > 0) + throw Error("some paths in the output closure of derivation '%s' could not be repaired", + worker.store.printStorePath(drvPath)); + co_return done(BuildResult::AlreadyValid, assertPathValidity()); + } +} + + static void chmod_(const Path & path, mode_t mode) { if (chmod(path.c_str(), mode) == -1) From b3b741973ec499607ae2ab2719e1b69024a8b8b7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 1 Feb 2025 18:37:54 -0500 Subject: [PATCH 2/2] Inline `inputsRealised` --- src/libstore/build/derivation-goal.cc | 5 ----- src/libstore/build/derivation-goal.hh | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 344b2b5a7..0d16f0975 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -382,12 +382,7 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution() } if (!waitees.empty()) co_await Suspend{}; /* to prevent hang (no wake-up event) */ - co_return inputsRealised(); -} - -Goal::Co DerivationGoal::inputsRealised() -{ trace("all inputs realised"); if (nrFailed != 0) { diff --git a/src/libstore/build/derivation-goal.hh b/src/libstore/build/derivation-goal.hh index 652fca035..4e9c14519 100644 --- a/src/libstore/build/derivation-goal.hh +++ b/src/libstore/build/derivation-goal.hh @@ -80,7 +80,7 @@ struct DerivationGoal : public Goal /** * Mapping from input derivations + output names to actual store * paths. This is filled in by waiteeDone() as each dependency - * finishes, before inputsRealised() is reached. + * finishes, before `trace("all inputs realised")` is reached. */ std::map, StorePath> inputDrvOutputs; @@ -235,7 +235,6 @@ struct DerivationGoal : public Goal Co init() override; Co haveDerivation(); Co gaveUpOnSubstitution(); - Co inputsRealised(); Co tryToBuild(); virtual Co tryLocalBuild(); Co buildDone();