* Re-enable dot graph generation.

This commit is contained in:
Eelco Dolstra 2005-03-26 22:06:57 +00:00
parent 298dd487bb
commit 6f788880b6
2 changed files with 44 additions and 34 deletions

View file

@ -2,7 +2,6 @@
#include "build.hh" #include "build.hh"
#if 0
static string dotQuote(const string & s) static string dotQuote(const string & s)
{ {
return "\"" + s + "\""; return "\"" + s + "\"";
@ -40,10 +39,8 @@ static string makeNode(const string & id, const string & label,
static string symbolicName(const string & path) static string symbolicName(const string & path)
{ {
string p = baseNameOf(path); string p = baseNameOf(path);
if (isHash(string(p, 0, md5HashSize * 2)) && int dash = p.find('-');
p[md5HashSize * 2] == '-') return string(p, dash + 1);
p = string(p, md5HashSize * 2 + 1);
return p;
} }
@ -53,12 +50,13 @@ string pathLabel(const Path & nePath, const string & elemPath)
} }
#if 0
void printClosure(const Path & nePath, const StoreExpr & fs) void printClosure(const Path & nePath, const StoreExpr & fs)
{ {
PathSet workList(fs.closure.roots); PathSet workList(fs.closure.roots);
PathSet doneSet; PathSet doneSet;
for (PathSet::iterator i = workList.begin(); i != workList.end(); i++) { for (PathSet::iterator i = workList.begin(); i != workList.end(); ++i) {
cout << makeEdge(pathLabel(nePath, *i), nePath); cout << makeEdge(pathLabel(nePath, *i), nePath);
} }
@ -74,7 +72,7 @@ void printClosure(const Path & nePath, const StoreExpr & fs)
throw Error(format("bad closure, missing path `%1%'") % path); throw Error(format("bad closure, missing path `%1%'") % path);
for (StringSet::const_iterator i = elem->second.refs.begin(); for (StringSet::const_iterator i = elem->second.refs.begin();
i != elem->second.refs.end(); i++) i != elem->second.refs.end(); ++i)
{ {
workList.insert(*i); workList.insert(*i);
cout << makeEdge(pathLabel(nePath, *i), pathLabel(nePath, path)); cout << makeEdge(pathLabel(nePath, *i), pathLabel(nePath, path));
@ -85,6 +83,7 @@ void printClosure(const Path & nePath, const StoreExpr & fs)
} }
} }
} }
#endif
void printDotGraph(const PathSet & roots) void printDotGraph(const PathSet & roots)
@ -95,43 +94,56 @@ void printDotGraph(const PathSet & roots)
cout << "digraph G {\n"; cout << "digraph G {\n";
while (!workList.empty()) { while (!workList.empty()) {
Path nePath = *(workList.begin()); Path path = *(workList.begin());
workList.erase(nePath); workList.erase(path);
if (doneSet.find(nePath) == doneSet.end()) { if (doneSet.find(path) != doneSet.end()) continue;
doneSet.insert(nePath); doneSet.insert(path);
StoreExpr ne = storeExprFromPath(nePath); cout << makeNode(path, symbolicName(path), "#ff0000");
PathSet references;
queryReferences(noTxn, path, references);
for (PathSet::iterator i = references.begin();
i != references.end(); ++i)
{
workList.insert(*i);
cout << makeEdge(*i, path);
}
#if 0
StoreExpr ne = storeExprFromPath(path);
string label, colour; string label, colour;
if (ne.type == StoreExpr::neDerivation) { if (ne.type == StoreExpr::neDerivation) {
for (PathSet::iterator i = ne.derivation.inputs.begin(); for (PathSet::iterator i = ne.derivation.inputs.begin();
i != ne.derivation.inputs.end(); i++) i != ne.derivation.inputs.end(); ++i)
{ {
workList.insert(*i); workList.insert(*i);
cout << makeEdge(*i, nePath); cout << makeEdge(*i, path);
} }
label = "derivation"; label = "derivation";
colour = "#00ff00"; colour = "#00ff00";
for (StringPairs::iterator i = ne.derivation.env.begin(); for (StringPairs::iterator i = ne.derivation.env.begin();
i != ne.derivation.env.end(); i++) i != ne.derivation.env.end(); ++i)
if (i->first == "name") label = i->second; if (i->first == "name") label = i->second;
} }
else if (ne.type == StoreExpr::neClosure) { else if (ne.type == StoreExpr::neClosure) {
label = "<closure>"; label = "<closure>";
colour = "#00ffff"; colour = "#00ffff";
printClosure(nePath, ne); printClosure(path, ne);
} }
else abort(); else abort();
cout << makeNode(nePath, label, colour); cout << makeNode(path, label, colour);
} #endif
} }
cout << "}\n"; cout << "}\n";
} }
#endif

View file

@ -67,20 +67,20 @@ static void opRealise(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
*i = fixPath(*i); *i = fixPath(*i);
if (opArgs.size() > 1) { if (opArgs.size() > 1) {
PathSet drvPaths; PathSet drvPaths;
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
if (isDerivation(*i)) if (isDerivation(*i))
drvPaths.insert(*i); drvPaths.insert(*i);
buildDerivations(drvPaths); buildDerivations(drvPaths);
} }
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
cout << format("%1%\n") % realisePath(*i); cout << format("%1%\n") % realisePath(*i);
} }
@ -91,7 +91,7 @@ static void opAdd(Strings opFlags, Strings opArgs)
{ {
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); i++) for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i)
cout << format("%1%\n") % addToStore(*i); cout << format("%1%\n") % addToStore(*i);
} }
@ -145,7 +145,7 @@ static Path maybeUseOutput(const Path & storePath, bool useOutput, bool forceRea
static void printPathSet(const PathSet & paths) static void printPathSet(const PathSet & paths)
{ {
for (PathSet::iterator i = paths.begin(); for (PathSet::iterator i = paths.begin();
i != paths.end(); i++) i != paths.end(); ++i)
cout << format("%s\n") % *i; cout << format("%s\n") % *i;
} }
@ -263,7 +263,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qOutputs: { case qOutputs: {
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
{ {
*i = fixPath(*i); *i = fixPath(*i);
if (forceRealise) realisePath(*i); if (forceRealise) realisePath(*i);
@ -279,7 +279,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qReferersClosure: { case qReferersClosure: {
PathSet paths; PathSet paths;
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
{ {
Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise); Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise);
if (query == qRequisites) if (query == qRequisites)
@ -294,7 +294,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qDeriver: case qDeriver:
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
{ {
Path deriver = queryDeriver(noTxn, fixPath(*i)); Path deriver = queryDeriver(noTxn, fixPath(*i));
cout << format("%1%\n") % cout << format("%1%\n") %
@ -304,7 +304,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qBinding: case qBinding:
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
{ {
*i = fixPath(*i); *i = fixPath(*i);
Derivation drv = derivationFromPath(*i); Derivation drv = derivationFromPath(*i);
@ -318,7 +318,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qHash: case qHash:
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
{ {
Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise); Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise);
Hash hash = queryPathHash(path); Hash hash = queryPathHash(path);
@ -330,21 +330,19 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qTree: { case qTree: {
PathSet done; PathSet done;
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
printDrvTree(fixPath(*i), "", "", done); printDrvTree(fixPath(*i), "", "", done);
break; break;
} }
#if 0
case qGraph: { case qGraph: {
PathSet roots; PathSet roots;
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); i++) i != opArgs.end(); ++i)
roots.insert(maybeNormalise(*i, normalise, realise)); roots.insert(maybeUseOutput(fixPath(*i), useOutput, forceRealise));
printDotGraph(roots); printDotGraph(roots);
break; break;
} }
#endif
default: default:
abort(); abort();