1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-09 12:06:01 +01:00

DerivationGoal inline gaveUpOnSubstitution lambda

We can shuffle around control flow so it's only called once. You'll
definitely want to review this diff ignoring whitespace.
This commit is contained in:
John Ericson 2025-08-14 00:21:37 -04:00
parent 88275e5723
commit 14441f9382

View file

@ -75,62 +75,19 @@ Goal::Co DerivationGoal::haveDerivation()
if (!drv->type().hasKnownOutputPaths())
experimentalFeatureSettings.require(Xp::CaDerivations);
/* At least one of the output paths could not be
produced using a substitute. So we have to build instead. */
auto gaveUpOnSubstitution = [&]() -> Goal::Co {
auto g = worker.makeDerivationBuildingGoal(drvPath, *drv, buildMode);
/* We will finish with it ourselves, as if we were the derivational goal. */
g->preserveException = true;
{
Goals waitees;
waitees.insert(g);
co_await await(std::move(waitees));
}
trace("outer build done");
buildResult = g->buildResult;
if (buildMode == bmCheck) {
/* In checking mode, the builder will not register any outputs.
So we want to make sure the ones that we wanted to check are
properly there. */
buildResult.builtOutputs = {{wantedOutput, assertPathValidity()}};
}
for (auto it = buildResult.builtOutputs.begin(); it != buildResult.builtOutputs.end();) {
if (it->first != wantedOutput) {
it = buildResult.builtOutputs.erase(it);
} else {
++it;
}
}
if (buildResult.success())
assert(buildResult.builtOutputs.count(wantedOutput) > 0);
co_return amDone(g->exitCode, g->ex);
};
for (auto & i : drv->outputsAndOptPaths(worker.store))
if (i.second.second)
worker.store.addTempRoot(*i.second.second);
{
if (auto * mOutputHash = get(staticOutputHashes(worker.evalStore, *drv), wantedOutput)) {
outputHash = *mOutputHash;
}
if (drv->type().isImpure()) {
experimentalFeatureSettings.require(Xp::ImpureDerivations);
/* We don't yet have any safe way to cache an impure derivation at
this step. */
co_return gaveUpOnSubstitution();
}
}
if (drv->type().isImpure()) {
experimentalFeatureSettings.require(Xp::ImpureDerivations);
} else {
/* Check what outputs paths are not already valid. */
auto checkResult = checkPathValidity();
@ -186,10 +143,46 @@ Goal::Co DerivationGoal::haveDerivation()
}
if (buildMode == bmCheck && !allValid)
throw Error(
"some outputs of '%s' are not valid, so checking is not possible", worker.store.printStorePath(drvPath));
"some outputs of '%s' are not valid, so checking is not possible",
worker.store.printStorePath(drvPath));
}
/* Nothing to wait for; tail call */
co_return gaveUpOnSubstitution();
/* Give up on substitution for the output we want, actually build this derivation */
auto g = worker.makeDerivationBuildingGoal(drvPath, *drv, buildMode);
/* We will finish with it ourselves, as if we were the derivational goal. */
g->preserveException = true;
{
Goals waitees;
waitees.insert(g);
co_await await(std::move(waitees));
}
trace("outer build done");
buildResult = g->buildResult;
if (buildMode == bmCheck) {
/* In checking mode, the builder will not register any outputs.
So we want to make sure the ones that we wanted to check are
properly there. */
buildResult.builtOutputs = {{wantedOutput, assertPathValidity()}};
}
for (auto it = buildResult.builtOutputs.begin(); it != buildResult.builtOutputs.end();) {
if (it->first != wantedOutput) {
it = buildResult.builtOutputs.erase(it);
} else {
++it;
}
}
if (buildResult.success())
assert(buildResult.builtOutputs.count(wantedOutput) > 0);
co_return amDone(g->exitCode, g->ex);
}
/**