[commit: packages/Cabal] ghc-head: Improve stdout flushing. (e04b9d0)

git at git.haskell.org git at git.haskell.org
Mon Aug 26 23:31:08 CEST 2013


Repository : ssh://git@git.haskell.org/Cabal

On branch  : ghc-head
Link       : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=e04b9d0e6fda47b60682d40ee627fafbd5ea5be2

>---------------------------------------------------------------

commit e04b9d0e6fda47b60682d40ee627fafbd5ea5be2
Author: Niklas Hambüchen <mail at nh2.me>
Date:   Fri Aug 23 20:54:06 2013 +0900

    Improve stdout flushing.
    
    Flushing after every line is helpful to see information quickly.
    
    By default, Haskell application use NoBuffering when piped into
    another process, which for example hides the output of cabal build
    when run via a Continuous Integration server, an output-capturing
    build tool, or ssh.


>---------------------------------------------------------------

e04b9d0e6fda47b60682d40ee627fafbd5ea5be2
 cabal-install/Main.hs |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cabal-install/Main.hs b/cabal-install/Main.hs
index cf3bf41..8f08bc6 100644
--- a/cabal-install/Main.hs
+++ b/cabal-install/Main.hs
@@ -117,6 +117,7 @@ import qualified Paths_cabal_install (version)
 import System.Environment       (getArgs, getProgName)
 import System.Exit              (exitFailure)
 import System.FilePath          (splitExtension, takeExtension)
+import System.IO                (BufferMode(LineBuffering), hSetBuffering, stdout)
 import System.Directory         (doesFileExist)
 import Data.List                (intercalate)
 import Data.Monoid              (Monoid(..))
@@ -125,7 +126,11 @@ import Control.Monad            (when, unless)
 -- | Entry point
 --
 main :: IO ()
-main = getArgs >>= mainWorker
+main = do
+  -- Enable line buffering so that we can get fast feedback even when piped.
+  -- This is especially important for CI and build systems.
+  hSetBuffering stdout LineBuffering
+  getArgs >>= mainWorker
 
 mainWorker :: [String] -> IO ()
 mainWorker args = topHandler $





More information about the ghc-commits mailing list