{-# LANGUAGE CPP #-}
module Distribution.Compat.Process
(
proc
, enableProcessJobs
) where
import System.Process (CreateProcess)
import qualified System.Process as Process
#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9)
import System.IO.Unsafe (unsafePerformIO)
import System.Win32.Info.Version (dwMajorVersion, dwMinorVersion, getVersionEx)
#endif
#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9)
{-# NOINLINE isWindows8OrLater #-}
isWindows8OrLater :: Bool
isWindows8OrLater :: Bool
isWindows8OrLater = IO Bool -> Bool
forall a. IO a -> a
unsafePerformIO (IO Bool -> Bool) -> IO Bool -> Bool
forall a b. (a -> b) -> a -> b
$ do
OSVERSIONINFOEX
v <- IO OSVERSIONINFOEX
getVersionEx
Bool -> IO Bool
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$ (OSVERSIONINFOEX -> DWORD
dwMajorVersion OSVERSIONINFOEX
v, OSVERSIONINFOEX -> DWORD
dwMinorVersion OSVERSIONINFOEX
v) (DWORD, DWORD) -> (DWORD, DWORD) -> Bool
forall a. Ord a => a -> a -> Bool
>= (DWORD
6, DWORD
2)
#endif
enableProcessJobs :: CreateProcess -> CreateProcess
#if defined(mingw32_HOST_OS) && MIN_VERSION_process(1,6,9)
enableProcessJobs :: CreateProcess -> CreateProcess
enableProcessJobs CreateProcess
cp = CreateProcess
cp {Process.use_process_jobs = isWindows8OrLater}
#else
enableProcessJobs cp = cp
#endif
proc :: FilePath -> [String] -> CreateProcess
proc :: FilePath -> [FilePath] -> CreateProcess
proc FilePath
path [FilePath]
args = CreateProcess -> CreateProcess
enableProcessJobs (FilePath -> [FilePath] -> CreateProcess
Process.proc FilePath
path [FilePath]
args){Process.delegate_ctlc = True}