about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin2c/Makefile.am3
-rw-r--r--src/libexpr/expr-to-xml.cc66
-rw-r--r--src/libexpr/expr-to-xml.hh2
-rw-r--r--src/libutil/util.cc10
-rw-r--r--src/libutil/xml-writer.cc1
-rw-r--r--src/nix-instantiate/help.txt2
-rw-r--r--src/nix-instantiate/nix-instantiate.cc15
7 files changed, 70 insertions, 29 deletions
diff --git a/src/bin2c/Makefile.am b/src/bin2c/Makefile.am
index bdd58808a159..bba3c3e3ac56 100644
--- a/src/bin2c/Makefile.am
+++ b/src/bin2c/Makefile.am
@@ -1,3 +1,6 @@
 noinst_PROGRAMS = bin2c
 
 bin2c_SOURCES = bin2c.c
+
+bin2c$(EXEEXT): bin2c.c
+	$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o bin2c bin2c.c
diff --git a/src/libexpr/expr-to-xml.cc b/src/libexpr/expr-to-xml.cc
index e401001ead01..1e59eebfc497 100644
--- a/src/libexpr/expr-to-xml.cc
+++ b/src/libexpr/expr-to-xml.cc
@@ -24,18 +24,35 @@ typedef set<Expr> ExprSet;
 
 
 static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
-    ExprSet & drvsSeen);
+    ExprSet & drvsSeen, bool location);
 
 
 static void showAttrs(const ATermMap & attrs, XMLWriter & doc,
-    PathSet & context, ExprSet & drvsSeen)
+    PathSet & context, ExprSet & drvsSeen, bool location)
 {
     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, context, drvsSeen);
+        ATerm attrRHS = attrs.get(toATerm(*i));
+	ATerm attr;
+	Pos pos;
+	XMLAttrs xmlAttrs;
+
+	xmlAttrs["name"] = *i;
+	if(matchAttrRHS(attrRHS, attr, pos)) {
+	    ATerm path;
+	    int line, column;
+            if (location && matchPos(pos, path, line, column)) {
+		xmlAttrs["path"] = aterm2String(path);
+		xmlAttrs["line"] = (format("%1%") % line).str();
+		xmlAttrs["column"] = (format("%1%") % column).str();
+	    }
+	} else
+	    abort(); // Should not happen.
+
+        XMLOpenElement _(doc, "attr", xmlAttrs);
+        printTermAsXML(attr, doc, context, drvsSeen, location);
     }
 }
 
@@ -66,7 +83,7 @@ static void printPatternAsXML(Pattern pat, XMLWriter & doc)
 
 
 static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
