[commit: ghc] master: Hadrian: introduce userDefaultFlavour, making default flavour overridable (c42eb2e)

git at git.haskell.org git at git.haskell.org
Mon Dec 17 06:16:48 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/c42eb2e67ae7f1e77c7bf365b7a41f808bc606cc/ghc

>---------------------------------------------------------------

commit c42eb2e67ae7f1e77c7bf365b7a41f808bc606cc
Author: Alp Mestanogullari <alp at well-typed.com>
Date:   Mon Dec 17 01:15:45 2018 -0500

    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


>---------------------------------------------------------------

c42eb2e67ae7f1e77c7bf365b7a41f808bc606cc
 hadrian/doc/user-settings.md | 21 +++++++++++++++++++--
 hadrian/src/Settings.hs      |  4 ++--
 hadrian/src/UserSettings.hs  |  9 +++++++--
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/hadrian/doc/user-settings.md b/hadrian/doc/user-settings.md
index b81c0dc..0c6d4ba 100644
--- a/hadrian/doc/user-settings.md
+++ b/hadrian/doc/user-settings.md
@@ -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
diff --git a/hadrian/src/Settings.hs b/hadrian/src/Settings.hs
index 3497f43..99a58db 100755
--- a/hadrian/src/Settings.hs
+++ b/hadrian/src/Settings.hs
@@ -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
diff --git a/hadrian/src/UserSettings.hs b/hadrian/src/UserSettings.hs
index 9246806..e029dad 100644
--- a/hadrian/src/UserSettings.hs
+++ b/hadrian/src/UserSettings.hs
@@ -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.



More information about the ghc-commits mailing list