about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/misc.cc76
-rw-r--r--src/libstore/normalise.cc3
-rw-r--r--src/libstore/normalise.hh39
-rw-r--r--src/libstore/store.cc2
-rw-r--r--src/libstore/storeexpr.cc15
-rw-r--r--src/libstore/storeexpr.hh30
6 files changed, 71 insertions, 94 deletions
diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc
index 24a522c1ed44..2757a061ece2 100644
--- a/src/libstore/misc.cc
+++ b/src/libstore/misc.cc
@@ -26,65 +26,39 @@ void computeFSClosure(const Path & storePath,
 }
 
 
-#if 0
-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)
-        for (DerivationOutputs::iterator i = ne.derivation.outputs.begin();
-             i != ne.derivation.outputs.end(); ++i)
-            paths.insert(i->second.path);
-    else abort();
-
-    return paths;
-}
-
-
-static void requisitesWorker(const Path & nePath,
-    bool includeExprs, bool includeSuccessors,
-    PathSet & paths, PathSet & doneSet)
+void storePathRequisites(const Path & storePath,
+    bool includeOutputs, PathSet & paths)
 {
     checkInterrupt();
     
-    if (doneSet.find(nePath) != doneSet.end()) return;
-    doneSet.insert(nePath);
+    if (paths.find(storePath) != paths.end()) return;
 
-    StoreExpr ne = storeExprFromPath(nePath);
+    if (isDerivation(storePath)) {
 
-    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);
+        paths.insert(storePath);
+        
+        Derivation drv = derivationFromPath(storePath);
 
-    else abort();
+        for (PathSet::iterator i = drv.inputDrvs.begin();
+             i != drv.inputDrvs.end(); ++i)
+            storePathRequisites(*i, includeOutputs, paths);
 
-    if (includeExprs) paths.insert(nePath);
+        for (PathSet::iterator i = drv.inputSrcs.begin();
+             i != drv.inputSrcs.end(); ++i)
+            storePathRequisites(*i, includeOutputs, paths);
 
-    Path nfPath;
-    if (includeSuccessors && querySuccessor(nePath, nfPath))
-        requisitesWorker(nfPath, includeExprs, includeSuccessors,
-            paths, doneSet);
-}
+        if (includeOutputs) {
 
+            for (DerivationOutputs::iterator i = drv.outputs.begin();
+                 i != drv.outputs.end(); ++i)
+                if (isValidPath(i->second.path))
+                    storePathRequisites(i->second.path, includeOutputs, paths);
 
-PathSet storeExprRequisites(const Path & nePath,
-    bool includeExprs, bool includeSuccessors)
-{
-    PathSet paths;
-    PathSet doneSet;
-    requisitesWorker(nePath, includeExprs, includeSuccessors,
-        paths, doneSet);
-    return paths;
+        }
+        
+    }
+
+    else {
+        computeFSClosure(storePath, paths);
+    }
 }
-#endif
diff --git a/src/libstore/normalise.cc b/src/libstore/normalise.cc
index a01b6d801704..9424bd24abd9 100644
--- a/src/libstore/normalise.cc
+++ b/src/libstore/normalise.cc
@@ -1307,6 +1307,9 @@ void SubstitutionGoal::init()
         return;
     }
 
+    /* !!! build the outgoing references of this path first to
+       maintain the closure invariant! */
+
     /* Otherwise, get the substitutes. */
     subs = querySubstitutes(storePath);
 
diff --git a/src/libstore/normalise.hh b/src/libstore/normalise.hh
index 2a084b7ed467..c5257f9b9dc5 100644
--- a/src/libstore/normalise.hh
+++ b/src/libstore/normalise.hh
@@ -3,7 +3,6 @@
 
 #include "storeexpr.hh"
 
-
 /* Perform the specified derivation, if necessary.  That is, do
    whatever is necessary to create the output paths of the
    derivation.  If the output paths already exists, we're done.  If
@@ -20,29 +19,29 @@ void ensurePath(const Path & storePath);
    through ensurePath(). */
 Derivation derivationFromPath(const Path & drvPath);
 
-
-/* Places in `paths' the set of all store paths in the file system
+/* Place in `paths' the set of all store paths in the file system
    closure of `storePath'; that is, all paths than can be directly or
    indirectly reached from it.  `paths' is not cleared. */
 void computeFSClosure(const Path & storePath,
     PathSet & paths);
 
