Fall back to assuming ghc-mid is on PATH when exeutable name is not available

This commit is contained in:
Daniel Gröber 2014-07-18 02:13:40 +02:00
parent 981051a642
commit ba9c70dff7

View File

@ -34,7 +34,7 @@ import Name (getOccString)
import System.Directory (doesDirectoryExist, getAppUserDataDirectory, doesFileExist, getModificationTime) import System.Directory (doesDirectoryExist, getAppUserDataDirectory, doesFileExist, getModificationTime)
import System.FilePath ((</>), takeDirectory) import System.FilePath ((</>), takeDirectory)
import System.IO import System.IO
import System.Environment (getExecutablePath) import System.Environment
#ifndef MIN_VERSION_containers #ifndef MIN_VERSION_containers
#define MIN_VERSION_containers(x,y,z) 1 #define MIN_VERSION_containers(x,y,z) 1
@ -90,11 +90,18 @@ loadSymbolDb = SymbolDb <$> readSymbolDb
ghcModExecutable :: IO FilePath ghcModExecutable :: IO FilePath
#ifndef SPEC #ifndef SPEC
ghcModExecutable = do ghcModExecutable = do
dir <- takeDirectory <$> getExecutablePath dir <- getExecutablePath'
return $ dir </> "ghc-mod" return $ dir </> "ghc-mod"
#else #else
ghcModExecutable = return "dist/build/ghc-mod/ghc-mod" ghcModExecutable = return "dist/build/ghc-mod/ghc-mod"
#endif #endif
where
getExecutablePath' :: IO FilePath
# if __GLASGOW_HASKELL__ >= 706
getExecutablePath' = takeDirectory <$> getExecutablePath
# else
getExecutablePath' = return ""
# endif
readSymbolDb :: IO (Map Symbol [ModuleString]) readSymbolDb :: IO (Map Symbol [ModuleString])
readSymbolDb = handle (\(SomeException _) -> return M.empty) $ do readSymbolDb = handle (\(SomeException _) -> return M.empty) $ do