Switch branches/tags
ghc-7.6.3-release ghc-7.6.2-release ghc-7.6.1-release dist/cabal-install-v1.20.0.6 checkpoint cabal-install_merged cabal-install-v2.0.0.0 cabal-install-v1.24.0.2 cabal-install-v1.24.0.1 cabal-install-v1.24.0.0 cabal-install-v1.22.9.0 cabal-install-v1.22.8.0 cabal-install-v1.22.7.0 cabal-install-v1.22.6.0 cabal-install-v1.22.5.0 cabal-install-v1.22.4.0 cabal-install-v1.22.3.0 cabal-install-v1.22.2.0 cabal-install-v1.22.0.1 cabal-install-v1.22.0.0 cabal-install-v1.22.0.0-rc cabal-install-v1.20.2.0 cabal-install-v1.20.1.0 cabal-install-v1.20.0.5 cabal-install-v1.20.0.4 cabal-install-v1.20.0.4-rc cabal-install-v1.20.0.3 cabal-install-v1.20.0.2 cabal-install-v1.20.0.1 cabal-install-v1.20.0.0 cabal-install-v1.20.0.0-rc2 cabal-install-v1.20.0-rc cabal-install-v1.18.2.0 cabal-install-v1.18.1.0 cabal-install-v1.18.0.8 cabal-install-v1.18.0.7 cabal-install-v1.18.0.6 cabal-install-v1.18.0.6-rc cabal-install-v1.18.0.5 cabal-install-v1.18.0.4 cabal-install-v1.18.0.3 cabal-install-v1.18.0.2 cabal-install-v1.18.0.1 cabal-install-v1.18.0 cabal-install-v1.16.1.0 cabal-install-v1.16.0.2 cabal-install-v1.16.0.1 cabal-install-v.1.16.0 cabal-install-v1.16.0 cabal-install-v0.14.1 cabal-install-0.14.0 GHC_6_12_3_release GHC_6_12_2_release GHC_6_8_3_release Cabal_1_8_0_6_release Cabal_1_8_0_2_release Cabal-v2.0.0.2 Cabal-v2.0.0.1 Cabal-v2.0.0.0 Cabal-v1.24.2.0 Cabal-v1.24.1.0 Cabal-v1.24.0.0 Cabal-v1.22.8.0 Cabal-v1.22.7.0 Cabal-v1.22.6.0 Cabal-v1.22.5.0 Cabal-v1.22.4.0 Cabal-v1.22.3.0 Cabal-v1.22.2.0 Cabal-v1.22.1.1 Cabal-v1.22.1.0 Cabal-v1.22.0.0 Cabal-v1.22.0.0-rc Cabal-v1.20.0.4 Cabal-v1.20.0.3 Cabal-v1.20.0.3-rc Cabal-v1.20.0.2 Cabal-v1.20.0.1 Cabal-v1.20.0.0 Cabal-v1.20.0.0-rc Cabal-v1.20.0-rc Cabal-v1.18.1.6 Cabal-v1.18.1.5 Cabal-v1.18.1.5-rc Cabal-v1.18.1.4 Cabal-v1.18.1.3 Cabal-v1.18.1.2 Cabal-v1.18.1.1 Cabal-v1.18.1 Cabal-v1.18.0 Cabal-v1.16.0.3 Cabal-v1.16.0.2 Cabal-v1.16.0.1 Cabal-v1.16.0 Cabal- Cabal- Cabal- Cabal- Cabal-1.18.1-release Cabal-1.18.0-release
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
216 lines (177 sloc) 7.28 KB
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
-- |
-- Module : Distribution.Compiler
-- Copyright : Isaac Jones 2003-2004
-- License : BSD3
-- Maintainer :
-- Portability : portable
-- This has an enumeration of the various compilers that Cabal knows about. It
-- also specifies the default compiler. Sadly you'll often see code that does
-- case analysis on this compiler flavour enumeration like:
-- > case compilerFlavor comp of
-- > GHC -> GHC.getInstalledPackages verbosity packageDb progdb
-- > JHC -> JHC.getInstalledPackages verbosity packageDb progdb
-- Obviously it would be better to use the proper 'Compiler' abstraction
-- because that would keep all the compiler-specific code together.
-- Unfortunately we cannot make this change yet without breaking the
-- 'UserHooks' api, which would break all custom @Setup.hs@ files, so for the
-- moment we just have to live with this deficiency. If you're interested, see
-- ticket #57.
module Distribution.Compiler (
-- * Compiler flavor
-- * Compiler id
-- * Compiler info
AbiTag(..), abiTagString
) where
import Prelude ()
import Distribution.Compat.Prelude
import Language.Haskell.Extension
import Distribution.Version (Version, mkVersion', nullVersion)
import qualified System.Info (compilerName, compilerVersion)
import Distribution.Parsec.Class (Parsec (..))
import Distribution.Pretty (Pretty (..))
import Distribution.Text (Text(..), display)
import qualified Distribution.Compat.ReadP as Parse
import qualified Distribution.Compat.Parsec as P
import qualified Text.PrettyPrint as Disp
data CompilerFlavor =
GHC | GHCJS | NHC | YHC | Hugs | HBC | Helium | JHC | LHC | UHC
| HaskellSuite String -- string is the id of the actual compiler
| OtherCompiler String
deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
instance Binary CompilerFlavor
knownCompilerFlavors :: [CompilerFlavor]
knownCompilerFlavors = [GHC, GHCJS, NHC, YHC, Hugs, HBC, Helium, JHC, LHC, UHC]
instance Pretty CompilerFlavor where
pretty (OtherCompiler name) = Disp.text name
pretty (HaskellSuite name) = Disp.text name
pretty NHC = Disp.text "nhc98"
pretty other = Disp.text (lowercase (show other))
instance Parsec CompilerFlavor where
parsec = classifyCompilerFlavor <$> component
component = do
cs <- P.munch1 isAlphaNum
if all isDigit cs then fail "all digits compiler name" else return cs
instance Text CompilerFlavor where
parse = do
comp <- Parse.munch1 isAlphaNum
when (all isDigit comp) Parse.pfail
return (classifyCompilerFlavor comp)
classifyCompilerFlavor :: String -> CompilerFlavor
classifyCompilerFlavor s =
fromMaybe (OtherCompiler s) $ lookup (lowercase s) compilerMap
compilerMap = [ (lowercase (display compiler), compiler)
| compiler <- knownCompilerFlavors ]
--TODO: In some future release, remove 'parseCompilerFlavorCompat' and use
-- ordinary 'parse'. Also add ("nhc", NHC) to the above 'compilerMap'.
-- | Like 'classifyCompilerFlavor' but compatible with the old ReadS parser.
-- It is compatible in the sense that it accepts only the same strings,
-- eg "GHC" but not "ghc". However other strings get mapped to 'OtherCompiler'.
-- The point of this is that we do not allow extra valid values that would
-- upset older Cabal versions that had a stricter parser however we cope with
-- new values more gracefully so that we'll be able to introduce new value in
-- future without breaking things so much.
parseCompilerFlavorCompat :: Parse.ReadP r CompilerFlavor
parseCompilerFlavorCompat = do
comp <- Parse.munch1 isAlphaNum
when (all isDigit comp) Parse.pfail
case lookup comp compilerMap of
Just compiler -> return compiler
Nothing -> return (OtherCompiler comp)
compilerMap = [ (show compiler, compiler)
| compiler <- knownCompilerFlavors
, compiler /= YHC ]
buildCompilerFlavor :: CompilerFlavor
buildCompilerFlavor = classifyCompilerFlavor System.Info.compilerName
buildCompilerVersion :: Version
buildCompilerVersion = mkVersion' System.Info.compilerVersion
buildCompilerId :: CompilerId
buildCompilerId = CompilerId buildCompilerFlavor buildCompilerVersion
-- | The default compiler flavour to pick when compiling stuff. This defaults
-- to the compiler used to build the Cabal lib.
-- However if it's not a recognised compiler then it's 'Nothing' and the user
-- will have to specify which compiler they want.
defaultCompilerFlavor :: Maybe CompilerFlavor
defaultCompilerFlavor = case buildCompilerFlavor of
OtherCompiler _ -> Nothing
_ -> Just buildCompilerFlavor
-- ------------------------------------------------------------
-- * Compiler Id
-- ------------------------------------------------------------
data CompilerId = CompilerId CompilerFlavor Version
deriving (Eq, Generic, Ord, Read, Show)
instance Binary CompilerId
instance Text CompilerId where
disp (CompilerId f v)
| v == nullVersion = disp f
| otherwise = disp f <<>> Disp.char '-' <<>> disp v
parse = do
flavour <- parse
version <- (Parse.char '-' >> parse) Parse.<++ return nullVersion
return (CompilerId flavour version)
lowercase :: String -> String
lowercase = map toLower
-- ------------------------------------------------------------
-- * Compiler Info
-- ------------------------------------------------------------
-- | Compiler information used for resolving configurations. Some
-- fields can be set to Nothing to indicate that the information is
-- unknown.
data CompilerInfo = CompilerInfo {
compilerInfoId :: CompilerId,
-- ^ Compiler flavour and version.
compilerInfoAbiTag :: AbiTag,
-- ^ Tag for distinguishing incompatible ABI's on the same
-- architecture/os.
compilerInfoCompat :: Maybe [CompilerId],
-- ^ Other implementations that this compiler claims to be
-- compatible with, if known.
compilerInfoLanguages :: Maybe [Language],
-- ^ Supported language standards, if known.
compilerInfoExtensions :: Maybe [Extension]
-- ^ Supported extensions, if known.
deriving (Generic, Show, Read)
instance Binary CompilerInfo
data AbiTag
= NoAbiTag
| AbiTag String
deriving (Eq, Generic, Show, Read)
instance Binary AbiTag
instance Text AbiTag where
disp NoAbiTag = Disp.empty
disp (AbiTag tag) = Disp.text tag
parse = do
tag <- Parse.munch (\c -> isAlphaNum c || c == '_')
if null tag then return NoAbiTag else return (AbiTag tag)
abiTagString :: AbiTag -> String
abiTagString NoAbiTag = ""
abiTagString (AbiTag tag) = tag
-- | Make a CompilerInfo of which only the known information is its CompilerId,
-- its AbiTag and that it does not claim to be compatible with other
-- compiler id's.
unknownCompilerInfo :: CompilerId -> AbiTag -> CompilerInfo
unknownCompilerInfo compilerId abiTag =
CompilerInfo compilerId abiTag (Just []) Nothing Nothing