on master help sign in
Proper conditional tracking
commit69f3a1b8e79da8c2dd737f80960ee2a2ecf61fb5 authorMichael Snoyman <michael@snoyman.com> dateSun 7 Dec 2014, 12:36 (12 years ago) parentc05cacf
3 files changed+77−18
Stackage2/BuildPlan.hs+20−6 Stackage2/PackageConstraints.hs+6 Stackage2/PackageDescription.hs+51−12
Stackage2/BuildPlan.hs+20−6
@@ -28,6 +28,8 @@ import qualified Data.Map as Map
2828import qualified Data.Set as Set
2929import Data.Aeson
3030import Stackage2.PackageDescription
31+import qualified Distribution.System
32+import qualified Distribution.Compiler
3133
3234data BuildPlan desc = BuildPlan
3335 { bpCore :: Map PackageName Version
@@ -251,10 +253,25 @@ isAllowed core = \name version ->
251253 Nothing -> True -- no constraints
252254 Just (range, _) -> withinRange version range
253255
254−mkPackageBuild :: Monad m
256+mkPackageBuild :: MonadThrow m
255257 => GenericPackageDescription
256258 -> m (PackageBuild FlatComponent)
257−mkPackageBuild gpd =
259+mkPackageBuild gpd = do
260+ let overrides = packageFlags name ++ defaultGlobalFlags
261+ getFlag MkFlag {..} =
262+ (flagName, fromMaybe flagDefault $ lookup flagName overrides)
263+ desc <- getFlattenedComponent
264+ CheckCond
265+ { ccPackageName = name
266+ , ccOS = Distribution.System.Linux
267+ , ccArch = Distribution.System.X86_64
268+ , ccCompilerFlavor = Distribution.Compiler.GHC
269+ , ccCompilerVersion = ghcVerCabal
270+ , ccFlags = mapFromList $ map getFlag $ genPackageFlags gpd
271+ }
272+ (tryBuildTest name)
273+ (tryBuildBenchmark name)
274+ gpd
258275 return PackageBuild
259276 { pbVersion = version
260277 , pbMaintainer = fmap snd $ lookup name $ pcPackages defaultPackageConstraints
@@ -275,10 +292,7 @@ mkPackageBuild gpd =
275292 -> ExpectFailure
276293 | otherwise -> ExpectSuccess
277294 , pbTryBuildBenchmark = tryBuildBenchmark name
278− , pbDesc = getFlattenedComponent
279− (tryBuildTest name)
280− (tryBuildBenchmark name)
281− gpd
295+ , pbDesc = desc
282296 }
283297 where
284298 PackageIdentifier name version = package $ packageDescription gpd
Stackage2/PackageConstraints.hs+6
@@ -9,6 +9,7 @@ module Stackage2.PackageConstraints
99 , packageFlags
1010 , tryBuildTest
1111 , tryBuildBenchmark
12+ , ghcVerCabal
1213 ) where
1314
1415import Stackage2.Prelude
@@ -36,9 +37,14 @@ defaultPackageConstraints = PackageConstraints
3637 , pcExpectedFailures = Old.defaultExpectedFailures ghcVer False
3738 }
3839
40+-- FIXME below here shouldn't be so hard-coded
41+
3942ghcVer :: Old.GhcMajorVersion
4043ghcVer = Old.GhcMajorVersion 7 8
4144
45+ghcVerCabal :: Version
46+ghcVerCabal = Version [7, 8, 3] []
47+
4248oldSettings :: Old.SelectSettings
4349oldSettings = Old.defaultSelectSettings ghcVer False
4450
Stackage2/PackageDescription.hs+51−12
@@ -1,4 +1,5 @@
11{-# LANGUAGE NoImplicitPrelude #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
23{-# LANGUAGE RecordWildCards #-}
34{-# LANGUAGE OverloadedStrings #-}
45{-# LANGUAGE DeriveFunctor #-}
@@ -11,6 +12,7 @@ module Stackage2.PackageDescription
1112 ( FlatComponent (..)
1213 , getFlattenedComponent
1314 , SimpleExtra (..)
15+ , CheckCond (..)
1416 ) where
1517
1618import Distribution.Package (Dependency (..))
@@ -25,6 +27,8 @@ import Control.Monad.State.Strict (execState, get, put)
2527import qualified Data.Map as Map
2628import qualified Data.Set as Set
2729import Data.Aeson
30+import Distribution.System (OS, Arch)
31+import Distribution.Compiler (CompilerFlavor)
2832
2933data SimpleTree = SimpleTree
3034 { stDeps :: Map PackageName VersionRange
@@ -51,12 +55,16 @@ instance Monoid SimpleExtra where
5155 (b ++ y)
5256
5357getFlattenedComponent
54− :: Bool -- ^ include test suites?
58+ :: MonadThrow m
59+ => CheckCond
60+ -> Bool -- ^ include test suites?
5561 -> Bool -- ^ include benchmarks?
5662 -> GenericPackageDescription
57− -> FlatComponent
58−getFlattenedComponent includeTests includeBench gpd =
59− foldMap flattenComponent $ getSimpleTrees includeTests includeBench gpd
63+ -> m FlatComponent
64+getFlattenedComponent checkCond' includeTests includeBench gpd =
65+ liftM fold
66+ $ mapM (flattenComponent checkCond')
67+ $ getSimpleTrees includeTests includeBench gpd
6068
6169getSimpleTrees :: Bool -- ^ include test suites?
6270 -> Bool -- ^ include benchmarks?
@@ -103,14 +111,45 @@ instance Monoid FlatComponent where
103111 (unionWith intersectVersionRanges a x)
104112 (b ++ y)
105113
106−flattenComponent :: SimpleTree -> FlatComponent
107−flattenComponent (SimpleTree deps conds extra) =
108− mconcat $ here : map goCond conds
114+flattenComponent :: MonadThrow m => CheckCond -> SimpleTree -> m FlatComponent
115+flattenComponent checkCond' (SimpleTree deps conds extra) = do
116+ conds' <- mapM goCond conds
117+ return $ mconcat $ here : conds'
109118 where
110119 here = FlatComponent { fcDeps = deps, fcExtra = extra }
111− goCond (cond, tree1, mtree2)
112− | checkCond cond = flattenComponent tree1
113− | otherwise = maybe mempty flattenComponent mtree2
120+ goCond (cond, tree1, mtree2) = do
121+ b <- checkCond checkCond' cond
122+ if b
123+ then flattenComponent checkCond' tree1
124+ else maybe (return mempty) (flattenComponent checkCond') mtree2
114125
115−checkCond :: Condition ConfVar -> Bool
116−checkCond _ = False -- FIXME
126+checkCond :: MonadThrow m => CheckCond -> Condition ConfVar -> m Bool
127+checkCond CheckCond {..} cond0 =
128+ go cond0
129+ where
130+ go (Var (OS os)) = return $ os == ccOS
131+ go (Var (Arch arch)) = return $ arch == ccArch
132+ go (Var (Flag flag)) =
133+ case lookup flag ccFlags of
134+ Nothing -> throwM $ FlagNotDefined ccPackageName flag cond0
135+ Just b -> return b
136+ go (Var (Impl flavor range)) = return
137+ $ flavor == ccCompilerFlavor
138+ && ccCompilerVersion `withinRange` range
139+ go (Lit b) = return b
140+ go (CNot c) = not `liftM` go c
141+ go (CAnd x y) = (&&) `liftM` go x `ap` go y
142+ go (COr x y) = (||) `liftM` go x `ap` go y
143+
144+data CheckCondException = FlagNotDefined PackageName FlagName (Condition ConfVar)
145+ deriving (Show, Typeable)
146+instance Exception CheckCondException
147+
148+data CheckCond = CheckCond
149+ { ccPackageName :: PackageName -- for debugging only
150+ , ccOS :: OS
151+ , ccArch :: Arch
152+ , ccFlags :: Map FlagName Bool
153+ , ccCompilerFlavor :: CompilerFlavor
154+ , ccCompilerVersion :: Version
155+ }