2006-09-04 21:06:23 +00:00
|
|
|
#include "dotgraph.hh"
|
|
|
|
#include "util.hh"
|
2006-11-30 17:43:04 +00:00
|
|
|
#include "store-api.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
|
2006-03-01 17:44:28 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
namespace nix {
|
2003-09-03 11:20:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
static string dotQuote(const string & s)
|
|
|
|
{
|
|
|
|
return "\"" + s + "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-03 14:49:58 +00:00
|
|
|
static string nextColour()
|
|
|
|
{
|
|
|
|
static int n = 0;
|
|
|
|
static string colours[] =
|
|
|
|
{ "black", "red", "green", "blue"
|
|
|
|
, "magenta", "burlywood" };
|
|
|
|
return colours[n++ % (sizeof(colours) / sizeof(string))];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static string makeEdge(const string & src, const string & dst)
|
|
|
|
{
|
|
|
|
format f = format("%1% -> %2% [color = %3%];\n")
|
|
|
|
% dotQuote(src) % dotQuote(dst) % dotQuote(nextColour());
|
|
|
|
return f.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static string makeNode(const string & id, const string & label,
|
|
|
|
const string & colour)
|
|
|
|
{
|
|
|
|
format f = format("%1% [label = %2%, shape = box, "
|
|
|
|
"style = filled, fillcolor = %3%];\n")
|
|
|
|
% dotQuote(id) % dotQuote(label) % dotQuote(colour);
|
|
|
|
return f.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static string symbolicName(const string & path)
|
|
|
|
{
|
|
|
|
string p = baseNameOf(path);
|
2005-03-26 22:06:57 +00:00
|
|
|
int dash = p.find('-');
|
|
|
|
return string(p, dash + 1);
|
2003-09-03 14:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-31 16:36:20 +00:00
|
|
|
#if 0
|
2003-10-08 15:06:59 +00:00
|
|
|
string pathLabel(const Path & nePath, const string & elemPath)
|
2003-09-03 14:49:58 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
return (string) nePath + "-" + elemPath;
|
2003-09-03 14:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-18 11:22:29 +00:00
|
|
|
void printClosure(const Path & nePath, const StoreExpr & fs)
|
2003-09-03 14:49:58 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet workList(fs.closure.roots);
|
|
|
|
PathSet doneSet;
|
2003-09-03 14:49:58 +00:00
|
|
|
|
2005-03-26 22:06:57 +00:00
|
|
|
for (PathSet::iterator i = workList.begin(); i != workList.end(); ++i) {
|
2003-10-08 15:06:59 +00:00
|
|
|
cout << makeEdge(pathLabel(nePath, *i), nePath);
|
2003-09-03 14:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!workList.empty()) {
|
2003-10-08 15:06:59 +00:00
|
|
|
Path path = *(workList.begin());
|
|
|
|
workList.erase(path);
|
2003-09-03 14:49:58 +00:00
|
|
|
|
|
|
|
if (doneSet.find(path) == doneSet.end()) {
|
|
|
|
doneSet.insert(path);
|
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
ClosureElems::const_iterator elem = fs.closure.elems.find(path);
|
|
|
|
if (elem == fs.closure.elems.end())
|
|
|
|
throw Error(format("bad closure, missing path `%1%'") % path);
|
2003-09-03 14:49:58 +00:00
|
|
|
|
|
|
|
for (StringSet::const_iterator i = elem->second.refs.begin();
|
2005-03-26 22:06:57 +00:00
|
|
|
i != elem->second.refs.end(); ++i)
|
2003-09-03 14:49:58 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
workList.insert(*i);
|
|
|
|
cout << makeEdge(pathLabel(nePath, *i), pathLabel(nePath, path));
|
2003-09-03 14:49:58 +00:00
|
|
|
}
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
cout << makeNode(pathLabel(nePath, path),
|
2003-09-03 14:49:58 +00:00
|
|
|
symbolicName(path), "#ff0000");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-03-26 22:06:57 +00:00
|
|
|
#endif
|
2003-09-03 14:49:58 +00:00
|
|
|
|
|
|
|
|
2003-10-08 15:06:59 +00:00
|
|
|
void printDotGraph(const PathSet & roots)
|
2003-09-03 11:20:18 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
PathSet workList(roots);
|
|
|
|
PathSet doneSet;
|
2003-09-03 11:20:18 +00:00
|
|
|
|
|
|
|
cout << "digraph G {\n";
|
|
|
|
|
|
|
|
while (!workList.empty()) {
|
2005-03-26 22:06:57 +00:00
|
|
|
Path path = *(workList.begin());
|
|
|
|
workList.erase(path);
|
2003-09-03 11:20:18 +00:00
|
|
|
|
2005-03-26 22:06:57 +00:00
|
|
|
if (doneSet.find(path) != doneSet.end()) continue;
|
|
|
|
doneSet.insert(path);
|
2003-10-16 16:29:57 +00:00
|
|
|
|
2005-03-26 22:06:57 +00:00
|
|
|
cout << makeNode(path, symbolicName(path), "#ff0000");
|
|
|
|
|
|
|
|
PathSet references;
|
2006-11-30 17:43:04 +00:00
|
|
|
store->queryReferences(path, references);
|
2005-03-26 22:06:57 +00:00
|
|
|
|
|
|
|
for (PathSet::iterator i = references.begin();
|
|
|
|
i != references.end(); ++i)
|
|
|
|
{
|
2006-01-19 15:35:34 +00:00
|
|
|
if (*i != path) {
|
|
|
|
workList.insert(*i);
|
|
|
|
cout << makeEdge(*i, path);
|
|
|
|
}
|
2005-03-26 22:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
StoreExpr ne = storeExprFromPath(path);
|
2003-09-03 11:20:18 +00:00
|
|
|
|
2003-09-03 14:49:58 +00:00
|
|
|
string label, colour;
|
2003-09-03 11:20:18 +00:00
|
|
|
|
2003-11-18 11:22:29 +00:00
|
|
|
if (ne.type == StoreExpr::neDerivation) {
|
2003-10-08 15:06:59 +00:00
|
|
|
for (PathSet::iterator i = ne.derivation.inputs.begin();
|
2005-03-26 22:06:57 +00:00
|
|
|
i != ne.derivation.inputs.end(); ++i)
|
2003-09-03 11:20:18 +00:00
|
|
|
{
|
2003-10-08 15:06:59 +00:00
|
|
|
workList.insert(*i);
|
2005-03-26 22:06:57 +00:00
|
|
|
cout << makeEdge(*i, path);
|
2003-09-03 11:20:18 +00:00
|
|
|
}
|
|
|
|
|
2003-10-07 12:27:49 +00:00
|
|
|
label = "derivation";
|
2003-09-03 14:49:58 +00:00
|
|
|
colour = "#00ff00";
|
2003-10-07 12:27:49 +00:00
|
|
|
for (StringPairs::iterator i = ne.derivation.env.begin();
|
2005-03-26 22:06:57 +00:00
|
|
|
i != ne.derivation.env.end(); ++i)
|
2003-09-03 11:20:18 +00:00
|
|
|
if (i->first == "name") label = i->second;
|
|
|
|
}
|
|
|
|
|
2003-11-18 11:22:29 +00:00
|
|
|
else if (ne.type == StoreExpr::neClosure) {
|
2003-10-07 12:27:49 +00:00
|
|
|
label = "<closure>";
|
2003-09-03 14:49:58 +00:00
|
|
|
colour = "#00ffff";
|
2005-03-26 22:06:57 +00:00
|
|
|
printClosure(path, ne);
|
2003-09-03 11:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else abort();
|
|
|
|
|
2005-03-26 22:06:57 +00:00
|
|
|
cout << makeNode(path, label, colour);
|
|
|
|
#endif
|
2003-09-03 11:20:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cout << "}\n";
|
|
|
|
}
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|