forked from lix-project/lix
libstore: turn DrvOutputSubstitutionGoal::work into *one* promise
Change-Id: I2d4dcedff0a278d2d8f3d264a9186dfb399275e2
This commit is contained in:
parent
9b05636937
commit
3edc272341
|
@ -19,36 +19,32 @@ DrvOutputSubstitutionGoal::DrvOutputSubstitutionGoal(
|
||||||
: Goal(worker, isDependency)
|
: Goal(worker, isDependency)
|
||||||
, id(id)
|
, id(id)
|
||||||
{
|
{
|
||||||
state = &DrvOutputSubstitutionGoal::init;
|
|
||||||
name = fmt("substitution of '%s'", id.to_string());
|
name = fmt("substitution of '%s'", id.to_string());
|
||||||
trace("created");
|
trace("created");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::init(bool inBuildSlot) noexcept
|
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::work() noexcept
|
||||||
try {
|
try {
|
||||||
trace("init");
|
trace("init");
|
||||||
|
|
||||||
/* If the derivation already exists, we’re done */
|
/* If the derivation already exists, we’re done */
|
||||||
if (worker.store.queryRealisation(id)) {
|
if (worker.store.queryRealisation(id)) {
|
||||||
return {Finished{ecSuccess, std::move(buildResult)}};
|
co_return Finished{ecSuccess, std::move(buildResult)};
|
||||||
}
|
}
|
||||||
|
|
||||||
subs = settings.useSubstitutes ? getDefaultSubstituters() : std::list<ref<Store>>();
|
subs = settings.useSubstitutes ? getDefaultSubstituters() : std::list<ref<Store>>();
|
||||||
return tryNext(inBuildSlot);
|
co_return co_await tryNext();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return {std::current_exception()};
|
co_return result::failure(std::current_exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::tryNext(bool inBuildSlot) noexcept
|
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::tryNext() noexcept
|
||||||
try {
|
try {
|
||||||
trace("trying next substituter");
|
trace("trying next substituter");
|
||||||
|
|
||||||
if (!inBuildSlot) {
|
if (!slotToken.valid()) {
|
||||||
return worker.substitutions.acquire().then([this](auto token) {
|
slotToken = co_await worker.substitutions.acquire();
|
||||||
slotToken = std::move(token);
|
|
||||||
return work();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
maintainRunningSubstitutions = worker.runningSubstitutions.addTemporarily(1);
|
maintainRunningSubstitutions = worker.runningSubstitutions.addTemporarily(1);
|
||||||
|
@ -65,7 +61,7 @@ try {
|
||||||
/* Hack: don't indicate failure if there were no substituters.
|
/* Hack: don't indicate failure if there were no substituters.
|
||||||
In that case the calling derivation should just do a
|
In that case the calling derivation should just do a
|
||||||
build. */
|
build. */
|
||||||
return {Finished{substituterFailed ? ecFailed : ecNoSubstituters, std::move(buildResult)}};
|
co_return Finished{substituterFailed ? ecFailed : ecNoSubstituters, std::move(buildResult)};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub = subs.front();
|
sub = subs.front();
|
||||||
|
@ -85,13 +81,13 @@ try {
|
||||||
return sub->queryRealisation(id);
|
return sub->queryRealisation(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
state = &DrvOutputSubstitutionGoal::realisationFetched;
|
co_await pipe.promise;
|
||||||
return pipe.promise.then([]() -> Result<WorkResult> { return StillAlive{}; });
|
co_return co_await realisationFetched();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return {std::current_exception()};
|
co_return result::failure(std::current_exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::realisationFetched(bool inBuildSlot) noexcept
|
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::realisationFetched() noexcept
|
||||||
try {
|
try {
|
||||||
maintainRunningSubstitutions.reset();
|
maintainRunningSubstitutions.reset();
|
||||||
slotToken = {};
|
slotToken = {};
|
||||||
|
@ -104,7 +100,7 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!outputInfo) {
|
if (!outputInfo) {
|
||||||
return tryNext(inBuildSlot);
|
co_return co_await tryNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Vector<std::pair<GoalPtr, kj::Promise<void>>> dependencies;
|
kj::Vector<std::pair<GoalPtr, kj::Promise<void>>> dependencies;
|
||||||
|
@ -121,7 +117,7 @@ try {
|
||||||
worker.store.printStorePath(localOutputInfo->outPath),
|
worker.store.printStorePath(localOutputInfo->outPath),
|
||||||
worker.store.printStorePath(depPath)
|
worker.store.printStorePath(depPath)
|
||||||
);
|
);
|
||||||
return tryNext(inBuildSlot);
|
co_return co_await tryNext();
|
||||||
}
|
}
|
||||||
dependencies.add(worker.goalFactory().makeDrvOutputSubstitutionGoal(depId));
|
dependencies.add(worker.goalFactory().makeDrvOutputSubstitutionGoal(depId));
|
||||||
}
|
}
|
||||||
|
@ -129,17 +125,15 @@ try {
|
||||||
|
|
||||||
dependencies.add(worker.goalFactory().makePathSubstitutionGoal(outputInfo->outPath));
|
dependencies.add(worker.goalFactory().makePathSubstitutionGoal(outputInfo->outPath));
|
||||||
|
|
||||||
if (dependencies.empty()) {
|
if (!dependencies.empty()) {
|
||||||
return outPathValid(inBuildSlot);
|
(co_await waitForGoals(dependencies.releaseAsArray())).value();
|
||||||
} else {
|
|
||||||
state = &DrvOutputSubstitutionGoal::outPathValid;
|
|
||||||
return waitForGoals(dependencies.releaseAsArray());
|
|
||||||
}
|
}
|
||||||
|
co_return co_await outPathValid();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
return {std::current_exception()};
|
co_return result::failure(std::current_exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::outPathValid(bool inBuildSlot) noexcept
|
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::outPathValid() noexcept
|
||||||
try {
|
try {
|
||||||
assert(outputInfo);
|
assert(outputInfo);
|
||||||
trace("output path substituted");
|
trace("output path substituted");
|
||||||
|
@ -166,10 +160,4 @@ try {
|
||||||
return {std::current_exception()};
|
return {std::current_exception()};
|
||||||
}
|
}
|
||||||
|
|
||||||
kj::Promise<Result<Goal::WorkResult>> DrvOutputSubstitutionGoal::work() noexcept
|
|
||||||
{
|
|
||||||
return (this->*state)(slotToken.valid());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,13 +65,9 @@ public:
|
||||||
std::optional<ContentAddress> ca = std::nullopt
|
std::optional<ContentAddress> ca = std::nullopt
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef kj::Promise<Result<WorkResult>> (DrvOutputSubstitutionGoal::*GoalState)(bool inBuildSlot) noexcept;
|
kj::Promise<Result<WorkResult>> tryNext() noexcept;
|
||||||
GoalState state;
|
kj::Promise<Result<WorkResult>> realisationFetched() noexcept;
|
||||||
|
kj::Promise<Result<WorkResult>> outPathValid() noexcept;
|
||||||
kj::Promise<Result<WorkResult>> init(bool inBuildSlot) noexcept;
|
|
||||||
kj::Promise<Result<WorkResult>> tryNext(bool inBuildSlot) noexcept;
|
|
||||||
kj::Promise<Result<WorkResult>> realisationFetched(bool inBuildSlot) noexcept;
|
|
||||||
kj::Promise<Result<WorkResult>> outPathValid(bool inBuildSlot) noexcept;
|
|
||||||
kj::Promise<Result<WorkResult>> finished() noexcept;
|
kj::Promise<Result<WorkResult>> finished() noexcept;
|
||||||
|
|
||||||
kj::Promise<Result<WorkResult>> work() noexcept override;
|
kj::Promise<Result<WorkResult>> work() noexcept override;
|
||||||
|
|
Loading…
Reference in a new issue