Skip to content

Commit 2babcb5

Browse files
committed
add a print statement for drv path -> builder name
1 parent 2e262c6 commit 2babcb5

File tree

3 files changed

+56
-40
lines changed

3 files changed

+56
-40
lines changed

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -263,23 +263,29 @@ Goal::Co DerivationBuildingGoal::tryToBuild()
263263
: buildMode == bmCheck ? "checking outputs of '%s'"
264264
: "building '%s'",
265265
worker.store.printStorePath(drvPath));
266-
#ifndef _WIN32 // TODO enable build hook on Windows
267-
if (hook)
268-
msg += fmt(" on '%s'", hook->machineName);
266+
267+
std::string builderName;
268+
#ifndef _WIN32
269+
if (hook) {
270+
builderName = fmt("remote builder: %s", hook->machineName);
271+
} else if (builder) {
272+
auto maybeUID = builder->getBuilderUID();
273+
if (maybeUID)
274+
builderName = fmt("localhost builder with uid: %s", std::to_string(*maybeUID));
275+
else
276+
builderName = "";
277+
} else {
278+
builderName = "";
279+
}
280+
#else
281+
builderName = "";
269282
#endif
283+
if (builderName != "")
284+
msg += fmt(" on '%s'", builderName);
285+
270286
act = std::make_unique<Activity>(
271-
*logger,
272-
lvlInfo,
273-
actBuild,
274-
msg,
275-
Logger::Fields{
276-
worker.store.printStorePath(drvPath),
277-
#ifndef _WIN32 // TODO enable build hook on Windows
278-
hook ? hook->machineName :
279-
#endif
280-
"",
281-
1,
282-
1});
287+
*logger, lvlInfo, actBuild, msg, Logger::Fields{worker.store.printStorePath(drvPath), builderName, 1, 1});
288+
283289
mcRunningBuilds = std::make_unique<MaintainCount<uint64_t>>(worker.runningBuilds);
284290
worker.updateProgress();
285291
};
@@ -1143,13 +1149,12 @@ DerivationBuildingGoal::checkPathValidity(std::map<std::string, InitialOutput> &
11431149
// derivation, and the output path is valid, but we don't have
11441150
// its realisation stored (probably because it has been built
11451151
// without the `ca-derivations` experimental flag).
1146-
worker.store.registerDrvOutput(
1147-
Realisation{
1148-
{
1149-
.outPath = info.known->path,
1150-
},
1151-
drvOutput,
1152-
});
1152+
worker.store.registerDrvOutput(Realisation{
1153+
{
1154+
.outPath = info.known->path,
1155+
},
1156+
drvOutput,
1157+
});
11531158
}
11541159
}
11551160
if (info.known && info.known->isValid())

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ struct DerivationBuilder : RestrictionContext
180180
* killed.
181181
*/
182182
virtual bool killChild() = 0;
183+
184+
/**
185+
* Get the builder UID.
186+
*
187+
* @returns the builder UID if run on localhost (e.g. if it exists).
188+
*/
189+
virtual std::optional<uid_t> getBuilderUID() = 0;
183190
};
184191

185192
struct ExternalBuilder

src/libstore/unix/build/derivation-builder.cc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ class DerivationBuilderImpl : public DerivationBuilder, public DerivationBuilder
415415

416416
bool killChild() override;
417417

418+
std::optional<uid_t> getBuilderUID() override;
419+
418420
private:
419421

420422
bool decideWhetherDiskFull();
@@ -443,14 +445,13 @@ void handleDiffHook(
443445
if (diffHookOpt && settings.runDiffHook) {
444446
auto & diffHook = *diffHookOpt;
445447
try {
446-
auto diffRes = runProgram(
447-
RunOptions{
448-
.program = diffHook,
449-
.lookupPath = true,
450-
.args = {tryA, tryB, drvPath, tmpDir},
451-
.uid = uid,
452-
.gid = gid,
453-
.chdir = "/"});
448+
auto diffRes = runProgram(RunOptions{
449+
.program = diffHook,
450+
.lookupPath = true,
451+
.args = {tryA, tryB, drvPath, tmpDir},
452+
.uid = uid,
453+
.gid = gid,
454+
.chdir = "/"});
454455
if (!statusOk(diffRes.first))
455456
throw ExecError(diffRes.first, "diff-hook program '%1%' %2%", diffHook, statusToString(diffRes.first));
456457

@@ -494,6 +495,11 @@ bool DerivationBuilderImpl::killChild()
494495
return ret;
495496
}
496497

498+
std::optional<uid_t> DerivationBuilderImpl::getBuilderUID()
499+
{
500+
return (buildUser) ? std::optional<uid_t>(buildUser->getUID()) : std::nullopt;
501+
}
502+
497503
SingleDrvOutputs DerivationBuilderImpl::unprepareBuild()
498504
{
499505
/* Since we got an EOF on the logger pipe, the builder is presumed
@@ -1691,11 +1697,10 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
16911697

16921698
std::filesystem::rename(tmpOutput, actualPath);
16931699

1694-
return newInfoFromCA(
1695-
DerivationOutput::CAFloating{
1696-
.method = dof.ca.method,
1697-
.hashAlgo = wanted.algo,
1698-
});
1700+
return newInfoFromCA(DerivationOutput::CAFloating{
1701+
.method = dof.ca.method,
1702+
.hashAlgo = wanted.algo,
1703+
});
16991704
},
17001705

17011706
[&](const DerivationOutput::CAFloating & dof) { return newInfoFromCA(dof); },
@@ -1707,11 +1712,10 @@ SingleDrvOutputs DerivationBuilderImpl::registerOutputs()
17071712
},
17081713

17091714
[&](const DerivationOutput::Impure & doi) {
1710-
return newInfoFromCA(
1711-
DerivationOutput::CAFloating{
1712-
.method = doi.method,
1713-
.hashAlgo = doi.hashAlgo,
1714-
});
1715+
return newInfoFromCA(DerivationOutput::CAFloating{
1716+
.method = doi.method,
1717+
.hashAlgo = doi.hashAlgo,
1718+
});
17151719
},
17161720

17171721
},

0 commit comments

Comments
 (0)