From 49c698cf7ff3d85de81416d4427cc710023ffe9c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 18 Jan 2026 19:20:35 +0100 Subject: [PATCH] legacycmd: don't print to stdout from printGraphML return a string instead, and write that to stdout explicitly. Change-Id: Ia2d2019064da16fd35630217c445b4bcc4cdf2c2 --- lix/legacy/graphml.cc | 34 ++++++++++++++++------------------ lix/legacy/graphml.hh | 3 +-- lix/legacy/nix-store.cc | 2 +- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/lix/legacy/graphml.cc b/lix/legacy/graphml.cc index b70aabf77..9b9df08eb 100644 --- a/lix/legacy/graphml.cc +++ b/lix/legacy/graphml.cc @@ -5,9 +5,7 @@ #include "lix/libutil/result.hh" #include - - -using std::cout; +#include namespace nix { @@ -47,21 +45,21 @@ static std::string makeNode(const ValidPathInfo & info) (info.path.isDerivation() ? "derivation" : "output-path")); } - -kj::Promise> printGraphML(ref store, StorePathSet && roots) +kj::Promise> printGraphML(ref store, StorePathSet && roots) try { StorePathSet workList(std::move(roots)); StorePathSet doneSet; std::pair ret; + std::stringstream result; - cout << "\n" - << "\n" - << "" - << "" - << "" - << "\n"; + result << "\n" + << "\n" + << "" + << "" + << "" + << "\n"; while (!workList.empty()) { auto path = std::move(workList.extract(workList.begin()).value()); @@ -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 << "\n"; - cout << "\n"; - co_return result::success(); + result << "\n"; + result << "\n"; + co_return result.str(); } catch (...) { co_return result::current_exception(); } diff --git a/lix/legacy/graphml.hh b/lix/legacy/graphml.hh index 48e04fe41..5de83e32a 100644 --- a/lix/legacy/graphml.hh +++ b/lix/legacy/graphml.hh @@ -5,6 +5,5 @@ namespace nix { -kj::Promise> printGraphML(ref store, StorePathSet && roots); - +kj::Promise> printGraphML(ref store, StorePathSet && roots); } diff --git a/lix/legacy/nix-store.cc b/lix/legacy/nix-store.cc index d1998f3da..b72640814 100644 --- a/lix/legacy/nix-store.cc +++ b/lix/legacy/nix-store.cc @@ -503,7 +503,7 @@ opQuery(std::shared_ptr store, AsyncIoRoot & aio, Strings opFlags, String { roots.insert(j); } - aio.blockOn(printGraphML(ref::unsafeFromPtr(store), std::move(roots))); + std::cout << aio.blockOn(printGraphML(ref::unsafeFromPtr(store), std::move(roots))); break; }