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 DynFlags
import Exception import Exception
import GHC import GHC
import GHC.Paths (libdir)
import Language.Haskell.GhcMod.CabalApi import Language.Haskell.GhcMod.CabalApi
import Language.Haskell.GhcMod.ErrMsg import Language.Haskell.GhcMod.ErrMsg
import Language.Haskell.GhcMod.GHCChoice import Language.Haskell.GhcMod.GHCChoice
@ -26,6 +25,16 @@ import qualified Language.Haskell.GhcMod.Gap as Gap
import Language.Haskell.GhcMod.Types import Language.Haskell.GhcMod.Types
import System.Exit import System.Exit
import System.IO 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. withGHC :: Alternative m => FilePath -- ^ A target file displayed in an error message.
-> Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities. -> Ghc (m a) -- ^ 'Ghc' actions created by the Ghc utilities.
-> IO (m a) -> IO (m a)
withGHC file body = ghandle ignore $ runGhc (Just libdir) $ do withGHC file body = do
dflags <- getSessionDynFlags mlibdir <- getSystemLibDir
defaultCleanupHandler dflags body ghandle ignore $ runGhc mlibdir $ do
dflags <- getSessionDynFlags
defaultCleanupHandler dflags body
where where
ignore :: Alternative m => SomeException -> IO (m a) ignore :: Alternative m => SomeException -> IO (m a)
ignore e = do ignore e = do
@ -150,4 +161,6 @@ setTargetFiles files = do
-- | Return the 'DynFlags' currently in use in the GHC session. -- | Return the 'DynFlags' currently in use in the GHC session.
getDynamicFlags :: IO DynFlags getDynamicFlags :: IO DynFlags
getDynamicFlags = runGhc (Just libdir) getSessionDynFlags getDynamicFlags = do
mlibdir <- getSystemLibDir
runGhc mlibdir getSessionDynFlags

View File

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