:cd affects the iserv process too
authorSimon Marlow <marlowsd@gmail.com>
Sun, 2 Apr 2017 14:43:32 +0000 (10:43 -0400)
committerBen Gamari <ben@smart-cactus.org>
Sun, 2 Apr 2017 16:01:47 +0000 (12:01 -0400)
Test Plan: validate

Reviewers: angerman, austin, bgamari, erikd

Reviewed By: bgamari

Subscribers: rwbarton, thomie

Differential Revision: https://phabricator.haskell.org/D3395

ghc/GHCi/UI.hs
testsuite/tests/ghci/scripts/GhciCurDir.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index 71be20c..deee24a 100644 (file)
@@ -1409,6 +1409,11 @@ changeDirectory dir = do
   GHC.workingDirectoryChanged
   dir' <- expandPath dir
   liftIO $ setCurrentDirectory dir'
+  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']
 
 trySuccess :: GHC.GhcMonad m => m SuccessFlag -> m SuccessFlag
 trySuccess act =
diff --git a/testsuite/tests/ghci/scripts/GhciCurDir.script b/testsuite/tests/ghci/scripts/GhciCurDir.script
new file mode 100644 (file)
index 0000000..785a773
--- /dev/null
@@ -0,0 +1,7 @@
+import System.Directory
+import Control.Monad
+
+createDirectory "test"
+createDirectory "test/test1"
+:cd test
+unless ("test1" `elem` getDirectoryContents ".") $ putStrLn "Uh oh."
index 00d8d81..cde72e4 100755 (executable)
@@ -251,3 +251,4 @@ test('StaticPtr', normal, ghci_script, ['StaticPtr.script'])
 test('T13202', normal, ghci_script, ['T13202.script'])
 test('T13202a', normal, ghci_script, ['T13202a.script'])
 test('T13466', normal, ghci_script, ['T13466.script'])
+test('GhciCurDir', normal, ghci_script, ['GhciCurDir.script'])