From 6423ee2b7e052f7975bc22bdf1836bdb8dc9af2a Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 1 Feb 2025 21:24:35 +0100 Subject: [PATCH] libstore: asyncify Store::exportReferences Change-Id: Ia4068d31afc48cf9d459bed3d5d8943be06718ee --- lix/libstore/build/local-derivation-goal.cc | 7 +++++-- lix/libstore/parsed-derivations.cc | 4 +++- lix/libstore/store-api.cc | 11 +++++++---- lix/libstore/store-api.hh | 3 ++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lix/libstore/build/local-derivation-goal.cc b/lix/libstore/build/local-derivation-goal.cc index f3f5d7549..82079ef7f 100644 --- a/lix/libstore/build/local-derivation-goal.cc +++ b/lix/libstore/build/local-derivation-goal.cc @@ -571,9 +571,12 @@ try { auto storePath = worker.store.toStorePath(storePathS).first; /* Write closure info to . */ - writeFile(tmpDir + "/" + fileName, + writeFile( + tmpDir + "/" + fileName, worker.store.makeValidityRegistration( - worker.store.exportReferences({storePath}, inputPaths), false, false)); + TRY_AWAIT(worker.store.exportReferences({storePath}, inputPaths)), false, false + ) + ); } } diff --git a/lix/libstore/parsed-derivations.cc b/lix/libstore/parsed-derivations.cc index a4ecec5f2..f01c7f28d 100644 --- a/lix/libstore/parsed-derivations.cc +++ b/lix/libstore/parsed-derivations.cc @@ -1,4 +1,5 @@ #include "lix/libstore/parsed-derivations.hh" +#include "lix/libutil/async.hh" #include "lix/libutil/strings.hh" #include @@ -154,7 +155,8 @@ std::optional ParsedDerivation::prepareStructuredAttrs(Store & s for (auto & p : *i) storePaths.insert(store.toStorePath(p.get()).first); json[i.key()] = store.pathInfoToJSON( - store.exportReferences(storePaths, inputPaths), false, true); + RUN_ASYNC_IN_NEW_THREAD(store.exportReferences(storePaths, inputPaths)), false, true + ); } } diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index d59f4619c..b4b4cfb27 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -918,8 +918,9 @@ std::string Store::makeValidityRegistration(const StorePathSet & paths, } -StorePathSet Store::exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths) -{ +kj::Promise> +Store::exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths) +try { StorePathSet paths; for (auto & storePath : storePaths) { @@ -937,7 +938,7 @@ StorePathSet Store::exportReferences(const StorePathSet & storePaths, const Stor for (auto & j : paths2) { if (j.isDerivation()) { - Derivation drv = RUN_ASYNC_IN_NEW_THREAD(derivationFromPath(j)); + Derivation drv = TRY_AWAIT(derivationFromPath(j)); for (auto & k : drv.outputsAndOptPaths(*this)) { if (!k.second.second) /* FIXME: I am confused why we are calling @@ -950,7 +951,9 @@ StorePathSet Store::exportReferences(const StorePathSet & storePaths, const Stor } } - return paths; + co_return paths; +} catch (...) { + co_return result::current_exception(); } json Store::pathInfoToJSON(const StorePathSet & storePaths, diff --git a/lix/libstore/store-api.hh b/lix/libstore/store-api.hh index f4710747b..0032f8a80 100644 --- a/lix/libstore/store-api.hh +++ b/lix/libstore/store-api.hh @@ -818,7 +818,8 @@ public: * Computes the full closure of of a set of store-paths for e.g. * derivations that need this information for `exportReferencesGraph`. */ - StorePathSet exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths); + kj::Promise> + exportReferences(const StorePathSet & storePaths, const StorePathSet & inputPaths); /** * Given a store path, return the realisation actually used in the realisation of this path: