1
- {-# LANGUAGE NoImplicitPrelude #-}
2
- {-# LANGUAGE OverloadedStrings #-}
3
- {-# LANGUAGE ScopedTypeVariables #-}
1
+ {-# LANGUAGE NoImplicitPrelude #-}
2
+ {-# LANGUAGE ExistentialQuantification #-}
3
+ {-# LANGUAGE OverloadedStrings #-}
4
+ {-# LANGUAGE ScopedTypeVariables #-}
4
5
5
6
module Stack.Prelude
6
- ( withSystemTempDir
7
+ ( PrettyException (.. )
8
+ , withSystemTempDir
7
9
, withKeepSystemTempDir
8
10
, sinkProcessStderrStdout
9
11
, sinkProcessStdout
@@ -25,41 +27,64 @@ module Stack.Prelude
25
27
, module X
26
28
) where
27
29
28
- import RIO as X
29
- import RIO.File as X hiding (writeBinaryFileAtomic )
30
- import Data.Conduit as X (ConduitM , runConduit , (.|) )
31
- import Path as X (Abs , Dir , File , Path , Rel ,
32
- toFilePath )
33
- import Pantry as X hiding (Package (.. ), loadSnapshot )
34
-
35
- import Data.Monoid as X (First (.. ), Any (.. ), Sum (.. ), Endo (.. ))
36
-
37
- import qualified Path.IO
38
-
39
- import System.IO.Echo (withoutInputEcho )
30
+ import Data.Monoid as X
31
+ ( First (.. ), Any (.. ), Sum (.. ), Endo (.. ) )
40
32
33
+ import Data.Conduit as X ( ConduitM , runConduit , (.|) )
41
34
import qualified Data.Conduit.Binary as CB
42
35
import qualified Data.Conduit.List as CL
43
- import Data.Conduit.Process.Typed (withLoggedProcess_ , createSource , byteStringInput )
44
- import RIO.Process (HasProcessContext (.. ), ProcessContext , setStdin , closed , getStderr , getStdout , proc , withProcessWait_ , setStdout , setStderr , ProcessConfig , readProcess_ , workingDirL , waitExitCode )
45
-
36
+ import Data.Conduit.Process.Typed
37
+ ( withLoggedProcess_ , createSource , byteStringInput )
46
38
import qualified Data.Text.IO as T
39
+ import Pantry as X hiding ( Package (.. ), loadSnapshot )
40
+ import Path as X
41
+ ( Abs , Dir , File , Path , Rel , toFilePath )
42
+ import qualified Path.IO
43
+ import RIO as X
44
+ import RIO.File as X hiding ( writeBinaryFileAtomic )
45
+ import RIO.PrettyPrint ( Pretty (.. ) )
46
+ import RIO.Process
47
+ ( HasProcessContext (.. ), ProcessContext , setStdin , closed
48
+ , getStderr , getStdout , proc , withProcessWait_ , setStdout
49
+ , setStderr , ProcessConfig , readProcess_ , workingDirL
50
+ , waitExitCode
51
+ )
47
52
import qualified RIO.Text as T
53
+ import System.IO.Echo ( withoutInputEcho )
54
+
55
+ -- | Type representing pretty exceptions
56
+ data PrettyException
57
+ = forall e . (Pretty e , Exception e ) => PrettyException e
58
+ deriving Typeable
59
+
60
+ instance Show PrettyException where
61
+ show (PrettyException e) = show e
62
+
63
+ instance Pretty PrettyException where
64
+ pretty (PrettyException e) = pretty e
65
+
66
+ instance Exception PrettyException
48
67
49
68
-- | Path version
50
69
withSystemTempDir :: MonadUnliftIO m => String -> (Path Abs Dir -> m a ) -> m a
51
- withSystemTempDir str inner = withRunInIO $ \ run -> Path.IO. withSystemTempDir str $ run . inner
70
+ withSystemTempDir str inner = withRunInIO $ \ run ->
71
+ Path.IO. withSystemTempDir str $ run . inner
52
72
53
73
-- | Like `withSystemTempDir`, but the temporary directory is not deleted.
54
- withKeepSystemTempDir :: MonadUnliftIO m => String -> (Path Abs Dir -> m a ) -> m a
74
+ withKeepSystemTempDir :: MonadUnliftIO m
75
+ => String
76
+ -> (Path Abs Dir -> m a )
77
+ -> m a
55
78
withKeepSystemTempDir str inner = withRunInIO $ \ run -> do
56
79
path <- Path.IO. getTempDir
57
80
dir <- Path.IO. createTempDir path str
58
81
run $ inner dir
59
82
60
- -- | Consume the stdout and stderr of a process feeding strict 'ByteString's to the consumers.
83
+ -- | Consume the stdout and stderr of a process feeding strict 'ByteString's to
84
+ -- the consumers.
61
85
--
62
- -- Throws a 'ReadProcessException' if unsuccessful in launching, or 'ExitCodeException' if the process itself fails.
86
+ -- Throws a 'ReadProcessException' if unsuccessful in launching, or
87
+ -- 'ExitCodeException' if the process itself fails.
63
88
sinkProcessStderrStdout
64
89
:: forall e o env . (HasProcessContext env , HasLogFunc env , HasCallStack )
65
90
=> String -- ^ Command
@@ -120,7 +145,10 @@ readProcessNull name args =
120
145
121
146
-- | Use the new 'ProcessContext', but retain the working directory
122
147
-- from the parent environment.
123
- withProcessContext :: HasProcessContext env => ProcessContext -> RIO env a -> RIO env a
148
+ withProcessContext :: HasProcessContext env
149
+ => ProcessContext
150
+ -> RIO env a
151
+ -> RIO env a
124
152
withProcessContext pcNew inner = do
125
153
pcOld <- view processContextL
126
154
let pcNew' = set workingDirL (view workingDirL pcOld) pcNew
0 commit comments