2005-01-19 16:39:47 +00:00
|
|
|
#include "build.hh"
|
2004-06-18 18:09:32 +00:00
|
|
|
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
Derivation derivationFromPath(const Path & drvPath)
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
2005-01-19 11:16:11 +00:00
|
|
|
assertStorePath(drvPath);
|
|
|
|
ensurePath(drvPath);
|
|
|
|
ATerm t = ATreadFromNamedFile(drvPath.c_str());
|
|
|
|
if (!t) throw Error(format("cannot read aterm from `%1%'") % drvPath);
|
|
|
|
return parseDerivation(t);
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
void computeFSClosure(const Path & storePath,
|
|
|
|
PathSet & paths)
|
|
|
|
{
|
|
|
|
if (paths.find(storePath) != paths.end()) return;
|
|
|
|
paths.insert(storePath);
|
|
|
|
|
|
|
|
PathSet references;
|
|
|
|
queryReferences(storePath, references);
|
|
|
|
|
|
|
|
for (PathSet::iterator i = references.begin();
|
|
|
|
i != references.end(); ++i)
|
|
|
|
computeFSClosure(*i, paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
void storePathRequisites(const Path & storePath,
|
|
|
|
bool includeOutputs, PathSet & paths)
|
2004-06-18 18:09:32 +00:00
|
|
|
{
|
|
|
|
checkInterrupt();
|
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
if (paths.find(storePath) != paths.end()) return;
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
if (isDerivation(storePath)) {
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
paths.insert(storePath);
|
|
|
|
|
|
|
|
Derivation drv = derivationFromPath(storePath);
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-20 14:10:19 +00:00
|
|
|
for (DerivationInputs::iterator i = drv.inputDrvs.begin();
|
2005-01-19 14:36:00 +00:00
|
|
|
i != drv.inputDrvs.end(); ++i)
|
2005-01-20 14:10:19 +00:00
|
|
|
/* !!! Maybe this is too strict, since it will include
|
|
|
|
*all* output paths of the input derivation, not just
|
|
|
|
the ones needed by this derivation. */
|
|
|
|
storePathRequisites(i->first, includeOutputs, paths);
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
for (PathSet::iterator i = drv.inputSrcs.begin();
|
|
|
|
i != drv.inputSrcs.end(); ++i)
|
|
|
|
storePathRequisites(*i, includeOutputs, paths);
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
if (includeOutputs) {
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
for (DerivationOutputs::iterator i = drv.outputs.begin();
|
|
|
|
i != drv.outputs.end(); ++i)
|
|
|
|
if (isValidPath(i->second.path))
|
|
|
|
storePathRequisites(i->second.path, includeOutputs, paths);
|
2004-06-18 18:09:32 +00:00
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
computeFSClosure(storePath, paths);
|
|
|
|
}
|
2004-06-18 18:09:32 +00:00
|
|
|
}
|