Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Other enhancements:
* Include default values for most command line flags in the `--help`
output. See
[#893](https://github.com/commercialhaskell/stack/issues/893).
* environment variable `GHC_ENVIRONMENT` is set to specify dependency
* Set the `GHC_ENVIRONMENT` environment variable to specify dependency
packages explicitly when running test. This is done to prevent
ambiguous module name errors in `doctest` tests.
- Document the way stack interacts with the Cabal library.
Expand All @@ -181,6 +181,13 @@ Other enhancements:
* User config files are respected for the script command. See
[#3705](https://github.com/commercialhaskell/stack/issues/3705),
[#3887](https://github.com/commercialhaskell/stack/issues/3887).
* Set the `GHC_ENVIRONMENT` environment variable to `-` to tell GHC to
ignore any such files when GHC is new enough (>= 8.4.4), otherwise
simply unset the variable. This allows Stack to have control of
package databases when running commands like `stack exec ghci`, even
in the presence of implicit environment files created by `cabal
new-build`. See
[#4706](https://github.com/commercialhaskell/stack/issues/4706).

Bug fixes:

Expand Down
14 changes: 13 additions & 1 deletion src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,18 @@ setupEnv needTargets boptsCLI mResolveMissingGHC = do
[ toFilePathNoTrailingSep deps
, ""
])
$ Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePathNoTrailingSep distDir) env
$ Map.insert "HASKELL_DIST_DIR" (T.pack $ toFilePathNoTrailingSep distDir)

-- Make sure that any .ghc.environment files
-- are ignored, since we're settting up our
-- own package databases. See
-- https://github.com/commercialhaskell/stack/issues/4706
$ (case cpCompilerVersion compilerPaths of
ACGhc version | version >= mkVersion [8, 4, 4] ->
Map.insert "GHC_ENVIRONMENT" "-"
_ -> id)

env

() <- atomicModifyIORef envRef $ \m' ->
(Map.insert es eo m', ())
Expand Down Expand Up @@ -1773,6 +1784,7 @@ removeHaskellEnvVars :: Map Text Text -> Map Text Text
removeHaskellEnvVars =
Map.delete "GHCJS_PACKAGE_PATH" .
Map.delete "GHC_PACKAGE_PATH" .
Map.delete "GHC_ENVIRONMENT" .
Map.delete "HASKELL_PACKAGE_SANDBOX" .
Map.delete "HASKELL_PACKAGE_SANDBOXES" .
Map.delete "HASKELL_DIST_DIR" .
Expand Down
27 changes: 27 additions & 0 deletions test/integration/tests/4706-ignore-ghc-env-files/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import StackTest
import Control.Exception (bracket_)
import Control.Monad (when)
import System.Environment
import System.Directory
import System.Info (arch, os)

main :: IO ()
main = when False $ do -- skip this test until we start using GHC 8.4.4 or later for integration tests
let ghcVer = "8.4.4"
fp = concat
[ ".ghc.environment."
, arch
, "-"
, os
, "-"
, ghcVer
]
writeFile "stack.yaml" $ "resolver: ghc-" ++ ghcVer
bracket_
(writeFile fp "This is an invalid GHC environment file")
(removeFile fp) $ do
envFile <- canonicalizePath fp
setEnv "GHC_ENVIRONMENT" envFile
stack ["clean"]
stack ["build"]
stack ["runghc", "Main.hs"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foo.cabal
stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
main :: IO ()
main = pure ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: foo
version: 0

dependencies:
- base

library: {}