Hadrian: implement key-value settings for builder options
authorAlp Mestanogullari <alpmestan@gmail.com>
Mon, 24 Jun 2019 18:43:49 +0000 (20:43 +0200)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Wed, 10 Jul 2019 02:57:31 +0000 (22:57 -0400)
commit18ac9ad404f490bd7ea0639a1b85a88ed4502613
treeb623b43f77709e148a83cef6f5b3be192ce15640
parent42ff8653bd5ce7f00af5783f2973393ebfcd7cc7
Hadrian: implement key-value settings for builder options

They take the general form `foo.bar.baz [+]= some values`, where
`=` completely overrides the arguments for a builder and `+=` extends
them. We currenly only support settings for updating the GHC and C
compiler options, of the form:

```
  {stage0, ..., stage3 or *}.{package name or *}
                            .ghc.{c, hs, link, deps, toolargs or *}.opts

  {stage0, ..., stage3 or *}.{package name or *}
                            .cc.{c, deps or *}.opts
```

The supported settings and their use is covered in the new section
of `hadrian/doc/user-settings.md`, while the implementation is explained
in a new Note [Hadrian settings].

Most of the logic is implemented in a new module, `Settings.Parser`, which
contains key-value assignment/extension parsers as well as utilities for
specifying allowed settings at a high-level, generating a `Predicate` from
such a description or generating the list of possible completions for a given
string.

The additions to the `Settings` module make use of this to describe the
settings that Hadrian currently supports, and apply all such
key-value settings (from the command line and `<root>/hadrian.settings`)
to the flavour that Hadrian is going to proceed with.

This new setting system comes with support for generating Bash completions,
implemented in `hadrian/completion.sh` and Hadrian's `autocomplete` target:

> source hadrian/completion.sh
> hadrian/build.sh stage1.base.ghc.<TAB>
stage1.base.ghc.c.opts     stage1.base.ghc.hs.opts
stage1.base.ghc.*.opts     stage1.base.ghc.deps.opts
stage1.base.ghc.link.opts  stage1.base.ghc.toolargs.opts
hadrian/completion.sh [new file with mode: 0755]
hadrian/doc/user-settings.md
hadrian/hadrian.cabal
hadrian/src/CommandLine.hs
hadrian/src/Hadrian/BuildPath.hs
hadrian/src/Main.hs
hadrian/src/Rules.hs
hadrian/src/Rules/Register.hs
hadrian/src/Rules/SimpleTargets.hs
hadrian/src/Settings.hs
hadrian/src/Settings/Parser.hs [new file with mode: 0644]