* Report evaluation errors per job, and don't bail out if a job fails

to evaluate.
This commit is contained in:
Eelco Dolstra 2009-03-07 14:06:10 +00:00
parent ba002c6ac5
commit 5c45661141

View file

@ -65,7 +65,18 @@ static void tryJobAlts(EvalState & state, XMLWriter & doc,
} }
static void findJobs(EvalState & state, XMLWriter & doc, static void showArgsUsed(XMLWriter & doc, const ATermMap & argsUsed)
{
foreach (ATermMap::const_iterator, i, argsUsed) {
XMLAttrs xmlAttrs2;
xmlAttrs2["name"] = aterm2String(i->key);
xmlAttrs2["value"] = showValue(i->value);
doc.writeEmptyElement("arg", xmlAttrs2);
}
}
static void findJobsWrapped(EvalState & state, XMLWriter & doc,
const ATermMap & argsUsed, const ATermMap & argsLeft, const ATermMap & argsUsed, const ATermMap & argsLeft,
Expr e, const string & attrPath) Expr e, const string & attrPath)
{ {
@ -99,13 +110,7 @@ static void findJobs(EvalState & state, XMLWriter & doc,
xmlAttrs["homepage"] = drv.queryMetaInfo(state, "homepage"); xmlAttrs["homepage"] = drv.queryMetaInfo(state, "homepage");
XMLOpenElement _(doc, "job", xmlAttrs); XMLOpenElement _(doc, "job", xmlAttrs);
showArgsUsed(doc, argsUsed);
foreach (ATermMap::const_iterator, i, argsUsed) {
XMLAttrs xmlAttrs2;
xmlAttrs2["name"] = aterm2String(i->key);
xmlAttrs2["value"] = showValue(i->value);
doc.writeEmptyElement("arg", xmlAttrs2);
}
} }
else { else {
@ -120,7 +125,23 @@ static void findJobs(EvalState & state, XMLWriter & doc,
} }
else else
printMsg(lvlError, format("unknown value: %1%") % showValue(e)); throw TypeError(format("unknown value: %1%") % showValue(e));
}
static void findJobs(EvalState & state, XMLWriter & doc,
const ATermMap & argsUsed, const ATermMap & argsLeft,
Expr e, const string & attrPath)
{
try {
findJobsWrapped(state, doc, argsUsed, argsLeft, e, attrPath);
} catch (Error & e) {
XMLAttrs xmlAttrs;
xmlAttrs["location"] = attrPath;
xmlAttrs["msg"] = e.msg();
XMLOpenElement _(doc, "error", xmlAttrs);
showArgsUsed(doc, argsUsed);
}
} }
@ -132,7 +153,7 @@ void run(Strings args)
for (Strings::iterator i = args.begin(); i != args.end(); ) { for (Strings::iterator i = args.begin(); i != args.end(); ) {
string arg = *i++; string arg = *i++;
if (arg == "--arg") { if (arg == "--arg" || arg == "--argstr") {
/* This is like --arg in nix-instantiate, except that it /* This is like --arg in nix-instantiate, except that it
supports multiple versions for the same argument. supports multiple versions for the same argument.
That is, autoArgs is a mapping from variable names to That is, autoArgs is a mapping from variable names to
@ -141,7 +162,9 @@ void run(Strings args)
string name = *i++; string name = *i++;
if (i == args.end()) throw UsageError("missing argument"); if (i == args.end()) throw UsageError("missing argument");
string value = *i++; string value = *i++;
Expr e = parseExprFromString(state, value, absPath(".")); Expr e = arg == "--arg"
? parseExprFromString(state, value, absPath("."))
: makeStr(value);
autoArgs.set(toATerm(name), (ATerm) ATinsert(autoArgs.get(toATerm(name)) autoArgs.set(toATerm(name), (ATerm) ATinsert(autoArgs.get(toATerm(name))
? (ATermList) autoArgs.get(toATerm(name)) ? (ATermList) autoArgs.get(toATerm(name))
: ATempty, e)); : ATempty, e));