Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabled_if in executable(s) stanza #3137

Merged
merged 6 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
- Fix bootstrap on bytecode only switches on windows or where `-j1` is set.
(#3112, @xclerc, @rgrinberg)

- Allow `enabled_if` fields in `executable(s)` stanzas (#3137,
fixes #1690 @voodoos)

2.2.0 (06/02/2020)
------------------

Expand Down
2 changes: 2 additions & 0 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ Executables can also be linked as object or shared object files. See

- ``(optional)`` is the same as the corresponding field of `library`_

- ``(enabled_if <blang expression>)`` is the same as the corresponding field of `library`_

- ``(promote <options>)`` allows promoting the linked executables to
the source tree. The options are the same as for the :ref:`rule
promote mode <promote>`. Adding ``(promote (until-clean))`` to an
Expand Down
4 changes: 4 additions & 0 deletions src/dune/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,7 @@ module Executables = struct
; install_conf : File_binding.Unexpanded.t Install_conf.t option
; forbidden_libraries : (Loc.t * Lib_name.t) list
; bootstrap_info : string option
; enabled_if : Blang.t
}

let bootstrap_info_extension =
Expand Down Expand Up @@ -1581,6 +1582,7 @@ module Executables = struct
User_error.raise ~loc
[ Pp.text "This field is reserved for Dune itself" ];
fname)
and+ enabled_if = enabled_if ~since:(Some (2, 3))
in
fun names ~multi ->
let has_public_name = Names.has_public_name names in
Expand Down Expand Up @@ -1621,6 +1623,7 @@ module Executables = struct
; install_conf
; forbidden_libraries
; bootstrap_info
; enabled_if
}

let single, multi =
Expand Down Expand Up @@ -2128,6 +2131,7 @@ module Tests = struct
; install_conf = None
; forbidden_libraries
; bootstrap_info = None
; enabled_if
}
; locks
; package
Expand Down
1 change: 1 addition & 0 deletions src/dune/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ module Executables : sig
; install_conf : File_binding.Unexpanded.t Install_conf.t option
; forbidden_libraries : (Loc.t * Lib_name.t) list
; bootstrap_info : string option
; enabled_if : Blang.t
}

(** Check if the executables have any foreign stubs or archives. *)
Expand Down
2 changes: 1 addition & 1 deletion src/dune/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ end = struct
| Foreign_library lib ->
Lib_rules.foreign_rules lib ~sctx ~dir ~dir_contents ~expander;
empty_none
| Executables exes ->
| Executables exes when Expander.eval_blang expander exes.enabled_if ->
Option.iter exes.install_conf ~f:files_to_install;
let cctx, merlin =
Exe_rules.rules exes ~sctx ~dir ~scope ~expander ~dir_contents
Expand Down
12 changes: 12 additions & 0 deletions test/blackbox-tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,16 @@
(run %{exe:cram.exe} run.t -sanitizer %{bin:sanitizer})
(diff? run.t run.t.corrected)))))

(rule
(alias enabled_if-exec)
(deps (package dune) (source_tree test-cases/enabled_if-exec))
(action
(chdir
test-cases/enabled_if-exec
(progn
(run %{exe:cram.exe} run.t -sanitizer %{bin:sanitizer})
(diff? run.t run.t.corrected)))))

(rule
(alias env-env-and-flags-include)
(deps (package dune) (source_tree test-cases/env/env-and-flags-include))
Expand Down Expand Up @@ -2687,6 +2697,7 @@
(alias duplicate-target-no-loc)
(alias embed-jbuild)
(alias enabled_if)
(alias enabled_if-exec)
(alias env-env-and-flags-include)
(alias env-env-bin-pform)
(alias env-env-bins)
Expand Down Expand Up @@ -2940,6 +2951,7 @@
(alias duplicate-target-no-loc)
(alias embed-jbuild)
(alias enabled_if)
(alias enabled_if-exec)
(alias env-env-and-flags-include)
(alias env-env-bin-pform)
(alias env-env-bins)
Expand Down
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/enabled_if-exec/dis.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Printf.eprintf "Ping"
9 changes: 9 additions & 0 deletions test/blackbox-tests/test-cases/enabled_if-exec/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(executable
(name main)
(modules main)
(enabled_if true))

(executable
(name dis)
(modules dis)
(enabled_if false))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 2.3)
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/enabled_if-exec/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Printf.eprintf "Pong"
15 changes: 15 additions & 0 deletions test/blackbox-tests/test-cases/enabled_if-exec/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Test that `enabled_if` fields work as expected for executables.
Since 2.3.

This executable is disabled, any attempt to build it should fail:
$ dune build dis.exe
Error: Don't know how to build dis.exe
[1]
$ dune exec ./dis.exe
Error: Program "./dis.exe" not found!
[1]

This one is enabled
$ dune exec ./main.exe
Pong

4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/enabled_if/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ This one is enabled:

Test the enabled_if field for libraries:

$ dune build foo
Error: Don't know how to build foo
[1]

$ dune build main.exe
File "dune", line 33, characters 12-15:
33 | (libraries foo))
Expand Down