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