initializeFlagsWithCradle also retuns PackageDescription.

This commit is contained in:
Kazu Yamamoto 2013-09-19 16:25:36 +09:00
parent 8e4d2cec21
commit 560f081727
2 changed files with 9 additions and 6 deletions

View File

@ -37,7 +37,7 @@ check _ _ [] = error "ghc-mod: check: No files given"
check opt cradle fileNames = checkIt `gcatch` handleErrMsg ls check opt cradle fileNames = checkIt `gcatch` handleErrMsg ls
where where
checkIt = do checkIt = do
readLog <- initializeFlagsWithCradle opt cradle options True (readLog,_) <- initializeFlagsWithCradle opt cradle options True
setTargetFiles fileNames setTargetFiles fileNames
checkSlowAndSet checkSlowAndSet
void $ load LoadAllTargets void $ load LoadAllTargets

View File

@ -17,6 +17,7 @@ import Control.Exception
import Control.Monad import Control.Monad
import CoreMonad import CoreMonad
import Data.Maybe (isJust,fromJust) import Data.Maybe (isJust,fromJust)
import Distribution.PackageDescription (PackageDescription)
import DynFlags import DynFlags
import Exception import Exception
import GHC import GHC
@ -24,8 +25,8 @@ 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
import Language.Haskell.GhcMod.Types
import qualified Language.Haskell.GhcMod.Gap as Gap import qualified Language.Haskell.GhcMod.Gap as Gap
import Language.Haskell.GhcMod.Types
import System.Exit import System.Exit
import System.IO import System.IO
@ -60,7 +61,7 @@ data Build = CabalPkg | SingleFile deriving Eq
-- | Initialize the 'DynFlags' relating to the compilation of a single -- | Initialize the 'DynFlags' relating to the compilation of a single
-- file or GHC session according to the 'Cradle' and 'Options' -- file or GHC session according to the 'Cradle' and 'Options'
-- provided. -- provided.
initializeFlagsWithCradle :: GhcMonad m => Options -> Cradle -> [GHCOption] -> Bool -> m LogReader initializeFlagsWithCradle :: GhcMonad m => Options -> Cradle -> [GHCOption] -> Bool -> m (LogReader, Maybe PackageDescription)
initializeFlagsWithCradle opt cradle ghcopts logging initializeFlagsWithCradle opt cradle ghcopts logging
| cabal = withCabal |||> withoutCabal | cabal = withCabal |||> withoutCabal
| otherwise = withoutCabal | otherwise = withoutCabal
@ -70,9 +71,11 @@ initializeFlagsWithCradle opt cradle ghcopts logging
withCabal = do withCabal = do
pkgDesc <- liftIO $ parseCabalFile $ fromJust mCradleFile pkgDesc <- liftIO $ parseCabalFile $ fromJust mCradleFile
compOpts <- liftIO $ getCompilerOptions ghcopts cradle pkgDesc compOpts <- liftIO $ getCompilerOptions ghcopts cradle pkgDesc
initSession CabalPkg opt compOpts logging logger <- initSession CabalPkg opt compOpts logging
withoutCabal = return (logger, Just pkgDesc)
initSession SingleFile opt compOpts logging withoutCabal = do
logger <- initSession SingleFile opt compOpts logging
return (logger, Nothing)
where where
compOpts = CompilerOptions ghcopts importDirs [] compOpts = CompilerOptions ghcopts importDirs []