mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 00:12:43 +01:00
libstore/derivation-goal: avoid double-parsing of JSON messages
To avoid that JSON messages are parsed twice in case of
remote builds with `ssh-ng://`, I split up the original
`handleJSONLogMessage` into three parts:
* `parseJSONMessage(const std::string&)` checks if it's a message in the
form of `@nix {...}` and tries to parse it (and prints an error if the
parsing fails).
* `handleJSONLogMessage(nlohmann::json&, ...)` reads the fields from the
message and passes them to the logger.
* `handleJSONLogMessage(const std::string&, ...)` behaves as before, but
uses the two functions mentioned above as implementation.
In case of `ssh-ng://`-logs the first two methods are invoked manually.
This commit is contained in:
parent
7a04839ea5
commit
cd92ea5885
3 changed files with 64 additions and 42 deletions
|
|
@ -1207,12 +1207,14 @@ void DerivationGoal::handleChildOutput(int fd, std::string_view data)
|
|||
if (hook && fd == hook->fromHook.readSide.get()) {
|
||||
for (auto c : data)
|
||||
if (c == '\n') {
|
||||
auto s = handleJSONLogMessage(currentHookLine, worker.act, hook->activities, true);
|
||||
if (s && !isWrittenToLog && logSink) {
|
||||
auto json = nlohmann::json::parse(std::string(currentHookLine, 5));
|
||||
if (json["type"] == resBuildLogLine) {
|
||||
auto f = json["fields"];
|
||||
(*logSink)((f.size() > 0 ? f.at(0).get<std::string>() : "") + "\n");
|
||||
auto json = parseJSONMessage(currentHookLine);
|
||||
if (json) {
|
||||
auto s = handleJSONLogMessage(*json, worker.act, hook->activities, true);
|
||||
if (s && !isWrittenToLog && logSink) {
|
||||
if ((*json)["type"] == resBuildLogLine) {
|
||||
auto f = (*json)["fields"];
|
||||
(*logSink)((f.size() > 0 ? f.at(0).get<std::string>() : "") + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
currentHookLine.clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue