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:
+9
-11
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user