From 7df7bde3065e3ffbadf8ef6c9c3d83f7f868209f Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Tue, 29 Apr 2025 18:36:56 -0700 Subject: [PATCH] Refactor, extract some shared code into `UnresolvedApp::build` --- src/libcmd/include/nix/cmd/installable-value.hh | 1 + src/nix/app.cc | 15 ++++++++++----- src/nix/formatter.cc | 6 +----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libcmd/include/nix/cmd/installable-value.hh b/src/libcmd/include/nix/cmd/installable-value.hh index 9c8f1a9fb..e65c199a5 100644 --- a/src/libcmd/include/nix/cmd/installable-value.hh +++ b/src/libcmd/include/nix/cmd/installable-value.hh @@ -21,6 +21,7 @@ struct App struct UnresolvedApp { App unresolved; + std::vector build(ref evalStore, ref store); App resolve(ref evalStore, ref store); }; diff --git a/src/nix/app.cc b/src/nix/app.cc index 75ef874ba..c9a9f9caf 100644 --- a/src/nix/app.cc +++ b/src/nix/app.cc @@ -129,18 +129,23 @@ UnresolvedApp InstallableValue::toApp(EvalState & state) throw Error("attribute '%s' has unsupported type '%s'", cursor->getAttrPathStr(), type); } -// FIXME: move to libcmd -App UnresolvedApp::resolve(ref evalStore, ref store) +std::vector UnresolvedApp::build(ref evalStore, ref store) { - auto res = unresolved; - Installables installableContext; for (auto & ctxElt : unresolved.context) installableContext.push_back( make_ref(store, DerivedPath { ctxElt })); - auto builtContext = Installable::build(evalStore, store, Realise::Outputs, installableContext); + return Installable::build(evalStore, store, Realise::Outputs, installableContext); +} + +// FIXME: move to libcmd +App UnresolvedApp::resolve(ref evalStore, ref store) +{ + auto res = unresolved; + + auto builtContext = build(evalStore, store); res.program = resolveString(*store, unresolved.program, builtContext); if (!store->isInStore(res.program)) throw Error("app program '%s' is not in the Nix store", res.program); diff --git a/src/nix/formatter.cc b/src/nix/formatter.cc index 31275eb35..f4cde7d68 100644 --- a/src/nix/formatter.cc +++ b/src/nix/formatter.cc @@ -141,11 +141,7 @@ struct CmdFormatterBuild : MixFormatter auto & installable = InstallableValue::require(*installable_); auto unresolvedApp = installable.toApp(*evalState); auto app = unresolvedApp.resolve(evalStore, store); - - Installables installableContext; - for (auto & ctxElt : unresolvedApp.unresolved.context) - installableContext.push_back(make_ref(store, DerivedPath{ctxElt})); - auto buildables = Installable::build(evalStore, store, Realise::Outputs, installableContext); + auto buildables = unresolvedApp.build(evalStore, store); if (outLink != "") if (auto store2 = store.dynamic_pointer_cast())