Fix build and handling of string inputs starting with a dash
Fixes #176.
This commit is contained in:
parent
69e3aa0438
commit
3520315fea
|
@ -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,57 +221,60 @@ 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_;
|
||||||
|
|
||||||
|
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
|
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
|
||||||
*lists* of values. */
|
*lists* of values. */
|
||||||
if (i == args.end()) throw UsageError("missing argument");
|
auto what = *arg;
|
||||||
string name = *i++;
|
string name = getArg(what, arg, end);
|
||||||
if (i == args.end()) throw UsageError("missing argument");
|
string value = getArg(what, arg, end);
|
||||||
string value = *i++;
|
autoArgs_[name].push_back((what == "--arg" ? 'E' : 'S') + value);
|
||||||
Value * v = state.allocValue();
|
}
|
||||||
if (arg == "--arg")
|
else if (parseSearchPathArg(arg, end, searchPath))
|
||||||
state.eval(state.parseExprFromString(value, absPath(".")), *v);
|
;
|
||||||
|
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;
|
||||||
}
|
});
|
||||||
else if (arg == "--gc-roots-dir") {
|
|
||||||
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");
|
if (releaseExpr == "") throw UsageError("no expression specified");
|
||||||
|
|
||||||
if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//evalAutoArgs(state, autoArgs_, autoArgs);
|
||||||
|
|
||||||
store = openStore();
|
store = openStore();
|
||||||
|
|
||||||
Value v;
|
Value v;
|
||||||
|
@ -288,7 +285,5 @@ void run(Strings args)
|
||||||
findJobs(state, doc, ArgsUsed(), autoArgs, v, "");
|
findJobs(state, doc, ArgsUsed(), autoArgs, v, "");
|
||||||
|
|
||||||
state.printStats();
|
state.printStats();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string programId = "hydra-eval-jobs";
|
|
||||||
|
|
Loading…
Reference in a new issue