From dd2241ea82eede9792793c21459ca48df9260182 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 21 Feb 2025 00:35:11 +0100 Subject: [PATCH] libcmd: asyncify getBuiltPath Change-Id: I301ab541c0367100f8a68041d482d4cb326fc028 --- lix/libcmd/installables.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index 7a64cc044..a0af3f873 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -524,28 +524,34 @@ ref SourceExprCommand::parseInstallable( return installables.front(); } -static SingleBuiltPath getBuiltPath(ref evalStore, ref store, const SingleDerivedPath & b) -{ - return std::visit( - overloaded{ - [&](const SingleDerivedPath::Opaque & bo) -> SingleBuiltPath { - return SingleBuiltPath::Opaque { bo.path }; - }, - [&](const SingleDerivedPath::Built & bfd) -> SingleBuiltPath { - auto drvPath = getBuiltPath(evalStore, store, *bfd.drvPath); +static kj::Promise> getBuiltPath(ref evalStore, ref store, const SingleDerivedPath & b) +try { + auto handlers = overloaded{ + [&](const SingleDerivedPath::Opaque & bo) -> kj::Promise> { + return {SingleBuiltPath::Opaque { bo.path }}; + }, + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines) + [&](const SingleDerivedPath::Built & bfd) -> kj::Promise> { + try { + auto drvPath = TRY_AWAIT(getBuiltPath(evalStore, store, *bfd.drvPath)); // Resolving this instead of `bfd` will yield the same result, but avoid duplicative work. SingleDerivedPath::Built truncatedBfd { .drvPath = makeConstantStorePathRef(drvPath.outPath()), .output = bfd.output, }; auto outputPath = resolveDerivedPath(*store, truncatedBfd, &*evalStore); - return SingleBuiltPath::Built { + co_return SingleBuiltPath::Built { .drvPath = make_ref(std::move(drvPath)), .output = { bfd.output, outputPath }, }; - }, + } catch (...) { + co_return result::current_exception(); + } }, - b.raw()); + }; + co_return TRY_AWAIT(std::visit(handlers, b.raw())); +} catch (...) { + co_return result::current_exception(); } std::vector Installable::build( @@ -635,7 +641,7 @@ std::vector, BuiltPathWithResult>> Installable::build auto outputs = resolveDerivedPath(*store, bfd, &*evalStore); res.push_back({aux.installable, { .path = BuiltPath::Built { - .drvPath = make_ref(getBuiltPath(evalStore, store, *bfd.drvPath)), + .drvPath = make_ref(state.aio.blockOn(getBuiltPath(evalStore, store, *bfd.drvPath))), .outputs = outputs, }, .info = aux.info}}); @@ -667,7 +673,7 @@ std::vector, BuiltPathWithResult>> Installable::build outputs.emplace(outputName, realisation.outPath); res.push_back({aux.installable, { .path = BuiltPath::Built { - .drvPath = make_ref(getBuiltPath(evalStore, store, *bfd.drvPath)), + .drvPath = make_ref(state.aio.blockOn(getBuiltPath(evalStore, store, *bfd.drvPath))), .outputs = outputs, }, .info = aux.info,