2018-09-29 10:42:11 +03:00
|
|
|
#include "graphml.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
static inline std::string_view xmlQuote(std::string_view s)
|
2018-09-29 10:42:11 +03:00
|
|
|
{
|
|
|
|
// Luckily, store paths shouldn't contain any character that needs to be
|
|
|
|
// quoted.
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
static string symbolicName(const std::string & p)
|
2018-09-29 10:42:11 +03:00
|
|
|
{
|
|
|
|
return string(p, p.find('-') + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
static string makeEdge(std::string_view src, std::string_view dst)
|
2018-09-29 10:42:11 +03:00
|
|
|
{
|
|
|
|
return fmt(" <edge source=\"%1%\" target=\"%2%\"/>\n",
|
|
|
|
xmlQuote(src), xmlQuote(dst));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static string makeNode(const ValidPathInfo & info)
|
|
|
|
{
|
|
|
|
return fmt(
|
|
|
|
" <node id=\"%1%\">\n"
|
|
|
|
" <data key=\"narSize\">%2%</data>\n"
|
|
|
|
" <data key=\"name\">%3%</data>\n"
|
|
|
|
" <data key=\"type\">%4%</data>\n"
|
|
|
|
" </node>\n",
|
2019-12-05 20:11:09 +02:00
|
|
|
info.path.to_string(),
|
2018-09-29 10:42:11 +03:00
|
|
|
info.narSize,
|
2019-12-05 20:11:09 +02:00
|
|
|
symbolicName(std::string(info.path.name())),
|
|
|
|
(info.path.isDerivation() ? "derivation" : "output-path"));
|
2018-09-29 10:42:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
void printGraphML(ref<Store> store, StorePathSet && roots)
|
2018-09-29 10:42:11 +03:00
|
|
|
{
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePathSet workList(std::move(roots));
|
|
|
|
StorePathSet doneSet;
|
|
|
|
std::pair<StorePathSet::iterator, bool> ret;
|
2018-09-29 10:42:11 +03:00
|
|
|
|
|
|
|
cout << "<?xml version='1.0' encoding='utf-8'?>\n"
|
|
|
|
<< "<graphml xmlns='http://graphml.graphdrawing.org/xmlns'\n"
|
|
|
|
<< " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
|
|
|
|
<< " xsi:schemaLocation='http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd'>\n"
|
|
|
|
<< "<key id='narSize' for='node' attr.name='narSize' attr.type='int'/>"
|
|
|
|
<< "<key id='name' for='node' attr.name='name' attr.type='string'/>"
|
|
|
|
<< "<key id='type' for='node' attr.name='type' attr.type='string'/>"
|
|
|
|
<< "<graph id='G' edgedefault='directed'>\n";
|
|
|
|
|
|
|
|
while (!workList.empty()) {
|
2019-12-05 20:11:09 +02:00
|
|
|
auto path = std::move(workList.extract(workList.begin()).value());
|
2018-09-29 10:42:11 +03:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
ret = doneSet.insert(path.clone());
|
2018-09-29 10:42:11 +03:00
|
|
|
if (ret.second == false) continue;
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
auto info = store->queryPathInfo(path);
|
|
|
|
cout << makeNode(*info);
|
2018-09-29 10:42:11 +03:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
for (auto & p : info->references) {
|
2018-09-29 10:42:11 +03:00
|
|
|
if (p != path) {
|
2019-12-05 20:11:09 +02:00
|
|
|
workList.insert(p.clone());
|
|
|
|
cout << makeEdge(path.to_string(), p.to_string());
|
2018-09-29 10:42:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "</graph>\n";
|
|
|
|
cout << "</graphml>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|