summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlp Mestanogullari <alpmestan@gmail.com>2019-03-15 21:35:59 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-03-27 07:20:05 -0400
commitfb12f53c2779f15ee24786e8c3beae3133506a01 (patch)
tree954591064a368662821b289a606a8a6706ca7d91
parent646f2e79c5d6e79341693b1b9660da974102cec2 (diff)
downloadhaskell-fb12f53c2779f15ee24786e8c3beae3133506a01.tar.gz
Hadrian: introduce an easy way for users to build with -split-sections
Any user can now trivially build any number of Haskell packages with `-split-sections` by using `splitSections`/`splitSectionsIf` on any existing or new flavour: -- build all packages but the ghc library with -split-sections splitSections :: Flavour -> Flavour -- build all packages that satisfy the given predicate -- with --split-sections splitSectionsIf :: (Package -> Bool) -> Flavour -> Flavour See the new section in `doc/user-settings.md`.
-rw-r--r--hadrian/doc/user-settings.md28
-rw-r--r--hadrian/src/Flavour.hs25
2 files changed, 53 insertions, 0 deletions
diff --git a/hadrian/doc/user-settings.md b/hadrian/doc/user-settings.md
index d0531a3f3d..b6b44521cc 100644
--- a/hadrian/doc/user-settings.md
+++ b/hadrian/doc/user-settings.md
@@ -271,6 +271,32 @@ all of the documentation targets:
You can pass several `--docs=...` flags, Hadrian will combine
their effects.
+## Split sections
+
+You can build all or just a few packages with
+[`-split-sections`][split-sections] by tweaking an existing
+flavour (whichever matches your needs) using
+`splitSections` or `splitSectionsIf`:
+
+``` haskell
+splitSections :: Flavour -> Flavour
+splitSectionsIf :: (Package -> Bool) -> Flavour -> Flavour
+```
+
+For example, you can easily start with the `quick` flavour and
+additionally build all Haskell packages with `-split-sections` by defining a new
+flavour as
+`(splitSectionsIf (const True) quickFlavour) { name = "quick-split" }`.
+You can then start a build with this flavour with `build --flavour=quick-split`.
+
+Changing `(const True)` to `(== base)` would only build `base` with
+`-split-sections`, not all Haskell packages as with `quick-split` above.
+
+`splitSections` is simply `splitSectionsIf` applied to the predicate
+`(/=ghc)`, i.e it builds all Haskell packages but the `ghc`
+library with `-split-sections` (it is usually not worth using that
+option with the `ghc` library).
+
## Miscellaneous
Hadrian prints various progress info during the build. You can change the colours
@@ -295,3 +321,5 @@ Dull Blue
Vivid Cyan
Extended "203"
```
+
+[split-sections]: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/phases.html#ghc-flag--split-sections
diff --git a/hadrian/src/Flavour.hs b/hadrian/src/Flavour.hs
index 06407e7022..230272ec62 100644
--- a/hadrian/src/Flavour.hs
+++ b/hadrian/src/Flavour.hs
@@ -1,10 +1,12 @@
module Flavour
( Flavour (..), werror
, DocTargets, DocTarget(..)
+ , splitSections, splitSectionsIf
) where
import Expression
import Data.Set (Set)
+import Packages
-- Please update doc/{flavours.md, user-settings.md} when changing this file.
-- | 'Flavour' is a collection of build settings that fully define a GHC build.
@@ -63,3 +65,26 @@ data DocTarget = Haddocks | SphinxHTML | SphinxPDFs | SphinxMan
-- It mimics the CI settings so is useful to turn on when developing.
werror :: Flavour -> Flavour
werror fl = fl { args = args fl <> (builder Ghc ? notStage0 ? arg "-Werror") }
+
+-- | Transform the input 'Flavour' so as to build with
+-- @-split-sections@ whenever appropriate. You can
+-- select which package gets built with split sections
+-- by passing a suitable predicate. If the predicate holds
+-- for a given package, then @split-sections@ is used when
+-- building it. If the given flavour doesn't build
+-- anything in a @dyn@-enabled way, then 'splitSections' is a no-op.
+splitSectionsIf :: (Package -> Bool) -> Flavour -> Flavour
+splitSectionsIf pkgPredicate fl = fl { args = args fl <> splitSectionsArg }
+
+ where splitSectionsArg = do
+ way <- getWay
+ pkg <- getPackage
+ (Dynamic `wayUnit` way) ? pkgPredicate pkg ?
+ builder (Ghc CompileHs) ? arg "-split-sections"
+
+-- | Like 'splitSectionsIf', but with a fixed predicate: use
+-- split sections for all packages but the GHC library.
+splitSections :: Flavour -> Flavour
+splitSections = splitSectionsIf (/=ghc)
+-- Disable section splitting for the GHC library. It takes too long and
+-- there is little benefit.