From aa5a5084e4855ff612d27913a920ffab073e7b42 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 12 May 2004 13:32:26 +0000 Subject: [PATCH] * Pass to the build hook all sorts of information useful for distributing a build action to another machine. In particular, the paths in the input closures, the output paths, and successor mapping for sub-derivations. --- src/libstore/normalise.cc | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc index 0c8a8057fd..b6746689e3 100644 --- a/src/libstore/normalise.cc +++ b/src/libstore/normalise.cc @@ -322,18 +322,17 @@ bool Normaliser::startBuild(Path nePath) return true; } - /* Right platform? */ - if (goal.expr.derivation.platform != thisSystem) - throw Error(format("a `%1%' is required, but I am a `%2%'") - % goal.expr.derivation.platform % thisSystem); - /* Realise inputs (and remember all input paths). */ + PathSet fnord; + map xyzzy; for (PathSet::iterator i = goal.expr.derivation.inputs.begin(); i != goal.expr.derivation.inputs.end(); ++i) { checkInterrupt(); Path nfPath = useSuccessor(*i); realiseClosure(nfPath); + fnord.insert(nfPath); + if (nfPath != *i) xyzzy[*i] = nfPath; /* !!! nfPath should be a root of the garbage collector while we are building */ StoreExpr ne = storeExprFromPath(nfPath); @@ -369,7 +368,38 @@ bool Normaliser::startBuild(Path nePath) Path buildHook = getEnv("NIX_BUILD_HOOK"); if (buildHook != "") { printMsg(lvlChatty, format("using build hook `%1%'") % buildHook); - int status = system((buildHook + " " + goal.nePath + " 1>&2").c_str()); + + Path hookTmpDir = createTempDir(); + Path inputListFN = hookTmpDir + "/inputs"; + Path outputListFN = hookTmpDir + "/outputs"; + Path successorsListFN = hookTmpDir + "/successors"; + + string s; + for (ClosureElems::iterator i = goal.inClosures.begin(); + i != goal.inClosures.end(); ++i) + s += i->first + "\n"; + for (PathSet::iterator i = fnord.begin(); + i != fnord.end(); ++i) + s += *i + "\n"; + writeStringToFile(inputListFN, s); + + s = ""; + for (PathSet::iterator i = goal.expr.derivation.outputs.begin(); + i != goal.expr.derivation.outputs.end(); ++i) + s += *i + "\n"; + writeStringToFile(outputListFN, s); + + s = ""; + for (map::iterator i = xyzzy.begin(); + i != xyzzy.end(); ++i) + s += i->first + " " + i->second + "\n"; + writeStringToFile(successorsListFN, s); + + int status = system((format("%1% %2% %3% %4% %5% %6% 1>&2") + % buildHook % goal.nePath % inputListFN % outputListFN + % successorsListFN + % goal.expr.derivation.platform).str().c_str()); + if (WIFEXITED(status)) { int code = WEXITSTATUS(status); if (code == 100) { /* == accepted */ @@ -384,6 +414,11 @@ bool Normaliser::startBuild(Path nePath) format("build hook died with status %1%") % status); } + /* Right platform? */ + if (goal.expr.derivation.platform != thisSystem) + throw Error(format("a `%1%' is required, but I am a `%2%'") + % goal.expr.derivation.platform % thisSystem); + /* Otherwise, start the build in a child process. */ startBuildChild(goal);