Skip to content

Commit

Permalink
* When querying all derivations, filter out syntactically equal deriv…
Browse files Browse the repository at this point in the history
…ations.
  • Loading branch information
edolstra committed Feb 8, 2006
1 parent 8688e83 commit 4eb637c
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions src/libexpr/get-drvs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#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;
e = evalExpr(state, e);
Expand All @@ -14,6 +18,13 @@ bool getDerivation(EvalState & state, Expr e, DrvInfo & drv)
Expr a = attrs.get("type");
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");
if (!a) throw badTerm("derivation name missing", e);
drv.name = evalString(state, a);
Expand All @@ -26,11 +37,23 @@ bool getDerivation(EvalState & state, Expr e, DrvInfo & drv)

drv.attrs = attrs;

drvs.push_back(drv);
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;
DrvInfo drv;
Expand All @@ -47,22 +70,16 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs)
queryAllAttrs(e, drvMap);
for (ATermIterator i(drvMap.keys()); i; ++i) {
debug(format("evaluating attribute `%1%'") % aterm2String(*i));
if (getDerivation(state, drvMap.get(*i), drv))
drvs.push_back(drv);
else
;
// parseDerivations(state, drvMap.get(*i), drvs);
getDerivation(state, drvMap.get(*i), drvs, doneExprs);
}
return;
}

if (matchList(e, es)) {
for (ATermIterator i(es); i; ++i) {
debug(format("evaluating list element"));
if (getDerivation(state, *i, drv))
drvs.push_back(drv);
else
getDerivations(state, *i, drvs);
if (!getDerivation(state, *i, drvs, doneExprs))
getDerivations(state, *i, drvs, doneExprs);
}
return;
}
Expand All @@ -78,9 +95,16 @@ void getDerivations(EvalState & state, Expr e, DrvInfos & drvs)
else if (!matchDefFormal(*i, name, def))
abort(); /* can't happen */
}
getDerivations(state, makeCall(e, makeAttrs(ATermMap())), drvs);
getDerivations(state, makeCall(e, makeAttrs(ATermMap())), drvs, doneExprs);
return;
}

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);
}

0 comments on commit 4eb637c

Please sign in to comment.