2003-07-20 22:29:38 +03:00
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "normalise.hh"
|
|
|
|
#include "references.hh"
|
|
|
|
#include "db.hh"
|
|
|
|
#include "exec.hh"
|
2003-08-01 17:11:19 +03:00
|
|
|
#include "pathlocks.hh"
|
2003-07-20 22:29:38 +03:00
|
|
|
#include "globals.hh"
|
|
|
|
|
|
|
|
|
2003-08-01 18:41:47 +03:00
|
|
|
void registerSuccessor(const Transaction & txn,
|
|
|
|
const FSId & id1, const FSId & id2)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
2003-07-31 19:05:35 +03:00
|
|
|
nixDB.setString(txn, dbSuccessors, id1, id2);
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-01 17:11:19 +03:00
|
|
|
static FSId useSuccessor(const FSId & id)
|
|
|
|
{
|
|
|
|
string idSucc;
|
|
|
|
if (nixDB.queryString(noTxn, dbSuccessors, id, idSucc)) {
|
|
|
|
debug(format("successor %1% -> %2%") % (string) id % idSucc);
|
|
|
|
return parseHash(idSucc);
|
|
|
|
} else
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
Strings pathsFromOutputs(const DeriveOutputs & ps)
|
2003-08-01 17:11:19 +03:00
|
|
|
{
|
|
|
|
Strings ss;
|
2003-08-20 17:11:40 +03:00
|
|
|
for (DeriveOutputs::const_iterator i = ps.begin();
|
2003-08-01 17:11:19 +03:00
|
|
|
i != ps.end(); i++)
|
|
|
|
ss.push_back(i->first);
|
|
|
|
return ss;
|
|
|
|
}
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
|
2003-07-29 12:45:03 +03:00
|
|
|
FSId normaliseFState(FSId id, FSIdSet pending)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
2003-07-24 16:43:16 +03:00
|
|
|
Nest nest(lvlTalkative, format("normalising fstate %1%") % (string) id);
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
/* Try to substitute $id$ by any known successors in order to
|
|
|
|
speed up the rewrite process. */
|
2003-08-01 17:11:19 +03:00
|
|
|
id = useSuccessor(id);
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
/* Get the fstate expression. */
|
|
|
|
FState fs = parseFState(termFromId(id));
|
|
|
|
|
2003-08-01 17:11:19 +03:00
|
|
|
/* If this is a normal form (i.e., a slice) we are done. */
|
2003-07-29 12:45:03 +03:00
|
|
|
if (fs.type == FState::fsSlice) return id;
|
2003-08-01 17:11:19 +03:00
|
|
|
if (fs.type != FState::fsDerive) abort();
|
2003-07-20 22:29:38 +03:00
|
|
|
|
2003-08-01 17:11:19 +03:00
|
|
|
|
|
|
|
/* Otherwise, it's a derive expression, and we have to build it to
|
|
|
|
determine its normal form. */
|
|
|
|
|
|
|
|
|
|
|
|
/* Some variables. */
|
|
|
|
|
|
|
|
/* Input paths, with their slice elements. */
|
2003-08-20 17:11:40 +03:00
|
|
|
SliceElems inSlices;
|
2003-08-01 17:11:19 +03:00
|
|
|
|
|
|
|
/* Referencable paths (i.e., input and output paths). */
|
2003-08-20 17:11:40 +03:00
|
|
|
StringSet allPaths;
|
2003-08-01 17:11:19 +03:00
|
|
|
|
|
|
|
/* The environment to be passed to the builder. */
|
|
|
|
Environment env;
|
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
/* The result. */
|
|
|
|
FState nfFS;
|
|
|
|
nfFS.type = FState::fsSlice;
|
|
|
|
|
2003-08-01 17:11:19 +03:00
|
|
|
|
|
|
|
/* Parse the outputs. */
|
|
|
|
for (DeriveOutputs::iterator i = fs.derive.outputs.begin();
|
|
|
|
i != fs.derive.outputs.end(); i++)
|
|
|
|
{
|
|
|
|
debug(format("building %1% in `%2%'") % (string) i->second % i->first);
|
2003-08-20 17:11:40 +03:00
|
|
|
allPaths.insert(i->first);
|
2003-08-01 17:11:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Obtain locks on all output paths. The locks are automatically
|
|
|
|
released when we exit this function or Nix crashes. */
|
2003-08-20 17:11:40 +03:00
|
|
|
PathLocks outputLocks(pathsFromOutputs(fs.derive.outputs));
|
2003-08-01 17:11:19 +03: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. */
|
|
|
|
{
|
|
|
|
FSId id2 = useSuccessor(id);
|
|
|
|
if (id2 != id) {
|
|
|
|
FState fs = parseFState(termFromId(id2));
|
|
|
|
debug(format("skipping build of %1%, someone beat us to it")
|
* 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 15:39:56 +03:00
|
|
|
% (string) id);
|
2003-08-01 17:11:19 +03:00
|
|
|
if (fs.type != FState::fsSlice) abort();
|
|
|
|
return id2;
|
|
|
|
}
|
|
|
|
}
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
/* Right platform? */
|
|
|
|
if (fs.derive.platform != thisSystem)
|
|
|
|
throw Error(format("a `%1%' is required, but I am a `%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 15:39:56 +03:00
|
|
|
% fs.derive.platform % thisSystem);
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
/* Realise inputs (and remember all input paths). */
|
2003-08-20 17:11:40 +03:00
|
|
|
for (FSIdSet::iterator i = fs.derive.inputs.begin();
|
|
|
|
i != fs.derive.inputs.end(); i++)
|
|
|
|
{
|
2003-07-29 12:45:03 +03:00
|
|
|
FSId nf = normaliseFState(*i, pending);
|
|
|
|
realiseSlice(nf, pending);
|
2003-08-01 17:11:19 +03:00
|
|
|
/* !!! nf should be a root of the garbage collector while we
|
|
|
|
are building */
|
2003-07-29 12:45:03 +03:00
|
|
|
FState fs = parseFState(termFromId(nf));
|
|
|
|
if (fs.type != FState::fsSlice) abort();
|
|
|
|
for (SliceElems::iterator j = fs.slice.elems.begin();
|
|
|
|
j != fs.slice.elems.end(); j++)
|
2003-08-20 17:11:40 +03:00
|
|
|
{
|
|
|
|
inSlices[j->first] = j->second;
|
|
|
|
allPaths.insert(j->first);
|
|
|
|
}
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
2003-08-18 17:54:54 +03: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 23:12:44 +03: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 22:29:38 +03:00
|
|
|
/* Build the environment. */
|
|
|
|
for (StringPairs::iterator i = fs.derive.env.begin();
|
|
|
|
i != fs.derive.env.end(); i++)
|
|
|
|
env[i->first] = i->second;
|
|
|
|
|
|
|
|
/* We can skip running the builder if we can expand all output
|
|
|
|
paths from their ids. */
|
2003-07-21 23:07:12 +03:00
|
|
|
bool fastBuild = true;
|
2003-08-20 17:11:40 +03:00
|
|
|
for (DeriveOutputs::iterator i = fs.derive.outputs.begin();
|
|
|
|
i != fs.derive.outputs.end(); i++)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
|
|
|
try {
|
2003-07-22 18:15:15 +03:00
|
|
|
expandId(i->second, i->first, "/", pending);
|
2003-07-21 23:07:12 +03:00
|
|
|
} catch (Error & e) {
|
2003-07-24 18:03:36 +03: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 15:39:56 +03:00
|
|
|
% i->first % e.what());
|
2003-07-20 22:29:38 +03:00
|
|
|
fastBuild = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fastBuild) {
|
|
|
|
|
2003-08-05 12:47:20 +03:00
|
|
|
/* If any of the outputs already exist but are not registered,
|
|
|
|
delete them. */
|
2003-08-20 17:11:40 +03:00
|
|
|
for (DeriveOutputs::iterator i = fs.derive.outputs.begin();
|
|
|
|
i != fs.derive.outputs.end(); i++)
|
2003-08-05 12:47:20 +03:00
|
|
|
{
|
|
|
|
string path = i->first;
|
|
|
|
FSId id;
|
|
|
|
if (queryPathId(path, id))
|
|
|
|
throw Error(format("obstructed build: path `%1%' exists") % path);
|
|
|
|
if (pathExists(path)) {
|
|
|
|
debug(format("removing unregistered path `%1%'") % path);
|
|
|
|
deletePath(path);
|
|
|
|
}
|
|
|
|
}
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
/* Run the builder. */
|
2003-07-24 16:43:16 +03:00
|
|
|
msg(lvlChatty, format("building..."));
|
2003-08-15 15:32:37 +03:00
|
|
|
runProgram(fs.derive.builder, fs.derive.args, env);
|
2003-07-24 16:43:16 +03:00
|
|
|
msg(lvlChatty, format("build completed"));
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
} else
|
2003-07-24 16:43:16 +03:00
|
|
|
msg(lvlChatty, format("fast build succesful"));
|
2003-07-20 22:29:38 +03:00
|
|
|
|
2003-08-01 18:41:47 +03:00
|
|
|
/* Check whether the output paths were created, and grep each
|
2003-08-22 23:12:44 +03:00
|
|
|
output path to determine what other paths it references. Also make all
|
|
|
|
output paths read-only. */
|
2003-08-20 14:30:45 +03:00
|
|
|
StringSet usedPaths;
|
2003-08-20 17:11:40 +03:00
|
|
|
for (DeriveOutputs::iterator i = fs.derive.outputs.begin();
|
|
|
|
i != fs.derive.outputs.end(); i++)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
|
|
|
string path = i->first;
|
|
|
|
if (!pathExists(path))
|
|
|
|
throw Error(format("path `%1%' does not exist") % path);
|
2003-08-20 17:11:40 +03:00
|
|
|
nfFS.slice.roots.insert(path);
|
2003-07-20 22:29:38 +03:00
|
|
|
|
2003-08-22 23:12:44 +03:00
|
|
|
makePathReadOnly(path);
|
|
|
|
|
2003-08-20 14:30:45 +03:00
|
|
|
/* For this output path, find the references to other paths contained
|
|
|
|
in it. */
|
2003-08-20 17:11:40 +03:00
|
|
|
Strings refPaths = filterReferences(path,
|
2003-08-22 23:12:44 +03:00
|
|
|
Strings(allPaths.begin(), allPaths.end()));
|
2003-07-20 22:29:38 +03:00
|
|
|
|
2003-08-20 14:30:45 +03:00
|
|
|
/* Construct a slice element for this output path. */
|
2003-07-20 22:29:38 +03:00
|
|
|
SliceElem elem;
|
|
|
|
elem.id = i->second;
|
|
|
|
|
2003-08-20 14:30:45 +03:00
|
|
|
/* For each path referenced by this output path, add its id to the
|
* 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 15:39:56 +03:00
|
|
|
slice element and add the id to the `usedPaths' set (so that the
|
2003-08-20 14:30:45 +03:00
|
|
|
elements referenced by *its* slice are added below). */
|
|
|
|
for (Strings::iterator j = refPaths.begin();
|
|
|
|
j != refPaths.end(); j++)
|
|
|
|
{
|
|
|
|
string path = *j;
|
2003-08-20 17:11:40 +03:00
|
|
|
elem.refs.insert(path);
|
|
|
|
if (inSlices.find(path) != inSlices.end())
|
|
|
|
usedPaths.insert(path);
|
|
|
|
else if (fs.derive.outputs.find(path) == fs.derive.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 15:39:56 +03:00
|
|
|
abort();
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
nfFS.slice.elems[path] = elem;
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
2003-08-20 14:30:45 +03:00
|
|
|
/* Close the slice. That is, for any referenced path, add the paths
|
|
|
|
referenced by it. */
|
* 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 15:39:56 +03:00
|
|
|
StringSet donePaths;
|
2003-08-20 14:30:45 +03:00
|
|
|
|
|
|
|
while (!usedPaths.empty()) {
|
|
|
|
StringSet::iterator i = usedPaths.begin();
|
|
|
|
string path = *i;
|
|
|
|
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 15:39:56 +03:00
|
|
|
if (donePaths.find(path) != donePaths.end()) continue;
|
|
|
|
donePaths.insert(path);
|
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
SliceElems::iterator j = inSlices.find(path);
|
|
|
|
if (j == inSlices.end()) abort();
|
2003-08-20 14:30:45 +03:00
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
nfFS.slice.elems[path] = j->second;
|
2003-08-20 14:30:45 +03:00
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
for (StringSet::iterator k = j->second.refs.begin();
|
2003-08-20 14:30:45 +03: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 15:39:56 +03:00
|
|
|
usedPaths.insert(*k);
|
2003-08-20 14:30:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For debugging, print out the referenced and unreferenced paths. */
|
2003-08-20 17:11:40 +03:00
|
|
|
for (SliceElems::iterator i = inSlices.begin();
|
|
|
|
i != inSlices.end(); i++)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
2003-08-20 17:11:40 +03:00
|
|
|
StringSet::iterator j = donePaths.find(i->first);
|
2003-08-20 14:30:45 +03:00
|
|
|
if (j == donePaths.end())
|
2003-08-20 17:11:40 +03:00
|
|
|
debug(format("NOT referenced: `%1%'") % i->first);
|
2003-08-20 14:30:45 +03:00
|
|
|
else
|
2003-08-20 17:11:40 +03:00
|
|
|
debug(format("referenced: `%1%'") % i->first);
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
2003-08-01 18:41:47 +03:00
|
|
|
/* Write the normal form. This does not have to occur in the
|
|
|
|
transaction below because writing terms is idem-potent. */
|
2003-08-20 17:11:40 +03:00
|
|
|
ATerm nf = unparseFState(nfFS);
|
2003-07-24 16:43:16 +03:00
|
|
|
msg(lvlVomit, format("normal form: %1%") % printTerm(nf));
|
2003-08-01 18:41:47 +03:00
|
|
|
FSId idNF = writeTerm(nf, "-s-" + (string) id);
|
|
|
|
|
|
|
|
/* 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. */
|
|
|
|
Transaction txn(nixDB);
|
2003-08-20 17:11:40 +03:00
|
|
|
for (DeriveOutputs::iterator i = fs.derive.outputs.begin();
|
|
|
|
i != fs.derive.outputs.end(); i++)
|
2003-08-01 18:41:47 +03:00
|
|
|
registerPath(txn, i->first, i->second);
|
|
|
|
registerSuccessor(txn, id, idNF);
|
|
|
|
txn.commit();
|
|
|
|
|
|
|
|
return idNF;
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-29 12:45:03 +03:00
|
|
|
void realiseSlice(const FSId & id, FSIdSet pending)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
2003-07-29 12:45:03 +03:00
|
|
|
Nest nest(lvlDebug,
|
|
|
|
format("realising slice %1%") % (string) id);
|
2003-07-20 22:29:38 +03:00
|
|
|
|
2003-07-29 12:45:03 +03:00
|
|
|
FState fs = parseFState(termFromId(id));
|
|
|
|
if (fs.type != FState::fsSlice)
|
|
|
|
throw Error(format("expected slice in %1%") % (string) id);
|
|
|
|
|
|
|
|
for (SliceElems::const_iterator i = fs.slice.elems.begin();
|
|
|
|
i != fs.slice.elems.end(); i++)
|
2003-08-20 17:11:40 +03:00
|
|
|
expandId(i->second.id, i->first, "/", pending);
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-29 13:43:12 +03:00
|
|
|
Strings fstatePaths(const FSId & id)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
|
|
|
Strings paths;
|
|
|
|
|
2003-07-29 13:43:12 +03:00
|
|
|
FState fs = parseFState(termFromId(id));
|
2003-07-20 22:29:38 +03:00
|
|
|
|
|
|
|
if (fs.type == FState::fsSlice) {
|
2003-08-20 17:11:40 +03:00
|
|
|
for (StringSet::const_iterator i = fs.slice.roots.begin();
|
2003-07-20 22:29:38 +03:00
|
|
|
i != fs.slice.roots.end(); i++)
|
2003-08-20 17:11:40 +03:00
|
|
|
paths.push_back(*i);
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (fs.type == FState::fsDerive) {
|
|
|
|
for (DeriveOutputs::iterator i = fs.derive.outputs.begin();
|
|
|
|
i != fs.derive.outputs.end(); i++)
|
|
|
|
paths.push_back(i->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
else abort();
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-29 17:28:17 +03:00
|
|
|
static void fstateRequisitesSet(const FSId & id,
|
|
|
|
bool includeExprs, bool includeSuccessors, StringSet & paths)
|
2003-07-29 13:43:12 +03:00
|
|
|
{
|
|
|
|
FState fs = parseFState(termFromId(id));
|
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
if (fs.type == FState::fsSlice)
|
2003-07-29 13:43:12 +03:00
|
|
|
for (SliceElems::iterator i = fs.slice.elems.begin();
|
|
|
|
i != fs.slice.elems.end(); i++)
|
2003-08-20 17:11:40 +03:00
|
|
|
paths.insert(i->first);
|
2003-07-29 13:43:12 +03:00
|
|
|
|
2003-08-20 17:11:40 +03:00
|
|
|
else if (fs.type == FState::fsDerive)
|
|
|
|
for (FSIdSet::iterator i = fs.derive.inputs.begin();
|
2003-07-29 13:43:12 +03:00
|
|
|
i != fs.derive.inputs.end(); i++)
|
2003-07-29 17:28:17 +03:00
|
|
|
fstateRequisitesSet(*i,
|
|
|
|
includeExprs, includeSuccessors, paths);
|
2003-07-29 13:43:12 +03:00
|
|
|
|
|
|
|
else abort();
|
2003-07-29 17:28:17 +03:00
|
|
|
|
|
|
|
if (includeExprs)
|
|
|
|
paths.insert(expandId(id));
|
|
|
|
|
|
|
|
string idSucc;
|
|
|
|
if (includeSuccessors &&
|
2003-07-31 16:47:13 +03:00
|
|
|
nixDB.queryString(noTxn, dbSuccessors, id, idSucc))
|
2003-07-29 17:28:17 +03:00
|
|
|
fstateRequisitesSet(parseHash(idSucc),
|
|
|
|
includeExprs, includeSuccessors, paths);
|
2003-07-29 13:43:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-29 17:28:17 +03:00
|
|
|
Strings fstateRequisites(const FSId & id,
|
|
|
|
bool includeExprs, bool includeSuccessors)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
2003-07-29 13:43:12 +03:00
|
|
|
StringSet paths;
|
2003-07-29 17:28:17 +03:00
|
|
|
fstateRequisitesSet(id, includeExprs, includeSuccessors, paths);
|
2003-07-29 13:43:12 +03:00
|
|
|
return Strings(paths.begin(), paths.end());
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-21 17:46:01 +03:00
|
|
|
FSIds findGenerators(const FSIds & _ids)
|
2003-07-20 22:29:38 +03:00
|
|
|
{
|
2003-07-21 17:46:01 +03:00
|
|
|
FSIdSet ids(_ids.begin(), _ids.end());
|
|
|
|
FSIds generators;
|
|
|
|
|
|
|
|
/* !!! hack; for performance, we just look at the rhs of successor
|
|
|
|
mappings, since we know that those are Nix expressions. */
|
|
|
|
|
|
|
|
Strings sucs;
|
2003-07-31 16:47:13 +03:00
|
|
|
nixDB.enumTable(noTxn, dbSuccessors, sucs);
|
2003-07-21 17:46:01 +03:00
|
|
|
|
|
|
|
for (Strings::iterator i = sucs.begin();
|
|
|
|
i != sucs.end(); i++)
|
|
|
|
{
|
|
|
|
string s;
|
2003-07-31 16:47:13 +03:00
|
|
|
if (!nixDB.queryString(noTxn, dbSuccessors, *i, s)) continue;
|
2003-07-21 17:46:01 +03:00
|
|
|
FSId id = parseHash(s);
|
|
|
|
|
|
|
|
FState fs;
|
|
|
|
try {
|
|
|
|
/* !!! should substitutes be used? */
|
|
|
|
fs = parseFState(termFromId(id));
|
|
|
|
} catch (...) { /* !!! only catch parse errors */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fs.type != FState::fsSlice) continue;
|
|
|
|
|
|
|
|
bool okay = true;
|
|
|
|
for (SliceElems::const_iterator i = fs.slice.elems.begin();
|
|
|
|
i != fs.slice.elems.end(); i++)
|
2003-08-20 17:11:40 +03:00
|
|
|
if (ids.find(i->second.id) == ids.end()) {
|
2003-07-21 17:46:01 +03:00
|
|
|
okay = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!okay) continue;
|
|
|
|
|
|
|
|
generators.push_back(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return generators;
|
2003-07-20 22:29:38 +03:00
|
|
|
}
|