#include "graphml.hh" #include #include "derivations.hh" #include "store-api.hh" #include "util.hh" 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 symbolicName(const string& path) { string p = baseNameOf(path); return string(p, p.find('-') + 1); } static string makeEdge(const string& src, const string& dst) { return fmt(" \n", xmlQuote(src), xmlQuote(dst)); } static string makeNode(const ValidPathInfo& info) { return fmt( " \n" " %2%\n" " %3%\n" " %4%\n" " \n", info.path, info.narSize, symbolicName(info.path), (isDerivation(info.path) ? "derivation" : "output-path")); } void printGraphML(const ref& store, const PathSet& roots) { PathSet workList(roots); PathSet doneSet; std::pair ret; cout << "\n" << "\n" << "" << "" << "" << "\n"; while (!workList.empty()) { Path path = *(workList.begin()); workList.erase(path); ret = doneSet.insert(path); if (!ret.second) { continue; } ValidPathInfo info = *(store->queryPathInfo(path)); cout << makeNode(info); for (auto& p : store->queryPathInfo(path)->references) { if (p != path) { workList.insert(p); cout << makeEdge(path, p); } } } cout << "\n"; cout << "\n"; } } // namespace nix