libstore: asyncify Worker::makeBasicDerivationGoal

Change-Id: I04af5dc0c70084daa18de61aa0f84c8e18981e26
This commit is contained in:
eldritch horrors
2025-02-12 19:22:20 +00:00
parent d7d0acdbb4
commit 4fec8b3214
3 changed files with 48 additions and 16 deletions
+14 -5
View File
@@ -76,11 +76,20 @@ kj::Promise<Result<BuildResult>> Store::buildDerivation(const StorePath & drvPat
try {
try {
auto results = TRY_AWAIT(processGoals(*this, *this, [&](GoalFactory & gf) {
Worker::Targets goals;
goals.emplace_back(
gf.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All{}, buildMode)
);
return goals;
// sometimes clang lints are really annoying. this would be safe without
// the explicit coroutine param captures, but clang-tidy does not see it
return [](auto && gf, auto && drvPath, auto && drv, auto buildMode
) -> kj::Promise<Result<Worker::Targets>> {
try {
Worker::Targets goals;
goals.emplace_back(TRY_AWAIT(
gf.makeBasicDerivationGoal(drvPath, drv, OutputsSpec::All{}, buildMode)
));
co_return goals;
} catch (...) {
co_return result::current_exception();
}
}(gf, drvPath, drv, buildMode);
}));
auto & result = results.goals.begin()->second;
co_return result.result.restrictTo(DerivedPath::Built {
+8 -6
View File
@@ -135,18 +135,20 @@ std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>
}
std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> Worker::makeBasicDerivationGoal(
kj::Promise<
Result<std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>>>>
Worker::makeBasicDerivationGoal(
const StorePath & drvPath,
const BasicDerivation & drv,
const OutputsSpec & wantedOutputs,
BuildMode buildMode
)
{
try {
/* Prevent the .chroot directory from being
garbage-collected. (See isActiveTempFile() in gc.cc.) */
store.addTempRoot(drvPath);
return makeGoalCommon(
co_return makeGoalCommon(
derivationGoals,
drvPath,
[&]() -> std::unique_ptr<DerivationGoal> {
@@ -160,6 +162,8 @@ std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>
},
[&](DerivationGoal & g) { return g.addWantedOutputs(wantedOutputs); }
);
} catch (...) {
co_return result::current_exception();
}
@@ -232,10 +236,8 @@ try {
co_return result::current_exception();
}
kj::Promise<Result<Worker::Results>> Worker::run(std::function<Targets (GoalFactory &)> req)
kj::Promise<Result<Worker::Results>> Worker::run(Targets topGoals)
try {
auto topGoals = req(goalFactory());
assert(!running);
running = true;
Finally const _stop([&] { running = false; });
+26 -5
View File
@@ -5,6 +5,7 @@
#include "lix/libutil/async-semaphore.hh"
#include "lix/libutil/concepts.hh"
#include "lix/libutil/notifying-counter.hh"
#include "lix/libutil/result.hh"
#include "lix/libutil/types.hh"
#include "lix/libstore/lock.hh"
#include "lix/libstore/store-api.hh"
@@ -35,7 +36,8 @@ public:
makeDerivationGoal(
const StorePath & drvPath, const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal
) = 0;
virtual std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>>
virtual kj::Promise<
Result<std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>>>>
makeBasicDerivationGoal(
const StorePath & drvPath,
const BasicDerivation & drv,
@@ -245,9 +247,14 @@ private:
std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> makeDerivationGoal(
const StorePath & drvPath,
const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override;
std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>> makeBasicDerivationGoal(
const StorePath & drvPath, const BasicDerivation & drv,
const OutputsSpec & wantedOutputs, BuildMode buildMode = bmNormal) override;
kj::Promise<
Result<std::pair<std::shared_ptr<DerivationGoal>, kj::Promise<Result<Goal::WorkResult>>>>>
makeBasicDerivationGoal(
const StorePath & drvPath,
const BasicDerivation & drv,
const OutputsSpec & wantedOutputs,
BuildMode buildMode = bmNormal
) override;
/**
* @ref SubstitutionGoal "substitution goal"
@@ -274,11 +281,25 @@ private:
std::pair<GoalPtr, kj::Promise<Result<Goal::WorkResult>>>
makeGoal(const DerivedPath & req, BuildMode buildMode = bmNormal) override;
kj::Promise<Result<Results>> run(Targets topGoals);
public:
/**
* Loop until the specified top-level goals have finished.
*/
kj::Promise<Result<Results>> run(std::function<Targets (GoalFactory &)> req);
kj::Promise<Result<Results>> run(std::function<kj::Promise<Result<Targets>>(GoalFactory &)> req)
try {
co_return co_await run(TRY_AWAIT(req(goalFactory())));
} catch (...) {
co_return result::current_exception();
}
kj::Promise<Result<Results>> run(std::function<Targets(GoalFactory &)> req)
try {
return run(req(goalFactory()));
} catch (...) {
return {result::current_exception()};
}
/**
* Check whether the given valid path exists and has the right