about summary refs log tree commit diff
path: root/src/nix-env/nix-env.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-28T12·49+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-11-28T12·49+0100
commit8eed07cda4c193bfcdd6ac4345ac6fb54aee0269 (patch)
tree1a06eea7b3dc23526a3aa1d87ec394cddbc8fbff /src/nix-env/nix-env.cc
parent6c98e6a5dec2bcbc25ddeb2c279aa4a0b274bd6a (diff)
nix-env -q --out-path: Support multiple outputs
We now print all output paths of a package, e.g.

  openssl-1.0.0i  bin=/nix/store/gq2mvh0wb9l90djvsagln3aqywqmr6vl-openssl-1.0.0i-bin;man=/nix/store/7zwf5r5hsdarl3n86dasvb4chm2xzw9n-openssl-1.0.0i-man;/nix/store/cj7xvk7fjp9q887359j75pw3pzjfmqf1-openssl-1.0.0i

or (in XML mode)

  <item attrPath="openssl" name="openssl-1.0.0i" system="x86_64-linux">
    <output name="bin" path="/nix/store/gq2mvh0wb9l90djvsagln3aqywqmr6vl-openssl-1.0.0i-bin" />
    <output name="man" path="/nix/store/7zwf5r5hsdarl3n86dasvb4chm2xzw9n-openssl-1.0.0i-man" />
    <output name="out" path="/nix/store/cj7xvk7fjp9q887359j75pw3pzjfmqf1-openssl-1.0.0i" />
  </item>
Diffstat (limited to 'src/nix-env/nix-env.cc')
-rw-r--r--src/nix-env/nix-env.cc79
1 files changed, 46 insertions, 33 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index 5e171d0a0b..c980116b20 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -1030,7 +1030,7 @@ static void opQuery(Globals & globals,
             if (xmlOutput) {
                 if (i->system != "") attrs["system"] = i->system;
             }
-            else if (printSystem) 
+            else if (printSystem)
                 columns.push_back(i->system);
 
             if (printDrvPath) {
@@ -1040,13 +1040,16 @@ static void opQuery(Globals & globals,
                 } else
                     columns.push_back(drvPath == "" ? "-" : drvPath);
             }
-        
-            if (printOutPath) {
-                string outPath = i->queryOutPath(globals.state);
-                if (xmlOutput) {
-                    if (outPath != "") attrs["outPath"] = outPath;
-                } else
-                    columns.push_back(outPath);
+
+            if (printOutPath && !xmlOutput) {
+                DrvInfo::Outputs outputs = i->queryOutputs(globals.state);
+                string s;
+                foreach (DrvInfo::Outputs::iterator, j, outputs) {
+                    if (!s.empty()) s += ';';
+                    if (j->first != "out") { s += j->first; s += "="; }
+                    s += j->second;
+                }
+                columns.push_back(s);
             }
 
             if (printDescription) {
@@ -1059,35 +1062,45 @@ static void opQuery(Globals & globals,
                     columns.push_back(descr);
             }
 
-            if (xmlOutput)
-                if (printMeta) {
+            if (xmlOutput) {
+                if (printOutPath || printMeta) {
                     XMLOpenElement item(xml, "item", attrs);
-                    MetaInfo meta = i->queryMetaInfo(globals.state);
-                    for (MetaInfo::iterator j = meta.begin(); j != meta.end(); ++j) {
-                        XMLAttrs attrs2;
-                        attrs2["name"] = j->first;
-                        if (j->second.type == MetaValue::tpString) {
-                            attrs2["type"] = "string";
-                            attrs2["value"] = j->second.stringValue;
-                            xml.writeEmptyElement("meta", attrs2);
-                        } else if (j->second.type == MetaValue::tpInt) {
-                            attrs2["type"] = "int";
-                            attrs2["value"] = (format("%1%") % j->second.intValue).str();
-                            xml.writeEmptyElement("meta", attrs2);
-                        } else if (j->second.type == MetaValue::tpStrings) {
-                            attrs2["type"] = "strings";
-                            XMLOpenElement m(xml, "meta", attrs2);
-                            foreach (Strings::iterator, k, j->second.stringValues) { 
-                                XMLAttrs attrs3;
-                                attrs3["value"] = *k;
-                                xml.writeEmptyElement("string", attrs3);
-                           }
+                    if (printOutPath) {
+                        DrvInfo::Outputs outputs = i->queryOutputs(globals.state);
+                        foreach (DrvInfo::Outputs::iterator, j, outputs) {
+                            XMLAttrs attrs2;
+                            attrs2["name"] = j->first;
+                            attrs2["path"] = j->second;
+                            xml.writeEmptyElement("output", attrs2);
                         }
                     }
-                }
-                else
+                    if (printMeta) {
+                        MetaInfo meta = i->queryMetaInfo(globals.state);
+                        for (MetaInfo::iterator j = meta.begin(); j != meta.end(); ++j) {
+                            XMLAttrs attrs2;
+                            attrs2["name"] = j->first;
+                            if (j->second.type == MetaValue::tpString) {
+                                attrs2["type"] = "string";
+                                attrs2["value"] = j->second.stringValue;
+                                xml.writeEmptyElement("meta", attrs2);
+                            } else if (j->second.type == MetaValue::tpInt) {
+                                attrs2["type"] = "int";
+                                attrs2["value"] = (format("%1%") % j->second.intValue).str();
+                                xml.writeEmptyElement("meta", attrs2);
+                            } else if (j->second.type == MetaValue::tpStrings) {
+                                attrs2["type"] = "strings";
+                                XMLOpenElement m(xml, "meta", attrs2);
+                                foreach (Strings::iterator, k, j->second.stringValues) { 
+                                    XMLAttrs attrs3;
+                                    attrs3["value"] = *k;
+                                    xml.writeEmptyElement("string", attrs3);
+                               }
+                            }
+                        }
+                    }
+                } else
                     xml.writeEmptyElement("item", attrs);
-            else
+            } else
                 table.push_back(columns);
 
             cout.flush();