getDerivation(): Don't always quietly ignore assertion failure

Ignoring assertion failures makes some sense for nix-env -qa, but not
for nix-instantiate/nix-build or hydra-eval-jobs.
This commit is contained in:
Eelco Dolstra 2012-10-04 15:22:25 -04:00
parent ad328bea15
commit 70f75be199
5 changed files with 27 additions and 21 deletions

View file

@ -84,7 +84,8 @@ typedef set<Bindings *> Done;
makes sense for the caller to recursively search for derivations in
`v'. */
static bool getDerivation(EvalState & state, Value & v,
const string & attrPath, DrvInfos & drvs, Done & done)
const string & attrPath, DrvInfos & drvs, Done & done,
bool ignoreAssertionFailures)
{
try {
state.forceValue(v);
@ -116,16 +117,18 @@ static bool getDerivation(EvalState & state, Value & v,
return false;
} catch (AssertionError & e) {
return false;
if (ignoreAssertionFailures) return false;
throw;
}
}
bool getDerivation(EvalState & state, Value & v, DrvInfo & drv)
bool getDerivation(EvalState & state, Value & v, DrvInfo & drv,
bool ignoreAssertionFailures)
{
Done done;
DrvInfos drvs;
getDerivation(state, v, "", drvs, done);
getDerivation(state, v, "", drvs, done, ignoreAssertionFailures);
if (drvs.size() != 1) return false;
drv = drvs.front();
return true;
@ -140,7 +143,8 @@ static string addToPath(const string & s1, const string & s2)
static void getDerivations(EvalState & state, Value & vIn,
const string & pathPrefix, Bindings & autoArgs,
DrvInfos & drvs, Done & done)
DrvInfos & drvs, Done & done,
bool ignoreAssertionFailures)
{
Value v;
state.autoCallFunction(autoArgs, vIn, v);
@ -148,7 +152,7 @@ static void getDerivations(EvalState & state, Value & vIn,
/* Process the expression. */
DrvInfo drv;
if (!getDerivation(state, v, pathPrefix, drvs, done)) ;
if (!getDerivation(state, v, pathPrefix, drvs, done, ignoreAssertionFailures)) ;
else if (v.type == tAttrs) {
@ -171,8 +175,8 @@ static void getDerivations(EvalState & state, Value & vIn,
string pathPrefix2 = addToPath(pathPrefix, i->first);
Value & v2(*v.attrs->find(i->second)->value);
if (combineChannels)
getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done);
else if (getDerivation(state, v2, pathPrefix2, drvs, done)) {
getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
else if (getDerivation(state, v2, pathPrefix2, drvs, done, ignoreAssertionFailures)) {
/* If the value of this attribute is itself an
attribute set, should we recurse into it? => Only
if it has a `recurseForDerivations = true'
@ -180,7 +184,7 @@ static void getDerivations(EvalState & state, Value & vIn,
if (v2.type == tAttrs) {
Bindings::iterator j = v2.attrs->find(state.symbols.create("recurseForDerivations"));
if (j != v2.attrs->end() && state.forceBool(*j->value))
getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done);
getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
}
}
}
@ -191,8 +195,8 @@ static void getDerivations(EvalState & state, Value & vIn,
startNest(nest, lvlDebug,
format("evaluating list element"));
string pathPrefix2 = addToPath(pathPrefix, (format("%1%") % n).str());
if (getDerivation(state, *v.list.elems[n], pathPrefix2, drvs, done))
getDerivations(state, *v.list.elems[n], pathPrefix2, autoArgs, drvs, done);
if (getDerivation(state, *v.list.elems[n], pathPrefix2, drvs, done, ignoreAssertionFailures))
getDerivations(state, *v.list.elems[n], pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
}
}
@ -201,10 +205,10 @@ static void getDerivations(EvalState & state, Value & vIn,
void getDerivations(EvalState & state, Value & v, const string & pathPrefix,
Bindings & autoArgs, DrvInfos & drvs)
Bindings & autoArgs, DrvInfos & drvs, bool ignoreAssertionFailures)
{
Done done;
getDerivations(state, v, pathPrefix, autoArgs, drvs, done);
getDerivations(state, v, pathPrefix, autoArgs, drvs, done, ignoreAssertionFailures);
}

View file

@ -75,10 +75,12 @@ typedef list<DrvInfo> DrvInfos;
/* If value `v' denotes a derivation, store information about the
derivation in `drv' and return true. Otherwise, return false. */
bool getDerivation(EvalState & state, Value & v, DrvInfo & drv);
bool getDerivation(EvalState & state, Value & v, DrvInfo & drv,
bool ignoreAssertionFailures);
void getDerivations(EvalState & state, Value & v, const string & pathPrefix,
Bindings & autoArgs, DrvInfos & drvs);
Bindings & autoArgs, DrvInfos & drvs,
bool ignoreAssertionFailures);
}

View file

@ -166,7 +166,7 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
Value v;
findAlongAttrPath(state, pathPrefix, autoArgs, loadSourceExpr(state, nixExprPath), v);
getDerivations(state, v, pathPrefix, autoArgs, elems);
getDerivations(state, v, pathPrefix, autoArgs, elems, true);
/* Filter out all derivations not applicable to the current
system. */
@ -362,7 +362,7 @@ static void queryInstSources(EvalState & state,
Expr * e2 = state.parseExprFromString(*i, absPath("."));
Expr * call = new ExprApp(e2, e1);
Value v; state.eval(call, v);
getDerivations(state, v, "", instSource.autoArgs, elems);
getDerivations(state, v, "", instSource.autoArgs, elems, true);
}
break;
@ -417,7 +417,7 @@ static void queryInstSources(EvalState & state,
Value v;
findAlongAttrPath(state, *i, instSource.autoArgs,
loadSourceExpr(state, instSource.nixExprPath), v);
getDerivations(state, v, "", instSource.autoArgs, elems);
getDerivations(state, v, "", instSource.autoArgs, elems, true);
}
break;
}

View file

@ -25,7 +25,7 @@ DrvInfos queryInstalled(EvalState & state, const Path & userEnv)
Value v;
state.evalFile(manifestFile, v);
Bindings bindings;
getDerivations(state, v, "", bindings, elems);
getDerivations(state, v, "", bindings, elems, false);
} else if (pathExists(oldManifestFile))
readLegacyManifest(oldManifestFile, elems);
@ -127,7 +127,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
/* Evaluate it. */
debug("evaluating user environment builder");
DrvInfo topLevelDrv;
if (!getDerivation(state, topLevel, topLevelDrv))
if (!getDerivation(state, topLevel, topLevelDrv, false))
abort();
/* Realise the resulting store expression. */

View file

@ -56,7 +56,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
}
else {
DrvInfos drvs;
getDerivations(state, v, "", autoArgs, drvs);
getDerivations(state, v, "", autoArgs, drvs, false);
foreach (DrvInfos::iterator, i, drvs) {
Path drvPath = i->queryDrvPath(state);
if (gcRoot == "")