Commit c42eb2e6 authored by Alp Mestanogullari's avatar Alp Mestanogullari 🦑 Committed by Ben Gamari

Hadrian: introduce userDefaultFlavour, making default flavour overridable

This patch introduces the `userDefaultFlavour` user setting. It should
be the name of the default flavour to use when no --flavour argument is
passed. Before this patch, we would just always default to... the
`default` flavour. With this patch, we default to whatever Flavour whose
name is `userDefaultFlavour`, therefore providing a way for users to
"persist" their choice of flavour, not having to repeat --flavour=[...]
in every hadrian command.

Test Plan:
Set `userDefaultFlavour = "quickest"`, run `hadrian/build.sh`, check
that the quickest flavour is indeed picked.

Reviewers: snowleopard, bgamari

Reviewed By: snowleopard

Subscribers: mpickering, rwbarton, carter

GHC Trac Issues: #15890

Differential Revision: https://phabricator.haskell.org/D5454
parent 205762bd
......@@ -34,7 +34,7 @@ data Flavour = Flavour {
-- | Build GHC with debug information.
ghcDebugged :: Bool }
```
Hadrian provides several built-in flavours (`defaultFlavour`, `quickFlavour`, and a few
Hadrian provides several built-in flavours (`default`, `quick`, and a few
others; see `hadrian/doc/flavours.md`), which can be activated from the command line,
e.g. by passing `--flavour=quick`. Users can define new build flavours by adding them
to `userFlavours` list:
......@@ -48,7 +48,24 @@ userFlavours = [userFlavour] -- Add more build flavours if need be.
userFlavour :: Flavour
userFlavour = defaultFlavour { name = "user" } -- Modify other settings here.
```
Now `--flavour=user` will run Hadrian with `userFlavour` settings. In the
Now `--flavour=user` will run Hadrian with `userFlavour` settings.
When no `--flavour` argument is passed to hadrian, it will use the
`default` one. You can however change this, and for example make
the "fallback" flavour be `user`, by changing `userDefaultFlavour`:
``` haskell
userDefaultFlavour :: String
-- before:
-- userDefaultFlavour = "default"
-- now:
userDefaultFlavour = "user"
```
This saves you from having to type `build --flavour=user [...]`
every time, allowing you to _persist_ the choice of flavour.
In the
following sections we look at specific fields of the `Flavour` record in
more detail. Note: `defaultFlavour`, as well as its individual fields such
as `defaultArgs`, `defaultPackages`, etc. that we use below, are defined in module
......
......@@ -8,7 +8,7 @@ import CommandLine
import Expression
import Flavour
import Packages
import UserSettings
import UserSettings (userFlavours, userPackages, userDefaultFlavour)
import {-# SOURCE #-} Settings.Default
import Settings.Flavours.Development
......@@ -40,7 +40,7 @@ hadrianFlavours =
flavour :: Action Flavour
flavour = do
flavourName <- fromMaybe "default" <$> cmdFlavour
flavourName <- fromMaybe userDefaultFlavour <$> cmdFlavour
let unknownFlavour = error $ "Unknown build flavour: " ++ flavourName
flavours = hadrianFlavours ++ userFlavours
return $ fromMaybe unknownFlavour $ find ((== flavourName) . name) flavours
......
......@@ -3,8 +3,8 @@
-- If you don't copy the file your changes will be tracked by git and you can
-- accidentally commit them.
module UserSettings (
userFlavours, userPackages, verboseCommand, buildProgressColour,
successColour, stage1Only
userFlavours, userPackages, userDefaultFlavour,
verboseCommand, buildProgressColour, successColour, stage1Only
) where
import Flavour
......@@ -14,6 +14,11 @@ import {-# SOURCE #-} Settings.Default
-- See doc/user-settings.md for instructions.
-- Please update doc/user-settings.md when committing changes to this file.
-- | Name of the default flavour, i.e the one used when no --flavour=<name>
-- argument is passed to Hadrian.
userDefaultFlavour :: String
userDefaultFlavour = "default"
-- | User-defined build flavours. See 'userFlavour' as an example.
userFlavours :: [Flavour]
userFlavours = [userFlavour] -- Add more build flavours if need be.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment