about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-08-23T16·20+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-08-23T16·20+0000
commit9638f3f3930bffab8a547ec59502ae72e203d9ff (patch)
tree1eff6f713e9ff4e90e04e098b158f110b7adc696 /src
parentb19cebc513c2d513ee1f91b5ce12f30c5dd095f2 (diff)
* Pass the autoArgs to findAlongAttrPath so that "nix-instantiate
  foo.nix -A attr --arg name value" will work if (name, value) is
  needed in the evaluation leading up to "attr".

Diffstat (limited to 'src')
-rw-r--r--src/libexpr/attr-path.cc5
-rw-r--r--src/libexpr/attr-path.hh3
-rw-r--r--src/nix-instantiate/main.cc10
3 files changed, 11 insertions, 7 deletions
diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc
index 63bb1e554041..7228adf95d01 100644
--- a/src/libexpr/attr-path.cc
+++ b/src/libexpr/attr-path.cc
@@ -12,7 +12,8 @@ bool isAttrs(EvalState & state, Expr e, ATermMap & attrs)
 }
 
 
-Expr findAlongAttrPath(EvalState & state, const string & attrPath, Expr e)
+Expr findAlongAttrPath(EvalState & state, const string & attrPath,
+    const ATermMap & autoArgs, Expr e)
 {
     Strings tokens = tokenizeString(attrPath, ".");
 
@@ -33,7 +34,7 @@ Expr findAlongAttrPath(EvalState & state, const string & attrPath, Expr e)
         if (string2Int(attr, attrIndex)) apType = apIndex;
 
         /* Evaluate the expression. */
-        e = evalExpr(state, autoCallFunction(evalExpr(state, e), ATermMap(1)));
+        e = evalExpr(state, autoCallFunction(evalExpr(state, e), autoArgs));
 
         /* It should evaluate to either an attribute set or an
            expression, according to what is specified in the
diff --git a/src/libexpr/attr-path.hh b/src/libexpr/attr-path.hh
index f64ef7a7cdee..0797ecc58218 100644
--- a/src/libexpr/attr-path.hh
+++ b/src/libexpr/attr-path.hh
@@ -7,7 +7,8 @@
 #include "eval.hh"
 
 
-Expr findAlongAttrPath(EvalState & state, const string & attrPath, Expr e);
+Expr findAlongAttrPath(EvalState & state, const string & attrPath,
+    const ATermMap & autoArgs, Expr e);
 
 
 #endif /* !__ATTR_PATH_H */
diff --git a/src/nix-instantiate/main.cc b/src/nix-instantiate/main.cc
index 0ea639dd91b3..29a28c3d8343 100644
--- a/src/nix-instantiate/main.cc
+++ b/src/nix-instantiate/main.cc
@@ -178,9 +178,10 @@ Expr strictEval(EvalState & state, Expr e)
 }
 
 
-Expr doEval(EvalState & state, string attrPath, bool parseOnly, bool strict, Expr e)
+Expr doEval(EvalState & state, string attrPath, bool parseOnly, bool strict,
+    const ATermMap & autoArgs, Expr e)
 {
-    e = findAlongAttrPath(state, attrPath, e);
+    e = findAlongAttrPath(state, attrPath, autoArgs, e);
     if (!parseOnly)
         if (strict)
             e = strictEval(state, e);
@@ -229,6 +230,7 @@ void run(Strings args)
             if (i == args.end())
                 throw UsageError("`--arg' requires two arguments");
             Expr value = parseExprFromString(state, *i++, absPath("."));
+            printMsg(lvlError, format("X %1% Y %2%") % name % value);
             autoArgs.set(toATerm(name), value);
         }
         else if (arg == "--add-root") {
@@ -252,7 +254,7 @@ void run(Strings args)
 
     if (readStdin) {
         Expr e = parseStdin(state);
-        e = doEval(state, attrPath, parseOnly, strict, e);
+        e = doEval(state, attrPath, parseOnly, strict, autoArgs, e);
         printResult(state, e, evalOnly, xmlOutput, autoArgs);
     }
 
@@ -261,7 +263,7 @@ void run(Strings args)
     {
         Path path = absPath(*i);
         Expr e = parseExprFromFile(state, path);
-        e = doEval(state, attrPath, parseOnly, strict, e);
+        e = doEval(state, attrPath, parseOnly, strict, autoArgs, e);
         printResult(state, e, evalOnly, xmlOutput, autoArgs);
     }