Skip to content

Commit 4a2de1d

Browse files
committed
DerivationGoal Make some fields immutable
We can set both during construction, yay!
1 parent f155dff commit 4a2de1d

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/libstore/build/derivation-goal.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ DerivationGoal::DerivationGoal(
3333
: Goal(worker, haveDerivation())
3434
, drvPath(drvPath)
3535
, wantedOutput(wantedOutput)
36-
, outputHash{Hash::dummy} // will be updated
36+
, outputHash{[&] {
37+
if (auto * mOutputHash = get(staticOutputHashes(worker.evalStore, drv), wantedOutput))
38+
return *mOutputHash;
39+
else
40+
throw Error(
41+
"derivation '%s' does not have output '%s'", worker.store.printStorePath(drvPath), wantedOutput);
42+
}()}
3743
, buildMode(buildMode)
3844
{
3945
this->drv = std::make_unique<Derivation>(drv);
@@ -79,10 +85,6 @@ Goal::Co DerivationGoal::haveDerivation()
7985
if (i.second.second)
8086
worker.store.addTempRoot(*i.second.second);
8187

82-
if (auto * mOutputHash = get(staticOutputHashes(worker.evalStore, *drv), wantedOutput)) {
83-
outputHash = *mOutputHash;
84-
}
85-
8688
/* We don't yet have any safe way to cache an impure derivation at
8789
this step. */
8890
if (drv->type().isImpure()) {

src/libstore/include/nix/store/build/derivation-goal.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ private:
7070
*/
7171
std::unique_ptr<Derivation> drv;
7272

73+
const Hash outputHash;
74+
75+
const BuildMode buildMode;
76+
7377
/**
7478
* The remainder is state held during the build.
7579
*/
7680

77-
Hash outputHash;
78-
79-
BuildMode buildMode;
80-
8181
std::unique_ptr<MaintainCount<uint64_t>> mcExpectedBuilds;
8282

8383
/**

0 commit comments

Comments
 (0)