Skip to content

Commit a41b9e2

Browse files
committed
DerivationBuildingGoal::initialOutputs make local variable
Also inline `assertPathValidity` in the process.
1 parent 8b00543 commit a41b9e2

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

src/libstore/build/derivation-building-goal.cc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ static void runPostBuildHook(
127127
produced using a substitute. So we have to build instead. */
128128
Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
129129
{
130+
std::map<std::string, InitialOutput> initialOutputs;
131+
130132
/* Recheck at goal start. In particular, whereas before we were
131133
given this information by the downstream goal, that cannot happen
132134
anymore if the downstream goal only cares about one output, but
@@ -150,7 +152,7 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
150152
std::move(v),
151153
});
152154
}
153-
checkPathValidity();
155+
checkPathValidity(initialOutputs);
154156

155157
Goals waitees;
156158

@@ -531,7 +533,7 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
531533
omitted, but that would be less efficient.) Note that since we
532534
now hold the locks on the output paths, no other process can
533535
build this derivation, so no further checks are necessary. */
534-
auto [allValid, validOutputs] = checkPathValidity();
536+
auto [allValid, validOutputs] = checkPathValidity(initialOutputs);
535537

536538
if (buildMode != bmCheck && allValid) {
537539
debug("skipping build of derivation '%s', someone beat us to it", worker.store.printStorePath(drvPath));
@@ -559,7 +561,7 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
559561
if (buildLocally) {
560562
useHook = false;
561563
} else {
562-
switch (tryBuildHook(inputPaths)) {
564+
switch (tryBuildHook(inputPaths, initialOutputs)) {
563565
case rpAccept:
564566
/* Yes, it has started doing so. Wait until we get
565567
EOF from the hook. */
@@ -647,8 +649,16 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
647649
648650
We can only early return when the outputs are known a priori. For
649651
floating content-addressing derivations this isn't the case.
652+
653+
Aborts if any output is not valid or corrupt, and otherwise
654+
returns a 'SingleDrvOutputs' structure containing all outputs.
650655
*/
651-
assertPathValidity();
656+
[&] {
657+
auto [allValid, validOutputs] = checkPathValidity(initialOutputs);
658+
if (!allValid)
659+
throw Error("some outputs are unexpectedly invalid");
660+
return validOutputs;
661+
}();
652662

653663
StorePathSet outputPaths;
654664
for (auto & [_, output] : builtOutputs)
@@ -963,7 +973,8 @@ BuildError DerivationBuildingGoal::fixupBuilderFailureErrorMessage(BuilderFailur
963973
return BuildError{e.status, msg};
964974
}
965975

966-
HookReply DerivationBuildingGoal::tryBuildHook(const StorePathSet & inputPaths)
976+
HookReply DerivationBuildingGoal::tryBuildHook(
977+
const StorePathSet & inputPaths, const std::map<std::string, InitialOutput> & initialOutputs)
967978
{
968979
#ifdef _WIN32 // TODO enable build hook on Windows
969980
return rpDecline;
@@ -1242,7 +1253,8 @@ std::map<std::string, std::optional<StorePath>> DerivationBuildingGoal::queryPar
12421253
return res;
12431254
}
12441255

1245-
std::pair<bool, SingleDrvOutputs> DerivationBuildingGoal::checkPathValidity()
1256+
std::pair<bool, SingleDrvOutputs>
1257+
DerivationBuildingGoal::checkPathValidity(std::map<std::string, InitialOutput> & initialOutputs)
12461258
{
12471259
if (drv->type().isImpure())
12481260
return {false, {}};
@@ -1299,14 +1311,6 @@ std::pair<bool, SingleDrvOutputs> DerivationBuildingGoal::checkPathValidity()
12991311
return {allValid, validOutputs};
13001312
}
13011313

1302-
SingleDrvOutputs DerivationBuildingGoal::assertPathValidity()
1303-
{
1304-
auto [allValid, validOutputs] = checkPathValidity();
1305-
if (!allValid)
1306-
throw Error("some outputs are unexpectedly invalid");
1307-
return validOutputs;
1308-
}
1309-
13101314
Goal::Done DerivationBuildingGoal::doneSuccess(BuildResult::Status status, SingleDrvOutputs builtOutputs)
13111315
{
13121316
buildResult.status = status;

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ struct DerivationBuildingGoal : public Goal
4343
* The remainder is state held during the build.
4444
*/
4545

46-
std::map<std::string, InitialOutput> initialOutputs;
47-
4846
/**
4947
* File descriptor for the log file.
5048
*/
@@ -104,7 +102,8 @@ struct DerivationBuildingGoal : public Goal
104102
/**
105103
* Is the build hook willing to perform the build?
106104
*/
107-
HookReply tryBuildHook(const StorePathSet & inputPaths);
105+
HookReply
106+
tryBuildHook(const StorePathSet & inputPaths, const std::map<std::string, InitialOutput> & initialOutputs);
108107

109108
/**
110109
* Open a log file and a pipe to it.
@@ -138,13 +137,7 @@ struct DerivationBuildingGoal : public Goal
138137
* whether all outputs are valid and non-corrupt, and a
139138
* 'SingleDrvOutputs' structure containing the valid outputs.
140139
*/
141-
std::pair<bool, SingleDrvOutputs> checkPathValidity();
142-
143-
/**
144-
* Aborts if any output is not valid or corrupt, and otherwise
145-
* returns a 'SingleDrvOutputs' structure containing all outputs.
146-
*/
147-
SingleDrvOutputs assertPathValidity();
140+
std::pair<bool, SingleDrvOutputs> checkPathValidity(std::map<std::string, InitialOutput> & initialOutputs);
148141

149142
/**
150143
* Forcibly kill the child process, if any.

0 commit comments

Comments
 (0)