* When querying all derivations, filter out syntactically equal derivations.

This commit is contained in:
Eelco Dolstra 2006-02-08 16:15:07 +00:00
parent 8688e83194
commit 4eb637c799

View file

@ -2,7 +2,11 @@
#include "nixexpr-ast.hh" #include "nixexpr-ast.hh"
bool getDerivation(EvalState & state, Expr e, DrvInfo & drv) typedef set<Expr> Exprs;
static bool getDerivation(EvalState & state, Expr e,
DrvInfos & drvs, Exprs & doneExprs)
{ {
ATermList es; ATermList es;
e = evalExpr(state, e); e = evalExpr(state, e);
@ -14,6 +18,13 @@ bool getDerivation(EvalState & state, Expr e, DrvInfo & drv)
Expr a = attrs.get("type"); Expr a = attrs.get("type");
if (!a || evalString(state, a) != "derivation") return false; if (!a || evalString(state, a) != "derivation") return false;
/* Remove spurious duplicates (e.g., an attribute set like `rec {
x = derivation {...}; y = x;}'. */
if (doneExprs.find(e) != doneExprs.end()) return true;
doneExprs.insert(e);
DrvInfo drv;
a = attrs.get("name"); a = attrs.get("name");
if (!a) throw badTerm("derivation name missing", e); if (!a) throw badTerm("derivation name missing", e);
drv.name = evalString(state, a); drv.name = evalString(state, a);
@ -26,11 +37,23 @@ bool getDerivation(EvalState & state, Expr e, DrvInfo & drv)
drv.attrs = attrs; drv.attrs = attrs;
drvs.push_back(drv);
return true; return true;
} }
void getDerivations(EvalState & state, Expr e, DrvInfos & drvs) bool getDerivation(EvalState & state, Expr e, DrvInfo & drv)
{
Exprs doneExprs;
DrvInfos drvs;
bool result = getDerivation(state, e, drvs, doneExprs);
if (result) drv = drvs.front();
return result;
}
static void getDerivations(EvalState & state, Expr e,
DrvInfos & drvs, Exprs & doneExprs)
{ {
ATermList es; ATermList es;
DrvInfo drv; DrvInfo drv;
@ -47,11 +70,7 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs)
queryAllAttrs(e, drvMap); queryAllAttrs(e, drvMap);
for (ATermIterator i(drvMap.keys()); i; ++i) { for (ATermIterator i(drvMap.keys()); i; ++i) {
debug(format("evaluating attribute `%1%'") % aterm2String(*i)); debug(format("evaluating attribute `%1%'") % aterm2String(*i));
if (getDerivation(state, drvMap.get(*i), drv)) getDerivation(state, drvMap.get(*i), drvs, doneExprs);
drvs.push_back(drv);
else
;
// parseDerivations(state, drvMap.get(*i), drvs);
} }
return; return;
} }
@ -59,10 +78,8 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs)
if (matchList(e, es)) { if (matchList(e, es)) {
for (ATermIterator i(es); i; ++i) { for (ATermIterator i(es); i; ++i) {
debug(format("evaluating list element")); debug(format("evaluating list element"));
if (getDerivation(state, *i, drv)) if (!getDerivation(state, *i, drvs, doneExprs))
drvs.push_back(drv); getDerivations(state, *i, drvs, doneExprs);
else
getDerivations(state, *i, drvs);
} }
return; return;
} }
@ -78,9 +95,16 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs)
else if (!matchDefFormal(*i, name, def)) else if (!matchDefFormal(*i, name, def))
abort(); /* can't happen */ abort(); /* can't happen */
} }
getDerivations(state, makeCall(e, makeAttrs(ATermMap())), drvs); getDerivations(state, makeCall(e, makeAttrs(ATermMap())), drvs, doneExprs);
return; return;
} }
throw Error("expression does not evaluate to a derivation (or a set or list of those)"); throw Error("expression does not evaluate to a derivation (or a set or list of those)");
} }
void getDerivations(EvalState & state, Expr e, DrvInfos & drvs)
{
Exprs doneExprs;
getDerivations(state, e, drvs, doneExprs);
}