update from upstream

This commit is contained in:
Jörg Thalheim 2021-03-14 23:16:57 +01:00
parent 0f22a976e5
commit ac566dea95
No known key found for this signature in database
GPG Key ID: B3F5D81B0C6967C4

View File

@ -1,6 +1,8 @@
#include <map> #include <map>
#include <iostream> #include <iostream>
#include <iomanip>
#include <thread> #include <thread>
#include <algorithm>
#include <nix/config.h> #include <nix/config.h>
#include <nix/shared.hh> #include <nix/shared.hh>
@ -41,9 +43,15 @@ struct MyArgs : MixEvalArgs, MixCommonArgs
.longName = "help", .longName = "help",
.description = "show usage information", .description = "show usage information",
.handler = {[&]() { .handler = {[&]() {
printHelp(programName, std::cout); std::cout << "Usage:" << std::endl;
throw Exit(); std::cout << " " << "hydra-eval-jobs [options] expr" << std::endl;
}} for (const auto & [name, flag] : longFlags) {
if (hiddenCategories.count(flag->category)) {
continue;
}
printf(" --%-20s %s\n", name.c_str(), flag->description.c_str());
}
}},
}); });
addFlag({ addFlag({
@ -96,12 +104,12 @@ static std::string queryMetaStrings(EvalState & state, DrvInfo & drv, const stri
rec = [&](Value & v) { rec = [&](Value & v) {
state.forceValue(v); state.forceValue(v);
if (v.type == tString) if (v.type() == nString)
res.push_back(v.string.s); res.push_back(v.string.s);
else if (v.isList()) else if (v.isList())
for (unsigned int n = 0; n < v.listSize(); ++n) for (unsigned int n = 0; n < v.listSize(); ++n)
rec(*v.listElems()[n]); rec(*v.listElems()[n]);
else if (v.type == tAttrs) { else if (v.type() == nAttrs) {
auto a = v.attrs->find(state.symbols.create(subAttribute)); auto a = v.attrs->find(state.symbols.create(subAttribute));
if (a != v.attrs->end()) if (a != v.attrs->end())
res.push_back(state.forceString(*a->value)); res.push_back(state.forceString(*a->value));
@ -219,7 +227,7 @@ static void worker(
for (unsigned int n = 0; n < a->value->listSize(); ++n) { for (unsigned int n = 0; n < a->value->listSize(); ++n) {
auto v = a->value->listElems()[n]; auto v = a->value->listElems()[n];
state.forceValue(*v); state.forceValue(*v);
if (v->type == tString) if (v->type() == nString)
job["namedConstituents"].push_back(state.forceStringNoCtx(*v)); job["namedConstituents"].push_back(state.forceStringNoCtx(*v));
} }
} }
@ -242,7 +250,7 @@ static void worker(
reply["job"] = std::move(job); reply["job"] = std::move(job);
} }
else if (v->type == tAttrs) { else if (v->type() == nAttrs) {
auto attrs = nlohmann::json::array(); auto attrs = nlohmann::json::array();
StringSet ss; StringSet ss;
for (auto & i : v->attrs->lexicographicOrder()) { for (auto & i : v->attrs->lexicographicOrder()) {
@ -256,18 +264,19 @@ static void worker(
reply["attrs"] = std::move(attrs); reply["attrs"] = std::move(attrs);
} }
else if (v->type == tNull) else if (v->type() == nNull)
; ;
else throw TypeError("attribute '%s' is %s, which is not supported", attrPath, showType(*v)); else throw TypeError("attribute '%s' is %s, which is not supported", attrPath, showType(*v));
} catch (EvalError & e) { } catch (EvalError & e) {
auto msg = e.msg();
// Transmits the error we got from the previous evaluation // Transmits the error we got from the previous evaluation
// in the JSON output. // in the JSON output.
reply["error"] = filterANSIEscapes(e.msg(), true); reply["error"] = filterANSIEscapes(msg, true);
// Don't forget to print it into the STDERR log, this is // Don't forget to print it into the STDERR log, this is
// what's shown in the Hydra UI. // what's shown in the Hydra UI.
printError("error: %s", reply["error"]); printError(msg);
} }
writeLine(to.get(), reply.dump()); writeLine(to.get(), reply.dump());
@ -347,13 +356,15 @@ int main(int argc, char * * argv)
EvalState state(myArgs.searchPath, openStore()); EvalState state(myArgs.searchPath, openStore());
Bindings & autoArgs = *myArgs.getAutoArgs(state); Bindings & autoArgs = *myArgs.getAutoArgs(state);
worker(state, autoArgs, *to, *from); worker(state, autoArgs, *to, *from);
} catch (std::exception & e) { } catch (Error & e) {
nlohmann::json err; nlohmann::json err;
err["error"] = e.what(); auto msg = e.msg();
err["error"] = filterANSIEscapes(msg, true);
printError(msg);
writeLine(to->get(), err.dump()); writeLine(to->get(), err.dump());
// Don't forget to print it into the STDERR log, this is // Don't forget to print it into the STDERR log, this is
// what's shown in the Hydra UI. // what's shown in the Hydra UI.
printError("error: %s", err["error"]); writeLine(to->get(), "restart");
} }
}, },
ProcessOptions { .allowVfork = false }); ProcessOptions { .allowVfork = false });