@@ -124,6 +124,17 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation
124124 , buildMode(buildMode)
125125{
126126 this ->drv = std::make_unique<BasicDerivation>(BasicDerivation (drv));
127+
128+ auto outputHashes = staticOutputHashes (worker.store , drv);
129+ for (auto &[outputName, outputHash] : outputHashes)
130+ initialOutputs.insert ({
131+ outputName,
132+ InitialOutput{
133+ .wanted = true , // Will be refined later
134+ .outputHash = outputHash
135+ }
136+ });
137+
127138 state = &DerivationGoal::haveDerivation;
128139 name = fmt (
129140 " building of '%s' from in-memory derivation" ,
@@ -258,8 +269,20 @@ void DerivationGoal::loadDerivation()
258269
259270 assert (worker.store .isValidPath (drvPath));
260271
272+ auto fullDrv = new Derivation (worker.store .derivationFromPath (drvPath));
273+
274+ auto outputHashes = staticOutputHashes (worker.store , *fullDrv);
275+ for (auto &[outputName, outputHash] : outputHashes)
276+ initialOutputs.insert ({
277+ outputName,
278+ InitialOutput{
279+ .wanted = true , // Will be refined later
280+ .outputHash = outputHash
281+ }
282+ });
283+
261284 /* Get the derivation. */
262- drv = std::unique_ptr<BasicDerivation>(new Derivation (worker. store . derivationFromPath (drvPath)) );
285+ drv = std::unique_ptr<BasicDerivation>(fullDrv );
263286
264287 haveDerivation ();
265288}
@@ -1022,14 +1045,6 @@ void DerivationGoal::buildDone()
10221045void DerivationGoal::resolvedFinished () {
10231046 assert (resolvedDrv);
10241047
1025- // If the derivation was originally a full `Derivation` (and not just
1026- // a `BasicDerivation`, we must retrieve it because the `staticOutputHashes`
1027- // will be wrong otherwise
1028- Derivation fullDrv = *drv;
1029- if (auto upcasted = dynamic_cast <Derivation *>(drv.get ()))
1030- fullDrv = *upcasted;
1031-
1032- auto originalHashes = staticOutputHashes (worker.store , fullDrv);
10331048 auto resolvedHashes = staticOutputHashes (worker.store , *resolvedDrv);
10341049
10351050 // `wantedOutputs` might be empty, which means “all the outputs”
@@ -1038,7 +1053,7 @@ void DerivationGoal::resolvedFinished() {
10381053 realWantedOutputs = resolvedDrv->outputNames ();
10391054
10401055 for (auto & wantedOutput : realWantedOutputs) {
1041- assert (originalHashes .count (wantedOutput) != 0 );
1056+ assert (initialOutputs .count (wantedOutput) != 0 );
10421057 assert (resolvedHashes.count (wantedOutput) != 0 );
10431058 auto realisation = worker.store .queryRealisation (
10441059 DrvOutput{resolvedHashes.at (wantedOutput), wantedOutput}
@@ -1047,7 +1062,7 @@ void DerivationGoal::resolvedFinished() {
10471062 // realisation won't be there
10481063 if (realisation) {
10491064 auto newRealisation = *realisation;
1050- newRealisation.id = DrvOutput{originalHashes .at (wantedOutput), wantedOutput};
1065+ newRealisation.id = DrvOutput{initialOutputs .at (wantedOutput). outputHash , wantedOutput};
10511066 worker.store .registerDrvOutput (newRealisation);
10521067 } else {
10531068 // If we don't have a realisation, then it must mean that something
@@ -3807,9 +3822,8 @@ void DerivationGoal::checkPathValidity()
38073822{
38083823 bool checkHash = buildMode == bmRepair;
38093824 for (auto & i : queryPartialDerivationOutputMap ()) {
3810- InitialOutput info {
3811- .wanted = wantOutput (i.first , wantedOutputs),
3812- };
3825+ InitialOutput & info = initialOutputs.at (i.first );
3826+ info.wanted = wantOutput (i.first , wantedOutputs);
38133827 if (i.second ) {
38143828 auto outputPath = *i.second ;
38153829 info.known = {
@@ -3822,19 +3836,14 @@ void DerivationGoal::checkPathValidity()
38223836 };
38233837 }
38243838 if (settings.isExperimentalFeatureEnabled (" ca-derivations" )) {
3825- Derivation fullDrv = *drv;
3826- if (auto upcasted = dynamic_cast <Derivation *>(drv.get ()))
3827- fullDrv = *upcasted;
3828- auto outputHashes = staticOutputHashes (worker.store , fullDrv);
38293839 if (auto real = worker.store .queryRealisation (
3830- DrvOutput{outputHashes .at (i.first ), i.first })) {
3840+ DrvOutput{initialOutputs .at (i.first ). outputHash , i.first })) {
38313841 info.known = {
38323842 .path = real->outPath ,
38333843 .status = PathStatus::Valid,
38343844 };
38353845 }
38363846 }
3837- initialOutputs.insert_or_assign (i.first , info);
38383847 }
38393848}
38403849
0 commit comments