Commit 8f3c149d authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by Ben Gamari

Add support for opting out of package environments

This implements the first part proposed in #13753:

Define a special magic "null" environment, which instructs GHC to ignore
any package environment files. To this end, I propose to use the name
`-` (i.e. a single dash), as that is more portable than using the empty
string for environment variables. In other words, a

- `-package-env -` CLI flag, or a
- `GHC_ENVIRONMENT=-` env var (unless a `-package-env` flag is present)

would inhibit GHC from looking up and interpreting any package
environment files from the filesystem; this is the equivalent of
`-ignore-dot-ghci` for package environment files.

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13753

Differential Revision: https://phabricator.haskell.org/D4690
parent cf88c2b1
......@@ -4894,12 +4894,14 @@ interpretPackageEnv :: DynFlags -> IO DynFlags
interpretPackageEnv dflags = do
mPkgEnv <- runMaybeT $ msum $ [
getCmdLineArg >>= \env -> msum [
probeEnvFile env
probeNullEnv env
, probeEnvFile env
, probeEnvName env
, cmdLineError env
]
, getEnvVar >>= \env -> msum [
probeEnvFile env
probeNullEnv env
, probeEnvFile env
, probeEnvName env
, envError env
]
......@@ -4912,6 +4914,9 @@ interpretPackageEnv dflags = do
Nothing ->
-- No environment found. Leave DynFlags unchanged.
return dflags
Just "-" -> do
-- Explicitly disabled environment file. Leave DynFlags unchanged.
return dflags
Just envfile -> do
content <- readFile envfile
putLogMsg dflags NoReason SevInfo noSrcSpan
......@@ -4941,6 +4946,10 @@ interpretPackageEnv dflags = do
guard =<< liftMaybeT (doesFileExist path)
return path
probeNullEnv :: FilePath -> MaybeT IO FilePath
probeNullEnv "-" = return "-"
probeNullEnv _ = mzero
parseEnvFile :: FilePath -> String -> DynP ()
parseEnvFile envfile = mapM_ parseEntry . lines
where
......
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