nix why-depends: Fix showing self-references
This commit is contained in:
parent
359ede1d72
commit
1c58ad2ffa
1 changed files with 16 additions and 8 deletions
|
@ -1,6 +1,4 @@
|
||||||
#include "command.hh"
|
#include "command.hh"
|
||||||
#include "common-args.hh"
|
|
||||||
#include "shared.hh"
|
|
||||||
#include "store-api.hh"
|
#include "store-api.hh"
|
||||||
#include "progress-bar.hh"
|
#include "progress-bar.hh"
|
||||||
#include "fs-accessor.hh"
|
#include "fs-accessor.hh"
|
||||||
|
@ -59,9 +57,17 @@ struct CmdWhyDepends : SourceExprCommand
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Example{
|
Example{
|
||||||
"To show which files in Hello's closure depend on Glibc:",
|
"To show one path through the dependency graph leading from Hello to Glibc:",
|
||||||
"nix why-depends nixpkgs.hello nixpkgs.glibc"
|
"nix why-depends nixpkgs.hello nixpkgs.glibc"
|
||||||
},
|
},
|
||||||
|
Example{
|
||||||
|
"To show all files and paths in the dependency graph leading from Thunderbird to libX11:",
|
||||||
|
"nix why-depends --all nixpkgs.thunderbird nixpkgs.xorg.libX11"
|
||||||
|
},
|
||||||
|
Example{
|
||||||
|
"To show why Glibc depends on itself:",
|
||||||
|
"nix why-depends nixpkgs.glibc nixpkgs.glibc"
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +147,9 @@ struct CmdWhyDepends : SourceExprCommand
|
||||||
and `dependency`. */
|
and `dependency`. */
|
||||||
std::function<void(Node &, const string &, const string &)> printNode;
|
std::function<void(Node &, const string &, const string &)> printNode;
|
||||||
|
|
||||||
const string treeConn = "├───";
|
const string treeConn = "╠═══";
|
||||||
const string treeLast = "└───";
|
const string treeLast = "╚═══";
|
||||||
const string treeLine = "│ ";
|
const string treeLine = "║ ";
|
||||||
const string treeNull = " ";
|
const string treeNull = " ";
|
||||||
|
|
||||||
struct BailOut { };
|
struct BailOut { };
|
||||||
|
@ -156,7 +162,9 @@ struct CmdWhyDepends : SourceExprCommand
|
||||||
firstPad != "" ? "=> " : "",
|
firstPad != "" ? "=> " : "",
|
||||||
node.path);
|
node.path);
|
||||||
|
|
||||||
if (node.path == dependencyPath && !all) throw BailOut();
|
if (node.path == dependencyPath && !all
|
||||||
|
&& packagePath != dependencyPath)
|
||||||
|
throw BailOut();
|
||||||
|
|
||||||
if (node.visited) return;
|
if (node.visited) return;
|
||||||
node.visited = true;
|
node.visited = true;
|
||||||
|
@ -167,7 +175,7 @@ struct CmdWhyDepends : SourceExprCommand
|
||||||
std::set<std::string> hashes;
|
std::set<std::string> hashes;
|
||||||
|
|
||||||
for (auto & ref : node.refs) {
|
for (auto & ref : node.refs) {
|
||||||
if (ref == node.path) continue;
|
if (ref == node.path && packagePath != dependencyPath) continue;
|
||||||
auto & node2 = graph.at(ref);
|
auto & node2 = graph.at(ref);
|
||||||
if (node2.dist == inf) continue;
|
if (node2.dist == inf) continue;
|
||||||
refs.emplace(node2.dist, &node2);
|
refs.emplace(node2.dist, &node2);
|
||||||
|
|
Loading…
Reference in a new issue