on master help sign in
Better condition checking
commitd8571ea0f02f2b8687a78047d084542fe1e3d63b authorMichael Snoyman <michael@snoyman.com> dateFri 23 Nov 2012, 11:00 (14 years ago) parentbcabc00
2 files changed+36−6
Stackage/Config.hs+6 Stackage/LoadDatabase.hs+30−6
Stackage/Config.hs+6
@@ -8,6 +8,12 @@ import Distribution.System (OS (..), buildOS)
88import Distribution.Text (simpleParse)
99import Stackage.Types
1010
11+targetCompilerVersion :: Version
12+targetCompilerVersion =
13+ case simpleParse "7.4.2" of
14+ Nothing -> error "Invalid targetCompilerVersion"
15+ Just v -> v
16+
1117-- | Packages which are shipped with GHC but are not included in the
1218-- Haskell Platform list of core packages.
1319extraCore :: Set PackageName
Stackage/LoadDatabase.hs+30−6
@@ -12,12 +12,17 @@ import Distribution.Package (Dependency (Dependency))
1212import Distribution.PackageDescription (condExecutables,
1313 condLibrary,
1414 condTestSuites,
15− condTreeConstraints)
15+ condBenchmarks,
16+ condTreeConstraints, condTreeComponents, ConfVar (..), Condition(..), flagName, flagDefault, genPackageFlags)
1617import Distribution.PackageDescription.Parse (ParseResult (ParseOk),
1718 parsePackageDescription)
1819import Distribution.Version (withinRange)
1920import Stackage.Types
2021import Stackage.Util
22+import Stackage.Config
23+import Data.Maybe (mapMaybe)
24+import Distribution.System (buildOS, buildArch)
25+import Distribution.Compiler (CompilerFlavor (GHC))
2126
2227-- | Load the raw package database.
2328--
@@ -64,11 +69,30 @@ loadPackageDB core deps = do
6469 parseDeps lbs =
6570 case parsePackageDescription $ L8.unpack lbs of
6671 ParseOk _ gpd -> mconcat
67− [ maybe mempty go $ condLibrary gpd
68− , mconcat $ map (go . snd) $ condExecutables gpd
69− , mconcat $ map (go . snd) $ condTestSuites gpd
70− -- , mconcat $ map (go . snd) $ condBenchmarks gpd
72+ [ maybe mempty (go gpd) $ condLibrary gpd
73+ , mconcat $ map (go gpd . snd) $ condExecutables gpd
74+ , mconcat $ map (go gpd . snd) $ condTestSuites gpd
75+ , mconcat $ map (go gpd . snd) $ condBenchmarks gpd
7176 ]
7277 _ -> mempty
7378 where
74− go = Set.fromList . map (\(Dependency p _) -> p) . condTreeConstraints
79+ go gpd tree
80+ = Set.unions
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