Skip to content

Make ‘cabal exec’ not pass -package-env to called executable #10990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2025
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
7 changes: 2 additions & 5 deletions cabal-install/src/Distribution/Client/CmdExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,13 @@ execAction flags extraArgs globalFlags = do

( if envFilesSupported
then withTempEnvFile verbosity baseCtx buildCtx buildStatus
else \f ->
if programIsConfiguredCompiler
then f environmentPackageArgs []
else f [] []
else \f -> f environmentPackageArgs []
)
$ \argOverrides envOverrides -> do
let program' =
withOverrides
envOverrides
argOverrides
(if programIsConfiguredCompiler then argOverrides else [])
program
invocation = programInvocation program' args
dryRun =
Expand Down
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/ExecCommand/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

module Main (main) where

import System.Environment
import System.Exit
import System.IO

main :: IO ()
main = do
args <- getArgs
case args of
["--required", "foo"] -> pure ()
other -> die $ "Unexpected arguments: " ++ show other
9 changes: 9 additions & 0 deletions cabal-testsuite/PackageTests/ExecCommand/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- my-0.1 (exe:my-executable) (first run)
Configuring executable 'my-executable' for my-0.1...
Preprocessing executable 'my-executable' for my-0.1...
Building executable 'my-executable' for my-0.1...
# cabal v2-exec
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/ExecCommand/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
18 changes: 18 additions & 0 deletions cabal-testsuite/PackageTests/ExecCommand/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import Test.Cabal.Prelude

main :: IO ()
main = cabalTest $ do
cabal "v2-build" ["my:exe:my-executable"]

withPlan $ do
exePath <- planExePath "my" "my-executable"

-- The test is to check that we’re not acceidentally passing more
-- than expected.
--
-- Target executable may not accept any extra option cabal may pass.
-- Or it may and it would lead to incorrect results and lengthy
-- debugging, which is worse.
cabal "v2-exec" [exePath, "--", "--required", "foo"]

10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/ExecCommand/my.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 3.0
name: my
version: 0.1
license: BSD-3-Clause
build-type: Simple

executable my-executable
main-is: Main.hs
build-depends: base
default-language: Haskell2010
15 changes: 15 additions & 0 deletions changelog.d/pr-10828.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
synopsis: "Isolate Cabal from the GHC_ENVIRONMENT variable"
packages: [Cabal]
prs: 10828 10990

issues: 10759
---

For GHC 8.4.4 and later, Cabal now passes the `-package-env=-` flag to GHC.
This prevents the `GHC_ENVIRONMENT` variable or any package environment files
from affecting Cabal builds.

This change eliminates unexpected build behavior that could occur when users
had GHC environment files configured in their system that Cabal wasn't aware
of.
2 changes: 1 addition & 1 deletion changelog.d/pr-10830.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
synopsis: Set <pkgname>_datadir to an absolute path when running tests
packages: [Cabal]
prs: 10828
prs: 10830
issues: [10717]
---

Expand Down
2 changes: 1 addition & 1 deletion release-notes/Cabal-3.14.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Cabal and Cabal-syntax 3.14.2.0 changelog and release notes
environment for these processes, Cabal would append the overridden environment
to the existing environment, creating duplicates of the same variable.

- 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)
- 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)

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