-
-#if 0
-/* Get the list of root (output) paths of the given store
-   expression. */
-PathSet storeExprRoots(const Path & nePath);
-
-/* Get the list of paths that are required to realise the given store
-   expression.  For a derive expression, this is the union of
-   requisites of the inputs; for a closure expression, it is the path
-   of each element in the closure.  If `includeExprs' is true, include
-   the paths of the store expressions themselves.  If
-   `includeSuccessors' is true, include the requisites of
-   successors. */
-PathSet storeExprRequisites(const Path & nePath,
-    bool includeExprs, bool includeSuccessors);
-#endif
-
+/* Place in `paths' the set of paths that are required to `realise'
+   the given store path, i.e., all paths necessary for valid
+   deployment of the path.  For a derivation, this is the union of
+   requisites of the inputs, plus the derivation; for other store
+   paths, it is the set of paths in the FS closure of the path.  If
+   `includeOutputs' is true, include the requisites of the output
+   paths of derivations as well.
+
+   Note that this function can be used to implement three different
+   deployment policies:
+
+   - Source deployment (when called on a derivation).
+   - Binary deployment (when called on an output path).
+   - Source/binary deployment (when called on a derivation with
+     `includeOutputs' set to true).
+*/
+void storePathRequisites(const Path & storePath,
+    bool includeOutputs, PathSet & paths);
 
 #endif /* !__NORMALISE_H */
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 51e2e7e7d2cc..01c724b918ae 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -217,6 +217,8 @@ void setReferences(const Transaction & txn, const Path & storePath,
 void queryReferences(const Path & storePath, PathSet & references)
 {
     Paths references2;
+    if (!isValidPath(storePath))
+        throw Error(format("path `%1%' is not valid") % storePath);
     nixDB.queryStrings(noTxn, dbReferences, storePath, references2);
     references.insert(references2.begin(), references2.end());
 }
diff --git a/src/libstore/storeexpr.cc b/src/libstore/storeexpr.cc
index d7c87bfa151c..a9240130e755 100644
--- a/src/libstore/storeexpr.cc
+++ b/src/libstore/storeexpr.cc
@@ -12,11 +12,10 @@ Hash hashTerm(ATerm t)
 }
 
 
-Path writeTerm(ATerm t, const string & suffix)
+Path writeDerivation(const Derivation & drv, const string & name)
 {
-    char * s = ATwriteToString(t);
-    if (!s) throw Error("cannot print aterm");
-    return addTextToStore(suffix + ".store", string(s));
+    return addTextToStore(name + drvExtension,
+        atPrint(unparseDerivation(drv)));
 }
 
 
@@ -133,3 +132,11 @@ ATerm unparseDerivation(const Derivation & drv)
         ATreverse(args),
         ATreverse(env));
 }
+
+
+bool isDerivation(const string & fileName)
+{
+    return
+        fileName.size() >= drvExtension.size() &&
+        string(fileName, fileName.size() - drvExtension.size()) == drvExtension;
+}
diff --git a/src/libstore/storeexpr.hh b/src/libstore/storeexpr.hh
index 8eb80a19a845..c7b35f8ebe45 100644
--- a/src/libstore/storeexpr.hh
+++ b/src/libstore/storeexpr.hh
@@ -5,23 +5,11 @@
 #include "store.hh"
 
 
-/* Abstract syntax of store expressions. */
+/* Extension of derivations in the Nix store. */
+const string drvExtension = ".drv";
 
-struct ClosureElem
-{
-    PathSet refs;
-};
-
-typedef map<Path, ClosureElem> ClosureElems;
-
-/*
-struct Closure
-{
-    PathSet roots;
-    ClosureElems elems;
-};
-*/
 
+/* Abstract syntax of derivations. */
 
 struct DerivationOutput
 {
@@ -57,14 +45,18 @@ struct Derivation
 /* Hash an aterm. */
 Hash hashTerm(ATerm t);
 
-/* Write an aterm to the Nix store directory, and return its path. */
-Path writeTerm(ATerm t, const string & suffix);
+/* Write a derivation to the Nix store, and return its path. */
+Path writeDerivation(const Derivation & drv, const string & name);
 
-/* Parse a store expression. */
+/* Parse a derivation. */
 Derivation parseDerivation(ATerm t);
 
-/* Parse a store expression. */
+/* Parse a derivation. */
 ATerm unparseDerivation(const Derivation & drv);
 
+/* Check whether a file name ends with the extensions for
+   derivations. */
+bool isDerivation(const string & fileName);
+
 
 #endif /* !__STOREEXPR_H */