@@ -842,63 +842,39 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
842842 ++ [" -package-db=" ++ toFilePathNoTrailingSep (bcoSnapDB eeBaseConfigOpts)]
843843
844844 setupArgs = (" --builddir=" ++ toFilePathNoTrailingSep distRelativeDir') : args
845- runExe exeName fullArgs = do
846- $ logProcessRun (toFilePath exeName) fullArgs
847-
848- -- Use createProcess_ to avoid the log file being closed afterwards
849- (Nothing , moutH, merrH, ph) <- liftIO $ createProcess_ " singleBuild" cp
850-
851- let makeAbsolute = stripTHLoading -- If users want control, we should add a config option for this
852-
853- ec <-
854- liftIO $
855- withAsync (runInBase $ maybePrintBuildOutput stripTHLoading makeAbsolute pkgDir LevelInfo mlogFile moutH) $ \ outThreadID ->
856- withAsync (runInBase $ maybePrintBuildOutput False makeAbsolute pkgDir LevelWarn mlogFile merrH) $ \ errThreadID -> do
857- ec <- waitForProcess ph
858- wait errThreadID
859- wait outThreadID
860- return ec
861- case ec of
862- ExitSuccess -> return ()
863- _ -> do
864- bss <-
865- case mlogFile of
866- Nothing -> return []
867- Just (logFile, h) -> do
868- liftIO $ hClose h
869- runResourceT
870- $ CB. sourceFile (toFilePath logFile)
871- =$= CT. decodeUtf8
872- $$ mungeBuildOutput stripTHLoading makeAbsolute pkgDir
873- =$ CL. consume
874- throwM $ CabalExitedUnsuccessfully
875- ec
876- taskProvides
877- exeName
878- fullArgs
879- (fmap fst mlogFile)
880- bss
881- where
882- cp0 = proc (toFilePath exeName) fullArgs
883- cp = cp0
884- { cwd = Just $ toFilePath pkgDir
885- , Process. env = envHelper menv
886- -- Ideally we'd create a new pipe here and then close it
887- -- below to avoid the child process from taking from our
888- -- stdin. However, if we do this, the child process won't
889- -- be able to get the codepage on Windows that we want.
890- -- See:
891- -- https://github.com/commercialhaskell/stack/issues/738
892- -- , std_in = CreatePipe
893- , std_out =
894- case mlogFile of
895- Nothing -> CreatePipe
896- Just (_, h) -> UseHandle h
897- , std_err =
845+ runExe exeName fullArgs =
846+ runAndOutput `catch` \ (ProcessExitedUnsuccessfully _ ec) -> do
847+ bss <-
898848 case mlogFile of
899- Nothing -> CreatePipe
900- Just (_, h) -> UseHandle h
901- }
849+ Nothing -> return []
850+ Just (logFile, h) -> do
851+ liftIO $ hClose h
852+ runResourceT
853+ $ CB. sourceFile (toFilePath logFile)
854+ =$= CT. decodeUtf8
855+ $$ mungeBuildOutput stripTHLoading makeAbsolute pkgDir
856+ =$ CL. consume
857+ throwM $ CabalExitedUnsuccessfully
858+ ec
859+ taskProvides
860+ exeName
861+ fullArgs
862+ (fmap fst mlogFile)
863+ bss
864+ where
865+ runAndOutput = case mlogFile of
866+ Just (_, h) ->
867+ sinkProcessStderrStdoutHandle (Just pkgDir) menv (toFilePath exeName) fullArgs h h
868+ Nothing ->
869+ void $ sinkProcessStderrStdout (Just pkgDir) menv (toFilePath exeName) fullArgs
870+ (outputSink False LevelWarn )
871+ (outputSink stripTHLoading LevelInfo )
872+ outputSink excludeTH level =
873+ CT. decodeUtf8
874+ =$ mungeBuildOutput excludeTH makeAbsolute pkgDir
875+ =$ CL. mapM_ (runInBase . monadLoggerLog $ (TH. location >>= liftLoc) " " level)
876+ -- If users want control, we should add a config option for this
877+ makeAbsolute = stripTHLoading
902878
903879 wc <- getWhichCompiler
904880 (exeName, fullArgs) <- case (esetupexehs, wc) of
@@ -927,14 +903,6 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
927903 return (outputFile, setupArgs)
928904 runExe exeName $ (if boptsCabalVerbose eeBuildOpts then (" --verbose" : ) else id ) fullArgs
929905
930- maybePrintBuildOutput stripTHLoading makeAbsolute pkgDir level mlogFile mh =
931- case mh of
932- Just h ->
933- case mlogFile of
934- Just {} -> return ()
935- Nothing -> printBuildOutput stripTHLoading makeAbsolute pkgDir level h
936- Nothing -> return ()
937-
938906singleBuild :: M env m
939907 => (m () -> IO () )
940908 -> ActionContext
@@ -1356,23 +1324,6 @@ singleBench runInBase beopts benchesToRun ac ee task installedMap = do
13561324 announce " benchmarks"
13571325 cabal False (" bench" : args)
13581326
1359- -- | Grab all output from the given @Handle@ and log it, stripping
1360- -- Template Haskell "Loading package" lines and making paths absolute.
1361- -- thread.
1362- printBuildOutput :: (MonadIO m , MonadBaseControl IO m , MonadLogger m ,
1363- MonadThrow m )
1364- => Bool -- ^ exclude TH loading?
1365- -> Bool -- ^ convert paths to absolute?
1366- -> Path Abs Dir -- ^ package's root directory
1367- -> LogLevel
1368- -> Handle
1369- -> m ()
1370- printBuildOutput excludeTHLoading makeAbsolute pkgDir level outH = void $
1371- CB. sourceHandle outH
1372- $$ CT. decodeUtf8
1373- =$ mungeBuildOutput excludeTHLoading makeAbsolute pkgDir
1374- =$ CL. mapM_ (monadLoggerLog $ (TH. location >>= liftLoc) " " level)
1375-
13761327-- | Strip Template Haskell "Loading package" lines and making paths absolute.
13771328mungeBuildOutput :: (MonadIO m , MonadThrow m )
13781329 => Bool -- ^ exclude TH loading?
0 commit comments