Skip to content

Add enabled_if to install stanzas and enforce variable restrictions#3408

Merged
rgrinberg merged 14 commits intoocaml:masterfrom
voodoos:install-enabled_if
May 6, 2020
Merged

Add enabled_if to install stanzas and enforce variable restrictions#3408
rgrinberg merged 14 commits intoocaml:masterfrom
voodoos:install-enabled_if

Conversation

@voodoos
Copy link
Copy Markdown
Collaborator

@voodoos voodoos commented Apr 21, 2020

This PR fixes #3354 by adding the enabled_if field to the install stanza.

Doing that I discovered that the enabled_if field was not guarded correctly in the executable stanza and any variables could be used. This PR enforce the same variable restrictions for enabled_if in the executables and install stanzas as in the library stanza.

To do that chose to upstream the ad-hoc variable checking code for the install stanza to the enabled_if decoder.

@voodoos voodoos force-pushed the install-enabled_if branch from 9c6fcde to cc776cd Compare April 21, 2020 15:16
@voodoos voodoos changed the title Add enabled_if to install stanzas and enfore variable restrictions Add enabled_if to install stanzas and enforce variable restrictions Apr 21, 2020
@rgrinberg
Copy link
Copy Markdown
Member

Needs a CHANGES entry.

There's a test failure as well:

--- a/test/blackbox-tests/test-cases/enabled_if/run.t
463+++ b/test/blackbox-tests/test-cases/enabled_if/run.t.corrected
464@@ -24,8 +24,8 @@ Test the enabled_if field for libraries:
465   [1]
466 
467   $ dune build main.exe
468-  File "dune", line 34, characters 12-15:
469-  34 |  (libraries foo))
470+  File "dune", line 35, characters 12-15:
471+  35 |  (libraries foo))
472                    ^^^
473   Error: Library "foo" in _build/default is hidden (unsatisfied 'enabled_if').

@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Apr 22, 2020

Needs a CHANGES entry.

There's a test failure as well

Done.

@voodoos voodoos force-pushed the install-enabled_if branch from f93946c to 4a432c0 Compare April 22, 2020 08:42
voodoos added 11 commits April 23, 2020 11:05
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
@voodoos voodoos force-pushed the install-enabled_if branch from 56458a9 to b8b805a Compare April 23, 2020 09:05
@voodoos
Copy link
Copy Markdown
Collaborator Author

voodoos commented Apr 23, 2020

I decided to move the enabled_if related code to it's own module (b8b805a) to stop bloating the Dune_file module.

It is not completely generic yet and does not replace the code in Lib_info that associates different minimal version to each variable.

let allowed_in_enabled_if =
List.map var_map ~f:(fun (var, _) ->
let min_version =
match var with
| "profile" -> (2, 5)
| "ccomp_type" -> (2, 0)
| "ocaml_version" -> (2, 5)
| _ -> (1, 0)
in
(var, min_version))

However I feel like it could be easily added when needed (when another variable will be allowed in these fields).

What do you think ?

@rgrinberg
Copy link
Copy Markdown
Member

The Enabled_if module looks good to me.

voodoos added 2 commits April 24, 2020 10:57
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
@rgrinberg rgrinberg merged commit 8b0a4c1 into ocaml:master May 6, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Jun 6, 2020
…lugin, dune-private-libs and dune-glob (2.6.0)

CHANGES:

