forked from lix-project/lix
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>
This commit is contained in:
parent
6c98e6a5de
commit
8eed07cda4
|
@ -138,6 +138,7 @@ EvalState::EvalState()
|
||||||
, sName(symbols.create("name"))
|
, sName(symbols.create("name"))
|
||||||
, sSystem(symbols.create("system"))
|
, sSystem(symbols.create("system"))
|
||||||
, sOverrides(symbols.create("__overrides"))
|
, sOverrides(symbols.create("__overrides"))
|
||||||
|
, sOutputs(symbols.create("outputs"))
|
||||||
, sOutputName(symbols.create("outputName"))
|
, sOutputName(symbols.create("outputName"))
|
||||||
, sIgnoreNulls(symbols.create("__ignoreNulls"))
|
, sIgnoreNulls(symbols.create("__ignoreNulls"))
|
||||||
, baseEnv(allocEnv(128))
|
, baseEnv(allocEnv(128))
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
SymbolTable symbols;
|
SymbolTable symbols;
|
||||||
|
|
||||||
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName,
|
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName,
|
||||||
sSystem, sOverrides, sOutputName, sIgnoreNulls;
|
sSystem, sOverrides, sOutputs, sOutputName, sIgnoreNulls;
|
||||||
|
|
||||||
/* If set, force copying files to the Nix store even if they
|
/* If set, force copying files to the Nix store even if they
|
||||||
already exist there. */
|
already exist there. */
|
||||||
|
|
|
@ -28,12 +28,42 @@ string DrvInfo::queryOutPath(EvalState & state) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DrvInfo::Outputs DrvInfo::queryOutputs(EvalState & state)
|
||||||
|
{
|
||||||
|
if (outputs.empty()) {
|
||||||
|
/* Get the ‘outputs’ list. */
|
||||||
|
Bindings::iterator i = attrs->find(state.sOutputs);
|
||||||
|
|
||||||
|
if (i == attrs->end())
|
||||||
|
outputs["out"] = queryOutPath(state);
|
||||||
|
else {
|
||||||
|
state.forceList(*i->value);
|
||||||
|
|
||||||
|
/* For each output... */
|
||||||
|
for (unsigned int j = 0; j < i->value->list.length; ++j) {
|
||||||
|
/* Evaluate the corresponding attribute set. */
|
||||||
|
string name = state.forceStringNoCtx(*i->value->list.elems[j]);
|
||||||
|
Bindings::iterator out = attrs->find(state.symbols.create(name));
|
||||||
|
if (out == attrs->end()) continue; // FIXME: throw error?
|
||||||
|
state.forceAttrs(*out->value);
|
||||||
|
|
||||||
|
/* And evaluate its ‘outPath’ attribute. */
|
||||||
|
Bindings::iterator outPath = out->value->attrs->find(state.sOutPath);
|
||||||
|
if (outPath == out->value->attrs->end()) continue; // FIXME: throw error?
|
||||||
|
PathSet context;
|
||||||
|
outputs[name] = state.coerceToPath(*outPath->value, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string DrvInfo::queryOutputName(EvalState & state) const
|
string DrvInfo::queryOutputName(EvalState & state) const
|
||||||
{
|
{
|
||||||
if (outputName == "" && attrs) {
|
if (outputName == "" && attrs) {
|
||||||
Bindings::iterator i = attrs->find(state.sOutputName);
|
Bindings::iterator i = attrs->find(state.sOutputName);
|
||||||
PathSet context;
|
(string &) outputName = i != attrs->end() ? state.forceStringNoCtx(*i->value) : "";
|
||||||
(string &) outputName = i != attrs->end() ? state.coerceToString(*i->value, context) : "";
|
|
||||||
}
|
}
|
||||||
return outputName;
|
return outputName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,14 @@ typedef std::map<string, MetaValue> MetaInfo;
|
||||||
|
|
||||||
struct DrvInfo
|
struct DrvInfo
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
typedef std::map<string, Path> Outputs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string drvPath;
|
string drvPath;
|
||||||
string outPath;
|
string outPath;
|
||||||
string outputName;
|
string outputName;
|
||||||
|
Outputs outputs;
|
||||||
|
|
||||||
bool metaInfoRead;
|
bool metaInfoRead;
|
||||||
MetaInfo meta;
|
MetaInfo meta;
|
||||||
|
@ -48,6 +52,7 @@ public:
|
||||||
string queryDrvPath(EvalState & state) const;
|
string queryDrvPath(EvalState & state) const;
|
||||||
string queryOutPath(EvalState & state) const;
|
string queryOutPath(EvalState & state) const;
|
||||||
string queryOutputName(EvalState & state) const;
|
string queryOutputName(EvalState & state) const;
|
||||||
|
Outputs queryOutputs(EvalState & state);
|
||||||
MetaInfo queryMetaInfo(EvalState & state) const;
|
MetaInfo queryMetaInfo(EvalState & state) const;
|
||||||
MetaValue queryMetaInfo(EvalState & state, const string & name) const;
|
MetaValue queryMetaInfo(EvalState & state, const string & name) const;
|
||||||
|
|
||||||
|
|
|
@ -1041,12 +1041,15 @@ static void opQuery(Globals & globals,
|
||||||
columns.push_back(drvPath == "" ? "-" : drvPath);
|
columns.push_back(drvPath == "" ? "-" : drvPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printOutPath) {
|
if (printOutPath && !xmlOutput) {
|
||||||
string outPath = i->queryOutPath(globals.state);
|
DrvInfo::Outputs outputs = i->queryOutputs(globals.state);
|
||||||
if (xmlOutput) {
|
string s;
|
||||||
if (outPath != "") attrs["outPath"] = outPath;
|
foreach (DrvInfo::Outputs::iterator, j, outputs) {
|
||||||
} else
|
if (!s.empty()) s += ';';
|
||||||
columns.push_back(outPath);
|
if (j->first != "out") { s += j->first; s += "="; }
|
||||||
|
s += j->second;
|
||||||
|
}
|
||||||
|
columns.push_back(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printDescription) {
|
if (printDescription) {
|
||||||
|
@ -1059,35 +1062,45 @@ static void opQuery(Globals & globals,
|
||||||
columns.push_back(descr);
|
columns.push_back(descr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xmlOutput)
|
if (xmlOutput) {
|
||||||
if (printMeta) {
|
if (printOutPath || printMeta) {
|
||||||
XMLOpenElement item(xml, "item", attrs);
|
XMLOpenElement item(xml, "item", attrs);
|
||||||
MetaInfo meta = i->queryMetaInfo(globals.state);
|
if (printOutPath) {
|
||||||
for (MetaInfo::iterator j = meta.begin(); j != meta.end(); ++j) {
|
DrvInfo::Outputs outputs = i->queryOutputs(globals.state);
|
||||||
XMLAttrs attrs2;
|
foreach (DrvInfo::Outputs::iterator, j, outputs) {
|
||||||
attrs2["name"] = j->first;
|
XMLAttrs attrs2;
|
||||||
if (j->second.type == MetaValue::tpString) {
|
attrs2["name"] = j->first;
|
||||||
attrs2["type"] = "string";
|
attrs2["path"] = j->second;
|
||||||
attrs2["value"] = j->second.stringValue;
|
xml.writeEmptyElement("output", attrs2);
|
||||||
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 (printMeta) {
|
||||||
else
|
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);
|
xml.writeEmptyElement("item", attrs);
|
||||||
else
|
} else
|
||||||
table.push_back(columns);
|
table.push_back(columns);
|
||||||
|
|
||||||
cout.flush();
|
cout.flush();
|
||||||
|
|
Loading…
Reference in a new issue