Skip to content

Commit 5de69f7

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 eb56b18 commit 5de69f7

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
@@ -450,7 +450,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
450450
fmt("building '%s'", worker.store.printStorePath(drvPath));
451451
#ifndef _WIN32 // TODO enable build hook on Windows
452452
if (hook)
453-
msg += fmt(" on '%s'", machineName);
453+
msg += fmt(" on '%s'", hook->machineName);
454454
#endif
455455
act = std::make_unique<Activity>(
456456
*logger,
@@ -460,7 +460,7 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
460460
Logger::Fields{
461461
worker.store.printStorePath(drvPath),
462462
#ifndef _WIN32 // TODO enable build hook on Windows
463-
hook ? machineName :
463+
hook ? hook->machineName :
464464
#endif
465465
"",
466466
1,
@@ -1027,7 +1027,7 @@ HookReply DerivationBuildingGoal::tryBuildHook()
10271027
hook = std::move(worker.hook);
10281028

10291029
try {
1030-
machineName = readLine(hook->fromHook.readSide.get());
1030+
hook->machineName = readLine(hook->fromHook.readSide.get());
10311031
} catch (Error & e) {
10321032
e.addTrace({}, "while reading the machine name from the build hook");
10331033
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
@@ -95,11 +95,6 @@ private:
9595

9696
std::map<ActivityId, Activity> builderActivities;
9797

98-
/**
99-
* The remote machine on which we're building.
100-
*/
101-
std::string machineName;
102-
10398
void timedOut(Error && ex) override;
10499

105100
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)