about summary refs log tree commit diff
path: root/src/nix-instantiate
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-08-17T08·53+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-08-17T08·53+0000
commit24e234a2fabd8930f1ef71a5bb03010725d0773a (patch)
tree788fcece67f02443c794ef2576811c273ec44879 /src/nix-instantiate
parent22ba63df162d3ac980f5c33210929177e0a3dfe0 (diff)
* Print attributes in sorted order, rather than the arbitrary order
  produced by ATermMap.  Necessary for testing.
* `--strict' should also work on stdin.

Diffstat (limited to 'src/nix-instantiate')
-rw-r--r--src/nix-instantiate/main.cc31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc
index 3f42de3f7879..0ea639dd91b3 100644
--- a/src/nix-instantiate/main.cc
+++ b/src/nix-instantiate/main.cc
@@ -75,9 +75,12 @@ static void printTermAsXML(Expr e, XMLWriter & doc)
         XMLOpenElement _(doc, "attrs");
         ATermMap attrs(128);
         queryAllAttrs(e, attrs);
-        for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
-            XMLOpenElement _(doc, "attr", singletonAttrs("name", aterm2String(i->key)));
-            printTermAsXML(i->value, doc);
+        StringSet names;
+        for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i)
+            names.insert(aterm2String(i->key));
+        for (StringSet::iterator i = names.begin(); i != names.end(); ++i) {
+            XMLOpenElement _(doc, "attr", singletonAttrs("name", *i));
+            printTermAsXML(attrs.get(toATerm(*i)), doc);
         }
     }
 
@@ -175,6 +178,18 @@ Expr strictEval(EvalState & state, Expr e)
 }
 
 
+Expr doEval(EvalState & state, string attrPath, bool parseOnly, bool strict, Expr e)
+{
+    e = findAlongAttrPath(state, attrPath, e);
+    if (!parseOnly)
+        if (strict)
+            e = strictEval(state, e);
+        else
+            e = evalExpr(state, e);
+    return e;
+}
+
+
 void run(Strings args)
 {
     EvalState state;
@@ -236,8 +251,8 @@ void run(Strings args)
     openDB();
 
     if (readStdin) {
-        Expr e = findAlongAttrPath(state, attrPath, parseStdin(state));
-        if (!parseOnly) e = evalExpr(state, e);
+        Expr e = parseStdin(state);
+        e = doEval(state, attrPath, parseOnly, strict, e);
         printResult(state, e, evalOnly, xmlOutput, autoArgs);
     }
 
@@ -245,10 +260,8 @@ void run(Strings args)
          i != files.end(); i++)
     {
         Path path = absPath(*i);
-        Expr e = findAlongAttrPath(state, attrPath,
-            parseExprFromFile(state, path));
-        if (!parseOnly) e = evalExpr(state, e);
-        if (strict) e = strictEval(state, e);
+        Expr e = parseExprFromFile(state, path);
+        e = doEval(state, attrPath, parseOnly, strict, e);
         printResult(state, e, evalOnly, xmlOutput, autoArgs);
     }