2009-03-05 14:59:43 +00:00
|
|
|
#include <map>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "shared.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "eval.hh"
|
|
|
|
#include "parser.hh"
|
2009-03-05 15:41:43 +00:00
|
|
|
#include "nixexpr-ast.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
#include "xml-writer.hh"
|
2009-03-06 15:16:29 +00:00
|
|
|
#include "get-drvs.hh"
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
|
|
using namespace nix;
|
|
|
|
|
|
|
|
|
|
|
|
void printHelp()
|
|
|
|
{
|
|
|
|
std::cout << "Syntax: eval-jobs <expr>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-05 15:41:43 +00:00
|
|
|
Expr evalAttr(EvalState & state, Expr e)
|
|
|
|
{
|
|
|
|
return e ? evalExpr(state, e) : e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void findJobs(EvalState & state, XMLWriter & doc,
|
|
|
|
Expr e, const string & attrPath)
|
|
|
|
{
|
|
|
|
std::cerr << "at `" << attrPath << "'\n";
|
|
|
|
|
|
|
|
e = evalExpr(state, e);
|
|
|
|
|
2009-03-06 15:18:59 +00:00
|
|
|
ATermList as, es, formals;
|
|
|
|
ATermBool ellipsis;
|
2009-03-05 15:41:43 +00:00
|
|
|
ATerm pat, body, pos;
|
|
|
|
string s;
|
|
|
|
PathSet context;
|
|
|
|
|
|
|
|
if (matchAttrs(e, as)) {
|
|
|
|
ATermMap attrs;
|
|
|
|
queryAllAttrs(e, attrs);
|
|
|
|
|
2009-03-06 15:16:29 +00:00
|
|
|
DrvInfo drv;
|
|
|
|
|
|
|
|
if (getDerivation(state, e, drv)) {
|
2009-03-05 15:41:43 +00:00
|
|
|
std::cerr << "derivation\n";
|
2009-03-06 15:16:29 +00:00
|
|
|
|
2009-03-05 15:41:43 +00:00
|
|
|
XMLAttrs xmlAttrs;
|
|
|
|
Path outPath, drvPath;
|
|
|
|
|
|
|
|
xmlAttrs["name"] = attrPath;
|
2009-03-06 15:16:29 +00:00
|
|
|
xmlAttrs["system"] = drv.system;
|
|
|
|
xmlAttrs["drvPath"] = drv.queryDrvPath(state);
|
|
|
|
xmlAttrs["outPath"] = drv.queryOutPath(state);
|
|
|
|
xmlAttrs["description"] = drv.queryMetaInfo(state, "description");
|
|
|
|
xmlAttrs["longDescription"] = drv.queryMetaInfo(state, "longDescription");
|
|
|
|
xmlAttrs["license"] = drv.queryMetaInfo(state, "license");
|
|
|
|
xmlAttrs["homepage"] = drv.queryMetaInfo(state, "homepage");
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
|
|
XMLOpenElement _(doc, "job", xmlAttrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
std::cerr << "attrset\n";
|
|
|
|
foreach (ATermMap::const_iterator, i, attrs)
|
|
|
|
findJobs(state, doc, i->value,
|
|
|
|
(attrPath.empty() ? "" : attrPath + ".") + aterm2String(i->key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-06 15:18:59 +00:00
|
|
|
else if (matchFunction(e, pat, body, pos) && matchAttrsPat(pat, formals, ellipsis)) {
|
2009-03-05 15:41:43 +00:00
|
|
|
std::cerr << "function\n";
|
2009-03-06 15:18:59 +00:00
|
|
|
|
|
|
|
ATermMap actualArgs(ATgetLength(formals));
|
|
|
|
|
|
|
|
for (ATermIterator i(formals); i; ++i) {
|
|
|
|
Expr name, def, value; ATerm def2;
|
|
|
|
if (!matchFormal(*i, name, def2)) abort();
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
std::cerr << showValue(e) << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-05 14:59:43 +00:00
|
|
|
void run(Strings args)
|
|
|
|
{
|
|
|
|
EvalState state;
|
|
|
|
Path releaseExpr;
|
|
|
|
|
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
|
|
|
string arg = *i++;
|
|
|
|
if (arg[0] == '-')
|
|
|
|
throw UsageError(format("unknown flag `%1%'") % arg);
|
|
|
|
else
|
|
|
|
releaseExpr = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
store = openStore();
|
|
|
|
|
2009-03-05 15:41:43 +00:00
|
|
|
Expr e = parseExprFromFile(state, releaseExpr);
|
|
|
|
|
|
|
|
XMLWriter doc(true, std::cout);
|
|
|
|
XMLOpenElement root(doc, "jobs");
|
|
|
|
findJobs(state, doc, e, "");
|
2009-03-05 14:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string programId = "eval-jobs";
|