diff options
Diffstat (limited to 'src/libstore/build/derivation-goal.cc')
-rw-r--r-- | src/libstore/build/derivation-goal.cc | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index f31c3acd5..b59033bae 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -9,6 +9,7 @@ #include "logging-json.hh" #include "substitution-goal.hh" #include "drv-output-substitution-goal.hh" +#include "strings.hh" #include <fstream> #include <sys/types.h> @@ -57,8 +58,8 @@ namespace nix { DerivationGoal::DerivationGoal(const StorePath & drvPath, - const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode) - : Goal(worker, DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs }) + const OutputsSpec & wantedOutputs, Worker & worker, bool isDependency, BuildMode buildMode) + : Goal(worker, isDependency) , useDerivation(true) , drvPath(drvPath) , wantedOutputs(wantedOutputs) @@ -70,13 +71,13 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, DerivedPath::Built { makeConstantStorePathRef(drvPath), wantedOutputs }.to_string(worker.store)); trace("created"); - mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds); + mcExpectedBuilds = worker.expectedBuilds.addTemporarily(1); } DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv, - const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode) - : Goal(worker, DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs }) + const OutputsSpec & wantedOutputs, Worker & worker, bool isDependency, BuildMode buildMode) + : Goal(worker, isDependency) , useDerivation(false) , drvPath(drvPath) , wantedOutputs(wantedOutputs) @@ -90,7 +91,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation DerivedPath::Built { makeConstantStorePathRef(drvPath), drv.outputNames() }.to_string(worker.store)); trace("created"); - mcExpectedBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.expectedBuilds); + mcExpectedBuilds = worker.expectedBuilds.addTemporarily(1); /* Prevent the .chroot directory from being garbage-collected. (See isActiveTempFile() in gc.cc.) */ @@ -169,7 +170,7 @@ Goal::WorkResult DerivationGoal::getDerivation(bool inBuildSlot) state = &DerivationGoal::loadDerivation; - return WaitForGoals{{worker.makePathSubstitutionGoal(drvPath)}}; + return WaitForGoals{{worker.goalFactory().makePathSubstitutionGoal(drvPath)}}; } @@ -261,24 +262,29 @@ Goal::WorkResult DerivationGoal::haveDerivation(bool inBuildSlot) through substitutes. If that doesn't work, we'll build them. */ WaitForGoals result; - if (settings.useSubstitutes && parsedDrv->substitutesAllowed()) - for (auto & [outputName, status] : initialOutputs) { - if (!status.wanted) continue; - if (!status.known) - result.goals.insert( - worker.makeDrvOutputSubstitutionGoal( - DrvOutput{status.outputHash, outputName}, - buildMode == bmRepair ? Repair : NoRepair - ) - ); - else { - auto * cap = getDerivationCA(*drv); - result.goals.insert(worker.makePathSubstitutionGoal( - status.known->path, - buildMode == bmRepair ? Repair : NoRepair, - cap ? std::optional { *cap } : std::nullopt)); + if (settings.useSubstitutes) { + if (parsedDrv->substitutesAllowed()) { + for (auto & [outputName, status] : initialOutputs) { + if (!status.wanted) continue; + if (!status.known) + result.goals.insert( + worker.goalFactory().makeDrvOutputSubstitutionGoal( + DrvOutput{status.outputHash, outputName}, + buildMode == bmRepair ? Repair : NoRepair + ) + ); + else { + auto * cap = getDerivationCA(*drv); + result.goals.insert(worker.goalFactory().makePathSubstitutionGoal( + status.known->path, + buildMode == bmRepair ? Repair : NoRepair, + cap ? std::optional { *cap } : std::nullopt)); + } } + } else { + trace("skipping substitute because allowSubstitutes is false"); } + } if (result.goals.empty()) { /* to prevent hang (no wake-up event) */ return outputsSubstitutionTried(inBuildSlot); @@ -368,7 +374,7 @@ Goal::WorkResult DerivationGoal::gaveUpOnSubstitution(bool inBuildSlot) addWaiteeDerivedPath = [&](ref<SingleDerivedPath> inputDrv, const DerivedPathMap<StringSet>::ChildNode & inputNode) { if (!inputNode.value.empty()) - result.goals.insert(worker.makeGoal( + result.goals.insert(worker.goalFactory().makeGoal( DerivedPath::Built { .drvPath = inputDrv, .outputs = inputNode.value, @@ -413,7 +419,7 @@ Goal::WorkResult DerivationGoal::gaveUpOnSubstitution(bool inBuildSlot) if (!settings.useSubstitutes) throw Error("dependency '%s' of '%s' does not exist, and substitution is disabled", worker.store.printStorePath(i), worker.store.printStorePath(drvPath)); - result.goals.insert(worker.makePathSubstitutionGoal(i)); + result.goals.insert(worker.goalFactory().makePathSubstitutionGoal(i)); } if (result.goals.empty()) {/* to prevent hang (no wake-up event) */ @@ -469,9 +475,9 @@ Goal::WorkResult DerivationGoal::repairClosure() worker.store.printStorePath(i), worker.store.printStorePath(drvPath)); auto drvPath2 = outputsToDrv.find(i); if (drvPath2 == outputsToDrv.end()) - result.goals.insert(worker.makePathSubstitutionGoal(i, Repair)); + result.goals.insert(worker.goalFactory().makePathSubstitutionGoal(i, Repair)); else - result.goals.insert(worker.makeGoal( + result.goals.insert(worker.goalFactory().makeGoal( DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath2->second), .outputs = OutputsSpec::All { }, @@ -574,7 +580,7 @@ Goal::WorkResult DerivationGoal::inputsRealised(bool inBuildSlot) worker.store.printStorePath(pathResolved), }); - resolvedDrvGoal = worker.makeDerivationGoal( + resolvedDrvGoal = worker.goalFactory().makeDerivationGoal( pathResolved, wantedOutputs, buildMode); state = &DerivationGoal::resolvedFinished; @@ -643,7 +649,7 @@ Goal::WorkResult DerivationGoal::inputsRealised(bool inBuildSlot) slot to become available, since we don't need one if there is a build hook. */ state = &DerivationGoal::tryToBuild; - return ContinueImmediately{}; + return tryToBuild(inBuildSlot); } void DerivationGoal::started() @@ -656,7 +662,7 @@ void DerivationGoal::started() if (hook) msg += fmt(" on '%s'", machineName); act = std::make_unique<Activity>(*logger, lvlInfo, actBuild, msg, Logger::Fields{worker.store.printStorePath(drvPath), hook ? machineName : "", 1, 1}); - mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds); + mcRunningBuilds = worker.runningBuilds.addTemporarily(1); } Goal::WorkResult DerivationGoal::tryToBuild(bool inBuildSlot) @@ -766,7 +772,7 @@ Goal::WorkResult DerivationGoal::tryToBuild(bool inBuildSlot) actLock.reset(); state = &DerivationGoal::tryLocalBuild; - return ContinueImmediately{}; + return tryLocalBuild(inBuildSlot); } Goal::WorkResult DerivationGoal::tryLocalBuild(bool inBuildSlot) { @@ -1538,9 +1544,14 @@ Goal::Finished DerivationGoal::done( fs << worker.store.printStorePath(drvPath) << "\t" << buildResult.toString() << std::endl; } + if (ex && isDependency) { + logError(ex->info()); + } + return Finished{ - .result = buildResult.success() ? ecSuccess : ecFailed, - .ex = ex ? std::make_unique<Error>(std::move(*ex)) : nullptr, + .exitCode = buildResult.success() ? ecSuccess : ecFailed, + .result = buildResult, + .ex = ex ? std::make_shared<Error>(std::move(*ex)) : nullptr, .permanentFailure = buildResult.status == BuildResult::PermanentFailure, .timedOut = buildResult.status == BuildResult::TimedOut, .hashMismatch = anyHashMismatchSeen, |