-
Notifications
You must be signed in to change notification settings - Fork 704
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
cabal repl: Change in PATH environment variable not reflected #2015
Comments
Does this work in |
Yes, it works within ghci. (see changes in first post) |
A simple workaround is to run |
I can repro by calling repl directly on Setup script, so it must be a Cabal library bug. |
This seems a more general issue that seemingly running |
I just lost an hour trying to figure out why the |
Looks like I am hitting the same issue with Any other workarounds? |
rm -rf dist-newstyle
... |
... or
I am not able to reproduce with cabal run or exec, only with |
Wow. Wow. |
I ran into this issue today. I'm curious why this behaviour is even possible. Like, it's probably the consequence of a well-meaning feature. Anyone know? |
This was a pretty surprising bug that led me down a debugging rabbit hole. I'd love to see this fixed some day. |
I just tried the reproducer in OP, and it works fine with cabal-head. @stephenjudkins which version are you using? Could you try with cabal-head? |
This does happen with Try in a package
The issue AFAIK is that
There are duplicate issues, e.g. #6497 |
Thank you, I can reproduce it with your example. Do you know where in
|
I don't. I'm quite sure it's a |
Yes, it does seem to be the library, as also was pointed above (long time ago though), e.g. by Edward here: #2015 (comment) What I don’t understand is where Cabal stashes the value of PATH between creating dist-newstyle and a call to |
All right, the place where it stores the old value seems to be
|
@ulysses4ever I think that if you modify |
Perhaps the way to do this is to store the current path in |
if PATH is changed, technically you should wipe the whole ProgramDb (i.e. configured programs) etc, in particular the used (implicit) |
Thanks, Matt! Oleg, is reconfiguring the whole ProgramDB a problem? What would be the downsides? Presumably, PATH doesn't change all the time, so this proposed check will hardly add much slowdown in practice and be noticed. Is this hard for some technical reason? Besides, if we we only reconfigure |
@ulysses4ever I'm trying to say that changing PATH may well as well require doing everything from the beginning, essentially wiping all work done. Changed I'm not sure We don't know before we try to implement this, but if the rebuild logic will be sketchy, I think it will be worse than just not reacting to PATH changes. Not reacting is a clear specification: if you need to see new PATH, force reconfiguration (by wiping |
And to add, How often people do really change PATH? IMHO it can be leaved as a known behavior. It's surprising at first, but IMHO it makes sense. Maybe what |
|
When a user's PATH environment variable changes between Cabal commands, the environment in the REPL becomes incorrect. This occurs because during initial package configuration, the current PATH is captured via `programSearchPathAsPATHVar` and then stored in the `programOverrideEnv` field of a ConfiguredProgram. These `ConfiguredProgram`s are subsequently serialized into the setup-config file, effectively baking in the PATH environment from the time of configuration. The issue manifests when `PATH` is updated after initial configuration. Although the solver re-runs when detecting `PATH` changes, the `dryRunLocalPkg` function examines `ElaboratedConfiguredPackage` and incorrectly determines that nothing has changed that would require reconfiguration. This decision is incorrect because `setup-config` now contains a stale reference to the original `PATH` value, which no longer matches the current environment. To fix this problem, we need to store the `ConfiguredProgram`s directly in `ElaboratedConfiguredPackage`. This approach will ensure that when `PATH` changes, the `ConfiguredProgram`s will also change, properly triggering reconfiguration. While this solution will cause more recompilations when `PATH` changes, it guarantees that the correct environment is always used during builds and REPL sessions. An alternative approach would be to stop baking the `PATH` variable into the environment of programs, but this would require more substantial changes to how Cabal manages environment variables. Fixes #2015
When a user's PATH environment variable changes between Cabal commands, the environment in the REPL becomes incorrect. This occurs because during initial package configuration, the current PATH is captured via `programSearchPathAsPATHVar` and then stored in the `programOverrideEnv` field of a ConfiguredProgram. These `ConfiguredProgram`s are subsequently serialized into the setup-config file, effectively baking in the PATH environment from the time of configuration. The issue manifests when `PATH` is updated after initial configuration. Although the solver re-runs when detecting `PATH` changes, the `dryRunLocalPkg` function examines `ElaboratedConfiguredPackage` and incorrectly determines that nothing has changed that would require reconfiguration. This decision is incorrect because `setup-config` now contains a stale reference to the original `PATH` value, which no longer matches the current environment. To fix this problem, we need to store the `ConfiguredProgram`s directly in `ElaboratedConfiguredPackage`. This approach will ensure that when `PATH` changes, the `ConfiguredProgram`s will also change, properly triggering reconfiguration. While this solution will cause more recompilations when `PATH` changes, it guarantees that the correct environment is always used during builds and REPL sessions. An alternative approach would be to stop baking the `PATH` variable into the environment of programs, but this would require more substantial changes to how Cabal manages environment variables. Fixes #2015
Good news everyone. 10 years later I have put a fix in #10817 |
Description
A change in the PATH environment variable is not visible in cabal repl.
Versions
Confirmed in versions:
cabal-install version 1.20.0.3,
using version 1.20.0.1 of the Cabal library,
ghc 7.6.3,
cabal-install version 1.18.0.5,
ghc 7.8.3
Steps to reproduce
The environment when accessed from cabal repl-based ghci does not reflect the change in the PATH variable.
It does work with newly created environment variables, though.
GHCI
In pure GHCI everything works fine:
The text was updated successfully, but these errors were encountered: