Skip to content

Commit 73e713b

Browse files
committed
Reduce CPP usage as well #4272
1 parent f4a580f commit 73e713b

File tree

25 files changed

+141
-153
lines changed

25 files changed

+141
-153
lines changed

package.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ dependencies:
9393
- project-template
9494
- regex-applicative-text
9595
- resourcet
96-
- retry
96+
- retry >= 0.7
9797
- rio
9898
- semigroups
9999
- split
@@ -258,6 +258,7 @@ library:
258258
- Stack.Upgrade
259259
- Stack.Upload
260260
- Text.PrettyPrint.Leijen.Extended
261+
- System.Permissions
261262
- System.Process.PagerEditor
262263
- System.Terminal
263264
when:

src/Data/Attoparsec/Interpreter.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE CPP #-}
43
{- | This module implements parsing of additional arguments embedded in a
54
comment when stack is invoked as a script interpreter
65
@@ -145,11 +144,7 @@ getInterpreterArgs file = do
145144

146145
decodeError e =
147146
case e of
148-
#if MIN_VERSION_conduit_extra(1,2,0)
149147
ParseError ctxs _ (Position line col _) ->
150-
#else
151-
ParseError ctxs _ (Position line col) ->
152-
#endif
153148
if null ctxs
154149
then "Parse error"
155150
else ("Expecting " ++ intercalate " or " ctxs)

src/Network/HTTP/Download/Verified.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE DeriveDataTypeable #-}
43
{-# LANGUAGE MultiParamTypeClasses #-}
54
{-# LANGUAGE OverloadedStrings #-}
@@ -192,11 +191,7 @@ hashChecksToZipSink req = traverse_ (ZipSink . sinkCheckHash req)
192191
-- 'Control.Retry.recovering' customized for HTTP failures
193192
recoveringHttp :: forall env a. HasRunner env => RetryPolicy -> RIO env a -> RIO env a
194193
recoveringHttp retryPolicy =
195-
#if MIN_VERSION_retry(0,7,0)
196194
helper $ \run -> recovering retryPolicy (handlers run) . const
197-
#else
198-
helper $ \run -> recovering retryPolicy (handlers run)
199-
#endif
200195
where
201196
helper :: (UnliftIO (RIO env) -> IO a -> IO a) -> RIO env a -> RIO env a
202197
helper wrapper action = withUnliftIO $ \run -> wrapper run (unliftIO run action)

src/Stack/Build.hs

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE ConstraintKinds #-}
43
{-# LANGUAGE DeriveDataTypeable #-}
54
{-# LANGUAGE FlexibleContexts #-}
@@ -46,16 +45,9 @@ import Stack.Types.Config
4645
import Stack.Types.NamedComponent
4746
import 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)
5449
import 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.
333281
queryBuildInfo :: HasEnvConfig env
334282
=> [Text] -- ^ selectors

src/Stack/Build/Cache.hs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE CPP #-}
21
{-# LANGUAGE NoImplicitPrelude #-}
32
{-# LANGUAGE DeriveGeneric #-}
43
{-# LANGUAGE MultiParamTypeClasses #-}
@@ -39,9 +38,7 @@ import qualified Data.ByteArray as Mem (convert)
3938
import qualified Data.ByteString.Base64.URL as B64URL
4039
import qualified Data.ByteString as B
4140
import qualified Data.ByteString.Char8 as S8
42-
#ifdef mingw32_HOST_OS
4341
import Data.Char (ord)
44-
#endif
4542
import qualified Data.Map as M
4643
import qualified Data.Set as Set
4744
import qualified Data.Store as Store
@@ -359,8 +356,9 @@ readPrecompiledCache loc copts depIDs = do
359356

360357
-- | Check if a filesystem path is too long.
361358
pathTooLong :: FilePath -> Bool
362-
#ifdef mingw32_HOST_OS
363-
pathTooLong path = utf16StringLength path >= win32MaxPath
359+
pathTooLong
360+
| osIsWindows = \path -> utf16StringLength path >= win32MaxPath
361+
| otherwise = const False
364362
where
365363
win32MaxPath = 260
366364
-- Calculate the length of a string in 16-bit units
@@ -370,6 +368,3 @@ pathTooLong path = utf16StringLength path >= win32MaxPath
370368
where
371369
utf16CharLength c | ord c < 0x10000 = 1
372370
| otherwise = 2
373-
#else
374-
pathTooLong _ = False
375-
#endif

src/Stack/Build/Execute.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE CPP #-}
32
{-# LANGUAGE ConstraintKinds #-}
43
{-# LANGUAGE DataKinds #-}
54
{-# LANGUAGE FlexibleContexts #-}

src/Stack/Config.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE ConstraintKinds #-}
3-
{-# LANGUAGE CPP #-}
43
{-# LANGUAGE DataKinds #-}
54
{-# LANGUAGE DeriveFoldable #-}
65
{-# LANGUAGE DeriveFunctor #-}

src/Stack/Config/Docker.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE CPP, DeriveDataTypeable, RecordWildCards #-}
3+
{-# LANGUAGE DeriveDataTypeable, RecordWildCards #-}
44

55
-- | Docker configuration
66
module Stack.Config.Docker where

src/Stack/Constants.hs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE CPP #-}
21
{-# LANGUAGE NoImplicitPrelude #-}
32
{-# LANGUAGE OverloadedStrings #-}
43
{-# LANGUAGE TemplateHaskell #-} -- keep TH usage here
@@ -132,6 +131,7 @@ import Path as FL
132131
import Stack.Prelude
133132
import Stack.Types.Compiler
134133
import Stack.Types.TemplateName
134+
import System.Permissions (osIsWindows)
135135

136136
-- | Extensions used for Haskell modules. Excludes preprocessor ones.
137137
haskellFileExts :: [Text]
@@ -325,15 +325,6 @@ maxTerminalWidth = 200
325325
defaultTerminalWidth :: Int
326326
defaultTerminalWidth = 100
327327

328-
-- | True if using Windows OS.
329-
osIsWindows :: Bool
330-
osIsWindows =
331-
#ifdef WINDOWS
332-
True
333-
#else
334-
False
335-
#endif
336-
337328
relFileSetupHs :: Path Rel File
338329
relFileSetupHs = $(mkRelFile "Setup.hs")
339330

src/Stack/Docker.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import System.IO.Unsafe (unsafePerformIO)
6666
import qualified System.PosixCompat.User as User
6767
import qualified System.PosixCompat.Files as Files
6868
import System.Process.PagerEditor (editByteString)
69+
import System.Terminal (hIsTerminalDeviceOrMinTTY)
6970
import RIO.Process
7071
import Text.Printf (printf)
7172

@@ -347,6 +348,8 @@ runContainerAndExit getCmdArgs
347348
,[cmnd]
348349
,args])
349350
before
351+
-- MSS 2018-08-30 can the CPP below be removed entirely, and instead exec the
352+
-- `docker` process so that it can handle the signals directly?
350353
#ifndef WINDOWS
351354
run <- askRunInIO
352355
oldHandlers <- forM [sigINT,sigABRT,sigHUP,sigPIPE,sigTERM,sigUSR1,sigUSR2] $ \sig -> do

0 commit comments

Comments
 (0)