legacycmd: don't print to stdout from printGraphML

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

Change-Id: Ia2d2019064da16fd35630217c445b4bcc4cdf2c2
This commit is contained in:
eldritch horrors
2026-01-18 19:16:39 +00:00
parent 7be922b3c8
commit 49c698cf7f
3 changed files with 18 additions and 21 deletions
+9 -11
View File
@@ -5,9 +5,7 @@
#include "lix/libutil/result.hh"
#include <iostream>
using std::cout;
#include <sstream>
namespace nix {
@@ -47,14 +45,14 @@ static std::string makeNode(const ValidPathInfo & info)
(info.path.isDerivation() ? "derivation" : "output-path"));
}
kj::Promise<Result<void>> printGraphML(ref<Store> store, StorePathSet && roots)
kj::Promise<Result<std::string>> printGraphML(ref<Store> store, StorePathSet && roots)
try {
StorePathSet workList(std::move(roots));
StorePathSet doneSet;
std::pair<StorePathSet::iterator, bool> ret;
std::stringstream result;
cout << "<?xml version='1.0' encoding='utf-8'?>\n"
result << "<?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"
@@ -70,20 +68,20 @@ try {
if (ret.second == false) continue;
auto info = TRY_AWAIT(store->queryPathInfo(path));
cout << makeNode(*info);
result << makeNode(*info);
for (auto & p : info->references) {
if (p != path) {
workList.insert(p);
cout << makeEdge(path.to_string(), p.to_string());
result << makeEdge(path.to_string(), p.to_string());
}
}
}
cout << "</graph>\n";
cout << "</graphml>\n";
co_return result::success();
result << "</graph>\n";
result << "</graphml>\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>> printGraphML(ref<Store> store, StorePathSet && roots);
kj::Promise<Result<std::string>> printGraphML(ref<Store> store, StorePathSet && roots);
}
+1 -1
View File
@@ -503,7 +503,7 @@ opQuery(std::shared_ptr<Store> store, AsyncIoRoot & aio, Strings opFlags, String
{
roots.insert(j);
}
aio.blockOn(printGraphML(ref<Store>::unsafeFromPtr(store), std::move(roots)));
std::cout << aio.blockOn(printGraphML(ref<Store>::unsafeFromPtr(store), std::move(roots)));
break;
}