From 23864c59abfc6dad5a6b137941d618903817e1e3 Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Sun, 4 Aug 2019 21:14:45 +0200 Subject: Allow passing override-env to process functions Unfortunately we need this to pass a custom GHC executable path to stack, since it doesn't have an option to override it on the commandline (yet?). --- src/CabalHelper/Compiletime/Process.hs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/CabalHelper/Compiletime/Process.hs') diff --git a/src/CabalHelper/Compiletime/Process.hs b/src/CabalHelper/Compiletime/Process.hs index 43c3cd5..5e9bbbd 100644 --- a/src/CabalHelper/Compiletime/Process.hs +++ b/src/CabalHelper/Compiletime/Process.hs @@ -44,19 +44,28 @@ readProcess' exe args inp = do return outp +-- | Essentially 'System.Process.callProcess' but returns exit code, has +-- additional options and logging to stderr when verbosity is enabled. callProcessStderr' - :: Verbose => Maybe FilePath -> FilePath -> [String] -> IO ExitCode -callProcessStderr' mwd exe args = do + :: Verbose => Maybe FilePath -> [(String, String)] + -> FilePath -> [String] -> IO ExitCode +callProcessStderr' mwd env exe args = do let cd = case mwd of Nothing -> []; Just wd -> [ "cd", formatProcessArg wd++";" ] vLog $ intercalate " " $ cd ++ map formatProcessArg (exe:args) - (_, _, _, h) <- createProcess (proc exe args) { std_out = UseHandle stderr - , cwd = mwd } + (_, _, _, h) <- createProcess (proc exe args) + { std_out = UseHandle stderr + , env = if env == [] then Nothing else Just env + , cwd = mwd + } waitForProcess h -callProcessStderr :: Verbose => Maybe FilePath -> FilePath -> [String] -> IO () -callProcessStderr mwd exe args = do - rv <- callProcessStderr' mwd exe args +-- | Essentially 'System.Process.callProcess' but with additional options +-- and logging to stderr when verbosity is enabled. +callProcessStderr :: Verbose => Maybe FilePath -> [(String, String)] + -> FilePath -> [String] -> IO () +callProcessStderr mwd env exe args = do + rv <- callProcessStderr' mwd env exe args case rv of ExitSuccess -> return () ExitFailure v -> processFailedException "callProcessStderr" exe args v -- cgit v1.2.3