Skip to content

Commit c623785

Browse files
committed
Cabal: Always pass -package-env=- to supported GHC versions
Issue #10759 highlighted the issue that we were not isolating the calls to ghc from the existence of environment files. This manifested in a terminal bug where extra arguments form the environment file were causing a link failure which was due to a combination of #10692. However, even before this bug the test executable was relinked to due to the extra flags from the environment file. ``` Building test suite 'aeson-schemas-test' for aeson-schemas-1.4.2.1... Loaded package environment from /home/runner/work/aeson-schemas/aeson-schemas/dist-newstyle/tmp/environment.-69233/.ghc.environment.x86_64-linux-9.6.6 Loaded package environment from /home/runner/work/aeson-schemas/aeson-schemas/dist-newstyle/tmp/environment.-69233/.ghc.environment.x86_64-linux-9.6.6 [23 of 23] Linking /home/runner/work/aeson-schemas/aeson-schemas/dist-newstyle/build/x86_64-linux/ghc-9.6.6/aeson-schemas-1.4.2.1/t/aeson-schemas-test/build/aeson-schemas-test/aeson-schemas-test [Flags changed] ``` The correct solution is that calls to `ghc` made by `Cabal` should never implicitly use an environment file. This is similar to how `GHC_PACKAGE_PATH` is treated. Fixes #10759
1 parent 44086db commit c623785

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

Cabal/src/Distribution/Simple/Program/Builtin.hs

+36-24
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,44 @@ ghcProgram :: Program
104104
ghcProgram =
105105
(simpleProgram "ghc")
106106
{ programFindVersion = findProgramVersion "--numeric-version" id
107-
, -- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/8825
108-
-- (spurious warning on non-english locales)
109-
programPostConf = \_verbosity ghcProg ->
110-
do
111-
let ghcProg' =
112-
ghcProg
113-
{ programOverrideEnv =
114-
("LANGUAGE", Just "en")
115-
: programOverrideEnv ghcProg
116-
}
117-
-- Only the 7.8 branch seems to be affected. Fixed in 7.8.4.
118-
affectedVersionRange =
119-
intersectVersionRanges
120-
(laterVersion $ mkVersion [7, 8, 0])
121-
(earlierVersion $ mkVersion [7, 8, 4])
122-
return $
123-
maybe
124-
ghcProg
125-
( \v ->
126-
if withinRange v affectedVersionRange
127-
then ghcProg'
128-
else ghcProg
129-
)
130-
(programVersion ghcProg)
107+
, programPostConf = ghcPostConf
131108
, programNormaliseArgs = normaliseGhcArgs
132109
}
110+
where
111+
ghcPostConf _verbosity ghcProg = do
112+
let setLanguageEnv prog =
113+
prog
114+
{ programOverrideEnv =
115+
("LANGUAGE", Just "en")
116+
: programOverrideEnv ghcProg
117+
}
118+
119+
ignorePackageEnv prog = prog{programDefaultArgs = "-package-env=-" : programDefaultArgs prog}
120+
121+
-- Only the 7.8 branch seems to be affected. Fixed in 7.8.4.
122+
affectedVersionRange =
123+
intersectVersionRanges
124+
(laterVersion $ mkVersion [7, 8, 0])
125+
(earlierVersion $ mkVersion [7, 8, 4])
126+
127+
canIgnorePackageEnv = orLaterVersion $ mkVersion [8, 4, 4]
128+
129+
applyWhen cond f prog = if cond then f prog else prog
130+
131+
return $
132+
maybe
133+
ghcProg
134+
( \v ->
135+
-- By default, ignore GHC_ENVIRONMENT variable of any package environmnet
136+
-- files. See #10759
137+
applyWhen (withinRange v canIgnorePackageEnv) ignorePackageEnv
138+
-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/8825
139+
-- (spurious warning on non-english locales)
140+
$
141+
applyWhen (withinRange v affectedVersionRange) setLanguageEnv $
142+
ghcProg
143+
)
144+
(programVersion ghcProg)
133145

134146
runghcProgram :: Program
135147
runghcProgram =

0 commit comments

Comments
 (0)