on master help sign in
Better condition checking
d8571eaMichael Snoyman
Stackage/Config.hs+6
@@ -8,6 +8,12 @@ import Distribution.System (OS (..), buildOS)
8import Distribution.Text (simpleParse)
8import Distribution.Text (simpleParse)
9import Stackage.Types
9import Stackage.Types
10
10
11+targetCompilerVersion :: Version
12+targetCompilerVersion =
13+ case simpleParse "7.4.2" of
14+ Nothing -> error "Invalid targetCompilerVersion"
15+ Just v -> v
16+
11-- | Packages which are shipped with GHC but are not included in the
17-- | Packages which are shipped with GHC but are not included in the
12-- Haskell Platform list of core packages.
18-- Haskell Platform list of core packages.
13extraCore :: Set PackageName
19extraCore :: Set PackageName
Stackage/LoadDatabase.hs+30−6
@@ -12,12 +12,17 @@ import Distribution.Package (Dependency (Dependency))
12import Distribution.PackageDescription (condExecutables,
12import Distribution.PackageDescription (condExecutables,
13 condLibrary,
13 condLibrary,
14 condTestSuites,
14 condTestSuites,
15− condTreeConstraints)
15+ condBenchmarks,
16+ condTreeConstraints, condTreeComponents, ConfVar (..), Condition(..), flagName, flagDefault, genPackageFlags)
16import Distribution.PackageDescription.Parse (ParseResult (ParseOk),
17import Distribution.PackageDescription.Parse (ParseResult (ParseOk),
17 parsePackageDescription)
18 parsePackageDescription)
18import Distribution.Version (withinRange)
19import Distribution.Version (withinRange)
19import Stackage.Types
20import Stackage.Types
20import Stackage.Util
21import Stackage.Util
22+import Stackage.Config
23+import Data.Maybe (mapMaybe)
24+import Distribution.System (buildOS, buildArch)
25+import Distribution.Compiler (CompilerFlavor (GHC))
21
26
22-- | Load the raw package database.
27-- | Load the raw package database.
23--
28--
@@ -64,11 +69,30 @@ loadPackageDB core deps = do
64 parseDeps lbs =
69 parseDeps lbs =
65 case parsePackageDescription $ L8.unpack lbs of
70 case parsePackageDescription $ L8.unpack lbs of
66 ParseOk _ gpd -> mconcat
71 ParseOk _ gpd -> mconcat
67− [ maybe mempty go $ condLibrary gpd
72+ [ maybe mempty (go gpd) $ condLibrary gpd
68− , mconcat $ map (go . snd) $ condExecutables gpd
73+ , mconcat $ map (go gpd . snd) $ condExecutables gpd
69− , mconcat $ map (go . snd) $ condTestSuites gpd
74+ , mconcat $ map (go gpd . snd) $ condTestSuites gpd
70− -- , mconcat $ map (go . snd) $ condBenchmarks gpd
75+ , mconcat $ map (go gpd . snd) $ condBenchmarks gpd
71 ]
76 ]
72 _ -> mempty
77 _ -> mempty
73 where
78 where
79+ go gpd tree
80+ = Set.unions
74− go = Set.fromList . map (\(Dependency p _) -> p) . condTreeConstraints
81+ $ Set.fromList (map (\(Dependency p _) -> p) $ condTreeConstraints tree)
82+ : map (go gpd) (mapMaybe (checkCond gpd) $ condTreeComponents tree)
83+
84+ checkCond gpd (cond, tree, melse)
85+ | checkCond' cond = Just tree
86+ | otherwise = melse
87+ where
88+ checkCond' (Var (OS os)) = os == buildOS
89+ checkCond' (Var (Arch arch)) = arch == buildArch
90+ checkCond' (Var (Flag flag)) = flag `elem` flags
91+ checkCond' (Var (Impl compiler range)) =
92+ compiler == GHC && withinRange targetCompilerVersion range
93+ checkCond' (Lit b) = b
94+ checkCond' (CNot c) = not $ checkCond' c
95+ checkCond' (COr c1 c2) = checkCond' c1 || checkCond' c2
96+ checkCond' (CAnd c1 c2) = checkCond' c1 && checkCond' c2
97+
98+ flags = map flagName $ filter flagDefault $ genPackageFlags gpd