the first step to make ghc-mod independent from GHC's version.

This commit is contained in:
Kazu Yamamoto 2014-03-17 16:58:55 +09:00
parent 16e050439d
commit dd7b7b8305
2 changed files with 18 additions and 7 deletions

View File

@ -18,7 +18,6 @@ import Distribution.PackageDescription (PackageDescription)
import DynFlags
import Exception
import GHC
import GHC.Paths (libdir)
import Language.Haskell.GhcMod.CabalApi
import Language.Haskell.GhcMod.ErrMsg
import Language.Haskell.GhcMod.GHCChoice
@ -26,6 +25,16 @@ import qualified Language.Haskell.GhcMod.Gap as Gap
import Language.Haskell.GhcMod.Types
import System.Exit
import System.IO
import System.Process
----------------------------------------------------------------
getSystemLibDir :: IO (Maybe FilePath)
getSystemLibDir = do
res <- readProcess "ghc" ["--print-libdir"] []
return $ case res of
"" -> Nothing
dirn -> Just (init dirn)
----------------------------------------------------------------
@ -38,9 +47,11 @@ withGHCDummyFile = withGHC "Dummy"
withGHC :: Alternative m => FilePath -- ^ A target file displayed in an error message.
-> Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities.
-> IO (m a)
withGHC file body = ghandle ignore $ runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
defaultCleanupHandler dflags body
withGHC file body = do
mlibdir <- getSystemLibDir
ghandle ignore $ runGhc mlibdir $ do
dflags <- getSessionDynFlags
defaultCleanupHandler dflags body
where
ignore :: Alternative m => SomeException -> IO (m a)
ignore e = do
@ -150,4 +161,6 @@ setTargetFiles files = do
-- | Return the 'DynFlags' currently in use in the GHC session.
getDynamicFlags :: IO DynFlags
getDynamicFlags = runGhc (Just libdir) getSessionDynFlags
getDynamicFlags = do
mlibdir <- getSystemLibDir
runGhc mlibdir getSessionDynFlags

View File

@ -66,7 +66,6 @@ Library
, directory
, filepath
, ghc
, ghc-paths
, ghc-syb-utils
, hlint >= 1.8.58
, io-choice
@ -121,7 +120,6 @@ Test-Suite spec
, directory
, filepath
, ghc
, ghc-paths
, ghc-syb-utils
, hlint >= 1.7.1
, io-choice