Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make DerivationGoal::drv a full Derivation
This field used to be a `BasicDerivation`, but this `BasicDerivation`
was downcasted to a `Derivation` when needed (implicitely or not), so we
might as well make it a full `Derivation` and upcast it when needed.

This also allows getting rid of a weird duplication in the way we
compute the static output hashes for the derivation. We had to
do it differently and in a different place depending on whether the
derivation was a full derivation or just a basic drv, but we can now do
it unconditionally on the full derivation.

Fix #4559
  • Loading branch information
thufschmitt committed Feb 23, 2021
1 parent 35205e2 commit ba1a256
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
37 changes: 13 additions & 24 deletions src/libstore/build/derivation-goal.cc
Expand Up @@ -123,17 +123,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation
, wantedOutputs(wantedOutputs)
, buildMode(buildMode)
{
this->drv = std::make_unique<BasicDerivation>(BasicDerivation(drv));

auto outputHashes = staticOutputHashes(worker.store, drv);
for (auto &[outputName, outputHash] : outputHashes)
initialOutputs.insert({
outputName,
InitialOutput{
.wanted = true, // Will be refined later
.outputHash = outputHash
}
});
this->drv = std::make_unique<Derivation>(drv);

state = &DerivationGoal::haveDerivation;
name = fmt(
Expand Down Expand Up @@ -271,18 +261,8 @@ void DerivationGoal::loadDerivation()

auto fullDrv = new Derivation(worker.store.derivationFromPath(drvPath));

auto outputHashes = staticOutputHashes(worker.store, *fullDrv);
for (auto &[outputName, outputHash] : outputHashes)
initialOutputs.insert({
outputName,
InitialOutput{
.wanted = true, // Will be refined later
.outputHash = outputHash
}
});

/* Get the derivation. */
drv = std::unique_ptr<BasicDerivation>(fullDrv);
drv = std::unique_ptr<Derivation>(fullDrv);

haveDerivation();
}
Expand All @@ -301,6 +281,16 @@ void DerivationGoal::haveDerivation()
if (i.second.second)
worker.store.addTempRoot(*i.second.second);

auto outputHashes = staticOutputHashes(worker.store, *drv);
for (auto &[outputName, outputHash] : outputHashes)
initialOutputs.insert({
outputName,
InitialOutput{
.wanted = true, // Will be refined later
.outputHash = outputHash
}
});

/* Check what outputs paths are not already valid. */
checkPathValidity();
bool allValid = true;
Expand Down Expand Up @@ -3517,10 +3507,9 @@ void DerivationGoal::registerOutputs()
but it's fine to do in all cases. */

if (settings.isExperimentalFeatureEnabled("ca-derivations")) {
auto outputHashes = staticOutputHashes(worker.store, *drv);
for (auto& [outputName, newInfo] : infos)
worker.store.registerDrvOutput(Realisation{
.id = DrvOutput{outputHashes.at(outputName), outputName},
.id = DrvOutput{initialOutputs.at(outputName).outputHash, outputName},
.outPath = newInfo.path});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/build/derivation-goal.hh
Expand Up @@ -64,7 +64,7 @@ struct DerivationGoal : public Goal
bool retrySubstitution;

/* The derivation stored at drvPath. */
std::unique_ptr<BasicDerivation> drv;
std::unique_ptr<Derivation> drv;

std::unique_ptr<ParsedDerivation> parsedDrv;

Expand Down

0 comments on commit ba1a256

Please sign in to comment.