11{-# LANGUAGE NoImplicitPrelude #-}
2- {-# LANGUAGE CPP #-}
32{-# LANGUAGE ConstraintKinds #-}
43{-# LANGUAGE DeriveDataTypeable #-}
54{-# LANGUAGE FlexibleContexts #-}
@@ -46,16 +45,9 @@ import Stack.Types.Config
4645import Stack.Types.NamedComponent
4746import Stack.Types.Package
4847
49- import Stack.Types.Compiler (compilerVersionText
50- #ifdef WINDOWS
51- ,getGhcVersion
52- #endif
53- )
48+ import Stack.Types.Compiler (compilerVersionText , getGhcVersion )
5449import System.FileLock (FileLock , unlockFile )
55-
56- #ifdef WINDOWS
57- import System.Win32.Console (setConsoleCP , setConsoleOutputCP , getConsoleCP , getConsoleOutputCP )
58- #endif
50+ import System.Terminal (fixCodePage )
5951
6052-- | Build.
6153--
@@ -67,7 +59,10 @@ build :: HasEnvConfig env
6759 -> Maybe FileLock
6860 -> BuildOptsCLI
6961 -> RIO env ()
70- build msetLocalFiles mbuildLk boptsCli = fixCodePage $ do
62+ build msetLocalFiles mbuildLk boptsCli = do
63+ mcp <- view $ configL. to configModifyCodePage
64+ ghcVersion <- view $ actualCompilerVersionL. to getGhcVersion
65+ fixCodePage mcp ghcVersion $ do
7166 bopts <- view buildOptsL
7267 let profiling = boptsLibProfile bopts || boptsExeProfile bopts
7368 let symbols = not (boptsLibStrip bopts || boptsExeStrip bopts)
@@ -282,53 +277,6 @@ loadPackage loc flags ghcOptions = do
282277 }
283278 resolvePackage pkgConfig <$> loadCabalFileImmutable loc
284279
285- -- | Set the code page for this process as necessary. Only applies to Windows.
286- -- See: https://github.com/commercialhaskell/stack/issues/738
287- fixCodePage :: HasEnvConfig env => RIO env a -> RIO env a
288- #ifdef WINDOWS
289- fixCodePage inner = do
290- mcp <- view $ configL. to configModifyCodePage
291- ghcVersion <- view $ actualCompilerVersionL. to getGhcVersion
292- if mcp && ghcVersion < mkVersion [7 , 10 , 3 ]
293- then fixCodePage'
294- -- GHC >=7.10.3 doesn't need this code page hack.
295- else inner
296- where
297- fixCodePage' = do
298- origCPI <- liftIO getConsoleCP
299- origCPO <- liftIO getConsoleOutputCP
300-
301- let setInput = origCPI /= expected
302- setOutput = origCPO /= expected
303- fixInput
304- | setInput = bracket_
305- (liftIO $ do
306- setConsoleCP expected)
307- (liftIO $ setConsoleCP origCPI)
308- | otherwise = id
309- fixOutput
310- | setOutput = bracket_
311- (liftIO $ do
312- setConsoleOutputCP expected)
313- (liftIO $ setConsoleOutputCP origCPO)
314- | otherwise = id
315-
316- case (setInput, setOutput) of
317- (False , False ) -> return ()
318- (True , True ) -> warn " "
319- (True , False ) -> warn " input"
320- (False , True ) -> warn " output"
321-
322- fixInput $ fixOutput inner
323- expected = 65001 -- UTF-8
324- warn typ = logInfo $
325- " Setting" <>
326- typ <>
327- " codepage to UTF-8 (65001) to ensure correct output from GHC"
328- #else
329- fixCodePage = id
330- #endif
331-
332280-- | Query information about the build and print the result to stdout in YAML format.
333281queryBuildInfo :: HasEnvConfig env
334282 => [Text ] -- ^ selectors
0 commit comments