Fix build and handling of string inputs starting with a dash

Fixes #176.
This commit is contained in:
Eelco Dolstra 2014-08-13 16:24:26 +02:00
parent 69e3aa0438
commit 3520315fea

View file

@ -15,12 +15,6 @@
using namespace nix; using namespace nix;
void printHelp()
{
std::cout << "Syntax: hydra-eval-jobs <expr>\n";
}
static Path gcRootsDir; static Path gcRootsDir;
@ -227,68 +221,69 @@ static void findJobs(EvalState & state, XMLWriter & doc,
} }
void run(Strings args) int main(int argc, char * * argv)
{ {
/* Prevent undeclared dependencies in the evaluation via /* Prevent undeclared dependencies in the evaluation via
$NIX_PATH. */ $NIX_PATH. */
unsetenv("NIX_PATH"); unsetenv("NIX_PATH");
/* FIXME: hack */ return handleExceptions(argv[0], [&]() {
Strings searchPath; initNix();
Strings args2;
for (Strings::iterator i = args.begin(); i != args.end(); ) {
string arg = *i++;
if (!parseSearchPathArg(arg, i, args.end(), searchPath))
args2.push_back(arg);
}
args = args2;
EvalState state(searchPath);
Path releaseExpr;
AutoArgs autoArgs;
for (Strings::iterator i = args.begin(); i != args.end(); ) { Strings searchPath;
string arg = *i++; Path releaseExpr;
if (arg == "--arg" || arg == "--argstr") { std::map<string, Strings> autoArgs_;
/* This is like --arg in nix-instantiate, except that it
supports multiple versions for the same argument. parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
That is, autoArgs is a mapping from variable names to if (*arg == "--arg" || *arg == "--argstr") {
*lists* of values. */ /* This is like --arg in nix-instantiate, except that it
if (i == args.end()) throw UsageError("missing argument"); supports multiple versions for the same argument.
string name = *i++; That is, autoArgs is a mapping from variable names to
if (i == args.end()) throw UsageError("missing argument"); *lists* of values. */
string value = *i++; auto what = *arg;
Value * v = state.allocValue(); string name = getArg(what, arg, end);
if (arg == "--arg") string value = getArg(what, arg, end);
state.eval(state.parseExprFromString(value, absPath(".")), *v); autoArgs_[name].push_back((what == "--arg" ? 'E' : 'S') + value);
}
else if (parseSearchPathArg(arg, end, searchPath))
;
else if (*arg == "--gc-roots-dir")
gcRootsDir = getArg(*arg, arg, end);
else if (*arg != "" && arg->at(0) == '-')
return false;
else else
mkString(*v, value); releaseExpr = absPath(*arg);
autoArgs[state.symbols.create(name)].push_back(v); return true;
});
if (releaseExpr == "") throw UsageError("no expression specified");
if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified");
EvalState state(searchPath);
AutoArgs autoArgs;
for (auto & i : autoArgs_) {
for (auto & j : i.second) {
Value * v = state.allocValue();
if (j[0] == 'E')
state.eval(state.parseExprFromString(string(j, 1), absPath(".")), *v);
else
mkString(*v, string(j, 1));
autoArgs[state.symbols.create(i.first)].push_back(v);
}
} }
else if (arg == "--gc-roots-dir") { //evalAutoArgs(state, autoArgs_, autoArgs);
if (i == args.end()) throw UsageError("missing argument");
gcRootsDir = *i++;
}
else if (arg[0] == '-')
throw UsageError(format("unknown flag `%1%'") % arg);
else
releaseExpr = arg;
}
if (releaseExpr == "") throw UsageError("no expression specified"); store = openStore();
if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified"); Value v;
state.evalFile(releaseExpr, v);
store = openStore(); XMLWriter doc(true, std::cout);
XMLOpenElement root(doc, "jobs");
findJobs(state, doc, ArgsUsed(), autoArgs, v, "");
Value v; state.printStats();
state.evalFile(releaseExpr, v); });
XMLWriter doc(true, std::cout);
XMLOpenElement root(doc, "jobs");
findJobs(state, doc, ArgsUsed(), autoArgs, v, "");
state.printStats();
} }
string programId = "hydra-eval-jobs";