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

Fix a bug causing all executables to be considered as optional #3163

Merged
8 commits merged into from Feb 19, 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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Fix versioning of artifact variables (eg %{cmxa:...}), which were introduced
in 2.0, not 1.11. (#3149, @nojb)

- Fix a bug causing all executables to be considered as optional (#3163, @diml)

2.3.0 (15/02/2020)
------------------

Expand Down
5 changes: 4 additions & 1 deletion src/dune/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ end = struct
Option.some_if
( match (stanza : Stanza.t) with
| Dune_file.Library lib ->
Lib.DB.available (Scope.libs scope) (Dune_file.Library.best_name lib)
(not lib.optional)
|| Lib.DB.available (Scope.libs scope) (Dune_file.Library.best_name lib)
| Dune_file.Documentation _
| Dune_file.Install _ ->
true
| Dune_file.Executables ({ install_conf = Some _; _ } as exes) ->
(not exes.optional)
||
let compile_info =
let dune_version = Scope.project scope |> Dune_project.dune_version in
Lib.DB.resolve_user_written_deps_for_exes (Scope.libs scope)
Expand Down
8 changes: 0 additions & 8 deletions test/blackbox-tests/test-cases/optional-executable/dune

This file was deleted.

This file was deleted.

38 changes: 38 additions & 0 deletions test/blackbox-tests/test-cases/optional-executable/run.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
Test optional executable
========================

$ cat >dune <<EOF
> (executable
> (public_name x)
> (libraries does-not-exist)
> (optional))
>
> (rule
> (alias run-x)
> (action (run %{exe:x.exe})))
> EOF

$ cat >dune-project <<EOF
> (lang dune 2.0)
> (package (name x))
> EOF

$ touch x.ml

$ dune build @install

Expand All @@ -17,3 +36,22 @@ Test optional executable
Error: Library "does-not-exist" not found.
Hint: try: dune external-lib-deps --missing @run-x
[1]

Reproduction case for a bug in dune < 2.4 where all executables where
considered as optional:

$ cat >dune <<EOF
> (executable
> (public_name x)
> (libraries does-not-exist))
> EOF

The following command should fail because the executable is not optional:

$ dune build @install
File "dune", line 3, characters 12-26:
3 | (libraries does-not-exist))
^^^^^^^^^^^^^^
Error: Library "does-not-exist" not found.
Hint: try: dune external-lib-deps --missing @install
[1]
Empty file.
Empty file.
6 changes: 0 additions & 6 deletions test/blackbox-tests/test-cases/optional/dune

This file was deleted.

2 changes: 0 additions & 2 deletions test/blackbox-tests/test-cases/optional/dune-project

This file was deleted.

Empty file.
39 changes: 39 additions & 0 deletions test/blackbox-tests/test-cases/optional/run.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
Various tests for optional libraries
------------------------------------

$ cat >dune-project <<EOF
> (lang dune 1.2)
> (name foo)
> (package (name foo))
> EOF

$ cat >dune <<EOF
> (library
> (name foo)
> (public_name foo)
> (wrapped false)
> (optional)
> (libraries lib_that_doesn't_exist))
> EOF

$ cat >x.ml <<EOF
> let x = 42
> EOF

Regression test for non-wrapped optional libraries with missing
dependencies (#1281):

Expand All @@ -9,3 +28,23 @@ dependencies (#1281):
Interaction between `@all` and optional libraries:

$ dune build @all

Reproduction case for a bug in dune < 2.4 where all libraries where
considered as optional:

$ cat >dune <<EOF
> (library
> (name foo)
> (public_name foo)
> (libraries lib_that_doesn't_exist))
> EOF

The following command should fail because the executable is not optional:

$ dune build @install
File "dune", line 4, characters 12-34:
4 | (libraries lib_that_doesn't_exist))
^^^^^^^^^^^^^^^^^^^^^^
Error: Library "lib_that_doesn't_exist" not found.
Hint: try: dune external-lib-deps --missing @install
[1]
1 change: 0 additions & 1 deletion test/blackbox-tests/test-cases/optional/x.ml

This file was deleted.