[commit: ghc] ghc-7.10: Respect GHC_CHARENC environment variable #10762 (108e35f)

git at git.haskell.org git at git.haskell.org
Sun Sep 6 17:02:46 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/108e35ff67586ffd570ca18d84a4f5fbf79727cc/ghc

>---------------------------------------------------------------

commit 108e35ff67586ffd570ca18d84a4f5fbf79727cc
Author: Michael Snoyman <michael at snoyman.com>
Date:   Sat Aug 29 12:23:48 2015 +0200

    Respect GHC_CHARENC environment variable #10762
    
    Only supports UTF-8 as a value right now. I expect some discussion to go
    on around the naming of this variable and whether it's valid to backport
    it to GHC 7.10 (which would be my preference). The motivation here is
    that, when capturing the output of GHC to a file, we often want to
    ensure that the output is UTF-8, regardless of the actual character
    encoding of the terminal/console.
    
    On the other hand, we don't want to necessary change the
    terminal/console encoding. The reason being:
    
    * On Windows, this requires a global-esque change to the console
      codepage, which adversely affects other processes in the same console
    
    * On all OSes, this can break features like smart quote auto-detection.
    
    Test Plan:
    Set LANG to C, GHC_CHARENC to UTF-8, and compile a Haskell source
    file with a non-ASCII warning produced. The output who include the UTF-8
    sequence instead of replacing it with ?.
    
    Reviewers: austin, rwbarton, bgamari
    
    Reviewed By: bgamari
    
    Subscribers: hsyl20, thomie
    
    Differential Revision: https://phabricator.haskell.org/D1167
    
    GHC Trac Issues: #10762


>---------------------------------------------------------------

108e35ff67586ffd570ca18d84a4f5fbf79727cc
 ghc/Main.hs | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ghc/Main.hs b/ghc/Main.hs
index 7b1c244..2a42c06 100644
--- a/ghc/Main.hs
+++ b/ghc/Main.hs
@@ -80,8 +80,18 @@ main = do
    initGCStatistics -- See Note [-Bsymbolic and hooks]
    hSetBuffering stdout LineBuffering
    hSetBuffering stderr LineBuffering
-   hSetTranslit stdout
-   hSetTranslit stderr
+
+   -- Handle GHC-specific character encoding flags, allowing us to control how
+   -- GHC produces output regardless of OS.
+   env <- getEnvironment
+   case lookup "GHC_CHARENC" env of
+    Just "UTF-8" -> do
+     hSetEncoding stdout utf8
+     hSetEncoding stderr utf8
+    _ -> do
+     -- Avoid GHC erroring out when trying to display unhandled characters
+     hSetTranslit stdout
+     hSetTranslit stderr
 
    GHC.defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
     -- 1. extract the -B flag from the args



More information about the ghc-commits mailing list