From 2297cc0daba549a1b8d2278ffb02bb3edd734f38 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 1 Feb 2025 18:56:42 -0500 Subject: [PATCH] Inline `getDerivation` and `loadDerivation` --- src/libstore/build/derivation-goal.cc | 80 +++++++++++---------------- src/libstore/build/derivation-goal.hh | 2 - 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index 4d0a7ebc7..70d2d30b1 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -36,14 +36,6 @@ namespace nix { -Goal::Co DerivationGoal::init() { - if (useDerivation) { - co_return getDerivation(); - } else { - co_return haveDerivation(); - } -} - DerivationGoal::DerivationGoal(const StorePath & drvPath, const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode) : Goal(worker, DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs }) @@ -141,50 +133,44 @@ void DerivationGoal::addWantedOutputs(const OutputsSpec & outputs) } -Goal::Co DerivationGoal::getDerivation() -{ +Goal::Co DerivationGoal::init() { trace("init"); - /* The first thing to do is to make sure that the derivation - exists. If it doesn't, it may be created through a - substitute. */ - if (buildMode == bmNormal && worker.evalStore.isValidPath(drvPath)) { - co_return loadDerivation(); - } + if (useDerivation) { + /* The first thing to do is to make sure that the derivation + exists. If it doesn't, it may be created through a + substitute. */ - addWaitee(upcast_goal(worker.makePathSubstitutionGoal(drvPath))); - - co_await Suspend{}; - co_return loadDerivation(); -} - - -Goal::Co DerivationGoal::loadDerivation() -{ - trace("loading derivation"); - - if (nrFailed != 0) { - co_return done(BuildResult::MiscFailure, {}, Error("cannot build missing derivation '%s'", worker.store.printStorePath(drvPath))); - } - - /* `drvPath' should already be a root, but let's be on the safe - side: if the user forgot to make it a root, we wouldn't want - things being garbage collected while we're busy. */ - worker.evalStore.addTempRoot(drvPath); - - /* Get the derivation. It is probably in the eval store, but it might be inthe main store: - - - Resolved derivation are resolved against main store realisations, and so must be stored there. - - - Dynamic derivations are built, and so are found in the main store. - */ - for (auto * drvStore : { &worker.evalStore, &worker.store }) { - if (drvStore->isValidPath(drvPath)) { - drv = std::make_unique(drvStore->readDerivation(drvPath)); - break; + if (buildMode != bmNormal || !worker.evalStore.isValidPath(drvPath)) { + addWaitee(upcast_goal(worker.makePathSubstitutionGoal(drvPath))); + co_await Suspend{}; } + + trace("loading derivation"); + + if (nrFailed != 0) { + co_return done(BuildResult::MiscFailure, {}, Error("cannot build missing derivation '%s'", worker.store.printStorePath(drvPath))); + } + + /* `drvPath' should already be a root, but let's be on the safe + side: if the user forgot to make it a root, we wouldn't want + things being garbage collected while we're busy. */ + worker.evalStore.addTempRoot(drvPath); + + /* Get the derivation. It is probably in the eval store, but it might be inthe main store: + + - Resolved derivation are resolved against main store realisations, and so must be stored there. + + - Dynamic derivations are built, and so are found in the main store. + */ + for (auto * drvStore : { &worker.evalStore, &worker.store }) { + if (drvStore->isValidPath(drvPath)) { + drv = std::make_unique(drvStore->readDerivation(drvPath)); + break; + } + } + assert(drv); } - assert(drv); co_return haveDerivation(); } diff --git a/src/libstore/build/derivation-goal.hh b/src/libstore/build/derivation-goal.hh index c21a12e4a..652fca035 100644 --- a/src/libstore/build/derivation-goal.hh +++ b/src/libstore/build/derivation-goal.hh @@ -233,8 +233,6 @@ struct DerivationGoal : public Goal * The states. */ Co init() override; - Co getDerivation(); - Co loadDerivation(); Co haveDerivation(); Co gaveUpOnSubstitution(); Co inputsRealised();