Refactor GHC/user packages, move builder-specific functions into Builder
[hadrian.git] / src / Settings.hs
1 module Settings (
2 getArgs, getLibraryWays, getRtsWays, flavour, knownPackages,
3 findPackageByName, getPkgData, getPkgDataList, isLibrary, stagePackages,
4 latestBuildStage, programContext, integerLibraryName, getDestDir, stage1Only
5 ) where
6
7 import Context
8 import CommandLine
9 import Expression
10 import Flavour
11 import GHC
12 import {-# SOURCE #-} Settings.Default
13 import Settings.Flavours.Development
14 import Settings.Flavours.Performance
15 import Settings.Flavours.Profiled
16 import Settings.Flavours.Quick
17 import Settings.Flavours.Quickest
18 import UserSettings
19
20 getArgs :: Args
21 getArgs = expr flavour >>= args
22
23 getLibraryWays :: Ways
24 getLibraryWays = expr flavour >>= libraryWays
25
26 getRtsWays :: Ways
27 getRtsWays = expr flavour >>= rtsWays
28
29 stagePackages :: Stage -> Action [Package]
30 stagePackages stage = do
31 f <- flavour
32 packages f stage
33
34 hadrianFlavours :: [Flavour]
35 hadrianFlavours =
36 [ defaultFlavour, developmentFlavour Stage1, developmentFlavour Stage2
37 , performanceFlavour, profiledFlavour, quickFlavour, quickestFlavour ]
38
39 flavour :: Action Flavour
40 flavour = do
41 flavourName <- fromMaybe "default" <$> cmdFlavour
42 let unknownFlavour = error $ "Unknown build flavour: " ++ flavourName
43 flavours = hadrianFlavours ++ userFlavours
44 return $ fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
45
46 integerLibraryName :: Action String
47 integerLibraryName = pkgName <$> (integerLibrary =<< flavour)
48
49 programContext :: Stage -> Package -> Action Context
50 programContext stage pkg = do
51 profiled <- ghcProfiled <$> flavour
52 return $ if pkg == ghc && profiled && stage > Stage0
53 then Context stage pkg profiling
54 else vanillaContext stage pkg
55
56 -- TODO: switch to Set Package as the order of packages should not matter?
57 -- Otherwise we have to keep remembering to sort packages from time to time.
58 knownPackages :: [Package]
59 knownPackages = sort $ ghcPackages ++ userPackages
60
61 -- TODO: Speed up? Switch to Set?
62 -- Note: this is slow but we keep it simple as there are just ~50 packages
63 findPackageByName :: PackageName -> Maybe Package
64 findPackageByName name = find (\pkg -> pkgName pkg == name) knownPackages
65
66 -- | Determine the latest 'Stage' in which a given 'Package' is built. Returns
67 -- Nothing if the package is never built.
68 latestBuildStage :: Package -> Action (Maybe Stage)
69 latestBuildStage pkg = do
70 stages <- filterM (fmap (pkg `elem`) . stagePackages) [Stage0 ..]
71 return $ if null stages then Nothing else Just $ maximum stages
72
73 -- TODO: Set this from command line
74 -- | Stage1Only flag.
75 stage1Only :: Bool
76 stage1Only = defaultStage1Only
77
78 -- | Install's DESTDIR setting.
79 getDestDir :: Action FilePath
80 getDestDir = fromMaybe "" <$> cmdInstallDestDir