- Fix a bug where valid lib names in `dune init exec --libs=lib1,lib2`
  results in an error. (ocaml/dune#3444, fix ocaml/dune#3443, @bikallem)

- Add and `enabled_ if` field to the `install` stanza. Enforce the same variable
  restrictions for `enabled_if` fields in the `executable` and `install` stanzas
  than in the `library` stanza. When using dune lang < 2.6, the usage of
  forbidden variables in executables stanzas with only trigger a warning to
  maintain compatibility. (ocaml/dune#3408 and ocaml/dune#3496, fixes ocaml/dune#3354, @voodoos)

- Insert a constraint one the version of dune when the user explicitly
  specify the dependency on dune in the `dune-project` file (ocaml/dune#3434 ,
  fixes ocaml/dune#3427, @diml)

- Generate correct META files for sub-libraries (of the form `lib.foo`) that
  contain .js runtime files. (ocaml/dune#3445, @hhugo)

- Add a `(no-infer ...)` action that prevents inference of targets and
  dependencies in actions. (ocaml/dune#3456, fixes ocaml/dune#2006, @roddyyaga)

- Correctly infer targets for the `diff?` action. (ocaml/dune#3457, fixes ocaml/dune#2990, @greedy)

- Fix `$ dune print-rules` crashing (ocaml/dune#3459, fixes ocaml/dune#3440, @rgrinberg)

- Simplify js_of_ocaml rules using js_of_ocaml.3.6 (ocaml/dune#3375, @hhugo)

- Add a new `ocaml-merlin` subcommand that can be used by Merlin to get
  configuration directly from dune instead of using `.merlin` files. (ocaml/dune#3395,
  @voodoos)

- Remove experimental variants feature and make default implementations part of
  the language (ocaml/dune#3491, fixes ocaml/dune#3483, @rgrinberg)
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Jun 7, 2020
…lugin, dune-private-libs and dune-glob (2.6.0)

CHANGES:

- Fix a bug where valid lib names in `dune init exec --libs=lib1,lib2`
  results in an error. (ocaml/dune#3444, fix ocaml/dune#3443, @bikallem)

- Add and `enabled_ if` field to the `install` stanza. Enforce the same variable
  restrictions for `enabled_if` fields in the `executable` and `install` stanzas
  than in the `library` stanza. When using dune lang < 2.6, the usage of
  forbidden variables in executables stanzas with only trigger a warning to
  maintain compatibility. (ocaml/dune#3408 and ocaml/dune#3496, fixes ocaml/dune#3354, @voodoos)

- Insert a constraint one the version of dune when the user explicitly
  specify the dependency on dune in the `dune-project` file (ocaml/dune#3434 ,
  fixes ocaml/dune#3427, @diml)

- Generate correct META files for sub-libraries (of the form `lib.foo`) that
  contain .js runtime files. (ocaml/dune#3445, @hhugo)

- Add a `(no-infer ...)` action that prevents inference of targets and
  dependencies in actions. (ocaml/dune#3456, fixes ocaml/dune#2006, @roddyyaga)

- Correctly infer targets for the `diff?` action. (ocaml/dune#3457, fixes ocaml/dune#2990, @greedy)

- Fix `$ dune print-rules` crashing (ocaml/dune#3459, fixes ocaml/dune#3440, @rgrinberg)

- Simplify js_of_ocaml rules using js_of_ocaml.3.6 (ocaml/dune#3375, @hhugo)

- Add a new `ocaml-merlin` subcommand that can be used by Merlin to get
  configuration directly from dune instead of using `.merlin` files. (ocaml/dune#3395,
  @voodoos)

- Remove experimental variants feature and make default implementations part of
  the language (ocaml/dune#3491, fixes ocaml/dune#3483, @rgrinberg)
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Jun 7, 2020
…lugin, dune-private-libs and dune-glob (2.6.0)

CHANGES:

- Fix a bug where valid lib names in `dune init exec --libs=lib1,lib2`
  results in an error. (ocaml/dune#3444, fix ocaml/dune#3443, @bikallem)

- Add and `enabled_ if` field to the `install` stanza. Enforce the same variable
  restrictions for `enabled_if` fields in the `executable` and `install` stanzas
  than in the `library` stanza. When using dune lang < 2.6, the usage of
  forbidden variables in executables stanzas with only trigger a warning to
  maintain compatibility. (ocaml/dune#3408 and ocaml/dune#3496, fixes ocaml/dune#3354, @voodoos)

- Insert a constraint one the version of dune when the user explicitly
  specify the dependency on dune in the `dune-project` file (ocaml/dune#3434 ,
  fixes ocaml/dune#3427, @diml)

- Generate correct META files for sub-libraries (of the form `lib.foo`) that
  contain .js runtime files. (ocaml/dune#3445, @hhugo)

- Add a `(no-infer ...)` action that prevents inference of targets and
  dependencies in actions. (ocaml/dune#3456, fixes ocaml/dune#2006, @roddyyaga)

- Correctly infer targets for the `diff?` action. (ocaml/dune#3457, fixes ocaml/dune#2990, @greedy)

- Fix `$ dune print-rules` crashing (ocaml/dune#3459, fixes ocaml/dune#3440, @rgrinberg)

- Simplify js_of_ocaml rules using js_of_ocaml.3.6 (ocaml/dune#3375, @hhugo)

- Add a new `ocaml-merlin` subcommand that can be used by Merlin to get
  configuration directly from dune instead of using `.merlin` files. (ocaml/dune#3395,
  @voodoos)

- Remove experimental variants feature and make default implementations part of
  the language (ocaml/dune#3491, fixes ocaml/dune#3483, @rgrinberg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to put enabled_if in install stanza

2 participants