From e6fee559f74b5615685ad692f8ff21bd79d21154 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 24 Feb 2025 04:54:41 +0100 Subject: [PATCH] libmain: asyncify printMissing Change-Id: Iac87ecbbab4c65ddd6e3a32bdb64107ed7f9b3c0 --- lix/legacy/nix-build.cc | 7 +++++-- lix/legacy/nix-env.cc | 4 ++-- lix/legacy/nix-store.cc | 7 +++++-- lix/libcmd/installables.cc | 4 ++-- lix/libmain/shared.cc | 19 ++++++++++++++----- lix/libmain/shared.hh | 4 ++-- lix/nix/build.cc | 2 +- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lix/legacy/nix-build.cc b/lix/legacy/nix-build.cc index aa0b99bf0..822e81c50 100644 --- a/lix/legacy/nix-build.cc +++ b/lix/legacy/nix-build.cc @@ -315,8 +315,11 @@ static void main_nix_build(AsyncIoRoot & aio, std::string programName, Strings a store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize); - if (settings.printMissing) - printMissing(ref(store), willBuild, willSubstitute, unknown, downloadSize, narSize); + if (settings.printMissing) { + aio.blockOn(printMissing( + ref(store), willBuild, willSubstitute, unknown, downloadSize, narSize + )); + } if (!dryRun) aio.blockOn(store->buildPaths(paths, buildMode, evalStore)); diff --git a/lix/legacy/nix-env.cc b/lix/legacy/nix-env.cc index fea427c0e..490c0fc9b 100644 --- a/lix/legacy/nix-env.cc +++ b/lix/legacy/nix-env.cc @@ -503,7 +503,7 @@ static void printMissing(EvalState & state, DrvInfos & elems) .path = i.queryOutPath(state), }); - printMissing(state.ctx.store, targets); + state.aio.blockOn(printMissing(state.ctx.store, targets)); } @@ -788,7 +788,7 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs) .path = drv.queryOutPath(*state), }), }; - printMissing(globals.state->store, paths); + globals.aio.blockOn(printMissing(globals.state->store, paths)); if (globals.dryRun) return; globals.aio.blockOn( globals.state->store->buildPaths(paths, globals.state->repair ? bmRepair : bmNormal) diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index 5d80b7c65..078ee4e6e 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -154,8 +154,11 @@ static void opRealise(AsyncIoRoot & aio, Strings opFlags, Strings opArgs) unknown = StorePathSet(); } - if (settings.printMissing) - printMissing(ref(store), willBuild, willSubstitute, unknown, downloadSize, narSize); + if (settings.printMissing) { + aio.blockOn(printMissing( + ref(store), willBuild, willSubstitute, unknown, downloadSize, narSize + )); + } if (dryRun) return; diff --git a/lix/libcmd/installables.cc b/lix/libcmd/installables.cc index 91dbf4f4e..a46863a43 100644 --- a/lix/libcmd/installables.cc +++ b/lix/libcmd/installables.cc @@ -632,7 +632,7 @@ std::vector, BuiltPathWithResult>> Installable::build case Realise::Nothing: case Realise::Derivation: - printMissing(store, pathsToBuild, lvlError); + state.aio.blockOn(printMissing(store, pathsToBuild, lvlError)); for (auto & path : pathsToBuild) { for (auto & aux : backmap[path]) { @@ -660,7 +660,7 @@ std::vector, BuiltPathWithResult>> Installable::build case Realise::Outputs: { if (settings.printMissing) - printMissing(store, pathsToBuild, lvlInfo); + state.aio.blockOn(printMissing(store, pathsToBuild, lvlInfo)); auto buildResults = state.aio.blockOn(store->buildPathsWithResults(pathsToBuild, bMode, evalStore)); diff --git a/lix/libmain/shared.cc b/lix/libmain/shared.cc index da76d90b5..d5aeb4824 100644 --- a/lix/libmain/shared.cc +++ b/lix/libmain/shared.cc @@ -3,6 +3,7 @@ #include "lix/libmain/shared.hh" #include "lix/libstore/store-api.hh" #include "lix/libstore/gc-store.hh" +#include "lix/libutil/result.hh" #include "lix/libutil/signals.hh" #include "lix/libmain/loggers.hh" #include "lix/libutil/current-process.hh" @@ -46,19 +47,23 @@ void printGCWarning() } -void printMissing(ref store, const std::vector & paths, Verbosity lvl) -{ +kj::Promise> +printMissing(ref store, const std::vector & paths, Verbosity lvl) +try { uint64_t downloadSize, narSize; StorePathSet willBuild, willSubstitute, unknown; store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize); - printMissing(store, willBuild, willSubstitute, unknown, downloadSize, narSize, lvl); + TRY_AWAIT(printMissing(store, willBuild, willSubstitute, unknown, downloadSize, narSize, lvl)); + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } -void printMissing(ref store, const StorePathSet & willBuild, +kj::Promise> printMissing(ref store, const StorePathSet & willBuild, const StorePathSet & willSubstitute, const StorePathSet & unknown, uint64_t downloadSize, uint64_t narSize, Verbosity lvl) -{ +try { if (!willBuild.empty()) { if (willBuild.size() == 1) printMsg(lvl, "this derivation will be built:"); @@ -103,6 +108,10 @@ void printMissing(ref store, const StorePathSet & willBuild, for (auto & i : unknown) printMsg(lvl, " %s", store->printStorePath(i)); } + + co_return result::success(); +} catch (...) { + co_return result::current_exception(); } diff --git a/lix/libmain/shared.hh b/lix/libmain/shared.hh index 2f6943216..042a38797 100644 --- a/lix/libmain/shared.hh +++ b/lix/libmain/shared.hh @@ -30,12 +30,12 @@ void printGCWarning(); class Store; -void printMissing( +kj::Promise> printMissing( ref store, const std::vector & paths, Verbosity lvl = lvlInfo); -void printMissing(ref store, const StorePathSet & willBuild, +kj::Promise> printMissing(ref store, const StorePathSet & willBuild, const StorePathSet & willSubstitute, const StorePathSet & unknown, uint64_t downloadSize, uint64_t narSize, Verbosity lvl = lvlInfo); diff --git a/lix/nix/build.cc b/lix/nix/build.cc index 432698fba..935d2351a 100644 --- a/lix/nix/build.cc +++ b/lix/nix/build.cc @@ -131,7 +131,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixJSON, MixProfile for (auto & b : i->toDerivedPaths(*state)) pathsToBuild.push_back(b.path); - printMissing(store, pathsToBuild, lvlError); + aio().blockOn(printMissing(store, pathsToBuild, lvlError)); if (json) logger->cout("%s", derivedPathsToJSON(aio(), pathsToBuild, *store).dump());