1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

Refactor, extract some shared code into UnresolvedApp::build

This commit is contained in:
Jeremy Fleischman 2025-04-29 18:36:56 -07:00
parent e14346c7da
commit 7df7bde306
No known key found for this signature in database
3 changed files with 12 additions and 10 deletions

View file

@ -21,6 +21,7 @@ struct App
struct UnresolvedApp
{
App unresolved;
std::vector<BuiltPathWithResult> build(ref<Store> evalStore, ref<Store> store);
App resolve(ref<Store> evalStore, ref<Store> store);
};

View file

@ -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<Store> evalStore, ref<Store> store)
std::vector<BuiltPathWithResult> UnresolvedApp::build(ref<Store> evalStore, ref<Store> store)
{
auto res = unresolved;
Installables installableContext;
for (auto & ctxElt : unresolved.context)
installableContext.push_back(
make_ref<InstallableDerivedPath>(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<Store> evalStore, ref<Store> 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);

View file

@ -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<InstallableDerivedPath>(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<LocalFSStore>())