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 ...@@ -20,6 +20,7 @@ executable ghc-shake
other-modules: Base other-modules: Base
, Builder , Builder
, CmdLineFlag , CmdLineFlag
, Environment
, Expression , Expression
, GHC , GHC
, Oracles , 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 ...@@ -3,7 +3,8 @@ module Main (main) where
import Development.Shake import Development.Shake
import qualified Base import qualified Base
import CmdLineFlag import qualified CmdLineFlag
import qualified Environment
import qualified Rules import qualified Rules
import qualified Rules.Cabal import qualified Rules.Cabal
import qualified Rules.Clean import qualified Rules.Clean
...@@ -16,8 +17,9 @@ import qualified Rules.Perl ...@@ -16,8 +17,9 @@ import qualified Rules.Perl
import qualified Test import qualified Test
main :: IO () main :: IO ()
main = shakeArgsWith options flags $ \cmdLineFlags targets -> do main = shakeArgsWith options CmdLineFlag.flags $ \cmdLineFlags targets -> do
putCmdLineFlags cmdLineFlags CmdLineFlag.putCmdLineFlags cmdLineFlags
Environment.setupEnvironment
return . Just $ if null targets return . Just $ if null targets
then rules then rules
else want targets >> withoutActions rules else want targets >> withoutActions rules
...@@ -27,13 +29,13 @@ main = shakeArgsWith options flags $ \cmdLineFlags targets -> do ...@@ -27,13 +29,13 @@ main = shakeArgsWith options flags $ \cmdLineFlags targets -> do
[ Rules.Cabal.cabalRules [ Rules.Cabal.cabalRules
, Rules.Clean.cleanRules , Rules.Clean.cleanRules
, Rules.Config.configRules , Rules.Config.configRules
, Rules.Generate.copyRules
, Rules.Generate.generateRules , Rules.Generate.generateRules
, Rules.Perl.perlScriptRules , Rules.Generate.copyRules
, Rules.generateTargets
, Rules.Gmp.gmpRules , Rules.Gmp.gmpRules
, Rules.Libffi.libffiRules , Rules.Libffi.libffiRules
, Rules.Oracles.oracleRules , Rules.Oracles.oracleRules
, Rules.Perl.perlScriptRules
, Rules.generateTargets
, Rules.packageRules , Rules.packageRules
, Test.testRules ] , Test.testRules ]
options = shakeOptions options = shakeOptions
......
...@@ -21,10 +21,4 @@ configRules = do ...@@ -21,10 +21,4 @@ configRules = do
-- TODO: Handle Windows paths in ACLOCAL_PATH more gracefully. -- TODO: Handle Windows paths in ACLOCAL_PATH more gracefully.
"configure" %> \_ -> do "configure" %> \_ -> do
putBuild "| Running boot..." putBuild "| Running boot..."
aclocal <- getEnv "ACLOCAL_PATH" quietly $ cmd (EchoStdout False) "perl boot"
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"
Supports Markdown
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