Skip to content

Commit f1ab63b

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

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
@@ -49,8 +49,6 @@ private:
4949
* The remainder is state held during the build.
5050
*/
5151

52-
std::map<std::string, InitialOutput> initialOutputs;
53-
5452
/**
5553
* File descriptor for the log file.
5654
*/
@@ -101,7 +99,8 @@ private:
10199
/**
102100
* Is the build hook willing to perform the build?
103101
*/
104-
HookReply tryBuildHook(const StorePathSet & inputPaths);
102+
HookReply
103+
tryBuildHook(const StorePathSet & inputPaths, const std::map<std::string, InitialOutput> & initialOutputs);
105104

106105
/**
107106
* Open a log file and a pipe to it.
@@ -135,13 +134,7 @@ private:
135134
* whether all outputs are valid and non-corrupt, and a
136135
* 'SingleDrvOutputs' structure containing the valid outputs.
137136
*/
138-
std::pair<bool, SingleDrvOutputs> checkPathValidity();
139-
140-
/**
141-
* Aborts if any output is not valid or corrupt, and otherwise
142-
* returns a 'SingleDrvOutputs' structure containing all outputs.
143-
*/
144-
SingleDrvOutputs assertPathValidity();
137+
std::pair<bool, SingleDrvOutputs> checkPathValidity(std::map<std::string, InitialOutput> & initialOutputs);
145138

146139
/**
147140
* Forcibly kill the child process, if any.

0 commit comments

Comments
 (0)