simplify the usage of IOChoice.
This commit is contained in:
parent
56b1e14219
commit
b632cb6df0
@ -33,7 +33,7 @@ fromCabalFile :: [GHCOption]
|
||||
fromCabalFile ghcOptions cradle = do
|
||||
cabal <- cabalParseFile cfile
|
||||
case cabalBuildInfo cabal of
|
||||
Nothing -> throwIO BrokenCabalFile
|
||||
Nothing -> throwIO $ userError "cabal file is broken"
|
||||
Just binfo -> return $ cookInfo ghcOptions cradle cabal binfo
|
||||
where
|
||||
Just cfile = cradleCabalFile cradle
|
||||
|
11
Debug.hs
11
Debug.hs
@ -1,10 +1,8 @@
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
|
||||
module Debug (debugInfo, debug) where
|
||||
|
||||
import CabalApi
|
||||
import Control.Applicative
|
||||
import Control.Exception.IOChoice.TH
|
||||
import Control.Exception.IOChoice
|
||||
import Control.Monad
|
||||
import Data.List (intercalate)
|
||||
import Data.Maybe
|
||||
@ -15,11 +13,6 @@ import Types
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
(||>>) :: IO a -> IO a -> IO a
|
||||
(||>>) = $(newIOChoice [''BrokenCabalFile])
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
debugInfo :: Options -> Cradle -> String -> String -> IO String
|
||||
debugInfo opt cradle ver fileName = unlines <$> debug opt cradle ver fileName
|
||||
|
||||
@ -27,7 +20,7 @@ debug :: Options -> Cradle -> String -> String -> IO [String]
|
||||
debug opt cradle ver fileName = do
|
||||
(gopts, incDir, pkgs) <-
|
||||
if cabal then
|
||||
fromCabalFile (ghcOpts opt) cradle ||>> return (ghcOpts opt, [], [])
|
||||
fromCabalFile (ghcOpts opt) cradle ||> return (ghcOpts opt, [], [])
|
||||
else
|
||||
return (ghcOpts opt, [], [])
|
||||
[fast] <- withGHC fileName $ do
|
||||
|
@ -22,6 +22,7 @@ import DynFlags
|
||||
import ErrMsg
|
||||
import Exception
|
||||
import GHC
|
||||
import GHCChoice
|
||||
import GHC.Paths (libdir)
|
||||
import System.Exit
|
||||
import System.IO
|
||||
@ -52,7 +53,7 @@ data Build = CabalPkg | SingleFile deriving Eq
|
||||
|
||||
initializeFlagsWithCradle :: Options -> Cradle -> [GHCOption] -> Bool -> Ghc LogReader
|
||||
initializeFlagsWithCradle opt cradle ghcOptions logging
|
||||
| cabal = withCabal `gcatch` fallback
|
||||
| cabal = withCabal ||> withoutCabal
|
||||
| otherwise = withoutCabal
|
||||
where
|
||||
cabal = isJust $ cradleCabalFile cradle
|
||||
@ -61,8 +62,6 @@ initializeFlagsWithCradle opt cradle ghcOptions logging
|
||||
initSession CabalPkg opt gopts idirs (Just depPkgs) logging
|
||||
withoutCabal =
|
||||
initSession SingleFile opt ghcOptions importDirs Nothing logging
|
||||
fallback :: BrokenCabalFile -> Ghc LogReader
|
||||
fallback _ = withoutCabal
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
|
10
Types.hs
10
Types.hs
@ -1,11 +1,7 @@
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
|
||||
module Types where
|
||||
|
||||
import Control.Exception as E
|
||||
import Data.Typeable
|
||||
|
||||
data OutputStyle = LispStyle | PlainStyle
|
||||
|
||||
data Options = Options {
|
||||
@ -82,9 +78,3 @@ type IncludeDir = FilePath
|
||||
type Package = String
|
||||
|
||||
data CheckSpeed = Slow | Fast
|
||||
|
||||
----------------------------------------------------------------
|
||||
|
||||
data BrokenCabalFile = BrokenCabalFile deriving (Show, Typeable)
|
||||
|
||||
instance Exception BrokenCabalFile
|
||||
|
Loading…
Reference in New Issue
Block a user