2003-07-20 19:29:38 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "normalise.hh"
|
|
|
|
#include "references.hh"
|
|
|
|
#include "exec.hh"
|
2003-08-01 14:11:19 +00:00
|
|
|
#include "pathlocks.hh"
|
2003-07-20 19:29:38 +00:00
|
|
|
#include "globals.hh"
|
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
static Path useSuccessor(const Path & path)
|
2003-08-01 14:11:19 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
string pathSucc;
|
2003-10-15 12:42:39 +00:00
|
|
|
if (querySuccessor(path, pathSucc)) {
|
2003-10-08 15:06:59 +00:00
|
|
|
debug(format("successor %1% -> %2%") % (string) path % pathSucc);
|
|
|
|
return pathSucc;
|
2003-08-01 14:11:19 +00:00
|
|
|
} else
|
2003-10-08 15:06:59 +00:00
|
|
|
return path;
|
2003-08-01 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
Path normaliseNixExpr(const Path & _nePath, PathSet pending)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2003-10-07 12:27:49 +00:00
|
|
|
Nest nest(lvlTalkative,
|
2003-10-08 15:06:59 +00:00
|
|
|
format("normalising expression in `%1%'") % (string) _nePath);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
/* Try to substitute the expression by any known successors in
|
|
|
|
order to speed up the rewrite process. */
|
|
|
|
Path nePath = useSuccessor(_nePath);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
/* Get the Nix expression. */
|
2003-10-16 16:29:57 +00:00
|
|
|
NixExpr ne = exprFromPath(nePath, pending);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
/* If this is a normal form (i.e., a closure) we are done. */
|
2003-10-08 15:06:59 +00:00
|
|
|
if (ne.type == NixExpr::neClosure) return nePath;
|
2003-10-07 12:27:49 +00:00
|
|
|
if (ne.type != NixExpr::neDerivation) abort();
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-08-01 14:11:19 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
/* Otherwise, it's a derivation expression, and we have to build it to
|
2003-08-01 14:11:19 +00:00
|
|
|
determine its normal form. */
|
|
|
|
|
|
|
|
|
|
|
|
/* Some variables. */
|
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
/* Input paths, with their closure elements. */
|
|
|
|
ClosureElems inClosures;
|
2003-08-01 14:11:19 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
/* Referenceable paths (i.e., input and output paths). */
|
|
|
|
PathSet allPaths;
|
2003-08-01 14:11:19 +00:00
|
|
|
|
|
|
|
/* The environment to be passed to the builder. */
|
|
|
|
Environment env;
|
|
|
|
|
2003-08-20 14:11:40 +00:00
|
|
|
/* The result. */
|
2003-10-07 12:27:49 +00:00
|
|
|
NixExpr nf;
|
|
|
|
nf.type = NixExpr::neClosure;
|
2003-08-20 14:11:40 +00:00
|
|
|
|
2003-08-01 14:11:19 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
/* The outputs are referenceable paths. */
|
|
|
|
for (PathSet::iterator i = ne.derivation.outputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.outputs.end(); i++)
|
2003-08-01 14:11:19 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
debug(format("building path `%1%'") % *i);
|
|
|
|
allPaths.insert(*i);
|
2003-08-01 14:11:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Obtain locks on all output paths. The locks are automatically
|
|
|
|
released when we exit this function or Nix crashes. */
|
2003-10-08 15:06:59 +00:00
|
|
|
PathLocks outputLocks(ne.derivation.outputs);
|
2003-08-01 14:11:19 +00:00
|
|
|
|
|
|
|
/* Now check again whether there is a successor. This is because
|
|
|
|
another process may have started building in parallel. After
|
|
|
|
it has finished and released the locks, we can (and should)
|
|
|
|
reuse its results. (Strictly speaking the first successor
|
|
|
|
check above can be omitted, but that would be less efficient.)
|
|
|
|
Note that since we now hold the locks on the output paths, no
|
|
|
|
other process can build this expression, so no further checks
|
|
|
|
are necessary. */
|
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
Path nePath2 = useSuccessor(nePath);
|
|
|
|
if (nePath != nePath2) {
|
2003-10-16 16:29:57 +00:00
|
|
|
NixExpr ne = exprFromPath(nePath2, pending);
|
2003-10-08 15:06:59 +00:00
|
|
|
debug(format("skipping build of expression `%1%', someone beat us to it")
|
|
|
|
% (string) nePath);
|
2003-10-07 12:27:49 +00:00
|
|
|
if (ne.type != NixExpr::neClosure) abort();
|
2003-10-08 15:06:59 +00:00
|
|
|
return nePath2;
|
2003-08-01 14:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-20 19:29:38 +00:00
|
|
|
|
|
|
|
/* Right platform? */
|
2003-10-07 12:27:49 +00:00
|
|
|
if (ne.derivation.platform != thisSystem)
|
2003-07-20 19:29:38 +00:00
|
|
|
throw Error(format("a `%1%' is required, but I am a `%2%'")
|
2003-10-07 12:27:49 +00:00
|
|
|
% ne.derivation.platform % thisSystem);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
|
|
|
/* Realise inputs (and remember all input paths). */
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.inputs.end(); i++)
|
2003-08-20 14:11:40 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
Path nfPath = normaliseNixExpr(*i, pending);
|
|
|
|
realiseClosure(nfPath, pending);
|
|
|
|
/* !!! nfPath should be a root of the garbage collector while
|
|
|
|
we are building */
|
2003-10-16 16:29:57 +00:00
|
|
|
NixExpr ne = exprFromPath(nfPath, pending);
|
2003-10-07 12:27:49 +00:00
|
|
|
if (ne.type != NixExpr::neClosure) abort();
|
|
|
|
for (ClosureElems::iterator j = ne.closure.elems.begin();
|
|
|
|
j != ne.closure.elems.end(); j++)
|
2003-08-20 14:11:40 +00:00
|
|
|
{
|
2003-10-07 12:27:49 +00:00
|
|
|
inClosures[j->first] = j->second;
|
2003-08-20 14:11:40 +00:00
|
|
|
allPaths.insert(j->first);
|
|
|
|
}
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2003-08-18 14:54:54 +00:00
|
|
|
/* Most shells initialise PATH to some default (/bin:/usr/bin:...) when
|
|
|
|
PATH is not set. We don't want this, so we fill it in with some dummy
|
|
|
|
value. */
|
|
|
|
env["PATH"] = "/path-not-set";
|
|
|
|
|
2003-08-22 20:12:44 +00:00
|
|
|
/* Set HOME to a non-existing path to prevent certain programs from using
|
|
|
|
/etc/passwd (or NIS, or whatever) to locate the home directory (for
|
|
|
|
example, wget looks for ~/.wgetrc). I.e., these tools use /etc/passwd
|
|
|
|
if HOME is not set, but they will just assume that the settings file
|
|
|
|
they are looking for does not exist if HOME is set but points to some
|
|
|
|
non-existing path. */
|
|
|
|
env["HOME"] = "/homeless-shelter";
|
|
|
|
|
2003-07-20 19:29:38 +00:00
|
|
|
/* Build the environment. */
|
2003-10-07 12:27:49 +00:00
|
|
|
for (StringPairs::iterator i = ne.derivation.env.begin();
|
|
|
|
i != ne.derivation.env.end(); i++)
|
2003-07-20 19:29:38 +00:00
|
|
|
env[i->first] = i->second;
|
|
|
|
|
|
|
|
/* We can skip running the builder if we can expand all output
|
|
|
|
paths from their ids. */
|
2003-10-08 15:06:59 +00:00
|
|
|
bool fastBuild = false;
|
|
|
|
#if 0
|
2003-07-21 20:07:12 +00:00
|
|
|
bool fastBuild = true;
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator i = ne.derivation.outputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.outputs.end(); i++)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
|
|
|
try {
|
2003-07-22 15:15:15 +00:00
|
|
|
expandId(i->second, i->first, "/", pending);
|
2003-07-21 20:07:12 +00:00
|
|
|
} catch (Error & e) {
|
2003-07-24 15:03:36 +00:00
|
|
|
debug(format("fast build failed for `%1%': %2%")
|
* Change the abstract syntax of slices. It used to be that ids were used as
keys to reference slice elements, e.g.,
Slice(["1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["8c99..."]), ...])
This was wrong, since ids represent contents, not locations. Therefore we
now have:
Slice(["/nix/store/1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["/nix/store/8c99-..."]), ...])
* Fix a bug in the computation of slice closures that could cause slice
elements to be duplicated.
2003-08-20 12:39:56 +00:00
|
|
|
% i->first % e.what());
|
2003-07-20 19:29:38 +00:00
|
|
|
fastBuild = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-10-08 15:06:59 +00:00
|
|
|
#endif
|
2003-07-20 19:29:38 +00:00
|
|
|
|
|
|
|
if (!fastBuild) {
|
|
|
|
|
2003-08-05 09:47:20 +00:00
|
|
|
/* If any of the outputs already exist but are not registered,
|
|
|
|
delete them. */
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator i = ne.derivation.outputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.outputs.end(); i++)
|
2003-08-05 09:47:20 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
Path path = *i;
|
|
|
|
if (isValidPath(path))
|
2003-08-05 09:47:20 +00:00
|
|
|
throw Error(format("obstructed build: path `%1%' exists") % path);
|
|
|
|
if (pathExists(path)) {
|
|
|
|
debug(format("removing unregistered path `%1%'") % path);
|
|
|
|
deletePath(path);
|
|
|
|
}
|
|
|
|
}
|
2003-07-20 19:29:38 +00:00
|
|
|
|
|
|
|
/* Run the builder. */
|
2003-07-24 13:43:16 +00:00
|
|
|
msg(lvlChatty, format("building..."));
|
2003-10-22 11:04:57 +00:00
|
|
|
runProgram(ne.derivation.builder, ne.derivation.args, env,
|
|
|
|
nixLogDir + "/" + baseNameOf(nePath));
|
2003-07-24 13:43:16 +00:00
|
|
|
msg(lvlChatty, format("build completed"));
|
2003-07-20 19:29:38 +00:00
|
|
|
|
|
|
|
} else
|
2003-07-24 13:43:16 +00:00
|
|
|
msg(lvlChatty, format("fast build succesful"));
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-08-01 15:41:47 +00:00
|
|
|
/* Check whether the output paths were created, and grep each
|
2003-08-22 20:12:44 +00:00
|
|
|
output path to determine what other paths it references. Also make all
|
|
|
|
output paths read-only. */
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet usedPaths;
|
|
|
|
for (PathSet::iterator i = ne.derivation.outputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.outputs.end(); i++)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
Path path = *i;
|
2003-07-20 19:29:38 +00:00
|
|
|
if (!pathExists(path))
|
|
|
|
throw Error(format("path `%1%' does not exist") % path);
|
2003-10-07 12:27:49 +00:00
|
|
|
nf.closure.roots.insert(path);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-08-22 20:12:44 +00:00
|
|
|
makePathReadOnly(path);
|
|
|
|
|
2003-08-20 11:30:45 +00:00
|
|
|
/* For this output path, find the references to other paths contained
|
|
|
|
in it. */
|
2003-08-20 14:11:40 +00:00
|
|
|
Strings refPaths = filterReferences(path,
|
2003-08-28 10:51:14 +00:00
|
|
|
Strings(allPaths.begin(), allPaths.end()));
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
/* Construct a closure element for this output path. */
|
|
|
|
ClosureElem elem;
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-08-20 11:30:45 +00:00
|
|
|
/* For each path referenced by this output path, add its id to the
|
2003-10-07 12:27:49 +00:00
|
|
|
closure element and add the id to the `usedPaths' set (so that the
|
|
|
|
elements referenced by *its* closure are added below). */
|
2003-10-08 15:06:59 +00:00
|
|
|
for (Paths::iterator j = refPaths.begin();
|
2003-08-20 11:30:45 +00:00
|
|
|
j != refPaths.end(); j++)
|
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
Path path = *j;
|
2003-08-20 14:11:40 +00:00
|
|
|
elem.refs.insert(path);
|
2003-10-07 12:27:49 +00:00
|
|
|
if (inClosures.find(path) != inClosures.end())
|
2003-08-20 14:11:40 +00:00
|
|
|
usedPaths.insert(path);
|
2003-10-07 12:27:49 +00:00
|
|
|
else if (ne.derivation.outputs.find(path) == ne.derivation.outputs.end())
|
* Change the abstract syntax of slices. It used to be that ids were used as
keys to reference slice elements, e.g.,
Slice(["1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["8c99..."]), ...])
This was wrong, since ids represent contents, not locations. Therefore we
now have:
Slice(["/nix/store/1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["/nix/store/8c99-..."]), ...])
* Fix a bug in the computation of slice closures that could cause slice
elements to be duplicated.
2003-08-20 12:39:56 +00:00
|
|
|
abort();
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
nf.closure.elems[path] = elem;
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
/* Close the closure. That is, for any referenced path, add the paths
|
2003-08-20 11:30:45 +00:00
|
|
|
referenced by it. */
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet donePaths;
|
2003-08-20 11:30:45 +00:00
|
|
|
|
|
|
|
while (!usedPaths.empty()) {
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet::iterator i = usedPaths.begin();
|
|
|
|
Path path = *i;
|
2003-08-20 11:30:45 +00:00
|
|
|
usedPaths.erase(i);
|
|
|
|
|
* Change the abstract syntax of slices. It used to be that ids were used as
keys to reference slice elements, e.g.,
Slice(["1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["8c99..."]), ...])
This was wrong, since ids represent contents, not locations. Therefore we
now have:
Slice(["/nix/store/1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["/nix/store/8c99-..."]), ...])
* Fix a bug in the computation of slice closures that could cause slice
elements to be duplicated.
2003-08-20 12:39:56 +00:00
|
|
|
if (donePaths.find(path) != donePaths.end()) continue;
|
|
|
|
donePaths.insert(path);
|
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
ClosureElems::iterator j = inClosures.find(path);
|
|
|
|
if (j == inClosures.end()) abort();
|
2003-08-20 11:30:45 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
nf.closure.elems[path] = j->second;
|
2003-08-20 11:30:45 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator k = j->second.refs.begin();
|
2003-08-20 11:30:45 +00:00
|
|
|
k != j->second.refs.end(); k++)
|
* Change the abstract syntax of slices. It used to be that ids were used as
keys to reference slice elements, e.g.,
Slice(["1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["8c99..."]), ...])
This was wrong, since ids represent contents, not locations. Therefore we
now have:
Slice(["/nix/store/1ef7..."], [("/nix/store/1ef7...-foo", "1ef7", ["/nix/store/8c99-..."]), ...])
* Fix a bug in the computation of slice closures that could cause slice
elements to be duplicated.
2003-08-20 12:39:56 +00:00
|
|
|
usedPaths.insert(*k);
|
2003-08-20 11:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For debugging, print out the referenced and unreferenced paths. */
|
2003-10-07 12:27:49 +00:00
|
|
|
for (ClosureElems::iterator i = inClosures.begin();
|
|
|
|
i != inClosures.end(); i++)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet::iterator j = donePaths.find(i->first);
|
2003-08-20 11:30:45 +00:00
|
|
|
if (j == donePaths.end())
|
2003-08-20 14:11:40 +00:00
|
|
|
debug(format("NOT referenced: `%1%'") % i->first);
|
2003-08-20 11:30:45 +00:00
|
|
|
else
|
2003-08-20 14:11:40 +00:00
|
|
|
debug(format("referenced: `%1%'") % i->first);
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
2003-08-01 15:41:47 +00:00
|
|
|
/* Write the normal form. This does not have to occur in the
|
|
|
|
transaction below because writing terms is idem-potent. */
|
2003-10-07 12:27:49 +00:00
|
|
|
ATerm nfTerm = unparseNixExpr(nf);
|
|
|
|
msg(lvlVomit, format("normal form: %1%") % printTerm(nfTerm));
|
2003-10-08 15:06:59 +00:00
|
|
|
Path nfPath = writeTerm(nfTerm, "-s");
|
2003-08-01 15:41:47 +00:00
|
|
|
|
|
|
|
/* Register each outpat path, and register the normal form. This
|
|
|
|
is wrapped in one database transaction to ensure that if we
|
|
|
|
crash, either everything is registered or nothing is. This is
|
|
|
|
for recoverability: unregistered paths in the store can be
|
|
|
|
deleted arbitrarily, while registered paths can only be deleted
|
|
|
|
by running the garbage collector. */
|
2003-10-15 12:42:39 +00:00
|
|
|
Transaction txn;
|
|
|
|
createStoreTransaction(txn);
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator i = ne.derivation.outputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.outputs.end(); i++)
|
2003-10-08 15:06:59 +00:00
|
|
|
registerValidPath(txn, *i);
|
|
|
|
registerSuccessor(txn, nePath, nfPath);
|
2003-08-01 15:41:47 +00:00
|
|
|
txn.commit();
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
return nfPath;
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
void realiseClosure(const Path & nePath, PathSet pending)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
Nest nest(lvlDebug, format("realising closure `%1%'") % nePath);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-16 16:29:57 +00:00
|
|
|
NixExpr ne = exprFromPath(nePath, pending);
|
2003-10-07 12:27:49 +00:00
|
|
|
if (ne.type != NixExpr::neClosure)
|
2003-10-08 15:06:59 +00:00
|
|
|
throw Error(format("expected closure in `%1%'") % nePath);
|
2003-07-29 09:45:03 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
for (ClosureElems::const_iterator i = ne.closure.elems.begin();
|
|
|
|
i != ne.closure.elems.end(); i++)
|
2003-10-16 16:29:57 +00:00
|
|
|
ensurePath(i->first, pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ensurePath(const Path & path, PathSet pending)
|
|
|
|
{
|
|
|
|
/* If the path is already valid, we're done. */
|
|
|
|
if (isValidPath(path)) return;
|
|
|
|
|
|
|
|
/* Otherwise, try the substitutes. */
|
|
|
|
Paths subPaths = querySubstitutes(path);
|
|
|
|
|
|
|
|
for (Paths::iterator i = subPaths.begin();
|
|
|
|
i != subPaths.end(); i++)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
normaliseNixExpr(*i, pending);
|
|
|
|
if (isValidPath(path)) return;
|
|
|
|
throw Error(format("substitute failed to produce expected output path"));
|
|
|
|
} catch (Error & e) {
|
|
|
|
msg(lvlTalkative,
|
|
|
|
format("building of substitute `%1%' for `%2%' failed: %3%")
|
|
|
|
% *i % path % e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Error(format("path `%1%' is required, "
|
|
|
|
"but there are no (successful) substitutes") % path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NixExpr exprFromPath(const Path & path, PathSet pending)
|
|
|
|
{
|
|
|
|
ensurePath(path, pending);
|
|
|
|
ATerm t = ATreadFromNamedFile(path.c_str());
|
|
|
|
if (!t) throw Error(format("cannot read aterm from `%1%'") % path);
|
|
|
|
return parseNixExpr(t);
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet nixExprRoots(const Path & nePath)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet paths;
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-16 16:29:57 +00:00
|
|
|
NixExpr ne = exprFromPath(nePath);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
if (ne.type == NixExpr::neClosure)
|
|
|
|
paths.insert(ne.closure.roots.begin(), ne.closure.roots.end());
|
|
|
|
else if (ne.type == NixExpr::neDerivation)
|
|
|
|
paths.insert(ne.derivation.outputs.begin(),
|
|
|
|
ne.derivation.outputs.end());
|
2003-07-20 19:29:38 +00:00
|
|
|
else abort();
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
static void requisitesWorker(const Path & nePath,
|
|
|
|
bool includeExprs, bool includeSuccessors,
|
|
|
|
PathSet & paths, PathSet & doneSet)
|
2003-07-29 10:43:12 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
if (doneSet.find(nePath) != doneSet.end()) return;
|
|
|
|
doneSet.insert(nePath);
|
2003-08-25 14:56:11 +00:00
|
|
|
|
2003-10-16 16:29:57 +00:00
|
|
|
NixExpr ne = exprFromPath(nePath);
|
2003-07-29 10:43:12 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
if (ne.type == NixExpr::neClosure)
|
|
|
|
for (ClosureElems::iterator i = ne.closure.elems.begin();
|
|
|
|
i != ne.closure.elems.end(); i++)
|
2003-08-20 14:11:40 +00:00
|
|
|
paths.insert(i->first);
|
2003-07-29 10:43:12 +00:00
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
else if (ne.type == NixExpr::neDerivation)
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
2003-10-07 12:27:49 +00:00
|
|
|
i != ne.derivation.inputs.end(); i++)
|
2003-10-08 15:06:59 +00:00
|
|
|
requisitesWorker(*i,
|
2003-08-25 14:56:11 +00:00
|
|
|
includeExprs, includeSuccessors, paths, doneSet);
|
2003-07-29 10:43:12 +00:00
|
|
|
|
|
|
|
else abort();
|
2003-07-29 14:28:17 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
if (includeExprs) paths.insert(nePath);
|
2003-07-29 14:28:17 +00:00
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
string nfPath;
|
|
|
|
if (includeSuccessors && (nfPath = useSuccessor(nePath)) != nePath)
|
|
|
|
requisitesWorker(nfPath, includeExprs, includeSuccessors,
|
|
|
|
paths, doneSet);
|
2003-07-29 10:43:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet nixExprRequisites(const Path & nePath,
|
2003-07-29 14:28:17 +00:00
|
|
|
bool includeExprs, bool includeSuccessors)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet paths;
|
|
|
|
PathSet doneSet;
|
|
|
|
requisitesWorker(nePath, includeExprs, includeSuccessors,
|
|
|
|
paths, doneSet);
|
|
|
|
return paths;
|
2003-07-20 19:29:38 +00:00
|
|
|
}
|