Skip to content

Commit 3e8cd2f

Browse files
authored
Merge pull request #12412 from obsidiansystems/simplify-state-machine-2
Simplify state machine 2
2 parents 02e6286 + b3b7419 commit 3e8cd2f

File tree

2 files changed

+68
-74
lines changed

2 files changed

+68
-74
lines changed

src/libstore/build/derivation-goal.cc

Lines changed: 67 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -382,79 +382,7 @@ Goal::Co DerivationGoal::gaveUpOnSubstitution()
382382
}
383383

384384
if (!waitees.empty()) co_await Suspend{}; /* to prevent hang (no wake-up event) */
385-
co_return inputsRealised();
386-
}
387-
388-
389-
Goal::Co DerivationGoal::repairClosure()
390-
{
391-
assert(!drv->type().isImpure());
392-
393-
/* If we're repairing, we now know that our own outputs are valid.
394-
Now check whether the other paths in the outputs closure are
395-
good. If not, then start derivation goals for the derivations
396-
that produced those outputs. */
397-
398-
/* Get the output closure. */
399-
auto outputs = queryDerivationOutputMap();
400-
StorePathSet outputClosure;
401-
for (auto & i : outputs) {
402-
if (!wantedOutputs.contains(i.first)) continue;
403-
worker.store.computeFSClosure(i.second, outputClosure);
404-
}
405-
406-
/* Filter out our own outputs (which we have already checked). */
407-
for (auto & i : outputs)
408-
outputClosure.erase(i.second);
409-
410-
/* Get all dependencies of this derivation so that we know which
411-
derivation is responsible for which path in the output
412-
closure. */
413-
StorePathSet inputClosure;
414-
if (useDerivation) worker.store.computeFSClosure(drvPath, inputClosure);
415-
std::map<StorePath, StorePath> outputsToDrv;
416-
for (auto & i : inputClosure)
417-
if (i.isDerivation()) {
418-
auto depOutputs = worker.store.queryPartialDerivationOutputMap(i, &worker.evalStore);
419-
for (auto & j : depOutputs)
420-
if (j.second)
421-
outputsToDrv.insert_or_assign(*j.second, i);
422-
}
423-
424-
/* Check each path (slow!). */
425-
for (auto & i : outputClosure) {
426-
if (worker.pathContentsGood(i)) continue;
427-
printError(
428-
"found corrupted or missing path '%s' in the output closure of '%s'",
429-
worker.store.printStorePath(i), worker.store.printStorePath(drvPath));
430-
auto drvPath2 = outputsToDrv.find(i);
431-
if (drvPath2 == outputsToDrv.end())
432-
addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i, Repair)));
433-
else
434-
addWaitee(worker.makeGoal(
435-
DerivedPath::Built {
436-
.drvPath = makeConstantStorePathRef(drvPath2->second),
437-
.outputs = OutputsSpec::All { },
438-
},
439-
bmRepair));
440-
}
441-
442-
if (waitees.empty()) {
443-
co_return done(BuildResult::AlreadyValid, assertPathValidity());
444-
} else {
445-
co_await Suspend{};
446-
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-
}
453-
}
454-
455385

456-
Goal::Co DerivationGoal::inputsRealised()
457-
{
458386
trace("all inputs realised");
459387

460388
if (nrFailed != 0) {
@@ -744,6 +672,73 @@ Goal::Co DerivationGoal::tryLocalBuild() {
744672
}
745673

746674

675+
Goal::Co DerivationGoal::repairClosure()
676+
{
677+
assert(!drv->type().isImpure());
678+
679+
/* If we're repairing, we now know that our own outputs are valid.
680+
Now check whether the other paths in the outputs closure are
681+
good. If not, then start derivation goals for the derivations
682+
that produced those outputs. */
683+
684+
/* Get the output closure. */
685+
auto outputs = queryDerivationOutputMap();
686+
StorePathSet outputClosure;
687+
for (auto & i : outputs) {
688+
if (!wantedOutputs.contains(i.first)) continue;
689+
worker.store.computeFSClosure(i.second, outputClosure);
690+
}
691+
692+
/* Filter out our own outputs (which we have already checked). */
693+
for (auto & i : outputs)
694+
outputClosure.erase(i.second);
695+
696+
/* Get all dependencies of this derivation so that we know which
697+
derivation is responsible for which path in the output
698+
closure. */
699+
StorePathSet inputClosure;
700+
if (useDerivation) worker.store.computeFSClosure(drvPath, inputClosure);
701+
std::map<StorePath, StorePath> outputsToDrv;
702+
for (auto & i : inputClosure)
703+
if (i.isDerivation()) {
704+
auto depOutputs = worker.store.queryPartialDerivationOutputMap(i, &worker.evalStore);
705+
for (auto & j : depOutputs)
706+
if (j.second)
707+
outputsToDrv.insert_or_assign(*j.second, i);
708+
}
709+
710+
/* Check each path (slow!). */
711+
for (auto & i : outputClosure) {
712+
if (worker.pathContentsGood(i)) continue;
713+
printError(
714+
"found corrupted or missing path '%s' in the output closure of '%s'",
715+
worker.store.printStorePath(i), worker.store.printStorePath(drvPath));
716+
auto drvPath2 = outputsToDrv.find(i);
717+
if (drvPath2 == outputsToDrv.end())
718+
addWaitee(upcast_goal(worker.makePathSubstitutionGoal(i, Repair)));
719+
else
720+
addWaitee(worker.makeGoal(
721+
DerivedPath::Built {
722+
.drvPath = makeConstantStorePathRef(drvPath2->second),
723+
.outputs = OutputsSpec::All { },
724+
},
725+
bmRepair));
726+
}
727+
728+
if (waitees.empty()) {
729+
co_return done(BuildResult::AlreadyValid, assertPathValidity());
730+
} else {
731+
co_await Suspend{};
732+
733+
trace("closure repaired");
734+
if (nrFailed > 0)
735+
throw Error("some paths in the output closure of derivation '%s' could not be repaired",
736+
worker.store.printStorePath(drvPath));
737+
co_return done(BuildResult::AlreadyValid, assertPathValidity());
738+
}
739+
}
740+
741+
747742
static void chmod_(const Path & path, mode_t mode)
748743
{
749744
if (chmod(path.c_str(), mode) == -1)

src/libstore/build/derivation-goal.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct DerivationGoal : public Goal
8080
/**
8181
* Mapping from input derivations + output names to actual store
8282
* paths. This is filled in by waiteeDone() as each dependency
83-
* finishes, before inputsRealised() is reached.
83+
* finishes, before `trace("all inputs realised")` is reached.
8484
*/
8585
std::map<std::pair<StorePath, std::string>, StorePath> inputDrvOutputs;
8686

@@ -235,7 +235,6 @@ struct DerivationGoal : public Goal
235235
Co init() override;
236236
Co haveDerivation();
237237
Co gaveUpOnSubstitution();
238-
Co inputsRealised();
239238
Co tryToBuild();
240239
virtual Co tryLocalBuild();
241240
Co buildDone();

0 commit comments

Comments
 (0)