Re-layout validate script
[ghc.git] / hadrian / src / Flavour.hs
1 module Flavour
2 ( Flavour (..), werror
3 , DocTargets, DocTarget(..)
4 -- * Flavour transformers
5 , addArgs
6 , splitSections, splitSectionsIf
7 , enableDebugInfo, enableTickyGhc
8 ) where
9
10 import Expression
11 import Data.Set (Set)
12 import Packages
13
14 -- Please update doc/{flavours.md, user-settings.md} when changing this file.
15 -- | 'Flavour' is a collection of build settings that fully define a GHC build.
16 -- Note the following type semantics:
17 -- * @Bool@: a plain Boolean flag whose value is known at compile time.
18 -- * @Action Bool@: a flag whose value can depend on the build environment.
19 -- * @Predicate@: a flag whose value can depend on the build environment and
20 -- on the current build target.
21 data Flavour = Flavour {
22 -- | Flavour name, to select this flavour from command line.
23 name :: String,
24 -- | Use these command line arguments.
25 args :: Args,
26 -- | Build these packages.
27 packages :: Stage -> Action [Package],
28 -- | Either 'integerGmp' or 'integerSimple'.
29 integerLibrary :: Action Package,
30 -- | Build libraries these ways.
31 libraryWays :: Ways,
32 -- | Build RTS these ways.
33 rtsWays :: Ways,
34 -- | Build dynamic GHC programs.
35 dynamicGhcPrograms :: Action Bool,
36 -- | Enable GHCi debugger.
37 ghciWithDebugger :: Bool,
38 -- | Build profiled GHC.
39 ghcProfiled :: Bool,
40 -- | Build GHC with debugging assertions.
41 ghcDebugged :: Bool,
42 -- | Whether to build docs and which ones
43 -- (haddocks, user manual, haddock manual)
44 ghcDocs :: Action DocTargets }
45
46 -- | A set of documentation targets
47 type DocTargets = Set DocTarget
48
49 -- | Documentation targets
50 --
51 -- While we can't reasonably expose settings or CLI options
52 -- to selectively disable, say, base's haddocks, we can offer
53 -- a less fine-grained choice:
54 --
55 -- - haddocks for libraries
56 -- - non-haddock html pages (e.g GHC's user manual)
57 -- - PDF documents (e.g haddock's manual)
58 -- - man pages (GHC's)
59 --
60 -- The main goal being to have easy ways to do away with the need
61 -- for e.g @sphinx-build@ or @xelatex@ and associated packages
62 -- while still being able to build a(n almost) complete binary
63 -- distribution.
64 data DocTarget = Haddocks | SphinxHTML | SphinxPDFs | SphinxMan | SphinxInfo
65 deriving (Eq, Ord, Show, Bounded, Enum)
66
67 -- | Add arguments to the 'args' of a 'Flavour'.
68 addArgs :: Args -> Flavour -> Flavour
69 addArgs args' fl = fl { args = args fl <> args' }
70
71 -- | Turn on -Werror for packages built with the stage1 compiler.
72 -- It mimics the CI settings so is useful to turn on when developing.
73 werror :: Flavour -> Flavour
74 werror = addArgs (builder Ghc ? notStage0 ? arg "-Werror")
75
76 -- | Build C and Haskell objects with debugging information.
77 enableDebugInfo :: Flavour -> Flavour
78 enableDebugInfo = addArgs $ mconcat
79 [ builder (Ghc CompileHs) ? notStage0 ? arg "-g3"
80 , builder (Cc CompileC) ? notStage0 ? arg "-g3"
81 ]
82
83 -- | Enable the ticky-ticky profiler in stage2 GHC
84 enableTickyGhc :: Flavour -> Flavour
85 enableTickyGhc =
86 addArgs $ foldMap enableTickyFor [ghc, compiler, base]
87 where
88 enableTickyFor pkg = stage1 ? package pkg ? mconcat
89 [ builder (Ghc CompileHs) ? ticky
90 , builder (Ghc LinkHs) ? ticky
91 ]
92 ticky = arg "-ticky" <> arg "-ticky-allocd"
93
94 -- | Transform the input 'Flavour' so as to build with
95 -- @-split-sections@ whenever appropriate. You can
96 -- select which package gets built with split sections
97 -- by passing a suitable predicate. If the predicate holds
98 -- for a given package, then @split-sections@ is used when
99 -- building it. If the given flavour doesn't build
100 -- anything in a @dyn@-enabled way, then 'splitSections' is a no-op.
101 splitSectionsIf :: (Package -> Bool) -> Flavour -> Flavour
102 splitSectionsIf pkgPredicate = addArgs $ do
103 way <- getWay
104 pkg <- getPackage
105 (Dynamic `wayUnit` way) ? pkgPredicate pkg ?
106 builder (Ghc CompileHs) ? arg "-split-sections"
107
108 -- | Like 'splitSectionsIf', but with a fixed predicate: use
109 -- split sections for all packages but the GHC library.
110 splitSections :: Flavour -> Flavour
111 splitSections = splitSectionsIf (/=ghc)
112 -- Disable section splitting for the GHC library. It takes too long and
113 -- there is little benefit.