Skip to content

Fix PATH changes not triggering REPL reconfiguration (#2015) #10817

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,7 @@ elaborateInstallPlan
]
<> perPkgOptionMapMappend pkgid packageConfigProgramArgs
elabProgramPathExtra = perPkgOptionNubList pkgid packageConfigProgramPathExtra
elabConfiguredPrograms = configuredPrograms compilerprogdb
elabConfigureScriptArgs = perPkgOptionList pkgid packageConfigConfigureArgs
elabExtraLibDirs = perPkgOptionList pkgid packageConfigExtraLibDirs
elabExtraLibDirsStatic = perPkgOptionList pkgid packageConfigExtraLibDirsStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ data ElaboratedConfiguredPackage = ElaboratedConfiguredPackage
, elabProgramPaths :: Map String FilePath
, elabProgramArgs :: Map String [String]
, elabProgramPathExtra :: [FilePath]
, elabConfiguredPrograms :: [ConfiguredProgram]
, elabConfigureScriptArgs :: [String]
, elabExtraLibDirs :: [FilePath]
, elabExtraLibDirsStatic :: [FilePath]
Expand Down
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/PathRecomp/PathRecomp.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: PathRecomp
version: 0.1.0.0
license: BSD3
author: Test Author
maintainer: [email protected]
build-type: Simple
cabal-version: >=1.10

library
exposed-modules: Lib
hs-source-dirs: src
build-depends: base
default-language: Haskell2010
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/PathRecomp/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Distribution.Simple
main = defaultMain

21 changes: 21 additions & 0 deletions cabal-testsuite/PackageTests/PathRecomp/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Test.Cabal.Prelude
import qualified Data.Map as Map
import qualified Control.Monad.IO.Class as IO
import System.Environment (getEnvironment)

main = cabalTest $ recordMode DoNotRecord $ do
-- First run cabal repl with the normal PATH
env <- IO.liftIO getEnvironment
let originalPath = maybe "" id (lookup "PATH" env)

-- Run repl with original PATH
cabalWithStdin "repl" ["lib:PathRecomp"] "" >>= assertOutputContains "module loaded"

-- Now modify the PATH by prefixing with a dummy directory
-- This simulates a user modifying their PATH between cabal commands
let modifiedPath = "/dummy/path:" ++ originalPath
withEnv [("PATH", Just modifiedPath)] $ do
-- Run repl with modified PATH - this should still work
r <- cabalWithStdin "repl" ["lib:PathRecomp"] "(Prelude.fmap . Prelude.fmap) (\"/dummy/path\" `Data.List.isInfixOf`) (System.Environment.lookupEnv \"PATH\")"
assertOutputContains "module loaded" r
assertOutputContains "Just True" r
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/PathRecomp/src/Lib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Lib
( someFunc
) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"

15 changes: 15 additions & 0 deletions changelog.d/pr-10817
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
synopsis: Fix PATH changes not triggering REPL reconfiguration
packages: cabal-install
prs: #10817
issues: #2015

When modifying your PATH environment variable between Cabal commands, REPL
sessions will now correctly use the updated environment. Previously, if you
changed your PATH after initial configuration, Cabal would continue using the
old PATH settings in REPL sessions without warning.

With this fix, Cabal properly detects PATH changes and reconfigures the REPL
accordingly, ensuring tools and libraries in your current PATH are available.
Comment on lines +6 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text, including the title, feels a little repetitive. I suggest dropping the first sentence in the description and make it into one paragraph:

Suggested change
When modifying your PATH environment variable between Cabal commands, REPL
sessions will now correctly use the updated environment. Previously, if you
changed your PATH after initial configuration, Cabal would continue using the
old PATH settings in REPL sessions without warning.
With this fix, Cabal properly detects PATH changes and reconfigures the REPL
accordingly, ensuring tools and libraries in your current PATH are available.
Previously, if you changed your PATH after initial configuration, Cabal would
continue using the old PATH settings in REPL sessions without warning.
With this fix, Cabal properly detects PATH changes and reconfigures the REPL
accordingly, ensuring tools and libraries in your current PATH are available.

Again, consider that it appears right after the title ("synopsis" field). And that the former third sentence basically repeated the former first one that I suggest to drop.

While this may cause additional rebuilds when PATH changes, it prevents the
confusing errors that could occur when your REPL environment didn't match your
system configuration.
Loading