diff options
author | Thomas Miedema <thomasmiedema@gmail.com> | 2016-06-11 10:43:59 +0200 |
---|---|---|
committer | Thomas Miedema <thomasmiedema@gmail.com> | 2016-06-14 18:09:49 +0200 |
commit | 753c5b24304fa1dd1af774be268794baef820f75 (patch) | |
tree | f33d6caced24f14c09ae1133dd48c6aa4f92eb49 | |
parent | 9d22fbe2d3d8c4609919040007ea8bb561bf9a38 (diff) | |
download | haskell-753c5b24304fa1dd1af774be268794baef820f75.tar.gz |
Simplify readProcessEnvWithExitCode + set LANGUAGE=C
`readProcessEnvWithExitCode` was added in
4d4d07704ee78221607a18b8118294b0aea1bac4, to start an external process
after making some modifications to the environment.
Since then, the `process` library has exposed
`readCreateProcessWithExitCode`, which allows for the refactoring we do
here.
Also change "en" to "C", as suggested in ticket:8825#comment:11.
Reviewed by: trofi
Differential Revision: https://phabricator.haskell.org/D2332
GHC Trac Issues: #8825
-rw-r--r-- | compiler/main/SysTools.hs | 52 |
1 files changed, 13 insertions, 39 deletions
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs index 9423b00296..c86935edbc 100644 --- a/compiler/main/SysTools.hs +++ b/compiler/main/SysTools.hs @@ -509,51 +509,25 @@ readCreateProcessWithExitCode' proc = do return (ex, output) +replaceVar :: (String, String) -> [(String, String)] -> [(String, String)] +replaceVar (var, value) env = + (var, value) : filter (\(var',_) -> var /= var') env + +-- | Version of @System.Process.readProcessWithExitCode@ that takes a +-- key-value tuple to insert into the environment. readProcessEnvWithExitCode :: String -- ^ program path -> [String] -- ^ program args - -> [(String, String)] -- ^ environment to override + -> (String, String) -- ^ addition to the environment -> IO (ExitCode, String, String) -- ^ (exit_code, stdout, stderr) readProcessEnvWithExitCode prog args env_update = do current_env <- getEnvironment - let new_env = env_update ++ [ (k, v) - | let overriden_keys = map fst env_update - , (k, v) <- current_env - , k `notElem` overriden_keys - ] - p = proc prog args - - (_stdin, Just stdoh, Just stdeh, pid) <- - createProcess p{ std_out = CreatePipe - , std_err = CreatePipe - , env = Just new_env - } - - outMVar <- newEmptyMVar - errMVar <- newEmptyMVar - - _ <- forkIO $ do - stdo <- hGetContents stdoh - _ <- evaluate (length stdo) - putMVar outMVar stdo - - _ <- forkIO $ do - stde <- hGetContents stdeh - _ <- evaluate (length stde) - putMVar errMVar stde - - out <- takeMVar outMVar - hClose stdoh - err <- takeMVar errMVar - hClose stdeh - - ex <- waitForProcess pid - - return (ex, out, err) + readCreateProcessWithExitCode (proc prog args) { + env = Just (replaceVar env_update current_env) } "" -- Don't let gcc localize version info string, #8825 -en_locale_env :: [(String, String)] -en_locale_env = [("LANGUAGE", "en")] +c_locale_env :: (String, String) +c_locale_env = ("LANGUAGE", "C") -- If the -B<dir> option is set, add <dir> to PATH. This works around -- a bug in gcc on Windows Vista where it can't find its auxiliary @@ -864,7 +838,7 @@ getLinkerInfo' dflags = do -- -Wl,--version to get linker version info. (exitc, stdo, stde) <- readProcessEnvWithExitCode pgm (["-Wl,--version"] ++ args3) - en_locale_env + c_locale_env -- Split the output by lines to make certain kinds -- of processing easier. In particular, 'clang' and 'gcc' -- have slightly different outputs for '-Wl,--version', but @@ -920,7 +894,7 @@ getCompilerInfo' dflags = do -- Process the executable call info <- catchIO (do (exitc, stdo, stde) <- - readProcessEnvWithExitCode pgm ["-v"] en_locale_env + readProcessEnvWithExitCode pgm ["-v"] c_locale_env -- Split the output by lines to make certain kinds -- of processing easier. parseCompilerInfo (lines stdo) (lines stde) exitc |