[commit: ghc] ghc-7.8: systools: fix gcc version detecton on non-english locale (7548ec8)
git at git.haskell.org
git at git.haskell.org
Mon Oct 27 16:04:51 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.8
Link : http://ghc.haskell.org/trac/ghc/changeset/7548ec859071c67d92632e4228aba74796d5d5ad/ghc
>---------------------------------------------------------------
commit 7548ec859071c67d92632e4228aba74796d5d5ad
Author: Sergei Trofimovich <slyfox at gentoo.org>
Date: Tue Sep 2 00:06:56 2014 +0300
systools: fix gcc version detecton on non-english locale
Summary:
ghc runs 'gcc -v' to check if we run under vanilla gcc
or disaguised clang by checking for string
"gcc version <something>"
But this check does not always work as gcc has that string
localized via gettext mechanism:
(some gcc's locale strings)
be.po-msgstr "версія gcc %s\n"
da.po-msgstr "GCC version %s\n"
de.po-msgstr "gcc-Version %s %s\n"
el.po-msgstr "έκδοση gcc %s\n"
...
To ping gcc to English locale we now override environment
variable with 'LANGUAGE=en' value.
Fixes Issue #8825
Signed-off-by: Sergei Trofimovich <slyfox at gentoo.org>
Test Plan: validate
Reviewers: austin
Reviewed By: austin
Subscribers: simonmar, ezyang, carter
Differential Revision: https://phabricator.haskell.org/D185
GHC Trac Issues: #8825
(cherry picked from commit 4d4d07704ee78221607a18b8118294b0aea1bac4)
>---------------------------------------------------------------
7548ec859071c67d92632e4228aba74796d5d5ad
compiler/main/SysTools.lhs | 56 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 52 insertions(+), 4 deletions(-)
diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 2945911..cd9b9f5 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -490,6 +490,51 @@ readCreateProcess proc = do
return (ex, output)
+readProcessEnvWithExitCode
+ :: String -- ^ program path
+ -> [String] -- ^ program args
+ -> [(String, String)] -- ^ environment to override
+ -> 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)
+
+-- Don't let gcc localize version info string, #8825
+en_locale_env :: [(String, String)]
+en_locale_env = [("LANGUAGE", "en")]
-- 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
@@ -744,8 +789,9 @@ getLinkerInfo' dflags = do
_ -> do
-- In practice, we use the compiler as the linker here. Pass
-- -Wl,--version to get linker version info.
- (exitc, stdo, stde) <- readProcessWithExitCode pgm
- ["-Wl,--version"] ""
+ (exitc, stdo, stde) <- readProcessEnvWithExitCode pgm
+ ["-Wl,--version"]
+ en_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
@@ -800,7 +846,8 @@ getCompilerInfo' dflags = do
-- Process the executable call
info <- catchIO (do
- (exitc, stdo, stde) <- readProcessWithExitCode pgm ["-v"] ""
+ (exitc, stdo, stde) <-
+ readProcessEnvWithExitCode pgm ["-v"] en_locale_env
-- Split the output by lines to make certain kinds
-- of processing easier.
parseCompilerInfo (lines stdo) (lines stde) exitc
@@ -900,7 +947,8 @@ readElfSection _dflags section exe = do
prog = "readelf"
args = [Option "-p", Option section, FileOption "" exe]
--
- r <- readProcessWithExitCode prog (filter notNull (map showOpt args)) ""
+ r <- readProcessEnvWithExitCode prog (filter notNull (map showOpt args))
+ en_locale_env
case r of
(ExitSuccess, out, _err) -> return (doFilter (lines out))
_ -> return Nothing
More information about the ghc-commits
mailing list