lix/src/nix-store/xmlgraph.cc

67 lines
1.2 KiB
C++
Raw Normal View History

#include "xmlgraph.hh"
#include "util.hh"
#include "store-api.hh"
#include <iostream>
using std::cout;
namespace nix {
static inline const string & xmlQuote(const string & s)
{
// Luckily, store paths shouldn't contain any character that needs to be
// quoted.
return s;
}
static string makeEdge(const string & src, const string & dst)
{
format f = format(" <edge src=\"%1%\" dst=\"%2%\"/>\n")
% xmlQuote(src) % xmlQuote(dst);
return f.str();
}
static string makeNode(const string & id)
{
format f = format(" <node name=\"%1%\"/>\n") % xmlQuote(id);
return f.str();
}
2016-02-04 14:10:47 +00:00
void printXmlGraph(ref<Store> store, const PathSet & roots)
{
PathSet workList(roots);
PathSet doneSet;
cout << "<?xml version='1.0' encoding='utf-8'?>\n"
2016-01-28 15:03:32 +00:00
<< "<nix>\n";
while (!workList.empty()) {
2016-01-28 15:03:32 +00:00
Path path = *(workList.begin());
workList.erase(path);
2016-01-28 15:03:32 +00:00
if (doneSet.find(path) != doneSet.end()) continue;
doneSet.insert(path);
2016-01-28 15:03:32 +00:00
cout << makeNode(path);
for (auto & p : store->queryPathInfo(path)->references) {
if (p != path) {
workList.insert(p);
cout << makeEdge(p, path);
2016-01-28 15:03:32 +00:00
}
}
}
cout << "</nix>\n";
}
}