libstore: create drv temp roots in Worker

constructors can't be async, and root creation must be made async.
creating roots outside of goal classes and passing a witness type
is a lot easier than changing the constructor structure of today.

Change-Id: Ic84a92f3db2e1a9a9164047456f227048c6871bd
This commit is contained in:
eldritch horrors
2025-02-12 01:32:01 +00:00
parent 3bca42eb00
commit d7d0acdbb4
5 changed files with 17 additions and 12 deletions
+1 -5
View File
@@ -82,7 +82,7 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath,
}
DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv,
DerivationGoal::DerivationGoal(DrvHasRoot, const StorePath & drvPath, const BasicDerivation & drv,
const OutputsSpec & wantedOutputs, Worker & worker, bool isDependency, BuildMode buildMode)
: Goal(worker, isDependency)
, useDerivation(false)
@@ -98,10 +98,6 @@ DerivationGoal::DerivationGoal(const StorePath & drvPath, const BasicDerivation
trace("created");
mcExpectedBuilds = worker.expectedBuilds.addTemporarily(1);
/* Prevent the .chroot directory from being
garbage-collected. (See isActiveTempFile() in gc.cc.) */
worker.store.addTempRoot(this->drvPath);
}
+4 -1
View File
@@ -245,10 +245,13 @@ struct DerivationGoal : public Goal
*/
std::string machineName;
/** Witness type to say that the drvPath has already been added as a temp root */
struct DrvHasRoot { explicit DrvHasRoot() = default; };
DerivationGoal(const StorePath & drvPath,
const OutputsSpec & wantedOutputs, Worker & worker, bool isDependency,
BuildMode buildMode = bmNormal);
DerivationGoal(const StorePath & drvPath, const BasicDerivation & drv,
DerivationGoal(DrvHasRoot, const StorePath & drvPath, const BasicDerivation & drv,
const OutputsSpec & wantedOutputs, Worker & worker, bool isDependency,
BuildMode buildMode = bmNormal);
virtual ~DerivationGoal() noexcept(false);
@@ -195,6 +195,7 @@ struct LocalDerivationGoal : public DerivationGoal
* possibly a platform-specific subclass
*/
static std::unique_ptr<LocalDerivationGoal> makeLocalDerivationGoal(
DrvHasRoot drvRoot,
const StorePath & drvPath,
const BasicDerivation & drv,
const OutputsSpec & wantedOutputs,
+6 -2
View File
@@ -142,16 +142,20 @@ std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>
BuildMode buildMode
)
{
/* Prevent the .chroot directory from being
garbage-collected. (See isActiveTempFile() in gc.cc.) */
store.addTempRoot(drvPath);
return makeGoalCommon(
derivationGoals,
drvPath,
[&]() -> std::unique_ptr<DerivationGoal> {
return !dynamic_cast<LocalStore *>(&store)
? std::make_unique<DerivationGoal>(
drvPath, drv, wantedOutputs, *this, running, buildMode
DerivationGoal::DrvHasRoot{}, drvPath, drv, wantedOutputs, *this, running, buildMode
)
: LocalDerivationGoal::makeLocalDerivationGoal(
drvPath, drv, wantedOutputs, *this, running, buildMode
DerivationGoal::DrvHasRoot{}, drvPath, drv, wantedOutputs, *this, running, buildMode
);
},
[&](DerivationGoal & g) { return g.addWantedOutputs(wantedOutputs); }
+5 -4
View File
@@ -45,6 +45,7 @@ std::unique_ptr<LocalDerivationGoal> LocalDerivationGoal::makeLocalDerivationGoa
}
std::unique_ptr<LocalDerivationGoal> LocalDerivationGoal::makeLocalDerivationGoal(
DrvHasRoot drvRoot,
const StorePath & drvPath,
const BasicDerivation & drv,
const OutputsSpec & wantedOutputs,
@@ -55,19 +56,19 @@ std::unique_ptr<LocalDerivationGoal> LocalDerivationGoal::makeLocalDerivationGoa
{
#if __linux__
return std::make_unique<LinuxLocalDerivationGoal>(
drvPath, drv, wantedOutputs, worker, isDependency, buildMode
drvRoot, drvPath, drv, wantedOutputs, worker, isDependency, buildMode
);
#elif __APPLE__
return std::make_unique<DarwinLocalDerivationGoal>(
drvPath, drv, wantedOutputs, worker, isDependency, buildMode
drvRoot, drvPath, drv, wantedOutputs, worker, isDependency, buildMode
);
#elif __FreeBSD__
return std::make_unique<FreeBSDLocalDerivationGoal>(
drvPath, drv, wantedOutputs, worker, isDependency, buildMode
drvRoot, drvPath, drv, wantedOutputs, worker, isDependency, buildMode
);
#else
return std::make_unique<FallbackLocalDerivationGoal>(
drvPath, drv, wantedOutputs, worker, isDependency, buildMode
drvRoot, drvPath, drv, wantedOutputs, worker, isDependency, buildMode
);
#endif
}