module Distribution.Simple.Compiler (
module Distribution.Compiler,
Compiler(..),
showCompilerId, compilerFlavor, compilerVersion,
PackageDB(..),
PackageDBStack,
registrationPackageDB,
OptimisationLevel(..),
flagToOptimisationLevel,
Flag,
languageToFlags,
unsupportedLanguages,
extensionsToFlags,
unsupportedExtensions
) where
import Distribution.Compiler
import Distribution.Version (Version(..))
import Distribution.Text (display)
import Language.Haskell.Extension (Language(Haskell98), Extension)
import Data.List (nub)
import Data.Maybe (catMaybes, isNothing)
data compilerExtensions :: [(Extension, Flag)]Compiler = Compiler {
compilerId :: CompilerId,
compilerLanguages :: [(Language, Flag)],
compilerExtensions :: [(Extension, Flag)]
}
deriving (D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead)
showCompilerId :: Compiler -> String
showCompilerId = display :: Text a => a -> Stringdisplay (.) :: (b -> c) -> (a -> b) -> a -> c. compilerId :: Compiler -> CompilerIdcompilerId
compilerFlavor :: Compiler -> CompilerFlavor
compilerFlavor = (\(CompilerId f _) -> f :: CompilerFlavorf) (.) :: (b -> c) -> (a -> b) -> a -> c. compilerId :: Compiler -> CompilerIdcompilerId
compilerVersion :: Compiler -> Version
compilerVersion = (\(CompilerId _ v) -> v :: Versionv) (.) :: (b -> c) -> (a -> b) -> a -> c. compilerId :: Compiler -> CompilerIdcompilerId
data PackageDB = GlobalPackageDB
| UserPackageDB
| SpecificPackageDB FilePath
deriving (($c==) :: OptimisationLevel -> OptimisationLevel -> BoolEq, D:Ord ::
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> T:Ord aOrd, D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead)
type PackageDBStack = [PackageDB]
registrationPackageDB :: PackageDBStack -> PackageDB
registrationPackageDB [] = error :: [Char] -> aerror "internal error: empty package db set"
registrationPackageDB dbs = last :: [a] -> alast dbs :: PackageDBStackdbs
data OptimisationLevel = NoOptimisation
| NormalOptimisation
| MaximumOptimisation
deriving (($c==) :: OptimisationLevel -> OptimisationLevel -> BoolEq, D:Show ::
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> T:Show aShow, D:Read ::
(Int -> ReadS a)
-> ReadS [a]
-> ReadPrec a
-> ReadPrec [a]
-> T:Read aRead, D:Enum ::
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> T:Enum aEnum, D:Bounded :: a -> a -> T:Bounded aBounded)
flagToOptimisationLevel :: Maybe String -> OptimisationLevel
flagToOptimisationLevel Nothing = NormalOptimisation :: OptimisationLevelNormalOptimisation
flagToOptimisationLevel (Just s) = case reads :: Read a => ReadS areads s :: Strings of
[(i, "")]
| i :: Inti (>=) :: Ord a => a -> a -> Bool>= fromEnum :: Enum a => a -> IntfromEnum (minBound :: Bounded a => aminBound :: OptimisationLevel)
(&&) :: Bool -> Bool -> Bool&& i :: Inti (<=) :: Ord a => a -> a -> Bool<= fromEnum :: Enum a => a -> IntfromEnum (maxBound :: Bounded a => amaxBound :: OptimisationLevel)
-> toEnum :: Enum a => Int -> atoEnum i :: Inti
| otherwise :: Boolotherwise -> error :: [Char] -> aerror ($) :: (a -> b) -> a -> b$ "Bad optimisation level: " (++) :: [a] -> [a] -> [a]++ show :: Show a => a -> Stringshow i :: Inti
(++) :: [a] -> [a] -> [a]++ ". Valid values are 0..2"
_ -> error :: [Char] -> aerror ($) :: (a -> b) -> a -> b$ "Can't parse optimisation level " (++) :: [a] -> [a] -> [a]++ s :: Strings
unsupportedLanguages :: Compiler -> [Language] -> [Language]
unsupportedLanguages comp langs =
[ lang :: Languagelang | lang <- langs :: [Language]langs
, isNothing :: Maybe a -> BoolisNothing (languageToFlag :: Compiler -> Language -> Maybe FlaglanguageToFlag comp :: Compilercomp lang :: Languagelang) ]
languageToFlags :: Compiler -> Maybe Language -> [Flag]
languageToFlags comp = filter :: (a -> Bool) -> [a] -> [a]filter (not :: Bool -> Boolnot (.) :: (b -> c) -> (a -> b) -> a -> c. null :: [a] -> Boolnull)
(.) :: (b -> c) -> (a -> b) -> a -> c. catMaybes :: [Maybe a] -> [a]catMaybes (.) :: (b -> c) -> (a -> b) -> a -> c. map :: (a -> b) -> [a] -> [b]map (languageToFlag :: Compiler -> Language -> Maybe FlaglanguageToFlag comp :: Compilercomp)
(.) :: (b -> c) -> (a -> b) -> a -> c. maybe :: b -> (a -> b) -> Maybe a -> bmaybe [Haskell98 :: LanguageHaskell98] (\x->[x :: Languagex])
languageToFlag :: Compiler -> Language -> Maybe Flag
languageToFlag comp ext = lookup :: Eq a => a -> [(a, b)] -> Maybe blookup ext :: Languageext (compilerLanguages :: Compiler -> [(Language, Flag)]compilerLanguages comp :: Compilercomp)
unsupportedExtensions :: Compiler -> [Extension] -> [Extension]
unsupportedExtensions comp exts =
[ ext :: Languageext | ext <- exts :: [Extension]exts
, isNothing :: Maybe a -> BoolisNothing (extensionToFlag :: Compiler -> Extension -> Maybe FlagextensionToFlag comp :: Compilercomp ext :: Languageext) ]
type Flag = String
extensionsToFlags :: Compiler -> [Extension] -> [Flag]
extensionsToFlags comp = nub :: Eq a => [a] -> [a]nub (.) :: (b -> c) -> (a -> b) -> a -> c. filter :: (a -> Bool) -> [a] -> [a]filter (not :: Bool -> Boolnot (.) :: (b -> c) -> (a -> b) -> a -> c. null :: [a] -> Boolnull)
(.) :: (b -> c) -> (a -> b) -> a -> c. catMaybes :: [Maybe a] -> [a]catMaybes (.) :: (b -> c) -> (a -> b) -> a -> c. map :: (a -> b) -> [a] -> [b]map (extensionToFlag :: Compiler -> Extension -> Maybe FlagextensionToFlag comp :: Compilercomp)
extensionToFlag :: Compiler -> Extension -> Maybe Flag
extensionToFlag comp ext = lookup :: Eq a => a -> [(a, b)] -> Maybe blookup ext :: Languageext (compilerExtensions :: Compiler -> [(Extension, Flag)]compilerExtensions comp :: Compilercomp)