@@ -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))
22-- | Load the raw package database.
27-- | Load the raw package database.
@@ -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
72 _ -> mempty
77 _ -> mempty
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)
84+ checkCond gpd (cond, tree, melse)
85+ | checkCond' cond = Just tree
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
98+ flags = map flagName $ filter flagDefault $ genPackageFlags gpd