Skip to content

Backport #10827: Fix environment variable handling when running executables #10887

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 2 commits into from
Mar 31, 2025

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 31, 2025

This fixes a bug where environment variables were duplicated when running executables.

overrideEnv <- fromMaybe [] <$> getEffectiveEnvironment ([("PATH", Just newPath)] ++ envOverrides)
let shellEnv = overrideEnv ++ existingEnv

Since getEffectiveEnvironment already calls getEnvironment internally, if any overrides
are passed then the result is a complete environment. Appending it to
the already existing environment results in duplicated environment variables.

The fix:

  • Added getFullEnvironment function to handle the common pattern correctly
  • Updated code in Bench, Test/ExeV10, Test/LibV09, and Client/Run to use this function

In the future it would be good to generalise getFullEnvironment
further so it can also handle the addLibraryPath case, which modifies
an environment variable, rather than merely setting or unsetting it.

Fixes #10718.


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:


Template B: This PR does not modify behaviour or interface

E.g. the PR only touches documentation or tests, does refactorings, etc.

Include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).

This is an automatic backport of pull request #10827 done by [Mergify](https://mergify.com).

This fixes a bug where environment variables were duplicated when running executables.

```
overrideEnv <- fromMaybe [] <$> getEffectiveEnvironment ([("PATH", Just newPath)] ++ envOverrides)
let shellEnv = overrideEnv ++ existingEnv
```

Since getEffectiveEnvironment already calls getEnvironment internally, if any overrides
are passed then the result is a complete environment. Appending it to
the already existing environment results in duplicated environment variables.

The fix:
* Added getFullEnvironment function to handle the common pattern correctly
* Updated code in Bench, Test/ExeV10, Test/LibV09, and Client/Run to use this function

In the future it would be good to generalise `getFullEnvironment`
further so it can also handle the `addLibraryPath` case, which modifies
an environment variable, rather than merely setting or unsetting it.

Fixes #10718

(cherry picked from commit 4375dd5)
Adds a simple test case that identifies and reports duplicate
environment variables in the Cabal environment.

For issue (#10718)

(cherry picked from commit 6e54b23)
@Mikolaj Mikolaj added the squash+merge me Tell Mergify Bot to squash-merge label Mar 31, 2025
@mergify mergify bot merged commit a8cf469 into 3.14 Mar 31, 2025
58 checks passed
@mergify mergify bot deleted the mergify/bp/3.14/pr-10827 branch March 31, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants