summaryrefslogtreecommitdiff
path: root/dev-lang/ghc/files/ghc-7.8.3-cc-lang.patch
blob: 032dc9a6762437f43b40caa914d4377066bc8f96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
commit 4d4d07704ee78221607a18b8118294b0aea1bac4
Author: Sergei Trofimovich <slyfox@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@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

diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 72fa19b..67926f5 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -492,6 +492,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
@@ -746,8 +791,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
@@ -802,7 +848,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
@@ -952,7 +999,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