@@ -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