55{-# LANGUAGE TemplateHaskell #-}
66{-# LANGUAGE OverloadedStrings #-}
77{-# LANGUAGE FlexibleContexts #-}
8-
8+ {-# LANGUAGE RecordWildCards #-}
99-- | Run sub-processes.
1010
1111module System.Process.Run
12- (runIn
12+ (runCmd
1313 ,callProcess
1414 ,callProcess'
1515 ,ProcessExitedUnsuccessfully )
@@ -23,38 +23,38 @@ import Data.Conduit.Process hiding (callProcess)
2323import Data.Foldable (forM_ )
2424import Data.Text (Text )
2525import qualified Data.Text as T
26- import Path (Path , Abs , Dir , toFilePath )
26+ import Path (toFilePath )
2727import Prelude -- Fix AMP warning
2828import System.Exit (exitWith , ExitCode (.. ))
2929import qualified System.Process
3030import System.Process.Read
31+ import Stack.Types (CMD (.. ))
3132
3233-- | Run the given command in the given directory, inheriting stdout and stderr.
3334--
3435-- If it exits with anything but success, prints an error
3536-- and then calls 'exitWith' to exit the program.
36- runIn :: forall (m :: * -> * ).
37+ runCmd :: forall (m :: * -> * ).
3738 (MonadLogger m ,MonadIO m ,MonadBaseControl IO m )
38- => Path Abs Dir -- ^ directory to run in
39- -> FilePath -- ^ command to run
40- -> EnvOverride
41- -> [String ] -- ^ command line arguments
42- -> Maybe Text -- ^ optional additional error message
39+ => CMD
40+ -> Maybe Text -- ^ optional additional error message
4341 -> m ()
44- runIn wd cmd menv args errMsg = do
45- result <- try (callProcess ( Just wd) menv cmd args )
42+ runCmd cmd@ ( CMD { .. }) mbErrMsg = do
43+ result <- try (callProcess cmd)
4644 case result of
4745 Left (ProcessExitedUnsuccessfully _ ec) -> do
4846 $ logError $
4947 T. pack $
50- concat
48+ concat $
5149 [ " Exit code "
5250 , show ec
5351 , " while running "
54- , show (cmd : args)
55- , " in "
56- , toFilePath wd]
57- forM_ errMsg $ logError
52+ , show (cmdCommandToRun : cmdCommandLineArguments)
53+ ] ++ (case cmdDirectoryToRunIn of
54+ Nothing -> []
55+ Just mbDir -> [" in " , toFilePath mbDir]
56+ )
57+ forM_ mbErrMsg $ logError
5858 liftIO (exitWith ec)
5959 Right () -> return ()
6060
@@ -63,14 +63,8 @@ runIn wd cmd menv args errMsg = do
6363-- process exits unsuccessfully.
6464--
6565-- Inherits stdout and stderr.
66- callProcess :: (MonadIO m , MonadLogger m )
67- => Maybe (Path Abs Dir ) -- ^ optional directory to run in
68- -> EnvOverride
69- -> String -- ^ command to run
70- -> [String ] -- ^ command line arguments
71- -> m ()
72- callProcess =
73- callProcess' id
66+ callProcess :: (MonadIO m , MonadLogger m ) => CMD -> m ()
67+ callProcess = callProcess' id
7468
7569-- | Like 'System.Process.callProcess', but takes an optional working directory and
7670-- environment override, and throws 'ProcessExitedUnsuccessfully' if the
@@ -79,12 +73,9 @@ callProcess =
7973-- Inherits stdout and stderr.
8074callProcess' :: (MonadIO m , MonadLogger m )
8175 => (CreateProcess -> CreateProcess )
82- -> Maybe (Path Abs Dir ) -- ^ optional directory to run in
83- -> EnvOverride
84- -> String -- ^ command to run
85- -> [String ] -- ^ command line arguments
76+ -> CMD
8677 -> m ()
87- callProcess' modCP wd menv cmd0 args = do
78+ callProcess' modCP ( CMD wd cmd0 menv args) = do
8879 cmd <- preProcess wd menv cmd0
8980 let c = modCP $ (proc cmd args) { delegate_ctlc = True
9081 , cwd = fmap toFilePath wd
0 commit comments