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: http://www.haskell.org/ghc/  :? for help
Prelude> :cd ..
Prelude> System.Directory.getCurrentDirectory
"/data/users/watashi"
Prelude> :!pwd
/data/users/watashi
Prelude>
Leaving GHCi.
```

  ./validate

Reviewers: simonmar, bgamari, RyanGlScott

Reviewed By: simonmar

Subscribers: rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5453
parent c42eb2e6
...@@ -1430,8 +1430,11 @@ changeDirectory dir = do ...@@ -1430,8 +1430,11 @@ changeDirectory dir = do
dflags <- getDynFlags dflags <- getDynFlags
-- With -fexternal-interpreter, we have to change the directory of the subprocess too. -- With -fexternal-interpreter, we have to change the directory of the subprocess too.
-- (this gives consistent behaviour with and without -fexternal-interpreter) -- (this gives consistent behaviour with and without -fexternal-interpreter)
when (gopt Opt_ExternalInterpreter dflags) $ when (gopt Opt_ExternalInterpreter dflags) $ do
lift $ enqueueCommands ["System.Directory.setCurrentDirectory " ++ show dir'] 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 :: GHC.GhcMonad m => m SuccessFlag -> m SuccessFlag
trySuccess act = trySuccess act =
......
...@@ -24,6 +24,8 @@ module GHCi.UI.Monad ( ...@@ -24,6 +24,8 @@ module GHCi.UI.Monad (
printForUserNeverQualify, printForUserModInfo, printForUserNeverQualify, printForUserModInfo,
printForUser, printForUserPartWay, prettyLocations, printForUser, printForUserPartWay, prettyLocations,
compileGHCiExpr,
initInterpBuffering, initInterpBuffering,
turnOffBuffering, turnOffBuffering_, turnOffBuffering, turnOffBuffering_,
flushInterpBuffers, flushInterpBuffers,
......
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