99a58db71f2b119e72483bc0b521138a08bbc35f
[ghc.git] / hadrian / src / Settings.hs
1 module Settings (
2 getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
3 findPackageByName, isLibrary, stagePackages, programContext,
4 getIntegerPackage
5 ) where
6
7 import CommandLine
8 import Expression
9 import Flavour
10 import Packages
11 import UserSettings (userFlavours, userPackages, userDefaultFlavour)
12
13 import {-# SOURCE #-} Settings.Default
14 import Settings.Flavours.Development
15 import Settings.Flavours.Performance
16 import Settings.Flavours.Profiled
17 import Settings.Flavours.Quick
18 import Settings.Flavours.Quickest
19 import Settings.Flavours.QuickCross
20
21 getArgs :: Args
22 getArgs = expr flavour >>= args
23
24 getLibraryWays :: Ways
25 getLibraryWays = expr flavour >>= libraryWays
26
27 getRtsWays :: Ways
28 getRtsWays = expr flavour >>= rtsWays
29
30 stagePackages :: Stage -> Action [Package]
31 stagePackages stage = do
32 f <- flavour
33 packages f stage
34
35 hadrianFlavours :: [Flavour]
36 hadrianFlavours =
37 [ defaultFlavour, developmentFlavour Stage1, developmentFlavour Stage2
38 , performanceFlavour, profiledFlavour, quickFlavour, quickestFlavour
39 , quickCrossFlavour ]
40
41 flavour :: Action Flavour
42 flavour = do
43 flavourName <- fromMaybe userDefaultFlavour <$> cmdFlavour
44 let unknownFlavour = error $ "Unknown build flavour: " ++ flavourName
45 flavours = hadrianFlavours ++ userFlavours
46 return $ fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
47
48 getIntegerPackage :: Expr Package
49 getIntegerPackage = expr (integerLibrary =<< flavour)
50
51 programContext :: Stage -> Package -> Action Context
52 programContext stage pkg = do
53 profiled <- ghcProfiled <$> flavour
54 return $ if pkg == ghc && profiled && stage > Stage0
55 then Context stage pkg profiling
56 else vanillaContext stage pkg
57
58 -- TODO: switch to Set Package as the order of packages should not matter?
59 -- Otherwise we have to keep remembering to sort packages from time to time.
60 knownPackages :: [Package]
61 knownPackages = sort $ ghcPackages ++ userPackages
62
63 -- TODO: Speed up? Switch to Set?
64 -- Note: this is slow but we keep it simple as there are just ~50 packages
65 findPackageByName :: PackageName -> Maybe Package
66 findPackageByName name = find (\pkg -> pkgName pkg == name) knownPackages