nix-store, nix-env: reformat some bits
this will make the next commit a lot more readable. Change-Id: I74ffad9b9f635c35d51861982558a5e020ab4687
This commit is contained in:
+69
-33
@@ -1135,6 +1135,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
|
||||
RunPager pager;
|
||||
|
||||
{
|
||||
Table table;
|
||||
std::ostringstream dummy;
|
||||
XMLWriter xml(true, *(xmlOutput ? &cout : &dummy));
|
||||
@@ -1142,14 +1143,17 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
|
||||
for (auto & i : elems) {
|
||||
try {
|
||||
if (i.hasFailed()) continue;
|
||||
if (i.hasFailed()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Activity act(*logger, lvlDebug, "outputting query result '%1%'", i.attrPath);
|
||||
|
||||
if (globals.prebuiltOnly &&
|
||||
!validPaths.count(i.queryOutPath(*state)) &&
|
||||
!substitutablePaths.count(i.queryOutPath(*state)))
|
||||
if (globals.prebuiltOnly && !validPaths.count(i.queryOutPath(*state))
|
||||
&& !substitutablePaths.count(i.queryOutPath(*state)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* For table output. */
|
||||
Strings columns;
|
||||
@@ -1166,17 +1170,19 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
attrs["installed"] = isInstalled ? "1" : "0";
|
||||
attrs["valid"] = isValid ? "1" : "0";
|
||||
attrs["substitutable"] = hasSubs ? "1" : "0";
|
||||
} else
|
||||
} else {
|
||||
columns.push_back(
|
||||
(std::string) (isInstalled ? "I" : "-")
|
||||
+ (isValid ? "P" : "-")
|
||||
+ (hasSubs ? "S" : "-"));
|
||||
(std::string) (isInstalled ? "I" : "-") + (isValid ? "P" : "-")
|
||||
+ (hasSubs ? "S" : "-")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (xmlOutput)
|
||||
if (xmlOutput) {
|
||||
attrs["attrPath"] = i.attrPath;
|
||||
else if (printAttrPath)
|
||||
} else if (printAttrPath) {
|
||||
columns.push_back(i.attrPath);
|
||||
}
|
||||
|
||||
if (xmlOutput) {
|
||||
auto drvName = DrvName(i.queryName(*state));
|
||||
@@ -1197,11 +1203,20 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
|
||||
char ch;
|
||||
switch (diff) {
|
||||
case cvLess: ch = '>'; break;
|
||||
case cvEqual: ch = '='; break;
|
||||
case cvGreater: ch = '<'; break;
|
||||
case cvUnavail: ch = '-'; break;
|
||||
default: abort();
|
||||
case cvLess:
|
||||
ch = '>';
|
||||
break;
|
||||
case cvEqual:
|
||||
ch = '=';
|
||||
break;
|
||||
case cvGreater:
|
||||
ch = '<';
|
||||
break;
|
||||
case cvUnavail:
|
||||
ch = '-';
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
|
||||
if (xmlOutput) {
|
||||
@@ -1211,35 +1226,47 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
}
|
||||
} else {
|
||||
auto column = (std::string) "" + ch + " " + version;
|
||||
if (diff == cvGreater && shouldANSI(StandardOutputStream::Stdout))
|
||||
if (diff == cvGreater && shouldANSI(StandardOutputStream::Stdout)) {
|
||||
column = ANSI_RED + column + ANSI_NORMAL;
|
||||
}
|
||||
columns.push_back(column);
|
||||
}
|
||||
}
|
||||
|
||||
if (xmlOutput) {
|
||||
if (i.querySystem(*state) != "") attrs["system"] = i.querySystem(*state);
|
||||
if (i.querySystem(*state) != "") {
|
||||
attrs["system"] = i.querySystem(*state);
|
||||
}
|
||||
else if (printSystem)
|
||||
} else if (printSystem) {
|
||||
columns.push_back(i.querySystem(*state));
|
||||
}
|
||||
|
||||
if (printDrvPath) {
|
||||
auto drvPath = i.queryDrvPath(*state);
|
||||
if (xmlOutput) {
|
||||
if (drvPath) attrs["drvPath"] = store.printStorePath(*drvPath);
|
||||
} else
|
||||
if (drvPath) {
|
||||
attrs["drvPath"] = store.printStorePath(*drvPath);
|
||||
}
|
||||
} else {
|
||||
columns.push_back(drvPath ? store.printStorePath(*drvPath) : "-");
|
||||
}
|
||||
}
|
||||
|
||||
if (xmlOutput)
|
||||
if (xmlOutput) {
|
||||
attrs["outputName"] = i.queryOutputName(*state);
|
||||
}
|
||||
|
||||
if (printOutPath && !xmlOutput) {
|
||||
DrvInfo::Outputs outputs = i.queryOutputs(*state);
|
||||
std::string s;
|
||||
for (auto & j : outputs) {
|
||||
if (!s.empty()) s += ';';
|
||||
if (j.first != "out") { s += j.first; s += "="; }
|
||||
if (!s.empty()) {
|
||||
s += ';';
|
||||
}
|
||||
if (j.first != "out") {
|
||||
s += j.first;
|
||||
s += "=";
|
||||
}
|
||||
s += store.printStorePath(*j.second);
|
||||
}
|
||||
columns.push_back(s);
|
||||
@@ -1248,10 +1275,13 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
if (printDescription) {
|
||||
auto descr = i.queryMetaString(*state, "description");
|
||||
if (xmlOutput) {
|
||||
if (descr != "") attrs["description"] = descr;
|
||||
} else
|
||||
if (descr != "") {
|
||||
attrs["description"] = descr;
|
||||
}
|
||||
} else {
|
||||
columns.push_back(descr);
|
||||
}
|
||||
}
|
||||
|
||||
if (xmlOutput) {
|
||||
XMLOpenElement item(xml, "item", attrs);
|
||||
@@ -1259,8 +1289,9 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
for (auto & j : outputs) {
|
||||
XMLAttrs attrs2;
|
||||
attrs2["name"] = j.first;
|
||||
if (j.second)
|
||||
if (j.second) {
|
||||
attrs2["path"] = store.printStorePath(*j.second);
|
||||
}
|
||||
xml.writeEmptyElement("output", attrs2);
|
||||
}
|
||||
if (printMeta) {
|
||||
@@ -1269,11 +1300,11 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
XMLAttrs attrs2;
|
||||
attrs2["name"] = j;
|
||||
Value * v = i.queryMeta(*state, j);
|
||||
if (!v)
|
||||
if (!v) {
|
||||
printError(
|
||||
"derivation '%s' has invalid meta attribute '%s'",
|
||||
i.queryName(*state), j);
|
||||
else {
|
||||
"derivation '%s' has invalid meta attribute '%s'", i.queryName(*state), j
|
||||
);
|
||||
} else {
|
||||
if (v->type() == nString) {
|
||||
attrs2["type"] = "string";
|
||||
attrs2["value"] = v->str();
|
||||
@@ -1319,13 +1350,18 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
table.push_back(columns);
|
||||
}
|
||||
|
||||
cout.flush();
|
||||
|
||||
} catch (AssertionError & e) {
|
||||
printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName(*state));
|
||||
printMsg(
|
||||
lvlTalkative,
|
||||
"skipping derivation named '%1%' which gives an assertion failure",
|
||||
i.queryName(*state)
|
||||
);
|
||||
} catch (Error & e) {
|
||||
e.addTrace(nullptr, "while querying the derivation named '%1%'", i.queryName(*state));
|
||||
throw;
|
||||
@@ -1336,7 +1372,7 @@ static void opQuery(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
std::cout << printTable(table);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void opSwitchProfile(Globals & globals, Strings opFlags, Strings opArgs)
|
||||
{
|
||||
|
||||
+62
-45
@@ -377,16 +377,17 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
|
||||
|
||||
RunPager pager;
|
||||
|
||||
{
|
||||
switch (*query) {
|
||||
|
||||
case qOutputs: {
|
||||
for (auto & i : opArgs) {
|
||||
auto outputs = aio.blockOn(
|
||||
maybeUseOutputs(store, store->followLinksToStorePath(i), true, forceRealise)
|
||||
);
|
||||
for (auto & outputPath : outputs)
|
||||
auto outputs =
|
||||
aio.blockOn(maybeUseOutputs(store, store->followLinksToStorePath(i), true, forceRealise));
|
||||
for (auto & outputPath : outputs) {
|
||||
cout << fmt("%1%\n", store->printStorePath(outputPath));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -396,54 +397,55 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
|
||||
case qReferrersClosure: {
|
||||
StorePathSet paths;
|
||||
for (auto & i : opArgs) {
|
||||
auto ps = aio.blockOn(maybeUseOutputs(
|
||||
store, store->followLinksToStorePath(i), useOutput, forceRealise
|
||||
));
|
||||
auto ps = aio.blockOn(
|
||||
maybeUseOutputs(store, store->followLinksToStorePath(i), useOutput, forceRealise)
|
||||
);
|
||||
for (auto & j : ps) {
|
||||
if (query == qRequisites) {
|
||||
aio.blockOn(store->computeFSClosure(j, paths, false, includeOutputs));
|
||||
}
|
||||
else if (query == qReferences) {
|
||||
for (auto & p : aio.blockOn(store->queryPathInfo(j))->references)
|
||||
} else if (query == qReferences) {
|
||||
for (auto & p : aio.blockOn(store->queryPathInfo(j))->references) {
|
||||
paths.insert(p);
|
||||
}
|
||||
else if (query == qReferrers) {
|
||||
} else if (query == qReferrers) {
|
||||
StorePathSet tmp;
|
||||
aio.blockOn(store->queryReferrers(j, tmp));
|
||||
for (auto & i : tmp)
|
||||
for (auto & i : tmp) {
|
||||
paths.insert(i);
|
||||
}
|
||||
else if (query == qReferrersClosure)
|
||||
} else if (query == qReferrersClosure) {
|
||||
aio.blockOn(store->computeFSClosure(j, paths, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
auto sorted = aio.blockOn(store->topoSortPaths(paths));
|
||||
for (StorePaths::reverse_iterator i = sorted.rbegin();
|
||||
i != sorted.rend(); ++i)
|
||||
for (StorePaths::reverse_iterator i = sorted.rbegin(); i != sorted.rend(); ++i) {
|
||||
cout << fmt("%s\n", store->printStorePath(*i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case qDeriver:
|
||||
for (auto & i : opArgs) {
|
||||
auto info = aio.blockOn(store->queryPathInfo(store->followLinksToStorePath(i)));
|
||||
cout << fmt("%s\n", info->deriver ? store->printStorePath(*info->deriver) : "unknown-deriver");
|
||||
cout << fmt(
|
||||
"%s\n", info->deriver ? store->printStorePath(*info->deriver) : "unknown-deriver"
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case qValidDerivers: {
|
||||
StorePathSet result;
|
||||
for (auto & i : opArgs) {
|
||||
auto derivers =
|
||||
aio.blockOn(store->queryValidDerivers(store->followLinksToStorePath(i)));
|
||||
auto derivers = aio.blockOn(store->queryValidDerivers(store->followLinksToStorePath(i)));
|
||||
for (const auto & i : derivers) {
|
||||
result.insert(i);
|
||||
}
|
||||
}
|
||||
auto sorted = aio.blockOn(store->topoSortPaths(result));
|
||||
for (StorePaths::reverse_iterator i = sorted.rbegin();
|
||||
i != sorted.rend(); ++i)
|
||||
for (StorePaths::reverse_iterator i = sorted.rbegin(); i != sorted.rend(); ++i) {
|
||||
cout << fmt("%s\n", store->printStorePath(*i));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -452,9 +454,13 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
|
||||
auto path = aio.blockOn(useDeriver(store, store->followLinksToStorePath(i)));
|
||||
Derivation drv = aio.blockOn(store->derivationFromPath(path));
|
||||
StringPairs::iterator j = drv.env.find(bindingName);
|
||||
if (j == drv.env.end())
|
||||
throw Error("derivation '%s' has no environment binding named '%s'",
|
||||
store->printStorePath(path), bindingName);
|
||||
if (j == drv.env.end()) {
|
||||
throw Error(
|
||||
"derivation '%s' has no environment binding named '%s'",
|
||||
store->printStorePath(path),
|
||||
bindingName
|
||||
);
|
||||
}
|
||||
cout << fmt("%s\n", j->second);
|
||||
}
|
||||
break;
|
||||
@@ -462,79 +468,89 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
|
||||
case qHash:
|
||||
case qSize:
|
||||
for (auto & i : opArgs) {
|
||||
for (auto & j : aio.blockOn(maybeUseOutputs(
|
||||
store, store->followLinksToStorePath(i), useOutput, forceRealise
|
||||
)))
|
||||
for (auto & j : aio.blockOn(
|
||||
maybeUseOutputs(store, store->followLinksToStorePath(i), useOutput, forceRealise)
|
||||
))
|
||||
{
|
||||
auto info = aio.blockOn(store->queryPathInfo(j));
|
||||
if (query == qHash) {
|
||||
assert(info->narHash.type == HashType::SHA256);
|
||||
cout << fmt("%s\n", info->narHash.to_string(HashFormat::Base32));
|
||||
} else if (query == qSize)
|
||||
} else if (query == qSize) {
|
||||
cout << fmt("%d\n", info->narSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case qTree: {
|
||||
StorePathSet done;
|
||||
for (auto & i : opArgs)
|
||||
for (auto & i : opArgs) {
|
||||
printTree(std::cout, store, aio, store->followLinksToStorePath(i), "", "", done);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case qGraph: {
|
||||
StorePathSet roots;
|
||||
for (auto & i : opArgs)
|
||||
for (auto & j : aio.blockOn(maybeUseOutputs(
|
||||
store, store->followLinksToStorePath(i), useOutput, forceRealise
|
||||
)))
|
||||
for (auto & i : opArgs) {
|
||||
for (auto & j : aio.blockOn(
|
||||
maybeUseOutputs(store, store->followLinksToStorePath(i), useOutput, forceRealise)
|
||||
))
|
||||
{
|
||||
roots.insert(j);
|
||||
}
|
||||
}
|
||||
std::cout << aio.blockOn(printDotGraph(ref<Store>::unsafeFromPtr(store), std::move(roots)));
|
||||
break;
|
||||
}
|
||||
|
||||
case qGraphML: {
|
||||
StorePathSet roots;
|
||||
for (auto & i : opArgs)
|
||||
for (auto & j : aio.blockOn(maybeUseOutputs(
|
||||
store, store->followLinksToStorePath(i), useOutput, forceRealise
|
||||
)))
|
||||
for (auto & i : opArgs) {
|
||||
for (auto & j : aio.blockOn(
|
||||
maybeUseOutputs(store, store->followLinksToStorePath(i), useOutput, forceRealise)
|
||||
))
|
||||
{
|
||||
roots.insert(j);
|
||||
}
|
||||
}
|
||||
std::cout << aio.blockOn(printGraphML(ref<Store>::unsafeFromPtr(store), std::move(roots)));
|
||||
break;
|
||||
}
|
||||
|
||||
case qResolve: {
|
||||
for (auto & i : opArgs)
|
||||
for (auto & i : opArgs) {
|
||||
cout << fmt("%s\n", store->printStorePath(store->followLinksToStorePath(i)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case qRoots: {
|
||||
StorePathSet args;
|
||||
for (auto & i : opArgs)
|
||||
for (auto & p : aio.blockOn(maybeUseOutputs(
|
||||
store, store->followLinksToStorePath(i), useOutput, forceRealise
|
||||
)))
|
||||
for (auto & i : opArgs) {
|
||||
for (auto & p : aio.blockOn(
|
||||
maybeUseOutputs(store, store->followLinksToStorePath(i), useOutput, forceRealise)
|
||||
))
|
||||
{
|
||||
args.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
StorePathSet referrers;
|
||||
aio.blockOn(store->computeFSClosure(
|
||||
args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations));
|
||||
args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations
|
||||
));
|
||||
|
||||
auto & gcStore = require<GcStore>(*store);
|
||||
Roots roots = aio.blockOn(gcStore.findRoots(false));
|
||||
for (auto & [target, links] : roots)
|
||||
if (referrers.find(target) != referrers.end())
|
||||
for (auto & link : links)
|
||||
for (auto & [target, links] : roots) {
|
||||
if (referrers.find(target) != referrers.end()) {
|
||||
for (auto & link : links) {
|
||||
cout << fmt("%1% -> %2%\n", link, gcStore.printStorePath(target));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -542,6 +558,7 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
opPrintEnv(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, Strings opArgs)
|
||||
|
||||
Reference in New Issue
Block a user