about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-16T08·30+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-16T08·30+0000
commitc11bbcfd26e554ca044c1cce293097e4e87ef31e (patch)
treeccbaf5b13b7f4d6de35ef7fcdaa00e51f194a25d /src
parentd41d085b771d0f87658fe22512178603b3a0c633 (diff)
* Fix self-referential outputs.
* Fix -qp query.

Diffstat (limited to 'src')
-rw-r--r--src/fix.cc2
-rw-r--r--src/fstate.cc30
-rw-r--r--src/fstate.hh16
-rw-r--r--src/nix.cc9
-rw-r--r--src/test-builder-2.sh1
5 files changed, 28 insertions, 30 deletions
diff --git a/src/fix.cc b/src/fix.cc
index f5f92a87b568..d954abfe4be2 100644
--- a/src/fix.cc
+++ b/src/fix.cc
@@ -164,7 +164,7 @@ static Expr evalExpr(Expr e)
             char * id;
 
             if (ATmatch(value, "FSId(<str>)", &id)) {
-                Strings paths = fstatePaths(parseHash(id));
+                Strings paths = fstatePaths(parseHash(id), false);
                 if (paths.size() != 1) abort();
                 string path = *(paths.begin());
                 ins = ATinsert(ins, ATmake("<str>", id));
diff --git a/src/fstate.cc b/src/fstate.cc
index d15219344fc9..60a8d475c981 100644
--- a/src/fstate.cc
+++ b/src/fstate.cc
@@ -332,19 +332,19 @@ Slice normaliseFState(FSId id)
     }
 
     /* Check that none of the output paths exist. */
-    typedef pair<string, FSId> OutPath;
-    list<OutPath> outPaths;
+    typedef map<string, FSId> OutPaths;
+    OutPaths outPaths;
     while (!ATisEmpty(outs)) {
         ATerm t = ATgetFirst(outs);
         char * s1, * s2;
         if (!ATmatch(t, "(<str>, <str>)", &s1, &s2))
             throw badTerm("string expected", t);
-        outPaths.push_back(OutPath(s1, parseHash(s2)));
+        outPaths[s1] = parseHash(s2);
         inPaths.push_back(s1);
         outs = ATgetNext(outs);
     }
 
-    for (list<OutPath>::iterator i = outPaths.begin(); 
+    for (OutPaths::iterator i = outPaths.begin(); 
          i != outPaths.end(); i++)
         if (pathExists(i->first))
             throw Error(format("path `%1%' exists") % i->first);
@@ -357,7 +357,7 @@ Slice normaliseFState(FSId id)
     /* Check whether the output paths were created, and register each
        one. */
     FSIdSet used;
-    for (list<OutPath>::iterator i = outPaths.begin(); 
+    for (OutPaths::iterator i = outPaths.begin(); 
          i != outPaths.end(); i++)
     {
         string path = i->first;
@@ -374,10 +374,15 @@ Slice normaliseFState(FSId id)
 
         for (Strings::iterator j = refs.begin(); j != refs.end(); j++) {
             ElemMap::iterator k;
+            OutPaths::iterator l;
             if ((k = inMap.find(*j)) != inMap.end()) {
                 elem.refs.push_back(k->second.id);
                 used.insert(k->second.id);
-            } else abort(); /* fix! check in created paths */
+            } else if ((l = outPaths.find(*j)) != outPaths.end()) {
+                elem.refs.push_back(l->second);
+                used.insert(l->second);
+            } else 
+                throw Error(format("unknown referenced path `%1%'") % *j);
         }
 
         slice.elems.push_back(elem);
@@ -470,7 +475,7 @@ void realiseSlice(const Slice & slice)
 }
 
 
-Strings fstatePaths(FSId id)
+Strings fstatePaths(FSId id, bool normalise)
 {
     Strings paths;
 
@@ -480,10 +485,15 @@ Strings fstatePaths(FSId id)
     char * builder;
     char * platform;
 
-    if (ATgetType(fs) == AT_APPL && 
-        (string) ATgetName(ATgetAFun(fs)) == "Slice")
+    if (normalise ||
+        (ATgetType(fs) == AT_APPL && 
+         (string) ATgetName(ATgetAFun(fs)) == "Slice"))
     {
-        Slice slice = parseSlice(fs);
+        Slice slice;
+        if (normalise)
+            slice = normaliseFState(id);
+        else
+            slice = parseSlice(fs);
 
         /* !!! fix complexity */
         for (FSIds::const_iterator i = slice.roots.begin();
diff --git a/src/fstate.hh b/src/fstate.hh
index afbf34dab28a..72fc52805291 100644
--- a/src/fstate.hh
+++ b/src/fstate.hh
@@ -74,20 +74,6 @@ struct Slice
 };
 
 
-#if 0
-/* Realise an fstate expression in the file system.  This requires
-   execution of all Derive() nodes. */
-FState realiseFState(FState fs, StringSet & paths);
-
-/* Return the path of an fstate expression.  An empty string is
-   returned if the term is not a valid fstate expression. (!!!) */
-string fstatePath(FState fs);
-
-/* Return the paths referenced by fstate expression. */
-void fstateRefs(FState fs, StringSet & paths);
-#endif
-
-
 /* Return a canonical textual representation of an expression. */
 string printTerm(ATerm t);
 
@@ -115,7 +101,7 @@ Slice normaliseFState(FSId id);
 /* Realise a Slice in the file system. */
 void realiseSlice(const Slice & slice);
 
-Strings fstatePaths(FSId id);
+Strings fstatePaths(FSId id, bool normalise);
 
 
 #endif /* !__FSTATE_H */
diff --git a/src/nix.cc b/src/nix.cc
index 9c77c68f4110..22928880f9ad 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -157,14 +157,15 @@ static void opQuery(Strings opFlags, Strings opArgs)
 
         switch (query) {
 
-#if 0
         case qPath: {
-            StringSet refs;
-            cout << format("%s\n") % 
-                (string) fstatePath(realiseFState(termFromHash(hash), refs));
+            Strings paths = fstatePaths(id, true);
+            for (Strings::iterator i = paths.begin(); 
+                 i != paths.end(); i++)
+                cout << format("%s\n") % *i;
             break;
         }
 
+#if 0
         case qRefs: {
             StringSet refs;
             FState fs = hash2fstate(hash);
diff --git a/src/test-builder-2.sh b/src/test-builder-2.sh
index a12fa27a67fd..1c4ac8494c47 100644
--- a/src/test-builder-2.sh
+++ b/src/test-builder-2.sh
@@ -6,3 +6,4 @@ mkdir $out || exit 1
 cd $out || exit 1
 echo "Hallo Wereld" > bla
 echo $builder >> bla
+echo $out >> bla