From 0f24400d90daf65cf20142a662f8245008437e2c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 19 Nov 2013 14:09:03 +0100 Subject: Generalise meta attributes --- src/nix-env/user-env.cc | 52 ++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) (limited to 'src/nix-env/user-env.cc') diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index 64ddaadb99cf..0ef28a12e73f 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -5,6 +5,7 @@ #include "globals.hh" #include "shared.hh" #include "eval.hh" +#include "eval-inline.hh" #include "profiles.hh" @@ -32,9 +33,9 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, /* Build the components in the user environment, if they don't exist already. */ PathSet drvsToBuild; - foreach (DrvInfos::const_iterator, i, elems) - if (i->queryDrvPath(state) != "") - drvsToBuild.insert(i->queryDrvPath(state)); + foreach (DrvInfos::iterator, i, elems) + if (i->queryDrvPath() != "") + drvsToBuild.insert(i->queryDrvPath()); debug(format("building user environment dependencies")); store->buildPaths(drvsToBuild, state.repair); @@ -48,7 +49,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, /* Create a pseudo-derivation containing the name, system, output paths, and optionally the derivation path, as well as the meta attributes. */ - Path drvPath = keepDerivations ? i->queryDrvPath(state) : ""; + Path drvPath = keepDerivations ? i->queryDrvPath() : ""; Value & v(*state.allocValue()); manifest.list.elems[n++] = &v; @@ -58,12 +59,12 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, mkString(*state.allocAttr(v, state.sName), i->name); if (!i->system.empty()) mkString(*state.allocAttr(v, state.sSystem), i->system); - mkString(*state.allocAttr(v, state.sOutPath), i->queryOutPath(state)); + mkString(*state.allocAttr(v, state.sOutPath), i->queryOutPath()); if (drvPath != "") - mkString(*state.allocAttr(v, state.sDrvPath), i->queryDrvPath(state)); + mkString(*state.allocAttr(v, state.sDrvPath), i->queryDrvPath()); // Copy each output. - DrvInfo::Outputs outputs = i->queryOutputs(state); + DrvInfo::Outputs outputs = i->queryOutputs(); Value & vOutputs = *state.allocAttr(v, state.sOutputs); state.mkList(vOutputs, outputs.size()); unsigned int m = 0; @@ -84,28 +85,12 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, // Copy the meta attributes. Value & vMeta = *state.allocAttr(v, state.sMeta); state.mkAttrs(vMeta, 16); - - MetaInfo meta = i->queryMetaInfo(state); - - foreach (MetaInfo::const_iterator, j, meta) { - Value & v2(*state.allocAttr(vMeta, state.symbols.create(j->first))); - switch (j->second.type) { - case MetaValue::tpInt: mkInt(v2, j->second.intValue); break; - case MetaValue::tpString: mkString(v2, j->second.stringValue); break; - case MetaValue::tpStrings: { - state.mkList(v2, j->second.stringValues.size()); - unsigned int m = 0; - foreach (Strings::const_iterator, k, j->second.stringValues) { - v2.list.elems[m] = state.allocValue(); - mkString(*v2.list.elems[m++], *k); - } - break; - } - default: abort(); - } + StringSet metaNames = i->queryMetaNames(); + foreach (StringSet::iterator, j, metaNames) { + Value * v = i->queryMeta(*j); + state.strictForceValue(*v); // FIXME + vMeta.attrs->push_back(Attr(state.symbols.create(*j), v)); } - - vMeta.attrs->sort(); v.attrs->sort(); if (drvPath != "") references.insert(drvPath); @@ -133,13 +118,14 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, /* Evaluate it. */ debug("evaluating user environment builder"); - DrvInfo topLevelDrv; - if (!getDerivation(state, topLevel, topLevelDrv, false)) - abort(); + state.forceValue(topLevel); + PathSet context; + Path topLevelDrv = state.coerceToPath(*topLevel.attrs->find(state.sDrvPath)->value, context); + Path topLevelOut = state.coerceToPath(*topLevel.attrs->find(state.sOutPath)->value, context); /* Realise the resulting store expression. */ debug("building user environment"); - store->buildPaths(singleton(topLevelDrv.queryDrvPath(state)), state.repair); + store->buildPaths(singleton(topLevelDrv), state.repair); /* Switch the current user environment to the output path. */ PathLocks lock; @@ -152,7 +138,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, } debug(format("switching to new user environment")); - Path generation = createGeneration(profile, topLevelDrv.queryOutPath(state)); + Path generation = createGeneration(profile, topLevelOut); switchLink(profile, generation); return true; -- cgit 1.4.1