Skip to content

Commit 31eb33d

Browse files
committed
Move machineName from DerivationBuildingGoal to HookInstance
Exactly why is is correct is a little subtle, because sometimes the worker is owned by the worker. But the commit message in e437b08 explained the situation well enough: I made that commit message part of the ABI docs, and now it should be understandable to the next person.
1 parent 8366d3b commit 31eb33d

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
456456
fmt("building '%s'", worker.store.printStorePath(drvPath));
457457
#ifndef _WIN32 // TODO enable build hook on Windows
458458
if (hook)
459-
msg += fmt(" on '%s'", machineName);
459+
msg += fmt(" on '%s'", hook->machineName);
460460
#endif
461461
act = std::make_unique<Activity>(
462462
*logger,
@@ -466,7 +466,7 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution()
466466
Logger::Fields{
467467
worker.store.printStorePath(drvPath),
468468
#ifndef _WIN32 // TODO enable build hook on Windows
469-
hook ? machineName :
469+
hook ? hook->machineName :
470470
#endif
471471
"",
472472
1,
@@ -1042,7 +1042,7 @@ HookReply DerivationBuildingGoal::tryBuildHook(
10421042
hook = std::move(worker.hook);
10431043

10441044
try {
1045-
machineName = readLine(hook->fromHook.readSide.get());
1045+
hook->machineName = readLine(hook->fromHook.readSide.get());
10461046
} catch (Error & e) {
10471047
e.addTrace({}, "while reading the machine name from the build hook");
10481048
throw;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ private:
8787

8888
std::map<ActivityId, Activity> builderActivities;
8989

90-
/**
91-
* The remote machine on which we're building.
92-
*/
93-
std::string machineName;
94-
9590
void timedOut(Error && ex) override;
9691

9792
std::string key() override;

src/libstore/unix/include/nix/store/build/hook-instance.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
namespace nix {
99

10+
/**
11+
* @note Sometimes this is owned by the `Worker`, and sometimes it is
12+
* owned by a `Goal`. This is for efficency: rather than starting the
13+
* hook every time we want to ask whether we can run a remote build
14+
* (which can be very often), we reuse a hook process for answering
15+
* those queries until it accepts a build. So if there are N
16+
* derivations to be built, at most N hooks will be started.
17+
*/
1018
struct HookInstance
1119
{
1220
/**
@@ -29,6 +37,15 @@ struct HookInstance
2937
*/
3038
Pid pid;
3139

40+
/**
41+
* The remote machine on which we're building.
42+
*
43+
* @Invariant When the hook instance is owned by the `Worker`, this
44+
* is the empty string. When it is owned by a `Goal`, this should be
45+
* set.
46+
*/
47+
std::string machineName;
48+
3249
FdSink sink;
3350

3451
std::map<ActivityId, Activity> activities;

0 commit comments

Comments
 (0)