From a93cff5882f5be8c77af268c34aa7e065ca5fc58 Mon Sep 17 00:00:00 2001 From: litlighilit Date: Fri, 8 Aug 2025 23:12:13 +0800 Subject: [PATCH] fix(gorgeEx): avoid discard trailling newline; fixes #25092 --- compiler/gorgeimpl.nim | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/gorgeimpl.nim b/compiler/gorgeimpl.nim index da911c84cf513..a0c06a667f704 100644 --- a/compiler/gorgeimpl.nim +++ b/compiler/gorgeimpl.nim @@ -19,14 +19,21 @@ when defined(nimPreviewSlimSystem): import ../dist/checksums/src/checksums/sha1 proc readOutput(p: Process): (string, int) = - result[0] = "" - var output = p.outputStream - while not output.atEnd: - result[0].add(output.readLine) - result[0].add("\n") - if result[0].len > 0: - result[0].setLen(result[0].len - "\n".len) - result[1] = p.waitForExit + var outp = p.outputStream + # the following code is copied from osproc.execCmdEx + # @eea4ce0e2cf1dfdd2a90c2ab7f93888 + + # consider `p.lines(keepNewLines=true)` to avoid exit code test + result = ("", -1) + var line = newStringOfCap(120) + while true: + if outp.readLine(line): + result[0].add(line) + result[0].add("\n") + else: + result[1] = peekExitCode(p) + if result[1] != -1: break + close(p) proc opGorge*(cmd, input, cache: string, info: TLineInfo; conf: ConfigRef): (string, int) = let workingDir = parentDir(toFullPath(conf, info))