From fc0bea42c22fb5157fc0bb37e9bbd103f573ee14 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 4 Mar 2025 23:08:34 +0100 Subject: [PATCH] libstore: asyncify staticOutputHashes Change-Id: Idb0daa96021656258c8018bb47cdf3c77871be0d --- lix/legacy/build-remote.cc | 2 +- lix/libcmd/built-path.cc | 3 ++- lix/libstore/build/derivation-goal.cc | 4 ++-- lix/libstore/derivations.cc | 9 ++++++--- lix/libstore/derivations.hh | 3 ++- lix/libstore/misc.cc | 4 ++-- lix/libstore/remote-store.cc | 3 ++- lix/libstore/store-api.cc | 2 +- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lix/legacy/build-remote.cc b/lix/legacy/build-remote.cc index dc902c289..dd994fdb7 100644 --- a/lix/legacy/build-remote.cc +++ b/lix/legacy/build-remote.cc @@ -346,7 +346,7 @@ connected: } - auto outputHashes = staticOutputHashes(*store, drv); + auto outputHashes = aio.blockOn(staticOutputHashes(*store, drv)); std::set missingRealisations; StorePathSet missingPaths; if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations) && !drv.type().hasKnownOutputPaths()) { diff --git a/lix/libcmd/built-path.cc b/lix/libcmd/built-path.cc index e7745ccf7..2e4caa804 100644 --- a/lix/libcmd/built-path.cc +++ b/lix/libcmd/built-path.cc @@ -4,6 +4,7 @@ #include "lix/libutil/async.hh" #include "lix/libutil/result.hh" +#include #include #include @@ -142,7 +143,7 @@ try { [&](const BuiltPath::Built & p) -> kj::Promise> { try { auto drvHashes = - staticOutputHashes(store, store.readDerivation(p.drvPath->outPath())); + TRY_AWAIT(staticOutputHashes(store, store.readDerivation(p.drvPath->outPath()))); for (auto& [outputName, outputPath] : p.outputs) { if (experimentalFeatureSettings.isEnabled( Xp::CaDerivations)) { diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index c7382fdab..c0ce5d50b 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -253,7 +253,7 @@ try { if (i.second.second) TRY_AWAIT(worker.store.addTempRoot(*i.second.second)); - auto outputHashes = staticOutputHashes(worker.evalStore, *drv); + auto outputHashes = TRY_AWAIT(staticOutputHashes(worker.evalStore, *drv)); for (auto & [outputName, outputHash] : outputHashes) initialOutputs.insert({ outputName, @@ -1151,7 +1151,7 @@ try { SingleDrvOutputs builtOutputs; if (resolvedResult.success()) { - auto resolvedHashes = staticOutputHashes(worker.store, resolvedDrv); + auto resolvedHashes = TRY_AWAIT(staticOutputHashes(worker.store, resolvedDrv)); StorePathSet outputPaths; diff --git a/lix/libstore/derivations.cc b/lix/libstore/derivations.cc index 50708db52..465bb9a0a 100644 --- a/lix/libstore/derivations.cc +++ b/lix/libstore/derivations.cc @@ -892,9 +892,12 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut } -std::map staticOutputHashes(Store & store, const Derivation & drv) -{ - return hashDerivationModulo(store, drv, true).hashes; +kj::Promise>> +staticOutputHashes(Store & store, const Derivation & drv) +try { + co_return hashDerivationModulo(store, drv, true).hashes; +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libstore/derivations.hh b/lix/libstore/derivations.hh index 1e4723d05..cdf9a5857 100644 --- a/lix/libstore/derivations.hh +++ b/lix/libstore/derivations.hh @@ -483,7 +483,8 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut * * \todo What is the Hash in this map? */ -std::map staticOutputHashes(Store & store, const Derivation & drv); +kj::Promise>> +staticOutputHashes(Store & store, const Derivation & drv); /** * Memoisation of hashDerivationModulo(). diff --git a/lix/libstore/misc.cc b/lix/libstore/misc.cc index 36bdf4004..0dbac91dc 100644 --- a/lix/libstore/misc.cc +++ b/lix/libstore/misc.cc @@ -267,7 +267,7 @@ struct QueryMissingContext // If there are unknown output paths, attempt to find if the // paths are known to substituters through a realisation. - auto outputHashes = staticOutputHashes(store, *drv); + auto outputHashes = aio.blockOn(staticOutputHashes(store, *drv)); knownOutputPaths = true; for (auto [outputName, hash] : outputHashes) { @@ -425,7 +425,7 @@ try { try { if (!inputNode.value.empty()) { auto outputHashes = - staticOutputHashes(evalStore, evalStore.readDerivation(inputDrv)); + TRY_AWAIT(staticOutputHashes(evalStore, evalStore.readDerivation(inputDrv))); for (const auto & outputName : inputNode.value) { auto outputHash = get(outputHashes, outputName); if (!outputHash) diff --git a/lix/libstore/remote-store.cc b/lix/libstore/remote-store.cc index f591e0b3f..13ea7e16e 100644 --- a/lix/libstore/remote-store.cc +++ b/lix/libstore/remote-store.cc @@ -758,7 +758,8 @@ try { OutputPathMap outputs; auto drvPath = TRY_AWAIT(resolveDerivedPath(*evalStore, *bfd.drvPath)); auto drv = evalStore->readDerivation(drvPath); - const auto outputHashes = staticOutputHashes(*evalStore, drv); // FIXME: expensive + const auto outputHashes = + TRY_AWAIT(staticOutputHashes(*evalStore, drv)); // FIXME: expensive auto built = TRY_AWAIT(resolveDerivedPath(*this, bfd, &*evalStore)); for (auto & [output, outputPath] : built) { auto outputHash = get(outputHashes, output); diff --git a/lix/libstore/store-api.cc b/lix/libstore/store-api.cc index 66f98a055..d906857d1 100644 --- a/lix/libstore/store-api.cc +++ b/lix/libstore/store-api.cc @@ -530,7 +530,7 @@ try { co_return outputs; auto drv = evalStore.readInvalidDerivation(path); - auto drvHashes = staticOutputHashes(*this, drv); + auto drvHashes = TRY_AWAIT(staticOutputHashes(*this, drv)); for (auto & [outputName, hash] : drvHashes) { auto realisation = TRY_AWAIT(queryRealisation(DrvOutput{hash, outputName})); if (realisation) {