1 : #include "misc.hh"
2 : #include "store.hh"
3 : #include "build.hh"
4 : #include "db.hh"
5 :
6 : #include <aterm2.h>
7 :
8 :
9 : namespace nix {
10 :
11 :
12 : Derivation derivationFromPath(const Path & drvPath)
13 193 : {
14 193 : assertStorePath(drvPath);
15 193 : ensurePath(drvPath);
16 193 : ATerm t = ATreadFromNamedFile(drvPath.c_str());
17 193 : if (!t) throw Error(format("cannot read aterm from `%1%'") % drvPath);
18 193 : return parseDerivation(t);
19 : }
20 :
21 :
22 : void computeFSClosure(const Path & storePath,
23 : PathSet & paths, bool flipDirection)
24 276 : {
25 276 : if (paths.find(storePath) != paths.end()) return;
26 234 : paths.insert(storePath);
27 :
28 234 : PathSet references;
29 234 : if (flipDirection)
30 2 : queryReferrers(noTxn, storePath, references);
31 : else
32 232 : queryReferences(noTxn, storePath, references);
33 :
34 353 : for (PathSet::iterator i = references.begin();
35 : i != references.end(); ++i)
36 119 : computeFSClosure(*i, paths, flipDirection);
37 : }
38 :
39 :
40 : Path findOutput(const Derivation & drv, string id)
41 47 : {
42 47 : for (DerivationOutputs::const_iterator i = drv.outputs.begin();
43 : i != drv.outputs.end(); ++i)
44 47 : if (i->first == id) return i->second.path;
45 0 : throw Error(format("derivation has no output `%1%'") % id);
46 : }
47 :
48 :
49 : void queryMissing(const PathSet & targets,
50 : PathSet & willBuild, PathSet & willSubstitute)
51 0 : {
52 0 : PathSet todo(targets.begin(), targets.end()), done;
53 :
54 0 : while (!todo.empty()) {
55 0 : Path p = *(todo.begin());
56 0 : todo.erase(p);
57 0 : if (done.find(p) != done.end()) continue;
58 0 : done.insert(p);
59 :
60 0 : if (isDerivation(p)) {
61 0 : if (!isValidPath(p)) continue;
62 0 : Derivation drv = derivationFromPath(p);
63 :
64 0 : bool mustBuild = false;
65 0 : for (DerivationOutputs::iterator i = drv.outputs.begin();
66 : i != drv.outputs.end(); ++i)
67 0 : if (!isValidPath(i->second.path) &&
68 0 : querySubstitutes(noTxn, i->second.path).size() == 0)
69 0 : mustBuild = true;
70 :
71 0 : if (mustBuild) {
72 0 : willBuild.insert(p);
73 0 : todo.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
74 0 : for (DerivationInputs::iterator i = drv.inputDrvs.begin();
75 : i != drv.inputDrvs.end(); ++i)
76 0 : todo.insert(i->first);
77 : } else
78 0 : for (DerivationOutputs::iterator i = drv.outputs.begin();
79 : i != drv.outputs.end(); ++i)
80 0 : todo.insert(i->second.path);
81 : }
82 :
83 : else {
84 0 : if (isValidPath(p)) continue;
85 0 : if (querySubstitutes(noTxn, p).size() > 0)
86 0 : willSubstitute.insert(p);
87 0 : PathSet refs;
88 0 : queryReferences(noTxn, p, todo);
89 : }
90 : }
91 : }
92 :
93 :
94 345 : }
|