Fix PATH changes not triggering REPL reconfiguration (#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
Showing
- cabal-install/src/Distribution/Client/ProjectPlanning.hs 1 addition, 0 deletionscabal-install/src/Distribution/Client/ProjectPlanning.hs
- cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs 1 addition, 0 deletions...-install/src/Distribution/Client/ProjectPlanning/Types.hs
- cabal-testsuite/PackageTests/PathRecomp/PathRecomp.cabal 13 additions, 0 deletionscabal-testsuite/PackageTests/PathRecomp/PathRecomp.cabal
- cabal-testsuite/PackageTests/PathRecomp/Setup.hs 3 additions, 0 deletionscabal-testsuite/PackageTests/PathRecomp/Setup.hs
- cabal-testsuite/PackageTests/PathRecomp/cabal.test.hs 21 additions, 0 deletionscabal-testsuite/PackageTests/PathRecomp/cabal.test.hs
- cabal-testsuite/PackageTests/PathRecomp/src/Lib.hs 7 additions, 0 deletionscabal-testsuite/PackageTests/PathRecomp/src/Lib.hs
- changelog.d/pr-10817 12 additions, 0 deletionschangelog.d/pr-10817
Loading
Please register or sign in to comment