Skip to content

Commit

Permalink
Rework subprocess helpers
Browse files Browse the repository at this point in the history
- Set enable_process_jobs on a variant of System.Process.proc
  instead of just for System.Process.createProcess
- In Distribution.Simple.Utils, only use this proc instance.
- Replace use of printRawCommand* by a unified helper logCommand,
  and use this more consistently. The output format is changed
  slightly.
- New helpers rawSystemProc{,Action} for use with new proc

Aside from the logging changes, this should be a no-op.
  • Loading branch information
robx committed Feb 22, 2022
1 parent eefe45d commit a5986e3
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 113 deletions.
20 changes: 13 additions & 7 deletions Cabal/src/Distribution/Compat/Process.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Distribution.Compat.Process (
-- * Redefined functions
createProcess,
proc,
runInteractiveProcess,
rawSystem,
-- * Additions
Expand All @@ -11,7 +12,7 @@ module Distribution.Compat.Process (
import System.Exit (ExitCode (..))
import System.IO (Handle)

import System.Process (CreateProcess, ProcessHandle, waitForProcess)
import System.Process (CreateProcess, ProcessHandle)
import qualified System.Process as Process

#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9)
Expand Down Expand Up @@ -60,6 +61,11 @@ enableProcessJobs cp = cp
-- process redefinitions
-------------------------------------------------------------------------------

-- | 'System.Process.proc' with process jobs enabled when appropriate,
-- and defaulting 'delegate_ctlc' to 'True'.
proc :: FilePath -> [String] -> CreateProcess
proc path args = enableProcessJobs (Process.proc path args)

-- | 'System.Process.createProcess' with process jobs enabled when appropriate.
-- See 'enableProcessJobs'.
createProcess :: CreateProcess
Expand All @@ -68,10 +74,10 @@ createProcess = Process.createProcess . enableProcessJobs

-- | 'System.Process.rawSystem' with process jobs enabled when appropriate.
-- See 'enableProcessJobs'.
rawSystem :: String -> [String] -> IO ExitCode
rawSystem cmd args = do
(_,_,_,p) <- createProcess (Process.proc cmd args) { Process.delegate_ctlc = True }
waitForProcess p
rawSystem :: FilePath -> [String] -> IO ExitCode
rawSystem path args = do
(_,_,_,p) <- Process.createProcess (proc path args) { Process.delegate_ctlc = True }
Process.waitForProcess p

-- | 'System.Process.runInteractiveProcess' with process jobs enabled when
-- appropriate. See 'enableProcessJobs'.
Expand All @@ -81,9 +87,9 @@ runInteractiveProcess
-> Maybe FilePath -- ^ Optional path to the working directory
-> Maybe [(String,String)] -- ^ Optional environment (otherwise inherit)
-> IO (Handle,Handle,Handle,ProcessHandle)
runInteractiveProcess cmd args mb_cwd mb_env = do
runInteractiveProcess path args mb_cwd mb_env = do
(mb_in, mb_out, mb_err, p) <-
createProcess (Process.proc cmd args)
Process.createProcess (proc path args)
{ Process.std_in = Process.CreatePipe,
Process.std_out = Process.CreatePipe,
Process.std_err = Process.CreatePipe,
Expand Down
Loading

0 comments on commit a5986e3

Please sign in to comment.