Commit f99d898b authored by Zejun Wu's avatar Zejun Wu Committed by Ben Gamari
Browse files

Handle :cd in external interpreter in a more robust way

We used to enqueue another command to change directory in the external
interpreter subprocess, this is not as robust as:

* it can fail with -fno-implict-import-qualified;
* it doesn't work when we `setGHCiMonad` to something other than `IO`.

Neither of them works if `directory` package is hidden though.

Test Plan:
$ inplace/bin/ghc-stage2 --interactive # -fexternal-interpreter
GHCi, version 8.7.20181213:  :? for help
Prelude> :cd ..
Prelude> System.Directory.getCurrentDirectory
Prelude> :!pwd
Leaving GHCi.


Reviewers: simonmar, bgamari, RyanGlScott

Reviewed By: simonmar

Subscribers: rwbarton, carter

Differential Revision:
parent c42eb2e6
......@@ -1430,8 +1430,11 @@ changeDirectory dir = do
dflags <- getDynFlags
-- With -fexternal-interpreter, we have to change the directory of the subprocess too.
-- (this gives consistent behaviour with and without -fexternal-interpreter)
when (gopt Opt_ExternalInterpreter dflags) $
lift $ enqueueCommands ["System.Directory.setCurrentDirectory " ++ show dir']
when (gopt Opt_ExternalInterpreter dflags) $ do
hsc_env <- GHC.getSession
fhv <- compileGHCiExpr $
"System.Directory.setCurrentDirectory " ++ show dir'
liftIO $ evalIO hsc_env fhv
trySuccess :: GHC.GhcMonad m => m SuccessFlag -> m SuccessFlag
trySuccess act =
......@@ -24,6 +24,8 @@ module GHCi.UI.Monad (
printForUserNeverQualify, printForUserModInfo,
printForUser, printForUserPartWay, prettyLocations,
turnOffBuffering, turnOffBuffering_,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment