about summary refs log tree commit diff
path: root/src/nix-instantiate/nix-instantiate.cc
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2010-03-31T12·38+0000
committerLudovic Courtès <ludo@gnu.org>2010-03-31T12·38+0000
commit09381cccffe675ccbc8d183f043788f99dc018cd (patch)
tree0c38ffd9438be5422dc871c75abd7b5b19ee11da /src/nix-instantiate/nix-instantiate.cc
parent471419d1fac21412dea9a47eff200d44cd75d825 (diff)
Make source location info in the XML output optional.
* src/libexpr/expr-to-xml.cc (nix::showAttrs): Add `location'
  parameter.  Provide location XML attributes when it's true.  Update
  callers.
  (nix::printTermAsXML): Likewise.

* src/libexpr/expr-to-xml.hh (nix::printTermAsXML): Update prototype;
  have `location' default to `false'.

* src/nix-instantiate/nix-instantiate.cc (printResult, processExpr): Add
  `location' parameter; update callers.
  (run): Add support for `--no-location'.

* src/nix-instantiate/help.txt: Update accordingly.

* tests/lang.sh: Invoke `nix-instantiate' with `--no-location' for the
  XML tests.

* tests/lang/eval-okay-toxml.exp, tests/lang/eval-okay-to-xml.nix: New
  files.
Diffstat (limited to 'src/nix-instantiate/nix-instantiate.cc')
-rw-r--r--src/nix-instantiate/nix-instantiate.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index 3822de5c6289..21f352f2580d 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -38,13 +38,13 @@ static bool indirectRoot = false;
 
 
 static void printResult(EvalState & state, Expr e,
-    bool evalOnly, bool xmlOutput, const ATermMap & autoArgs)
+    bool evalOnly, bool xmlOutput, bool location, const ATermMap & autoArgs)
 {
     PathSet context;
     
     if (evalOnly)
         if (xmlOutput)
-            printTermAsXML(e, std::cout, context);
+            printTermAsXML(e, std::cout, context, location);
         else
             std::cout << format("%1%\n") % canonicaliseExpr(e);
     
@@ -67,7 +67,7 @@ static void printResult(EvalState & state, Expr e,
 
 void processExpr(EvalState & state, const Strings & attrPaths,
     bool parseOnly, bool strict, const ATermMap & autoArgs,
-    bool evalOnly, bool xmlOutput, Expr e)
+    bool evalOnly, bool xmlOutput, bool location, Expr e)
 {
     for (Strings::const_iterator i = attrPaths.begin(); i != attrPaths.end(); ++i) {
         Expr e2 = findAlongAttrPath(state, *i, autoArgs, e);
@@ -76,7 +76,7 @@ void processExpr(EvalState & state, const Strings & attrPaths,
                 e2 = strictEvalExpr(state, e2);
             else
                 e2 = evalExpr(state, e2);
-        printResult(state, e2, evalOnly, xmlOutput, autoArgs);
+        printResult(state, e2, evalOnly, xmlOutput, location, autoArgs);
     }
 }
 
@@ -89,6 +89,7 @@ void run(Strings args)
     bool evalOnly = false;
     bool parseOnly = false;
     bool xmlOutput = false;
+    bool xmlOutputSourceLocation = true;
     bool strict = false;
     Strings attrPaths;
     ATermMap autoArgs(128);
@@ -124,6 +125,8 @@ void run(Strings args)
             indirectRoot = true;
         else if (arg == "--xml")
             xmlOutput = true;
+        else if (arg == "--no-location")
+            xmlOutputSourceLocation = false;
         else if (arg == "--strict")
             strict = true;
         else if (arg[0] == '-')
@@ -139,7 +142,7 @@ void run(Strings args)
     if (readStdin) {
         Expr e = parseStdin(state);
         processExpr(state, attrPaths, parseOnly, strict, autoArgs,
-            evalOnly, xmlOutput, e);
+            evalOnly, xmlOutput, xmlOutputSourceLocation, e);
     }
 
     for (Strings::iterator i = files.begin();
@@ -148,7 +151,7 @@ void run(Strings args)
         Path path = absPath(*i);
         Expr e = parseExprFromFile(state, path);
         processExpr(state, attrPaths, parseOnly, strict, autoArgs,
-            evalOnly, xmlOutput, e);
+            evalOnly, xmlOutput, xmlOutputSourceLocation, e);
     }
 
     printEvalStats(state);