Fix -fobject-code with -fexternal-interpreter
authorSimon Marlow <marlowsd@gmail.com>
Tue, 15 Nov 2016 16:49:33 +0000 (16:49 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 16 Nov 2016 14:31:01 +0000 (14:31 +0000)
If the user does :cd in GHCi with -fexternal-interpreter, then we can
fail to find the object files.

compiler/ghci/GHCi.hs
testsuite/driver/extra_files.py
testsuite/tests/ghci/scripts/all.T
testsuite/tests/ghci/scripts/ghci062.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/ghci062.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/ghci062/Test.hs [new file with mode: 0644]

index c6d0d22..755771e 100644 (file)
@@ -79,6 +79,7 @@ import GHC.IO.Handle.Types (Handle)
 import Foreign.C
 import GHC.IO.Handle.FD (fdToHandle)
 #else
+import System.Directory
 import System.Posix as Posix
 #endif
 import System.Process
@@ -383,13 +384,24 @@ loadDLL :: HscEnv -> String -> IO (Maybe String)
 loadDLL hsc_env str = iservCmd hsc_env (LoadDLL str)
 
 loadArchive :: HscEnv -> String -> IO ()
-loadArchive hsc_env str = iservCmd hsc_env (LoadArchive str)
+loadArchive hsc_env path = do
+  path' <- canonicalizePath path -- Note [loadObj and relative paths]
+  iservCmd hsc_env (LoadArchive path')
 
 loadObj :: HscEnv -> String -> IO ()
-loadObj hsc_env str = iservCmd hsc_env (LoadObj str)
+loadObj hsc_env path = do
+  path' <- canonicalizePath path -- Note [loadObj and relative paths]
+  iservCmd hsc_env (LoadObj path')
 
 unloadObj :: HscEnv -> String -> IO ()
-unloadObj hsc_env str = iservCmd hsc_env (UnloadObj str)
+unloadObj hsc_env path = do
+  path' <- canonicalizePath path -- Note [loadObj and relative paths]
+  iservCmd hsc_env (UnloadObj path')
+
+-- Note [loadObj and relative paths]
+-- the iserv process might have a different current directory from the
+-- GHC process, so we must make paths absolute before sending them
+-- over.
 
 addLibrarySearchPath :: HscEnv -> String -> IO (Ptr ())
 addLibrarySearchPath hsc_env str =
index eb0aa27..3b92935 100644 (file)
@@ -290,6 +290,7 @@ extra_src_files = {
   'ghci026': ['../prog002'],
   'ghci038': ['../shell.hs'],
   'ghci058': ['../shell.hs'],
+  'ghci062': ['ghci062/', 'ghci062/Test.hs'],
   'ghcilink001': ['TestLink.hs', 'f.c'],
   'ghcilink002': ['TestLink.hs', 'f.c'],
   'ghcilink004': ['TestLink.hs', 'f.c'],
index 20888ae..4927abc 100755 (executable)
@@ -97,6 +97,7 @@ test('ghci056',
 test('ghci057', normal, ghci_script, ['ghci057.script'])
 test('ghci060', normal, ghci_script, ['ghci060.script'])
 test('ghci061', normal, ghci_script, ['ghci061.script'])
+test('ghci062', extra_ways(['ghci-ext']), ghci_script, ['ghci062.script'])
 
 test('T2452', normal, ghci_script, ['T2452.script'])
 test('T2766', normal, ghci_script, ['T2766.script'])
diff --git a/testsuite/tests/ghci/scripts/ghci062.script b/testsuite/tests/ghci/scripts/ghci062.script
new file mode 100644 (file)
index 0000000..80aad1a
--- /dev/null
@@ -0,0 +1,9 @@
+-- Tests for a bug in -fexternal-interpreter where we call loadObj
+-- with a local path for the object file, and the iserv process is
+-- running with a different current directory so it can't load the
+-- object file.
+
+:cd ghci062
+:set -fobject-code
+:load Test
+test
diff --git a/testsuite/tests/ghci/scripts/ghci062.stdout b/testsuite/tests/ghci/scripts/ghci062.stdout
new file mode 100644 (file)
index 0000000..8b8441b
--- /dev/null
@@ -0,0 +1 @@
+"test"
diff --git a/testsuite/tests/ghci/scripts/ghci062/Test.hs b/testsuite/tests/ghci/scripts/ghci062/Test.hs
new file mode 100644 (file)
index 0000000..f840579
--- /dev/null
@@ -0,0 +1,3 @@
+module Test where
+
+test = "test"