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

DerivationBuildingGoal::initialOutputs make local variable

Also inline `assertPathValidity` in the process.
This commit is contained in:
John Ericson 2025-08-29 15:26:15 -04:00
parent c0c2a89f05
commit a30bf96349
2 changed files with 20 additions and 25 deletions

View file

@ -417,7 +417,9 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
Goal::Co DerivationBuildingGoal::tryToBuild() Goal::Co DerivationBuildingGoal::tryToBuild()
{ {
/* Recheck at goal start. In particular, whereas before we were std::map<std::string, InitialOutput> initialOutputs;
/* Recheck at this point. In particular, whereas before we were
given this information by the downstream goal, that cannot happen given this information by the downstream goal, that cannot happen
anymore if the downstream goal only cares about one output, but anymore if the downstream goal only cares about one output, but
we care about all outputs. */ we care about all outputs. */
@ -440,7 +442,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
std::move(v), std::move(v),
}); });
} }
checkPathValidity(); checkPathValidity(initialOutputs);
auto started = [&]() { auto started = [&]() {
auto msg = auto msg =
@ -528,7 +530,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
omitted, but that would be less efficient.) Note that since we omitted, but that would be less efficient.) Note that since we
now hold the locks on the output paths, no other process can now hold the locks on the output paths, no other process can
build this derivation, so no further checks are necessary. */ build this derivation, so no further checks are necessary. */
auto [allValid, validOutputs] = checkPathValidity(); auto [allValid, validOutputs] = checkPathValidity(initialOutputs);
if (buildMode != bmCheck && allValid) { if (buildMode != bmCheck && allValid) {
debug("skipping build of derivation '%s', someone beat us to it", worker.store.printStorePath(drvPath)); debug("skipping build of derivation '%s', someone beat us to it", worker.store.printStorePath(drvPath));
@ -556,7 +558,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
if (buildLocally) { if (buildLocally) {
useHook = false; useHook = false;
} else { } else {
switch (tryBuildHook()) { switch (tryBuildHook(initialOutputs)) {
case rpAccept: case rpAccept:
/* Yes, it has started doing so. Wait until we get /* Yes, it has started doing so. Wait until we get
EOF from the hook. */ EOF from the hook. */
@ -644,8 +646,16 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
We can only early return when the outputs are known a priori. For We can only early return when the outputs are known a priori. For
floating content-addressing derivations this isn't the case. floating content-addressing derivations this isn't the case.
Aborts if any output is not valid or corrupt, and otherwise
returns a 'SingleDrvOutputs' structure containing all outputs.
*/ */
assertPathValidity(); [&] {
auto [allValid, validOutputs] = checkPathValidity(initialOutputs);
if (!allValid)
throw Error("some outputs are unexpectedly invalid");
return validOutputs;
}();
StorePathSet outputPaths; StorePathSet outputPaths;
for (auto & [_, output] : builtOutputs) for (auto & [_, output] : builtOutputs)
@ -960,7 +970,7 @@ BuildError DerivationBuildingGoal::fixupBuilderFailureErrorMessage(BuilderFailur
return BuildError{e.status, msg}; return BuildError{e.status, msg};
} }
HookReply DerivationBuildingGoal::tryBuildHook() HookReply DerivationBuildingGoal::tryBuildHook(const std::map<std::string, InitialOutput> & initialOutputs)
{ {
#ifdef _WIN32 // TODO enable build hook on Windows #ifdef _WIN32 // TODO enable build hook on Windows
return rpDecline; return rpDecline;
@ -1239,7 +1249,8 @@ std::map<std::string, std::optional<StorePath>> DerivationBuildingGoal::queryPar
return res; return res;
} }
std::pair<bool, SingleDrvOutputs> DerivationBuildingGoal::checkPathValidity() std::pair<bool, SingleDrvOutputs>
DerivationBuildingGoal::checkPathValidity(std::map<std::string, InitialOutput> & initialOutputs)
{ {
if (drv->type().isImpure()) if (drv->type().isImpure())
return {false, {}}; return {false, {}};
@ -1296,14 +1307,6 @@ std::pair<bool, SingleDrvOutputs> DerivationBuildingGoal::checkPathValidity()
return {allValid, validOutputs}; return {allValid, validOutputs};
} }
SingleDrvOutputs DerivationBuildingGoal::assertPathValidity()
{
auto [allValid, validOutputs] = checkPathValidity();
if (!allValid)
throw Error("some outputs are unexpectedly invalid");
return validOutputs;
}
Goal::Done DerivationBuildingGoal::doneSuccess(BuildResult::Status status, SingleDrvOutputs builtOutputs) Goal::Done DerivationBuildingGoal::doneSuccess(BuildResult::Status status, SingleDrvOutputs builtOutputs)
{ {
buildResult.status = status; buildResult.status = status;

View file

@ -55,8 +55,6 @@ private:
*/ */
StorePathSet inputPaths; StorePathSet inputPaths;
std::map<std::string, InitialOutput> initialOutputs;
/** /**
* File descriptor for the log file. * File descriptor for the log file.
*/ */
@ -108,7 +106,7 @@ private:
/** /**
* Is the build hook willing to perform the build? * Is the build hook willing to perform the build?
*/ */
HookReply tryBuildHook(); HookReply tryBuildHook(const std::map<std::string, InitialOutput> & initialOutputs);
/** /**
* Open a log file and a pipe to it. * Open a log file and a pipe to it.
@ -142,13 +140,7 @@ private:
* whether all outputs are valid and non-corrupt, and a * whether all outputs are valid and non-corrupt, and a
* 'SingleDrvOutputs' structure containing the valid outputs. * 'SingleDrvOutputs' structure containing the valid outputs.
*/ */
std::pair<bool, SingleDrvOutputs> checkPathValidity(); std::pair<bool, SingleDrvOutputs> checkPathValidity(std::map<std::string, InitialOutput> & initialOutputs);
/**
* Aborts if any output is not valid or corrupt, and otherwise
* returns a 'SingleDrvOutputs' structure containing all outputs.
*/
SingleDrvOutputs assertPathValidity();
/** /**
* Forcibly kill the child process, if any. * Forcibly kill the child process, if any.