Commit f6cd23dc authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Add Environment module for setting up environment variables.

Fix #191.
parent e01bf2f9
......@@ -20,6 +20,7 @@ executable ghc-shake
other-modules: Base
, Builder
, CmdLineFlag
, Environment
, Expression
, GHC
, Oracles
......
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"
......@@ -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
......
......@@ -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"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment