|
36 | 36 |
|
37 | 37 | namespace nix { |
38 | 38 |
|
39 | | -Goal::Co DerivationGoal::init() { |
40 | | - if (useDerivation) { |
41 | | - co_return getDerivation(); |
42 | | - } else { |
43 | | - co_return haveDerivation(); |
44 | | - } |
45 | | -} |
46 | | - |
47 | 39 | DerivationGoal::DerivationGoal(const StorePath & drvPath, |
48 | 40 | const OutputsSpec & wantedOutputs, Worker & worker, BuildMode buildMode) |
49 | 41 | : Goal(worker, DerivedPath::Built { .drvPath = makeConstantStorePathRef(drvPath), .outputs = wantedOutputs }) |
@@ -141,50 +133,44 @@ void DerivationGoal::addWantedOutputs(const OutputsSpec & outputs) |
141 | 133 | } |
142 | 134 |
|
143 | 135 |
|
144 | | -Goal::Co DerivationGoal::getDerivation() |
145 | | -{ |
| 136 | +Goal::Co DerivationGoal::init() { |
146 | 137 | trace("init"); |
147 | 138 |
|
148 | | - /* The first thing to do is to make sure that the derivation |
149 | | - exists. If it doesn't, it may be created through a |
150 | | - substitute. */ |
151 | | - if (buildMode == bmNormal && worker.evalStore.isValidPath(drvPath)) { |
152 | | - co_return loadDerivation(); |
153 | | - } |
154 | | - |
155 | | - addWaitee(upcast_goal(worker.makePathSubstitutionGoal(drvPath))); |
156 | | - |
157 | | - co_await Suspend{}; |
158 | | - co_return loadDerivation(); |
159 | | -} |
| 139 | + if (useDerivation) { |
| 140 | + /* The first thing to do is to make sure that the derivation |
| 141 | + exists. If it doesn't, it may be created through a |
| 142 | + substitute. */ |
160 | 143 |
|
| 144 | + if (buildMode != bmNormal || !worker.evalStore.isValidPath(drvPath)) { |
| 145 | + addWaitee(upcast_goal(worker.makePathSubstitutionGoal(drvPath))); |
| 146 | + co_await Suspend{}; |
| 147 | + } |
161 | 148 |
|
162 | | -Goal::Co DerivationGoal::loadDerivation() |
163 | | -{ |
164 | | - trace("loading derivation"); |
| 149 | + trace("loading derivation"); |
165 | 150 |
|
166 | | - if (nrFailed != 0) { |
167 | | - co_return done(BuildResult::MiscFailure, {}, Error("cannot build missing derivation '%s'", worker.store.printStorePath(drvPath))); |
168 | | - } |
| 151 | + if (nrFailed != 0) { |
| 152 | + co_return done(BuildResult::MiscFailure, {}, Error("cannot build missing derivation '%s'", worker.store.printStorePath(drvPath))); |
| 153 | + } |
169 | 154 |
|
170 | | - /* `drvPath' should already be a root, but let's be on the safe |
171 | | - side: if the user forgot to make it a root, we wouldn't want |
172 | | - things being garbage collected while we're busy. */ |
173 | | - worker.evalStore.addTempRoot(drvPath); |
| 155 | + /* `drvPath' should already be a root, but let's be on the safe |
| 156 | + side: if the user forgot to make it a root, we wouldn't want |
| 157 | + things being garbage collected while we're busy. */ |
| 158 | + worker.evalStore.addTempRoot(drvPath); |
174 | 159 |
|
175 | | - /* Get the derivation. It is probably in the eval store, but it might be inthe main store: |
| 160 | + /* Get the derivation. It is probably in the eval store, but it might be inthe main store: |
176 | 161 |
|
177 | | - - Resolved derivation are resolved against main store realisations, and so must be stored there. |
| 162 | + - Resolved derivation are resolved against main store realisations, and so must be stored there. |
178 | 163 |
|
179 | | - - Dynamic derivations are built, and so are found in the main store. |
180 | | - */ |
181 | | - for (auto * drvStore : { &worker.evalStore, &worker.store }) { |
182 | | - if (drvStore->isValidPath(drvPath)) { |
183 | | - drv = std::make_unique<Derivation>(drvStore->readDerivation(drvPath)); |
184 | | - break; |
| 164 | + - Dynamic derivations are built, and so are found in the main store. |
| 165 | + */ |
| 166 | + for (auto * drvStore : { &worker.evalStore, &worker.store }) { |
| 167 | + if (drvStore->isValidPath(drvPath)) { |
| 168 | + drv = std::make_unique<Derivation>(drvStore->readDerivation(drvPath)); |
| 169 | + break; |
| 170 | + } |
185 | 171 | } |
| 172 | + assert(drv); |
186 | 173 | } |
187 | | - assert(drv); |
188 | 174 |
|
189 | 175 | co_return haveDerivation(); |
190 | 176 | } |
@@ -235,12 +221,14 @@ Goal::Co DerivationGoal::haveDerivation() |
235 | 221 | } |
236 | 222 | }); |
237 | 223 |
|
238 | | - /* Check what outputs paths are not already valid. */ |
239 | | - auto [allValid, validOutputs] = checkPathValidity(); |
| 224 | + { |
| 225 | + /* Check what outputs paths are not already valid. */ |
| 226 | + auto [allValid, validOutputs] = checkPathValidity(); |
240 | 227 |
|
241 | | - /* If they are all valid, then we're done. */ |
242 | | - if (allValid && buildMode == bmNormal) { |
243 | | - co_return done(BuildResult::AlreadyValid, std::move(validOutputs)); |
| 228 | + /* If they are all valid, then we're done. */ |
| 229 | + if (allValid && buildMode == bmNormal) { |
| 230 | + co_return done(BuildResult::AlreadyValid, std::move(validOutputs)); |
| 231 | + } |
244 | 232 | } |
245 | 233 |
|
246 | 234 | /* We are first going to try to create the invalid output paths |
@@ -268,12 +256,7 @@ Goal::Co DerivationGoal::haveDerivation() |
268 | 256 | } |
269 | 257 |
|
270 | 258 | if (!waitees.empty()) co_await Suspend{}; /* to prevent hang (no wake-up event) */ |
271 | | - co_return outputsSubstitutionTried(); |
272 | | -} |
273 | 259 |
|
274 | | - |
275 | | -Goal::Co DerivationGoal::outputsSubstitutionTried() |
276 | | -{ |
277 | 260 | trace("all outputs substituted (maybe)"); |
278 | 261 |
|
279 | 262 | assert(!drv->type().isImpure()); |
@@ -460,18 +443,13 @@ Goal::Co DerivationGoal::repairClosure() |
460 | 443 | co_return done(BuildResult::AlreadyValid, assertPathValidity()); |
461 | 444 | } else { |
462 | 445 | co_await Suspend{}; |
463 | | - co_return closureRepaired(); |
464 | | - } |
465 | | -} |
466 | | - |
467 | 446 |
|
468 | | -Goal::Co DerivationGoal::closureRepaired() |
469 | | -{ |
470 | | - trace("closure repaired"); |
471 | | - if (nrFailed > 0) |
472 | | - throw Error("some paths in the output closure of derivation '%s' could not be repaired", |
473 | | - worker.store.printStorePath(drvPath)); |
474 | | - co_return done(BuildResult::AlreadyValid, assertPathValidity()); |
| 447 | + trace("closure repaired"); |
| 448 | + if (nrFailed > 0) |
| 449 | + throw Error("some paths in the output closure of derivation '%s' could not be repaired", |
| 450 | + worker.store.printStorePath(drvPath)); |
| 451 | + co_return done(BuildResult::AlreadyValid, assertPathValidity()); |
| 452 | + } |
475 | 453 | } |
476 | 454 |
|
477 | 455 |
|
|
0 commit comments