ocaml/dune

[PROPOSAL] Env Defaults

オープン

#1,073 opened on 2018/07/31

 (18 件のコメント) (1 件のリアクション) (0 人の担当者)OCaml (478 件のフォーク)github user discovery
confighelp wantedrule

Repository metrics

Stars
 (1,882 個のスター)
PR merge metrics
 (平均マージ 1d 20h) (30d で 345 merged PRs)

説明

Problem

This proposal is coming out of my general annoyance of having to work harder than necessary to allow to customization of the same option at the stanza and the environment level. Clearly, both mechanisms are useful (see flags for example), and ideally this mechanism would work for pretty much every option as well: no_dynlink, preprocess, modes, etc.

Solution

Allow for defining all optional fields inside inside the env stanza. For example:

(env
 (_
  (libraries foo bar)
  (no_dynlink)))

To specify the defaults for a particular stanza, we can:

(env
 (_
  (test
   (enabled_if (= %{foo} foo)))))

Where the stanza could be test, executable, library, alias, and possibly things like buildable as well. We could also entertain setting defaults for multiple stanzas at once but that isn't necessary for a first version.

Implementation

This is the most difficult part, and I haven't yet thought about this too much in the hopes that others might suggest productive ideas. But here are some points that I'd like to mention:

  • Easiest way to implement this feature would be the parse the defaults when parsing the stanzas and inserting them into the correct ~default args. But this is also wrong and will make implementing polling mode harder.

  • All fields that have a default value today will basically need to be options. This is unfortunate as we'll need a layer of indirection to access the values of things once the default values have been set. I wonder if we could save ourselves from this massive refactoring by parameterizing the types appropriately - by using a functor for example.

  • The interaction of :standard with the default value. Should we make it official that :standard will henceforth refer to the current default. Perhaps it should be renamed to :default then? (with a deprecation cycle of course).

コントリビューターガイド