* Add a primop to return the context of a string.

This commit is contained in:
Eelco Dolstra 2010-01-31 20:54:44 +00:00
parent 6d1abdc6d9
commit 29fd60131b
2 changed files with 19 additions and 3 deletions

View File

@ -350,8 +350,13 @@ string coerceToString(EvalState & state, Expr e, Context & context,
if (matchAttrs(e, es)) {
Expr e2 = queryAttr(e, "outPath");
if (!e2) throwTypeError("cannot coerce an attribute set (except a derivation) to a string");
/* XXX handle derivation */
return coerceToString(state, e2, context, coerceMore, copyToStore);
/* !!! hacky */
ATermList c;
string s = evalString(state, e2, c);
Context c2; matchContext(c, c2);
foreach (Context::const_iterator, i, c2)
context.set(i->key, e);
return s;
}
if (coerceMore) {

View File

@ -524,7 +524,6 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
state.drvHashes[drvPath] = hashDerivationModulo(state, drv);
/* !!! assumes a single output */
/* XXX makeNull? */
ATermMap outAttrs(2);
outAttrs.set(toATerm("outPath"),
makeAttrRHS(makeStr(outPath, ATmakeList1(makeContextElem(toATerm(drvPath), makeNull()))), makeNoPos()));
@ -1065,6 +1064,17 @@ static Expr prim_unsafeDiscardOutputDependency(EvalState & state, const ATermVec
}
static Expr prim_queryStringContext(EvalState & state, const ATermVector & args)
{
Context context;
string s = coerceToString(state, args[0], context);
ATermList l = ATempty;
foreach (Context::const_iterator, i, context)
l = ATinsert(l, i->value);
return makeList(l);
}
/* Expression serialization/deserialization */
@ -1181,6 +1191,7 @@ void EvalState::addPrimOps()
addPrimOp("__stringLength", 1, prim_stringLength);
addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext);
addPrimOp("__unsafeDiscardOutputDependency", 1, prim_unsafeDiscardOutputDependency);
addPrimOp("__queryStringContext", 1, prim_queryStringContext);
// Versions
addPrimOp("__parseDrvName", 1, prim_parseDrvName);