[commit: ghc] wip/nfs-locking: Add Environment module for setting up environment variables. (f6cd23d)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:14:30 UTC 2017


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

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/f6cd23dc4b92bcedc230754f06b4c3f11438f6ae/ghc

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

commit f6cd23dc4b92bcedc230754f06b4c3f11438f6ae
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Sun Jan 24 01:35:03 2016 +0000

    Add Environment module for setting up environment variables.
    
    Fix #191.


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

f6cd23dc4b92bcedc230754f06b4c3f11438f6ae
 shaking-up-ghc.cabal |  1 +
 src/Environment.hs   | 22 ++++++++++++++++++++++
 src/Main.hs          | 14 ++++++++------
 src/Rules/Config.hs  |  8 +-------
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/shaking-up-ghc.cabal b/shaking-up-ghc.cabal
index bd21d28..cdd512a 100644
--- a/shaking-up-ghc.cabal
+++ b/shaking-up-ghc.cabal
@@ -20,6 +20,7 @@ executable ghc-shake
     other-modules:       Base
                        , Builder
                        , CmdLineFlag
+                       , Environment
                        , Expression
                        , GHC
                        , Oracles
diff --git a/src/Environment.hs b/src/Environment.hs
new file mode 100644
index 0000000..fd207ed
--- /dev/null
+++ b/src/Environment.hs
@@ -0,0 +1,22 @@
+module Environment (setupEnvironment) where
+
+import Base
+import System.Environment
+
+-- | The build system invokes many external builders whose behaviour is
+-- influenced by the environment variables. We need to modify some of them
+-- for better robustness of the build system.
+setupEnvironment :: IO ()
+setupEnvironment = do
+    -- ghc-cabal refuses to work when GHC_PACKAGE_PATH is set (e.g. by Stack)
+    unsetEnv "GHC_PACKAGE_PATH"
+
+    -- On Windows, some path variables start a prefix like "C:\\" which may
+    -- lead to failures of scripts such as autoreconf. One particular variable
+    -- which causes issues is ACLOCAL_PATH. At the moment we simply reset it
+    -- if it contains a problematic Windows path.
+    -- TODO: Handle Windows paths in ACLOCAL_PATH more gracefully.
+    aclocal <- lookupEnv "ACLOCAL_PATH"
+    case aclocal of
+        Nothing -> return ()
+        Just s  -> when (":\\" `isPrefixOf` drop 1 s) $ unsetEnv "ACLOCAL_PATH"
diff --git a/src/Main.hs b/src/Main.hs
index 7321f88..69f739b 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -3,7 +3,8 @@ module Main (main) where
 import Development.Shake
 
 import qualified Base
-import           CmdLineFlag
+import qualified CmdLineFlag
+import qualified Environment
 import qualified Rules
 import qualified Rules.Cabal
 import qualified Rules.Clean
@@ -16,8 +17,9 @@ import qualified Rules.Perl
 import qualified Test
 
 main :: IO ()
-main = shakeArgsWith options flags $ \cmdLineFlags targets -> do
-    putCmdLineFlags cmdLineFlags
+main = shakeArgsWith options CmdLineFlag.flags $ \cmdLineFlags targets -> do
+    CmdLineFlag.putCmdLineFlags cmdLineFlags
+    Environment.setupEnvironment
     return . Just $ if null targets
                     then rules
                     else want targets >> withoutActions rules
@@ -27,13 +29,13 @@ main = shakeArgsWith options flags $ \cmdLineFlags targets -> do
         [ Rules.Cabal.cabalRules
         , Rules.Clean.cleanRules
         , Rules.Config.configRules
-        , Rules.Generate.copyRules
         , Rules.Generate.generateRules
-        , Rules.Perl.perlScriptRules
-        , Rules.generateTargets
+        , Rules.Generate.copyRules
         , Rules.Gmp.gmpRules
         , Rules.Libffi.libffiRules
         , Rules.Oracles.oracleRules
+        , Rules.Perl.perlScriptRules
+        , Rules.generateTargets
         , Rules.packageRules
         , Test.testRules ]
     options = shakeOptions
diff --git a/src/Rules/Config.hs b/src/Rules/Config.hs
index 77ac1ac..1297825 100644
--- a/src/Rules/Config.hs
+++ b/src/Rules/Config.hs
@@ -21,10 +21,4 @@ configRules = do
     -- TODO: Handle Windows paths in ACLOCAL_PATH more gracefully.
     "configure" %> \_ -> do
         putBuild "| Running boot..."
-        aclocal <- getEnv "ACLOCAL_PATH"
-        let env = case aclocal of
-                Nothing -> []
-                Just s  -> if ":\\" `isPrefixOf` (drop 1 s)
-                           then [AddEnv "ACLOCAL_PATH" ""]
-                           else []
-        quietly $ cmd (EchoStdout False) env "perl boot"
+        quietly $ cmd (EchoStdout False) "perl boot"



More information about the ghc-commits mailing list