Skip to content

Commit

Permalink
Line-buffer stdout and stderr
Browse files Browse the repository at this point in the history
I though this was the default, but apparently not! This seems to fix
output ordering issues.

Noticed here: #10573 (comment)
  • Loading branch information
9999years committed Dec 10, 2024
1 parent c205a8b commit 9f3fdb0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cabal-validate/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import qualified Data.Text.Lazy as T (toStrict)
import qualified Data.Text.Lazy.Encoding as T (decodeUtf8)
import Data.Version (makeVersion, showVersion)
import System.FilePath ((</>))
import System.IO (BufferMode (LineBuffering), hSetBuffering, stderr, stdout)
import System.Process.Typed (proc, readProcessStdout_)

import Cli (Compiler (..), HackageTests (..), Opts (..), parseOpts, whenVerbose)
Expand All @@ -24,6 +25,18 @@ import Step (Step (..), displayStep)
-- | Entry-point for @cabal-validate@.
main :: IO ()
main = do
-- You'd _think_ that line-buffering for stdout and stderr would be the
-- default behavior, and the documentation makes gestures at it, but it
-- appears to not be the case!
--
-- > For most implementations, physical files will normally be
-- > block-buffered and terminals will normally be line-buffered.
--
-- However, on GitHub Actions and on my machine (macOS M1), adding these
-- lines makes output appear in the correct order!
hSetBuffering stdout LineBuffering
hSetBuffering stderr LineBuffering

opts <- parseOpts
printConfig opts
printToolVersions opts
Expand Down Expand Up @@ -103,11 +116,11 @@ cabalListBinArgs opts = "list-bin" : cabalArgs opts
cabalListBin :: Opts -> String -> IO FilePath
cabalListBin opts target = do
let args = cabalListBinArgs opts ++ [target]
stdout <-
stdout' <-
readProcessStdout_ $
proc (cabal opts) args

pure (T.unpack $ T.strip $ T.toStrict $ T.decodeUtf8 stdout)
pure (T.unpack $ T.strip $ T.toStrict $ T.decodeUtf8 stdout')

-- | Get the RTS arguments for invoking test suites.
--
Expand Down

0 comments on commit 9f3fdb0

Please sign in to comment.