mirror of
https://github.com/NixOS/nix.git
synced 2025-02-16 08:53:14 +00:00
* Add a primop to return the context of a string.
This commit is contained in:
parent
6d1abdc6d9
commit
29fd60131b
@ -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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user