From 6f0bf9798a66e292ca073f1729286c501589409a Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 5 Sep 2025 19:55:47 +0200 Subject: [PATCH] libstore: process post-build-hook logs directly using a sink for this has long been a bit weird anyway. originally it was necessary due to api limitations, but it hasn't been for a while. Change-Id: I3dfa157944618349bfd6f398ee1667fc31519d86 --- lix/libstore/build/derivation-goal.cc | 55 +++++++++++---------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/lix/libstore/build/derivation-goal.cc b/lix/libstore/build/derivation-goal.cc index d03f6e8f7..dc10eefd8 100644 --- a/lix/libstore/build/derivation-goal.cc +++ b/lix/libstore/build/derivation-goal.cc @@ -854,36 +854,6 @@ void runPostBuildHook( hookEnvironment.emplace("OUT_PATHS", chomp(concatStringsSep(" ", store.printStorePathSet(outputPaths)))); hookEnvironment.emplace("NIX_CONFIG", globalConfig.toKeyValue(true)); - struct LogSink : Sink { - Activity & act; - std::string currentLine; - - LogSink(Activity & act) : act(act) { } - - void operator() (std::string_view data) override { - for (auto c : data) { - if (c == '\n') { - flushLine(); - } else { - currentLine += c; - } - } - } - - void flushLine() { - act.result(resPostBuildLogLine, currentLine); - currentLine.clear(); - } - - ~LogSink() { - if (currentLine != "") { - currentLine += '\n'; - flushLine(); - } - } - }; - LogSink sink(act); - auto proc = runProgram2({ .program = settings.postBuildHook, .environment = hookEnvironment, @@ -903,8 +873,29 @@ void runPostBuildHook( } }); - // FIXME just process the data, without a wrapper sink class - proc.getStdout()->drainInto(sink); + auto & hookStdout = *proc.getStdout(); + std::string currentLine; + std::vector buffer(8192); + try { + while (true) { + const auto got = hookStdout.read(buffer.data(), buffer.size()); + const std::string_view data{buffer.data(), got}; + for (auto c : data) { + if (c == '\n') { + act.result(resPostBuildLogLine, currentLine); + currentLine.clear(); + } else { + currentLine += c; + } + } + } + } catch (EndOfFile &) { + } + + if (currentLine != "") { + currentLine += '\n'; + act.result(resPostBuildLogLine, currentLine); + } } std::string DerivationGoal::buildErrorContents(const std::string & exitMsg, bool diskFull)