Skip to content

Commit d958545

Browse files
authored
Merge pull request #10990 from sergv/fix-cabal-exec
Make ‘cabal exec’ not pass -package-env to called executable
2 parents 413621c + 3f83721 commit d958545

File tree

9 files changed

+70
-7
lines changed

9 files changed

+70
-7
lines changed

cabal-install/src/Distribution/Client/CmdExec.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,13 @@ execAction flags extraArgs globalFlags = do
200200

201201
( if envFilesSupported
202202
then withTempEnvFile verbosity baseCtx buildCtx buildStatus
203-
else \f ->
204-
if programIsConfiguredCompiler
205-
then f environmentPackageArgs []
206-
else f [] []
203+
else \f -> f environmentPackageArgs []
207204
)
208205
$ \argOverrides envOverrides -> do
209206
let program' =
210207
withOverrides
211208
envOverrides
212-
argOverrides
209+
(if programIsConfiguredCompiler then argOverrides else [])
213210
program
214211
invocation = programInvocation program' args
215212
dryRun =
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
module Main (main) where
3+
4+
import System.Environment
5+
import System.Exit
6+
import System.IO
7+
8+
main :: IO ()
9+
main = do
10+
args <- getArgs
11+
case args of
12+
["--required", "foo"] -> pure ()
13+
other -> die $ "Unexpected arguments: " ++ show other
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- my-0.1 (exe:my-executable) (first run)
6+
Configuring executable 'my-executable' for my-0.1...
7+
Preprocessing executable 'my-executable' for my-0.1...
8+
Building executable 'my-executable' for my-0.1...
9+
# cabal v2-exec
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import Test.Cabal.Prelude
3+
4+
main :: IO ()
5+
main = cabalTest $ do
6+
cabal "v2-build" ["my:exe:my-executable"]
7+
8+
withPlan $ do
9+
exePath <- planExePath "my" "my-executable"
10+
11+
-- The test is to check that we’re not acceidentally passing more
12+
-- than expected.
13+
--
14+
-- Target executable may not accept any extra option cabal may pass.
15+
-- Or it may and it would lead to incorrect results and lengthy
16+
-- debugging, which is worse.
17+
cabal "v2-exec" [exePath, "--", "--required", "foo"]
18+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cabal-version: 3.0
2+
name: my
3+
version: 0.1
4+
license: BSD-3-Clause
5+
build-type: Simple
6+
7+
executable my-executable
8+
main-is: Main.hs
9+
build-depends: base
10+
default-language: Haskell2010

changelog.d/pr-10828.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
synopsis: "Isolate Cabal from the GHC_ENVIRONMENT variable"
3+
packages: [Cabal]
4+
prs: 10828 10990
5+
6+
issues: 10759
7+
---
8+
9+
For GHC 8.4.4 and later, Cabal now passes the `-package-env=-` flag to GHC.
10+
This prevents the `GHC_ENVIRONMENT` variable or any package environment files
11+
from affecting Cabal builds.
12+
13+
This change eliminates unexpected build behavior that could occur when users
14+
had GHC environment files configured in their system that Cabal wasn't aware
15+
of.

changelog.d/pr-10830.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
synopsis: Set <pkgname>_datadir to an absolute path when running tests
33
packages: [Cabal]
4-
prs: 10828
4+
prs: 10830
55
issues: [10717]
66
---
77

release-notes/Cabal-3.14.2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Cabal and Cabal-syntax 3.14.2.0 changelog and release notes
1919
environment for these processes, Cabal would append the overridden environment
2020
to the existing environment, creating duplicates of the same variable.
2121

22-
- Set `<pkgname>_datadir` to an absolute path when running tests [#10717](https://github.com/haskell/cabal/issues/10717) [#10828](https://github.com/haskell/cabal/pull/10828)
22+
- Set `<pkgname>_datadir` to an absolute path when running tests [#10717](https://github.com/haskell/cabal/issues/10717) [#10830](https://github.com/haskell/cabal/pull/10830)
2323

2424
Fix a regression where `<pkgname>_datadir` was set to a relative path. This
2525
caused issues when running testsuites which changed the working directory and

0 commit comments

Comments
 (0)