diff options
author | Maximilian Bosch <maximilian@mbosch.me> | 2022-02-19 22:34:50 +0100 |
---|---|---|
committer | Maximilian Bosch <maximilian@mbosch.me> | 2022-02-28 17:27:52 +0100 |
commit | cd92ea588504db697103d3ff56166fe61e6da131 (patch) | |
tree | 86bb62fe1e4aedfc8f48e87611bd1f7b89daee90 /src/libstore/build | |
parent | 7a04839ea53986a0175bf085e7d061ab8a32d59b (diff) |
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.
Diffstat (limited to 'src/libstore/build')
-rw-r--r-- | src/libstore/build/derivation-goal.cc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/libstore/build/derivation-goal.cc b/src/libstore/build/derivation-goal.cc index ef1135601..c49be5e79 100644 --- a/src/libstore/build/derivation-goal.cc +++ b/src/libstore/build/derivation-goal.cc @@ -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(); |