mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 00:12:43 +01:00
For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
(cherry picked from commit cc24766fa6)
70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
#include "dotgraph.hh"
|
|
#include "nix/store/store-api.hh"
|
|
|
|
#include <iostream>
|
|
|
|
|
|
using std::cout;
|
|
|
|
namespace nix {
|
|
|
|
|
|
static std::string dotQuote(std::string_view s)
|
|
{
|
|
return "\"" + std::string(s) + "\"";
|
|
}
|
|
|
|
|
|
static const std::string & nextColour()
|
|
{
|
|
static int n = 0;
|
|
static std::vector<std::string> colours
|
|
{ "black", "red", "green", "blue"
|
|
, "magenta", "burlywood" };
|
|
return colours[n++ % colours.size()];
|
|
}
|
|
|
|
|
|
static std::string makeEdge(std::string_view src, std::string_view dst)
|
|
{
|
|
return fmt("%1% -> %2% [color = %3%];\n",
|
|
dotQuote(src), dotQuote(dst), dotQuote(nextColour()));
|
|
}
|
|
|
|
|
|
static std::string makeNode(std::string_view id, std::string_view label,
|
|
std::string_view colour)
|
|
{
|
|
return fmt("%1% [label = %2%, shape = box, "
|
|
"style = filled, fillcolor = %3%];\n",
|
|
dotQuote(id), dotQuote(label), dotQuote(colour));
|
|
}
|
|
|
|
|
|
void printDotGraph(ref<Store> store, StorePathSet && roots)
|
|
{
|
|
StorePathSet workList(std::move(roots));
|
|
StorePathSet doneSet;
|
|
|
|
cout << "digraph G {\n";
|
|
|
|
while (!workList.empty()) {
|
|
auto path = std::move(workList.extract(workList.begin()).value());
|
|
|
|
if (!doneSet.insert(path).second) continue;
|
|
|
|
cout << makeNode(std::string(path.to_string()), path.name(), "#ff0000");
|
|
|
|
for (auto & p : store->queryPathInfo(path)->references) {
|
|
if (p != path) {
|
|
workList.insert(p);
|
|
cout << makeEdge(std::string(p.to_string()), std::string(path.to_string()));
|
|
}
|
|
}
|
|
}
|
|
|
|
cout << "}\n";
|
|
}
|
|
|
|
|
|
}
|