2009-03-05 14:59:43 +00:00
|
|
|
|
#include <map>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include "shared.hh"
|
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
#include "eval.hh"
|
2012-10-04 15:24:25 -04:00
|
|
|
|
#include "eval-inline.hh"
|
2009-03-05 15:41:43 +00:00
|
|
|
|
#include "util.hh"
|
2009-03-06 15:16:29 +00:00
|
|
|
|
#include "get-drvs.hh"
|
2014-09-12 14:30:01 +02:00
|
|
|
|
#include "globals.hh"
|
2017-10-26 13:10:14 +02:00
|
|
|
|
#include "common-eval-args.hh"
|
2020-02-19 21:10:22 +01:00
|
|
|
|
#include "attr-path.hh"
|
|
|
|
|
#include "derivations.hh"
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2018-05-16 14:14:53 +02:00
|
|
|
|
#include "hydra-config.hh"
|
|
|
|
|
|
2018-06-05 12:18:55 +02:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/wait.h>
|
2020-02-19 21:10:22 +01:00
|
|
|
|
#include <sys/resource.h>
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
#include <nlohmann/json.hpp>
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
using namespace nix;
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2009-03-15 11:56:11 +00:00
|
|
|
|
static Path gcRootsDir;
|
2020-02-19 21:10:22 +01:00
|
|
|
|
static size_t maxMemorySize;
|
2009-03-15 11:56:11 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
struct MyArgs : MixEvalArgs, MixCommonArgs
|
|
|
|
|
{
|
|
|
|
|
Path releaseExpr;
|
|
|
|
|
bool dryRun = false;
|
|
|
|
|
|
|
|
|
|
MyArgs() : MixCommonArgs("hydra-eval-jobs")
|
|
|
|
|
{
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("help")
|
|
|
|
|
.description("show usage information")
|
|
|
|
|
.handler([&]() {
|
|
|
|
|
printHelp(programName, std::cout);
|
|
|
|
|
throw Exit();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("gc-roots-dir")
|
|
|
|
|
.description("garbage collector roots directory")
|
|
|
|
|
.labels({"path"})
|
|
|
|
|
.dest(&gcRootsDir);
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("dry-run")
|
|
|
|
|
.description("don't create store derivations")
|
|
|
|
|
.set(&dryRun, true);
|
|
|
|
|
|
|
|
|
|
expectArg("expr", &releaseExpr);
|
|
|
|
|
}
|
|
|
|
|
};
|
2009-03-15 11:56:11 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
static MyArgs myArgs;
|
2009-03-07 14:06:10 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
static std::string queryMetaStrings(EvalState & state, DrvInfo & drv, const string & name, const string & subAttribute)
|
2009-07-07 13:20:00 +00:00
|
|
|
|
{
|
2015-10-08 11:56:30 +02:00
|
|
|
|
Strings res;
|
|
|
|
|
std::function<void(Value & v)> rec;
|
|
|
|
|
|
|
|
|
|
rec = [&](Value & v) {
|
|
|
|
|
state.forceValue(v);
|
|
|
|
|
if (v.type == tString)
|
|
|
|
|
res.push_back(v.string.s);
|
|
|
|
|
else if (v.isList())
|
|
|
|
|
for (unsigned int n = 0; n < v.listSize(); ++n)
|
|
|
|
|
rec(*v.listElems()[n]);
|
|
|
|
|
else if (v.type == tAttrs) {
|
2018-12-29 14:47:03 +01:00
|
|
|
|
auto a = v.attrs->find(state.symbols.create(subAttribute));
|
2015-10-08 11:56:30 +02:00
|
|
|
|
if (a != v.attrs->end())
|
|
|
|
|
res.push_back(state.forceString(*a->value));
|
2013-11-04 22:50:32 +01:00
|
|
|
|
}
|
2015-10-08 11:56:30 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Value * v = drv.queryMeta(name);
|
|
|
|
|
if (v) rec(*v);
|
|
|
|
|
|
|
|
|
|
return concatStringsSep(", ", res);
|
2013-11-04 22:50:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
static void worker(
|
|
|
|
|
EvalState & state,
|
|
|
|
|
Bindings & autoArgs,
|
|
|
|
|
AutoCloseFD & to,
|
|
|
|
|
AutoCloseFD & from)
|
|
|
|
|
{
|
|
|
|
|
Value vTop;
|
|
|
|
|
state.evalFile(lookupFileArg(state, myArgs.releaseExpr), vTop);
|
2013-11-04 22:50:32 +01:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto vRoot = state.allocValue();
|
|
|
|
|
state.autoCallFunction(autoArgs, vTop, *vRoot);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
while (true) {
|
|
|
|
|
/* Wait for the master to send us a job name. */
|
|
|
|
|
writeLine(to.get(), "next");
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto s = readLine(from.get());
|
|
|
|
|
if (s == "exit") break;
|
|
|
|
|
if (!hasPrefix(s, "do ")) abort();
|
|
|
|
|
std::string attrPath(s, 3);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
debug("worker process %d at '%s'", getpid(), attrPath);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Evaluate it and send info back to the master. */
|
|
|
|
|
nlohmann::json reply;
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
try {
|
2020-03-04 15:16:04 +01:00
|
|
|
|
auto vTmp = findAlongAttrPath(state, attrPath, autoArgs, *vRoot);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-03-04 15:16:04 +01:00
|
|
|
|
auto v = state.allocValue();
|
|
|
|
|
state.autoCallFunction(autoArgs, *vTmp, *v);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (auto drv = getDerivation(state, *v, false)) {
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
DrvInfo::Outputs outputs = drv->queryOutputs();
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (drv->querySystem() == "unknown")
|
|
|
|
|
throw EvalError("derivation must have a 'system' attribute");
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto drvPath = drv->queryDrvPath();
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
nlohmann::json job;
|
2013-08-14 01:59:29 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
job["nixName"] = drv->queryName();
|
|
|
|
|
job["system"] =drv->querySystem();
|
|
|
|
|
job["drvPath"] = drvPath;
|
|
|
|
|
job["description"] = drv->queryMetaString("description");
|
|
|
|
|
job["license"] = queryMetaStrings(state, *drv, "license", "shortName");
|
|
|
|
|
job["homepage"] = drv->queryMetaString("homepage");
|
|
|
|
|
job["maintainers"] = queryMetaStrings(state, *drv, "maintainers", "email");
|
|
|
|
|
job["schedulingPriority"] = drv->queryMetaInt("schedulingPriority", 100);
|
|
|
|
|
job["timeout"] = drv->queryMetaInt("timeout", 36000);
|
|
|
|
|
job["maxSilent"] = drv->queryMetaInt("maxSilent", 7200);
|
|
|
|
|
job["isChannel"] = drv->queryMetaBool("isHydraChannel", false);
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* If this is an aggregate, then get its constituents. */
|
|
|
|
|
auto a = v->attrs->get(state.symbols.create("_hydraAggregate"));
|
2020-02-20 11:19:45 +01:00
|
|
|
|
if (a && state.forceBool(*(*a)->value, *(*a)->pos)) {
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto a = v->attrs->get(state.symbols.create("constituents"));
|
|
|
|
|
if (!a)
|
|
|
|
|
throw EvalError("derivation must have a ‘constituents’ attribute");
|
2015-03-18 22:03:55 +01:00
|
|
|
|
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
PathSet context;
|
2020-02-20 11:19:45 +01:00
|
|
|
|
state.coerceToString(*(*a)->pos, *(*a)->value, context, true, false);
|
2020-02-19 21:10:22 +01:00
|
|
|
|
for (auto & i : context)
|
|
|
|
|
if (i.at(0) == '!') {
|
|
|
|
|
size_t index = i.find("!", 1);
|
|
|
|
|
job["constituents"].push_back(string(i, index + 1));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 11:19:45 +01:00
|
|
|
|
state.forceList(*(*a)->value, *(*a)->pos);
|
|
|
|
|
for (unsigned int n = 0; n < (*a)->value->listSize(); ++n) {
|
|
|
|
|
auto v = (*a)->value->listElems()[n];
|
2020-02-19 21:10:22 +01:00
|
|
|
|
state.forceValue(*v);
|
|
|
|
|
if (v->type == tString)
|
|
|
|
|
job["namedConstituents"].push_back(state.forceStringNoCtx(*v));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Register the derivation as a GC root. !!! This
|
|
|
|
|
registers roots for jobs that we may have already
|
|
|
|
|
done. */
|
|
|
|
|
auto localStore = state.store.dynamic_pointer_cast<LocalFSStore>();
|
|
|
|
|
if (gcRootsDir != "" && localStore) {
|
|
|
|
|
Path root = gcRootsDir + "/" + std::string(baseNameOf(drvPath));
|
|
|
|
|
if (!pathExists(root))
|
|
|
|
|
localStore->addPermRoot(localStore->parseStorePath(drvPath), root, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nlohmann::json out;
|
|
|
|
|
for (auto & j : outputs)
|
|
|
|
|
out[j.first] = j.second;
|
|
|
|
|
job["outputs"] = std::move(out);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
reply["job"] = std::move(job);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
else if (v->type == tAttrs) {
|
|
|
|
|
auto attrs = nlohmann::json::array();
|
|
|
|
|
StringSet ss;
|
|
|
|
|
for (auto & i : v->attrs->lexicographicOrder()) {
|
2018-06-05 12:18:55 +02:00
|
|
|
|
std::string name(i->name);
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (name.find('.') != std::string::npos || name.find(' ') != std::string::npos) {
|
2018-06-05 12:18:55 +02:00
|
|
|
|
printError("skipping job with illegal name '%s'", name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2020-02-19 21:10:22 +01:00
|
|
|
|
attrs.push_back(name);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
}
|
2020-02-19 21:10:22 +01:00
|
|
|
|
reply["attrs"] = std::move(attrs);
|
2012-10-04 14:31:47 -04:00
|
|
|
|
}
|
2012-02-16 11:03:22 +01:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
} catch (EvalError & e) {
|
|
|
|
|
reply["error"] = filterANSIEscapes(e.msg(), true);
|
|
|
|
|
}
|
2009-03-07 14:06:10 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
writeLine(to.get(), reply.dump());
|
2009-03-07 14:06:10 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* If our RSS exceeds the maximum, exit. The master will
|
|
|
|
|
start a new process. */
|
|
|
|
|
struct rusage r;
|
|
|
|
|
getrusage(RUSAGE_SELF, &r);
|
|
|
|
|
if ((size_t) r.ru_maxrss > maxMemorySize * 1024) break;
|
2009-03-07 14:06:10 +00:00
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
writeLine(to.get(), "restart");
|
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2014-08-13 16:24:26 +02:00
|
|
|
|
int main(int argc, char * * argv)
|
2009-03-05 14:59:43 +00:00
|
|
|
|
{
|
2012-05-23 14:44:10 -04:00
|
|
|
|
/* Prevent undeclared dependencies in the evaluation via
|
|
|
|
|
$NIX_PATH. */
|
|
|
|
|
unsetenv("NIX_PATH");
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2014-08-13 16:24:26 +02:00
|
|
|
|
return handleExceptions(argv[0], [&]() {
|
2018-05-16 14:14:53 +02:00
|
|
|
|
|
|
|
|
|
auto config = std::make_unique<::Config>();
|
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto nrWorkers = config->getIntOption("evaluator_workers", 1);
|
|
|
|
|
maxMemorySize = config->getIntOption("evaluator_max_memory_size", 4096);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2014-08-13 16:24:26 +02:00
|
|
|
|
initNix();
|
2015-03-19 20:16:38 +01:00
|
|
|
|
initGC();
|
2014-08-13 16:24:26 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
myArgs.parseCmdline(argvToStrings(argc, argv));
|
2018-12-21 22:57:07 -05:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* FIXME: The build hook in conjunction with import-from-derivation is causing "unexpected EOF" during eval */
|
|
|
|
|
settings.builders = "";
|
|
|
|
|
|
|
|
|
|
/* Prevent access to paths outside of the Nix search path and
|
|
|
|
|
to the environment. */
|
|
|
|
|
evalSettings.restrictEval = true;
|
|
|
|
|
|
|
|
|
|
if (myArgs.dryRun) settings.readOnlyMode = true;
|
|
|
|
|
|
|
|
|
|
if (myArgs.releaseExpr == "") throw UsageError("no expression specified");
|
2018-12-21 22:57:07 -05:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (gcRootsDir == "") printMsg(lvlError, "warning: `--gc-roots-dir' not specified");
|
2017-10-26 13:10:14 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
struct State
|
2017-10-26 13:10:14 +02:00
|
|
|
|
{
|
2020-02-19 21:10:22 +01:00
|
|
|
|
std::set<std::string> todo{""};
|
|
|
|
|
std::set<std::string> active;
|
|
|
|
|
nlohmann::json jobs;
|
|
|
|
|
std::exception_ptr exc;
|
2017-10-26 13:10:14 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
std::condition_variable wakeup;
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
Sync<State> state_;
|
2017-03-20 12:57:05 -04:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Start a handler thread per worker process. */
|
|
|
|
|
auto handler = [&]()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
pid_t pid = -1;
|
|
|
|
|
AutoCloseFD from, to;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
|
|
/* Start a new worker process if necessary. */
|
|
|
|
|
if (pid == -1) {
|
|
|
|
|
Pipe toPipe, fromPipe;
|
|
|
|
|
toPipe.create();
|
|
|
|
|
fromPipe.create();
|
|
|
|
|
pid = startProcess(
|
|
|
|
|
[&,
|
|
|
|
|
to{std::make_shared<AutoCloseFD>(std::move(fromPipe.writeSide))},
|
|
|
|
|
from{std::make_shared<AutoCloseFD>(std::move(toPipe.readSide))}
|
|
|
|
|
]()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
EvalState state(myArgs.searchPath, openStore());
|
|
|
|
|
Bindings & autoArgs = *myArgs.getAutoArgs(state);
|
|
|
|
|
worker(state, autoArgs, *to, *from);
|
|
|
|
|
} catch (std::exception & e) {
|
|
|
|
|
nlohmann::json err;
|
|
|
|
|
err["error"] = e.what();
|
|
|
|
|
writeLine(to->get(), err.dump());
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ProcessOptions { .allowVfork = false });
|
|
|
|
|
from = std::move(fromPipe.readSide);
|
|
|
|
|
to = std::move(toPipe.writeSide);
|
|
|
|
|
debug("created worker process %d", pid);
|
|
|
|
|
}
|
2015-04-14 15:16:00 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Check whether the existing worker process is still there. */
|
|
|
|
|
auto s = readLine(from.get());
|
|
|
|
|
if (s == "restart") {
|
|
|
|
|
pid = -1;
|
|
|
|
|
continue;
|
|
|
|
|
} else if (s != "next") {
|
|
|
|
|
auto json = nlohmann::json::parse(s);
|
|
|
|
|
throw Error("worker error: %s", (std::string) json["error"]);
|
|
|
|
|
}
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Wait for a job name to become available. */
|
|
|
|
|
std::string attrPath;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
checkInterrupt();
|
|
|
|
|
auto state(state_.lock());
|
|
|
|
|
if ((state->todo.empty() && state->active.empty()) || state->exc) {
|
|
|
|
|
writeLine(to.get(), "exit");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!state->todo.empty()) {
|
|
|
|
|
attrPath = *state->todo.begin();
|
|
|
|
|
state->todo.erase(state->todo.begin());
|
|
|
|
|
state->active.insert(attrPath);
|
|
|
|
|
break;
|
|
|
|
|
} else
|
|
|
|
|
state.wait(wakeup);
|
|
|
|
|
}
|
2013-01-22 14:41:02 +01:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Tell the worker to evaluate it. */
|
|
|
|
|
writeLine(to.get(), "do " + attrPath);
|
2018-08-10 20:25:43 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Wait for the response. */
|
|
|
|
|
auto response = nlohmann::json::parse(readLine(from.get()));
|
2017-10-26 13:10:14 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Handle the response. */
|
|
|
|
|
StringSet newAttrs;
|
2018-08-10 20:25:43 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (response.find("job") != response.end()) {
|
|
|
|
|
auto state(state_.lock());
|
|
|
|
|
state->jobs[attrPath] = response["job"];
|
|
|
|
|
}
|
2009-03-05 15:41:43 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (response.find("attrs") != response.end()) {
|
|
|
|
|
for (auto & i : response["attrs"]) {
|
|
|
|
|
auto s = (attrPath.empty() ? "" : attrPath + ".") + (std::string) i;
|
|
|
|
|
newAttrs.insert(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-05 14:59:43 +00:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (response.find("error") != response.end()) {
|
|
|
|
|
auto state(state_.lock());
|
|
|
|
|
state->jobs[attrPath]["error"] = response["error"];
|
|
|
|
|
}
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* Add newly discovered job names to the queue. */
|
|
|
|
|
{
|
|
|
|
|
auto state(state_.lock());
|
|
|
|
|
state->active.erase(attrPath);
|
|
|
|
|
for (auto & s : newAttrs)
|
|
|
|
|
state->todo.insert(s);
|
|
|
|
|
wakeup.notify_all();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (...) {
|
|
|
|
|
auto state(state_.lock());
|
|
|
|
|
state->exc = std::current_exception();
|
|
|
|
|
wakeup.notify_all();
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
|
for (size_t i = 0; i < nrWorkers; i++)
|
|
|
|
|
threads.emplace_back(std::thread(handler));
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
for (auto & thread : threads)
|
|
|
|
|
thread.join();
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto state(state_.lock());
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (state->exc)
|
|
|
|
|
std::rethrow_exception(state->exc);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
/* For aggregate jobs that have named consistuents
|
|
|
|
|
(i.e. constituents that are a job name rather than a
|
|
|
|
|
derivation), look up the referenced job and add it to the
|
|
|
|
|
dependencies of the aggregate derivation. */
|
|
|
|
|
auto store = openStore();
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
for (auto i = state->jobs.begin(); i != state->jobs.end(); ++i) {
|
|
|
|
|
auto jobName = i.key();
|
|
|
|
|
auto & job = i.value();
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
auto named = job.find("namedConstituents");
|
|
|
|
|
if (named == job.end()) continue;
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
if (myArgs.dryRun) {
|
|
|
|
|
for (std::string jobName2 : *named) {
|
|
|
|
|
auto job2 = state->jobs.find(jobName2);
|
|
|
|
|
if (job2 == state->jobs.end())
|
|
|
|
|
throw Error("aggregate job '%s' references non-existent job '%s'", jobName, jobName2);
|
|
|
|
|
std::string drvPath2 = (*job2)["drvPath"];
|
|
|
|
|
job["constituents"].push_back(drvPath2);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
std::string drvPath = job["drvPath"];
|
|
|
|
|
auto drv = readDerivation(*store, drvPath);
|
|
|
|
|
|
|
|
|
|
for (std::string jobName2 : *named) {
|
|
|
|
|
auto job2 = state->jobs.find(jobName2);
|
|
|
|
|
if (job2 == state->jobs.end())
|
|
|
|
|
throw Error("aggregate job '%s' references non-existent job '%s'", jobName, jobName2);
|
|
|
|
|
std::string drvPath2 = (*job2)["drvPath"];
|
|
|
|
|
auto drv2 = readDerivation(*store, drvPath2);
|
|
|
|
|
job["constituents"].push_back(drvPath2);
|
|
|
|
|
drv.inputDrvs[store->parseStorePath(drvPath2)] = {drv2.outputs.begin()->first};
|
|
|
|
|
}
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
std::string drvName(store->parseStorePath(drvPath).name());
|
|
|
|
|
assert(hasSuffix(drvName, drvExtension));
|
|
|
|
|
drvName.resize(drvName.size() - drvExtension.size());
|
|
|
|
|
auto h = hashDerivationModulo(*store, drv, true);
|
|
|
|
|
auto outPath = store->makeOutputPath("out", h, drvName);
|
|
|
|
|
drv.env["out"] = store->printStorePath(outPath);
|
|
|
|
|
drv.outputs.insert_or_assign("out", DerivationOutput(outPath.clone(), "", ""));
|
|
|
|
|
auto newDrvPath = store->printStorePath(writeDerivation(store, drv, drvName));
|
2018-08-10 20:25:43 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
debug("rewrote aggregate derivation %s -> %s", drvPath, newDrvPath);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
job["drvPath"] = newDrvPath;
|
|
|
|
|
job["outputs"]["out"] = store->printStorePath(outPath);
|
2018-06-05 12:18:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
job.erase("namedConstituents");
|
|
|
|
|
}
|
2018-08-07 11:47:53 +02:00
|
|
|
|
|
2020-02-19 21:10:22 +01:00
|
|
|
|
std::cout << state->jobs.dump(2) << "\n";
|
2014-08-13 16:24:26 +02:00
|
|
|
|
});
|
|
|
|
|
}
|