legacycmd: don't print to stdout from printDotGraph

return a string instead, and write that to stdout explicitly.

Change-Id: I21e7a1eb22f2772e31b754823f64f941be080c56
This commit is contained in:
eldritch horrors
2026-01-18 19:16:45 +00:00
parent 49c698cf7f
commit 98cb3014e8
3 changed files with 10 additions and 13 deletions
+8 -10
View File
@@ -4,9 +4,7 @@
#include "lix/libutil/result.hh"
#include <iostream>
using std::cout;
#include <sstream>
namespace nix {
@@ -42,31 +40,31 @@ static std::string makeNode(std::string_view id, std::string_view label,
dotQuote(id), dotQuote(label), dotQuote(colour));
}
kj::Promise<Result<void>> printDotGraph(ref<Store> store, StorePathSet && roots)
kj::Promise<Result<std::string>> printDotGraph(ref<Store> store, StorePathSet && roots)
try {
StorePathSet workList(std::move(roots));
StorePathSet doneSet;
std::stringstream result;
cout << "digraph G {\n";
result << "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");
result << makeNode(std::string(path.to_string()), path.name(), "#ff0000");
for (auto & p : TRY_AWAIT(store->queryPathInfo(path))->references) {
if (p != path) {
workList.insert(p);
cout << makeEdge(std::string(p.to_string()), std::string(path.to_string()));
result << makeEdge(std::string(p.to_string()), std::string(path.to_string()));
}
}
}
cout << "}\n";
co_return result::success();
result << "}\n";
co_return result.str();
} catch (...) {
co_return result::current_exception();
}
+1 -2
View File
@@ -5,6 +5,5 @@
namespace nix {
kj::Promise<Result<void>> printDotGraph(ref<Store> store, StorePathSet && roots);
kj::Promise<Result<std::string>> printDotGraph(ref<Store> store, StorePathSet && roots);
}
+1 -1
View File
@@ -490,7 +490,7 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
{
roots.insert(j);
}
aio.blockOn(printDotGraph(ref<Store>::unsafeFromPtr(store), std::move(roots)));
std::cout << aio.blockOn(printDotGraph(ref<Store>::unsafeFromPtr(store), std::move(roots)));
break;
}