about summary refs log tree commit diff
path: root/src/nix-instantiate
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2007-01-13T18·25+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2007-01-13T18·25+0000
commitf25f9000451ec5b9fb3221cdf2a297fe24ab7357 (patch)
treee9a60d00072644c24cf05151cddaa5c73d718c33 /src/nix-instantiate
parent215505bb46503b083fd64dd9a65e7b79d6eadf21 (diff)
* Allow multiple --attr / -A arguments in nix-build / nix-instantiate
  (NIX-74).

Diffstat (limited to 'src/nix-instantiate')
-rw-r--r--src/nix-instantiate/nix-instantiate.cc35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index 41015c0eee..b49b84e36a 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -64,16 +64,19 @@ static void printResult(EvalState & state, Expr e,
 }
 
 
-Expr doEval(EvalState & state, string attrPath, bool parseOnly, bool strict,
-    const ATermMap & autoArgs, Expr e)
+void processExpr(EvalState & state, const Strings & attrPaths,
+    bool parseOnly, bool strict, const ATermMap & autoArgs,
+    bool evalOnly, bool xmlOutput, Expr e)
 {
-    e = findAlongAttrPath(state, attrPath, autoArgs, e);
-    if (!parseOnly)
-        if (strict)
-            e = strictEvalExpr(state, e);
-        else
-            e = evalExpr(state, e);
-    return e;
+    for (Strings::const_iterator i = attrPaths.begin(); i != attrPaths.end(); ++i) {
+        Expr e2 = findAlongAttrPath(state, *i, autoArgs, e);
+        if (!parseOnly)
+            if (strict)
+                e2 = strictEvalExpr(state, e2);
+            else
+                e2 = evalExpr(state, e2);
+        printResult(state, e2, evalOnly, xmlOutput, autoArgs);
+    }
 }
 
 
@@ -86,7 +89,7 @@ void run(Strings args)
     bool parseOnly = false;
     bool xmlOutput = false;
     bool strict = false;
-    string attrPath;
+    Strings attrPaths;
     ATermMap autoArgs(128);
 
     for (Strings::iterator i = args.begin();
@@ -107,7 +110,7 @@ void run(Strings args)
         else if (arg == "--attr" || arg == "-A") {
             if (i == args.end())
                 throw UsageError("`--attr' requires an argument");
-            attrPath = *i++;
+            attrPaths.push_back(*i++);
         }
         else if (arg == "--arg") {
             if (i == args.end())
@@ -135,12 +138,14 @@ void run(Strings args)
             files.push_back(arg);
     }
 
+    if (attrPaths.empty()) attrPaths.push_back("");
+
     store = openStore();
 
     if (readStdin) {
         Expr e = parseStdin(state);
-        e = doEval(state, attrPath, parseOnly, strict, autoArgs, e);
-        printResult(state, e, evalOnly, xmlOutput, autoArgs);
+        processExpr(state, attrPaths, parseOnly, strict, autoArgs,
+            evalOnly, xmlOutput, e);
     }
 
     for (Strings::iterator i = files.begin();
@@ -148,8 +153,8 @@ void run(Strings args)
     {
         Path path = absPath(*i);
         Expr e = parseExprFromFile(state, path);
-        e = doEval(state, attrPath, parseOnly, strict, autoArgs, e);
-        printResult(state, e, evalOnly, xmlOutput, autoArgs);
+        processExpr(state, attrPaths, parseOnly, strict, autoArgs,
+            evalOnly, xmlOutput, e);
     }
 
     printEvalStats(state);