diff options
Diffstat (limited to 'src/nix.cc')
-rw-r--r-- | src/nix.cc | 64 |
1 files changed, 4 insertions, 60 deletions
diff --git a/src/nix.cc b/src/nix.cc index 04195e8d4428..41ed16839725 100644 --- a/src/nix.cc +++ b/src/nix.cc @@ -5,6 +5,7 @@ #include "normalise.hh" #include "archive.hh" #include "shared.hh" +#include "dotgraph.hh" typedef void (* Operation) (Strings opFlags, Strings opArgs); @@ -80,12 +81,6 @@ static void opAdd(Strings opFlags, Strings opArgs) } -static string dotQuote(const string & s) -{ - return "\"" + s + "\""; -} - - FSId maybeNormalise(const FSId & id, bool normalise) { return normalise ? normaliseFState(id) : id; @@ -170,62 +165,11 @@ static void opQuery(Strings opFlags, Strings opArgs) } case qGraph: { - - FSIds workList; - + FSIds roots; for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) - workList.push_back(argToId(*i)); - - FSIdSet doneSet; - - cout << "digraph G {\n"; - - while (!workList.empty()) { - FSId id = workList.front(); - workList.pop_front(); - - if (doneSet.find(id) == doneSet.end()) { - doneSet.insert(id); - - FState fs = parseFState(termFromId(id)); - - string label, shape; - - if (fs.type == FState::fsDerive) { - for (FSIdSet::iterator i = fs.derive.inputs.begin(); - i != fs.derive.inputs.end(); i++) - { - workList.push_back(*i); - cout << dotQuote(*i) << " -> " - << dotQuote(id) << ";\n"; - } - - label = "derive"; - shape = "box"; - for (StringPairs::iterator i = fs.derive.env.begin(); - i != fs.derive.env.end(); i++) - if (i->first == "name") label = i->second; - } - - else if (fs.type == FState::fsSlice) { - label = baseNameOf((*fs.slice.elems.begin()).first); - shape = "ellipse"; - if (isHash(string(label, 0, Hash::hashSize * 2)) && - label[Hash::hashSize * 2] == '-') - label = string(label, Hash::hashSize * 2 + 1); - } - - else abort(); - - cout << dotQuote(id) << "[label = " - << dotQuote(label) - << ", shape = " << shape - << "];\n"; - } - } - - cout << "}\n"; + roots.push_back(argToId(*i)); + printDotGraph(roots); break; } |