Commit 220091eb authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Use CompilerFlavor rather than String in configurations expressions

Better type safety and more robust parsing.
parent c8e8f052
......@@ -84,7 +84,7 @@ import Distribution.Package (PackageIdentifier(..), Package(..))
import Distribution.Version (Version(Version), VersionRange(AnyVersion))
import Distribution.License (License(AllRightsReserved))
import Distribution.Version (Dependency, showVersionRange)
import Distribution.Compiler (CompilerFlavor)
import Distribution.Compiler (CompilerFlavor, showCompilerFlavor)
import Distribution.System (OS, showOS, Arch, showArch)
import Distribution.Simple.Utils (currentDir)
import Language.Haskell.Extension (Extension)
......@@ -457,14 +457,15 @@ data ConfFlag = ConfFlag String
data ConfVar = OS OS
| Arch Arch
| Flag ConfFlag
| Impl String VersionRange
| Impl CompilerFlavor VersionRange
deriving Eq
instance Show ConfVar where
show (OS os) = "os(" ++ showOS os ++ ")"
show (Arch arch) = "arch(" ++ showArch arch ++ ")"
show (Flag (ConfFlag f)) = "flag(" ++ f ++ ")"
show (Impl c v) = "impl(" ++ c ++ " " ++ showVersionRange v ++ ")"
show (Impl c v) = "impl(" ++ showCompilerFlavor c
++ " " ++ showVersionRange v ++ ")"
-- | A boolean expression parameterized over the variable type used.
data Condition c = Var c
......
......@@ -62,9 +62,10 @@ import qualified Distribution.Simple.PackageIndex as PackageIndex
import Distribution.Version
( Version(..), Dependency(..), VersionRange(..)
, withinRange, parseVersionRange )
import Distribution.Compiler (CompilerFlavor, readCompilerFlavor)
import Distribution.System
( OS, readOS, Arch, readArch )
import Distribution.Simple.Utils (currentDir, lowercase)
import Distribution.Simple.Utils (currentDir)
import Distribution.Compat.ReadP as ReadP hiding ( char )
import qualified Distribution.Compat.ReadP as ReadP ( char )
......@@ -117,15 +118,15 @@ simplifyCondition cond i = fv . walk $ cond
-- | Simplify a configuration condition using the os and arch names. Returns
-- the names of all the flags occurring in the condition.
simplifyWithSysParams :: OS -> Arch -> (String, Version) -> Condition ConfVar
simplifyWithSysParams :: OS -> Arch -> (CompilerFlavor, Version) -> Condition ConfVar
-> (Condition ConfFlag, [String])
simplifyWithSysParams os arch (impl, implVer) cond = (cond', flags)
simplifyWithSysParams os arch (comp, compVer) cond = (cond', flags)
where
(cond', fvs) = simplifyCondition cond interp
interp (OS os') = Right $ os' == os
interp (Arch arch') = Right $ arch' == arch
interp (Impl i vr) = Right $ lowercase impl == lowercase i
&& implVer `withinRange` vr
interp (Impl comp' vr) = Right $ comp' == comp
&& compVer `withinRange` vr
interp (Flag f) = Left f
flags = [ fname | ConfFlag fname <- fvs ]
......@@ -171,7 +172,7 @@ parseCondition = condOr
sp = skipSpaces
implIdent = do i <- ident
vr <- sp >> option AnyVersion parseVersionRange
return $ Impl i vr
return $ Impl (readCompilerFlavor i) vr
------------------------------------------------------------------------------
......@@ -231,7 +232,7 @@ resolveWithFlags :: Monoid a =>
-- ^ Domain for each flag name, will be tested in order.
-> OS -- ^ OS as returned by Distribution.System.buildOS
-> Arch -- ^ Arch as returned by Distribution.System.buildArch
-> (String, Version) -- ^ Compiler name + version
-> (CompilerFlavor, Version) -- ^ Compiler flavour + version
-> [CondTree ConfVar [d] a]
-> ([d] -> DepTestRslt [d]) -- ^ Dependency test function.
-> (Either [d] -- missing dependencies
......@@ -346,7 +347,7 @@ finalizePackageDescription
-- this is unknown.
-> OS -- ^ OS-name
-> Arch -- ^ Arch-name
-> (String, Version) -- ^ Compiler + Version
-> (CompilerFlavor, Version) -- ^ Compiler + Version
-> GenericPackageDescription
-> Either [Dependency]
(PackageDescription, [(String,Bool)])
......
......@@ -116,8 +116,6 @@ import Control.Monad
( when, unless, foldM )
import Control.Exception as Exception
( catch )
import Data.Char
( toLower )
import Data.List
( nub, partition, isPrefixOf, maximumBy )
import Data.Maybe
......@@ -295,7 +293,7 @@ configure (pkg_descr0, pbi) cfg
maybePackageIndex
Distribution.System.buildOS
Distribution.System.buildArch
(map toLower (show flavor),version)
(flavor, version)
ppd
of Right r -> return r
Left missing ->
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment