about summary refs log tree commit diff
path: root/src/libstore/misc.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-06-18T18·09+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-06-18T18·09+0000
commit41ec982f3132c32991a48a82735a036f844e7299 (patch)
tree9606ec3c8e90de2e60edd44acd12d761bf3e3d1c /src/libstore/misc.cc
parent3454c685eec2aebe6f61f7deebc40162bab22e69 (diff)
* Big refactoring. Move to a much more explicitly state machine based
  approach.  This makes it much easier to add extra complexity in the
  normaliser / realiser (e.g., build hooks, substitutes).

Diffstat (limited to 'src/libstore/misc.cc')
-rw-r--r--src/libstore/misc.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
new file mode 100644
index 000000000000..d7c32336e4cd
--- /dev/null
+++ b/src/libstore/misc.cc
@@ -0,0 +1,72 @@
+#include "normalise.hh"
+
+
+StoreExpr storeExprFromPath(const Path & path)
+{
+    assertStorePath(path);
+    ensurePath(path);
+    ATerm t = ATreadFromNamedFile(path.c_str());
+    if (!t) throw Error(format("cannot read aterm from `%1%'") % path);
+    return parseStoreExpr(t);
+}
+
+
+PathSet storeExprRoots(const Path & nePath)
+{
+    PathSet paths;
+
+    StoreExpr ne = storeExprFromPath(nePath);
+
+    if (ne.type == StoreExpr::neClosure)
+        paths.insert(ne.closure.roots.begin(), ne.closure.roots.end());
+    else if (ne.type == StoreExpr::neDerivation)
+        paths.insert(ne.derivation.outputs.begin(),
+            ne.derivation.outputs.end());
+    else abort();
+
+    return paths;
+}
+
+
+static void requisitesWorker(const Path & nePath,
+    bool includeExprs, bool includeSuccessors,
+    PathSet & paths, PathSet & doneSet)
+{
+    checkInterrupt();
+    
+    if (doneSet.find(nePath) != doneSet.end()) return;
+    doneSet.insert(nePath);
+
+    StoreExpr ne = storeExprFromPath(nePath);
+
+    if (ne.type == StoreExpr::neClosure)
+        for (ClosureElems::iterator i = ne.closure.elems.begin();
+             i != ne.closure.elems.end(); ++i)
+            paths.insert(i->first);
+    
+    else if (ne.type == StoreExpr::neDerivation)
+        for (PathSet::iterator i = ne.derivation.inputs.begin();
+             i != ne.derivation.inputs.end(); ++i)
+            requisitesWorker(*i,
+                includeExprs, includeSuccessors, paths, doneSet);
+
+    else abort();
+
+    if (includeExprs) paths.insert(nePath);
+
+    Path nfPath;
+    if (includeSuccessors && querySuccessor(nePath, nfPath))
+        requisitesWorker(nfPath, includeExprs, includeSuccessors,
+            paths, doneSet);
+}
+
+
+PathSet storeExprRequisites(const Path & nePath,
+    bool includeExprs, bool includeSuccessors)
+{
+    PathSet paths;
+    PathSet doneSet;
+    requisitesWorker(nePath, includeExprs, includeSuccessors,
+        paths, doneSet);
+    return paths;
+}