on master help sign in
Log runNixShellAttr in Debug
commit186501d2235b15b48e67baee038bdc486d8eb9cb authorSridhar Ratnakumar <srid@srid.ca> dateTue 15 May 2018, 11:00 (8 years ago) parent17d2461
2 files changed+25−5
lib/command/src/Obelisk/CLI/Process.hs+22−2 lib/command/src/Obelisk/Command/Project.hs+3−3
lib/command/src/Obelisk/CLI/Process.hs+22−2
@@ -11,6 +11,8 @@
1111module Obelisk.CLI.Process
1212 ( readProcessAndLogStderr
1313 , callProcessAndLogOutput
14+ , createProcess
15+ , createProcess_
1416 ) where
1517
1618import Control.Applicative (liftA2)
@@ -30,8 +32,9 @@ import System.IO (Handle)
3032import System.IO.Streams (InputStream, handleToInputStream)
3133import qualified System.IO.Streams as Streams
3234import System.IO.Streams.Concurrent (concurrentMerge)
33−import System.Process (CreateProcess, StdStream (CreatePipe), cmdspec, createProcess, std_err, std_out,
35+import System.Process (CreateProcess, ProcessHandle, StdStream (CreatePipe), cmdspec, std_err, std_out,
3436 waitForProcess)
37+import qualified System.Process as Process
3538
3639import Obelisk.CLI.Logging (Output, Severity (..), failWith, putLog, putLogRaw)
3740
@@ -62,13 +65,30 @@ callProcessAndLogOutput (sev_out, sev_err) process = do
6265 where
6366 combineStream s1 s2 = concurrentMerge [s1, s2]
6467
68+-- | Like `System.Process.createProcess` but also logs (debug) the process being run
69+createProcess
70+ :: (MonadIO m, MonadLog Output m)
71+ => CreateProcess -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
72+createProcess p = do
73+ putLog Debug $ "Creating process: " <> T.pack (show p)
74+ liftIO $ Process.createProcess p
75+
76+-- | Like `System.Process.createProcess_` but also logs (debug) the process being run
77+createProcess_
78+ :: (MonadIO m, MonadLog Output m)
79+ => String -> CreateProcess -> m (Maybe Handle, Maybe Handle, Maybe Handle, ProcessHandle)
80+createProcess_ name p = do
81+ putLog Debug $ "Creating process " <> T.pack name <> ": " <> T.pack (show p)
82+ liftIO $ Process.createProcess p
83+
84+
6585withProcess
6686 :: (MonadIO m, MonadMask m, MonadLog Output m)
6787 => CreateProcess -> (Handle -> Handle -> m ()) -> m (Handle, Handle)
6888withProcess process f = do
6989 let procTitle = T.pack $ show $ cmdspec process
7090 putLog Debug $ "Starting process: " <> procTitle
71− (_, Just out, Just err, p) <- liftIO $ createProcess $ process
91+ (_, Just out, Just err, p) <- createProcess $ process
7292 { std_out = CreatePipe
7393 , std_err = CreatePipe
7494 }
lib/command/src/Obelisk/Command/Project.hs+3−3
@@ -23,13 +23,13 @@ import System.Directory
2323import System.FilePath
2424import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
2525import System.Posix.Files
26−import System.Process (CreateProcess, createProcess_, cwd, proc, waitForProcess)
26+import System.Process (CreateProcess, cwd, proc, waitForProcess)
2727
2828import GitHub.Data.GitData (Branch)
2929import GitHub.Data.Name (Name)
3030
3131import Obelisk.App (MonadObelisk)
32−import Obelisk.CLI (Severity (..), callProcessAndLogOutput, failWith, putLog, withSpinner)
32+import Obelisk.CLI (Severity (..), callProcessAndLogOutput, createProcess_, failWith, putLog, withSpinner)
3333import Obelisk.Command.Thunk
3434import Obelisk.Command.Utils (cp)
3535--TODO: Make this module resilient to random exceptions
@@ -186,7 +186,7 @@ inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
186186
187187projectShell :: MonadObelisk m => FilePath -> Bool -> String -> String -> m ()
188188projectShell root isPure shellName command = do
189− (_, _, _, ph) <- liftIO $ createProcess_ "runNixShellAttr" $ setCwd (Just root) $ proc "nix-shell" $
189+ (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCwd (Just root) $ proc "nix-shell" $
190190 [ "--pure" | isPure ] <>
191191 [ "-A"
192192 , "shells." <> shellName