2006-09-04 23:06:23 +02:00
|
|
|
#include "misc.hh"
|
2006-11-30 18:43:04 +01:00
|
|
|
#include "store-api.hh"
|
2008-08-02 14:54:35 +02:00
|
|
|
#include "local-store.hh"
|
2006-09-04 23:06:23 +02:00
|
|
|
|
2006-09-05 00:08:40 +02:00
|
|
|
#include <aterm2.h>
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
namespace nix {
|
2004-06-18 20:09:32 +02:00
|
|
|
|
|
|
|
|
2005-01-19 12:16:11 +01:00
|
|
|
Derivation derivationFromPath(const Path & drvPath)
|
2004-06-18 20:09:32 +02:00
|
|
|
{
|
2005-01-19 12:16:11 +01:00
|
|
|
assertStorePath(drvPath);
|
2006-11-30 19:02:04 +01:00
|
|
|
store->ensurePath(drvPath);
|
2005-01-19 12:16:11 +01:00
|
|
|
ATerm t = ATreadFromNamedFile(drvPath.c_str());
|
|
|
|
if (!t) throw Error(format("cannot read aterm from `%1%'") % drvPath);
|
|
|
|
return parseDerivation(t);
|
2004-06-18 20:09:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 12:16:11 +01:00
|
|
|
void computeFSClosure(const Path & storePath,
|
2010-01-25 18:18:44 +01:00
|
|
|
PathSet & paths, bool flipDirection, bool includeOutputs)
|
2005-01-19 12:16:11 +01:00
|
|
|
{
|
|
|
|
if (paths.find(storePath) != paths.end()) return;
|
|
|
|
paths.insert(storePath);
|
|
|
|
|
|
|
|
PathSet references;
|
2005-01-25 12:18:03 +01:00
|
|
|
if (flipDirection)
|
2006-11-30 18:43:04 +01:00
|
|
|
store->queryReferrers(storePath, references);
|
2005-01-25 12:18:03 +01:00
|
|
|
else
|
2006-11-30 18:43:04 +01:00
|
|
|
store->queryReferences(storePath, references);
|
2005-01-19 12:16:11 +01:00
|
|
|
|
2010-01-25 18:18:44 +01:00
|
|
|
if (includeOutputs && isDerivation(storePath)) {
|
|
|
|
Derivation drv = derivationFromPath(storePath);
|
|
|
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
|
|
|
if (store->isValidPath(i->second.path))
|
|
|
|
computeFSClosure(i->second.path, paths, flipDirection, true);
|
|
|
|
}
|
|
|
|
|
2009-04-21 13:52:16 +02:00
|
|
|
foreach (PathSet::iterator, i, references)
|
2010-01-25 18:18:44 +01:00
|
|
|
computeFSClosure(*i, paths, flipDirection, includeOutputs);
|
2005-01-19 12:16:11 +01:00
|
|
|
}
|
2005-02-14 18:35:10 +01:00
|
|
|
|
|
|
|
|
2006-03-06 12:21:15 +01:00
|
|
|
Path findOutput(const Derivation & drv, string id)
|
2005-02-14 18:35:10 +01:00
|
|
|
{
|
2009-04-21 13:52:16 +02:00
|
|
|
foreach (DerivationOutputs::const_iterator, i, drv.outputs)
|
2005-02-14 18:35:10 +01:00
|
|
|
if (i->first == id) return i->second.path;
|
|
|
|
throw Error(format("derivation has no output `%1%'") % id);
|
|
|
|
}
|
2006-03-06 12:21:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
void queryMissing(const PathSet & targets,
|
2008-08-04 14:29:04 +02:00
|
|
|
PathSet & willBuild, PathSet & willSubstitute, PathSet & unknown,
|
|
|
|
unsigned long long & downloadSize)
|
2006-03-06 12:21:15 +01:00
|
|
|
{
|
2008-08-04 14:29:04 +02:00
|
|
|
downloadSize = 0;
|
|
|
|
|
2006-03-06 12:21:15 +01:00
|
|
|
PathSet todo(targets.begin(), targets.end()), done;
|
|
|
|
|
|
|
|
while (!todo.empty()) {
|
|
|
|
Path p = *(todo.begin());
|
|
|
|
todo.erase(p);
|
|
|
|
if (done.find(p) != done.end()) continue;
|
|
|
|
done.insert(p);
|
|
|
|
|
|
|
|
if (isDerivation(p)) {
|
2008-08-04 13:44:50 +02:00
|
|
|
if (!store->isValidPath(p)) {
|
|
|
|
unknown.insert(p);
|
|
|
|
continue;
|
|
|
|
}
|
2006-03-06 12:21:15 +01:00
|
|
|
Derivation drv = derivationFromPath(p);
|
|
|
|
|
|
|
|
bool mustBuild = false;
|
2009-04-21 13:52:16 +02:00
|
|
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
2007-08-12 02:29:28 +02:00
|
|
|
if (!store->isValidPath(i->second.path) && !store->hasSubstitutes(i->second.path))
|
2006-03-06 12:21:15 +01:00
|
|
|
mustBuild = true;
|
|
|
|
|
|
|
|
if (mustBuild) {
|
|
|
|
willBuild.insert(p);
|
|
|
|
todo.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
2009-04-21 13:52:16 +02:00
|
|
|
foreach (DerivationInputs::iterator, i, drv.inputDrvs)
|
2006-03-06 12:21:15 +01:00
|
|
|
todo.insert(i->first);
|
|
|
|
} else
|
2009-04-21 13:52:16 +02:00
|
|
|
foreach (DerivationOutputs::iterator, i, drv.outputs)
|
2006-03-06 12:21:15 +01:00
|
|
|
todo.insert(i->second.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2006-11-30 18:43:04 +01:00
|
|
|
if (store->isValidPath(p)) continue;
|
2008-08-02 14:54:35 +02:00
|
|
|
SubstitutablePathInfo info;
|
2008-08-04 13:44:50 +02:00
|
|
|
if (store->querySubstitutablePathInfo(p, info)) {
|
2006-03-06 12:21:15 +01:00
|
|
|
willSubstitute.insert(p);
|
2008-08-04 14:29:04 +02:00
|
|
|
downloadSize += info.downloadSize;
|
2008-08-02 14:54:35 +02:00
|
|
|
todo.insert(info.references.begin(), info.references.end());
|
2008-08-04 13:44:50 +02:00
|
|
|
} else
|
|
|
|
unknown.insert(p);
|
2006-03-06 12:21:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|