-    ExprSet & drvsSeen)
+    ExprSet & drvsSeen, bool location)
 {
     XMLAttrs attrs;
     string s;
@@ -97,45 +114,58 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
 
     else if (matchAttrs(e, as)) {
         ATermMap attrs;
-        queryAllAttrs(e, attrs);
+        queryAllAttrs(e, attrs, true);
 
-        Expr a = attrs.get(toATerm("type"));
+        Expr aRHS = attrs.get(toATerm("type"));
+	Expr a = NULL;
+	if (aRHS)
+	    matchAttrRHS(aRHS, a, pos);
         if (a && matchStr(a, s, context) && s == "derivation") {
 
             XMLAttrs xmlAttrs;
             Path outPath, drvPath;
-            
-            a = attrs.get(toATerm("drvPath"));
+
+            aRHS = attrs.get(toATerm("drvPath"));
+            matchAttrRHS(aRHS, a, pos);
             if (matchStr(a, drvPath, context))
                 xmlAttrs["drvPath"] = drvPath;
-        
-            a = attrs.get(toATerm("outPath"));
+
+            aRHS = attrs.get(toATerm("outPath"));
+            matchAttrRHS(aRHS, a, pos);
             if (matchStr(a, outPath, context))
                 xmlAttrs["outPath"] = outPath;
-        
+
             XMLOpenElement _(doc, "derivation", xmlAttrs);
 
             if (drvsSeen.find(e) == drvsSeen.end()) {
                 drvsSeen.insert(e);
-                showAttrs(attrs, doc, context, drvsSeen);
+                showAttrs(attrs, doc, context, drvsSeen, location);
             } else
                 doc.writeEmptyElement("repeated");
         }
 
         else {
             XMLOpenElement _(doc, "attrs");
-            showAttrs(attrs, doc, context, drvsSeen);
+            showAttrs(attrs, doc, context, drvsSeen, location);
         }
     }
 
     else if (matchList(e, es)) {
         XMLOpenElement _(doc, "list");
         for (ATermIterator i(es); i; ++i)
-            printTermAsXML(*i, doc, context, drvsSeen);
+            printTermAsXML(*i, doc, context, drvsSeen, location);
     }
 
     else if (matchFunction(e, pat, body, pos)) {
-        XMLOpenElement _(doc, "function");
+        ATerm path;
+	int line, column;
+	XMLAttrs xmlAttrs;
+	if (location && matchPos(pos, path, line, column)) {
+	    xmlAttrs["path"] = aterm2String(path);
+	    xmlAttrs["line"] = (format("%1%") % line).str();
+	    xmlAttrs["column"] = (format("%1%") % column).str();
+	}
+	XMLOpenElement _(doc, "function", xmlAttrs);
         printPatternAsXML(pat, doc);
     }
 
@@ -144,12 +174,12 @@ static void printTermAsXML(Expr e, XMLWriter & doc, PathSet & context,
 }
 
 
-void printTermAsXML(Expr e, std::ostream & out, PathSet & context)
+void printTermAsXML(Expr e, std::ostream & out, PathSet & context, bool location)
 {
     XMLWriter doc(true, out);
     XMLOpenElement root(doc, "expr");
     ExprSet drvsSeen;    
-    printTermAsXML(e, doc, context, drvsSeen);
+    printTermAsXML(e, doc, context, drvsSeen, location);
 }
 
  
diff --git a/src/libexpr/expr-to-xml.hh b/src/libexpr/expr-to-xml.hh
index 576a46fc36d0..cf64f26e3b9a 100644
--- a/src/libexpr/expr-to-xml.hh
+++ b/src/libexpr/expr-to-xml.hh
@@ -8,7 +8,7 @@
 
 namespace nix {
 
-void printTermAsXML(Expr e, std::ostream & out, PathSet & context);
+void printTermAsXML(Expr e, std::ostream & out, PathSet & context, bool location = false);
     
 }
 
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 3f76be670839..1c1c9a9e5b74 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -809,7 +809,8 @@ void killUser(uid_t uid)
     case 0:
         try { /* child */
 
-            if (setuid(uid) == -1) abort();
+            if (setuid(uid) == -1)
+                throw SysError("setting uid");
 
 	    while (true) {
 		if (kill(-1, SIGKILL) == 0) break;
@@ -819,7 +820,7 @@ void killUser(uid_t uid)
 	    }
 
         } catch (std::exception & e) {
-            std::cerr << format("killing processes beloging to uid `%1%': %1%")
+            std::cerr << format("killing processes belonging to uid `%1%': %2%")
                 % uid % e.what() << std::endl;
             quickExit(1);
         }
@@ -827,8 +828,9 @@ void killUser(uid_t uid)
     }
     
     /* parent */
-    if (pid.wait(true) != 0)
-        throw Error(format("cannot kill processes for uid `%1%'") % uid);
+    int status = pid.wait(true);
+    if (status != 0)
+        throw Error(format("cannot kill processes for uid `%1%': %2%") % uid % statusToString(status));
 
     /* !!! We should really do some check to make sure that there are
        no processes left running under `uid', but there is no portable
diff --git a/src/libutil/xml-writer.cc b/src/libutil/xml-writer.cc
index 20351e2c30ac..7d698bf6aed5 100644
--- a/src/libutil/xml-writer.cc
+++ b/src/libutil/xml-writer.cc
@@ -91,6 +91,7 @@ void XMLWriter::writeAttrs(const XMLAttrs & attrs)
             char c = i->second[j];
             if (c == '"') output << "&quot;";
             else if (c == '<') output << "&lt;";
+            else if (c == '>') output << "&gt;";
             else if (c == '&') output << "&amp;";
             /* Escape newlines to prevent attribute normalisation (see
                XML spec, section 3.3.3. */
diff --git a/src/nix-instantiate/help.txt b/src/nix-instantiate/help.txt
index fa0a4590ee92..21822132aece 100644
--- a/src/nix-instantiate/help.txt
+++ b/src/nix-instantiate/help.txt
@@ -22,6 +22,8 @@ Options:
 For --eval-only / --parse-only:
 
   --xml: print an XML representation of the abstract syntax tree
+  --no-location: don't provide source location information in the
+    output XML tree
 
 For --eval-only:
 
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index d8b39eca2694..03fb35ada18e 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -39,13 +39,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);
     
@@ -68,7 +68,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);
@@ -77,7 +77,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);
     }
 }
 
@@ -90,6 +90,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);
@@ -125,6 +126,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] == '-')
@@ -140,7 +143,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();
@@ -149,7 +152,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);