2018-09-29 07:42:11 +00:00
|
|
|
#include "graphml.hh"
|
|
|
|
#include "util.hh"
|
|
|
|
#include "store-api.hh"
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
using std::cout;
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
static inline std::string_view xmlQuote(std::string_view s)
|
2018-09-29 07:42:11 +00:00
|
|
|
{
|
|
|
|
// Luckily, store paths shouldn't contain any character that needs to be
|
|
|
|
// quoted.
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
static std::string symbolicName(std::string_view p)
|
2018-09-29 07:42:11 +00:00
|
|
|
{
|
2022-02-25 15:00:00 +00:00
|
|
|
return std::string(p.substr(0, p.find('-') + 1));
|
2018-09-29 07:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
static std::string makeEdge(std::string_view src, std::string_view dst)
|
2018-09-29 07:42:11 +00:00
|
|
|
{
|
|
|
|
return fmt(" <edge source=\"%1%\" target=\"%2%\"/>\n",
|
|
|
|
xmlQuote(src), xmlQuote(dst));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
static std::string makeNode(const ValidPathInfo & info)
|
2018-09-29 07:42:11 +00:00
|
|
|
{
|
|
|
|
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 18:11:09 +00:00
|
|
|
info.path.to_string(),
|
2018-09-29 07:42:11 +00:00
|
|
|
info.narSize,
|
2019-12-05 18:11:09 +00:00
|
|
|
symbolicName(std::string(info.path.name())),
|
|
|
|
(info.path.isDerivation() ? "derivation" : "output-path"));
|
2018-09-29 07:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
void printGraphML(ref<Store> store, StorePathSet && roots)
|
2018-09-29 07:42:11 +00:00
|
|
|
{
|
2019-12-05 18:11:09 +00:00
|
|
|
StorePathSet workList(std::move(roots));
|
|
|
|
StorePathSet doneSet;
|
|
|
|
std::pair<StorePathSet::iterator, bool> ret;
|
2018-09-29 07:42:11 +00: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 18:11:09 +00:00
|
|
|
auto path = std::move(workList.extract(workList.begin()).value());
|
2018-09-29 07:42:11 +00:00
|
|
|
|
2020-06-16 20:20:18 +00:00
|
|
|
ret = doneSet.insert(path);
|
2018-09-29 07:42:11 +00:00
|
|
|
if (ret.second == false) continue;
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
auto info = store->queryPathInfo(path);
|
|
|
|
cout << makeNode(*info);
|
2018-09-29 07:42:11 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
for (auto & p : info->references) {
|
2018-09-29 07:42:11 +00:00
|
|
|
if (p != path) {
|
2020-06-16 20:20:18 +00:00
|
|
|
workList.insert(p);
|
2019-12-05 18:11:09 +00:00
|
|
|
cout << makeEdge(path.to_string(), p.to_string());
|
2018-09-29 07:42:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "</graph>\n";
|
|
|
|
cout << "</graphml>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|