Skip to content

Commit

Permalink
Make (public_name -) equivalent to no public name (#7576)
Browse files Browse the repository at this point in the history
* Make (public_name -) equivalent to no public name

Fixes #5852

This brings consistency with `(public_names)` in `(executables)`: a
plural stanza with only `-` in `(public_names)` installs nothing.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored May 2, 2023
1 parent 08aaf59 commit 23c2389
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ Unreleased
- Handle "Too many links" errors when using Dune cache on Windows. The fix in
3.7.0 for this same issue was not effective due to a typo. (#7472, @nojb)

- In `(executable)`, `(public_name -)` is now equivalent to no `(public_name)`.
This is consistent with how `(executables)` handles this field.
(#7576 , fixes #5852, @emillon)

3.7.0 (2023-02-17)
------------------

Expand Down
3 changes: 3 additions & 0 deletions doc/stanzas/executable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ files for executables. See `executables_implicit_empty_intf`_.
(section bin)
(files (<name>.exe as <public-name>)))
As a special case, ``(public_name -)`` is the same as if the field was
absent.

.. _shared-exe-fields:

- ``(package <package>)`` if there is a ``(public_name ...)`` field, this
Expand Down
14 changes: 9 additions & 5 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1103,17 +1103,19 @@ module Executables = struct

let has_public_name t = Option.is_some t.public

let public_name =
let public_name ~dash_is_none =
located string >>| fun (loc, s) ->
( loc
, match s with
| "-" -> None
| "-" -> if dash_is_none then None else Some s
| s -> Some s )

let multi_fields =
map_validate
(let+ names = field_o "names" (repeat1 (located string))
and+ pub_names = field_o "public_names" (repeat1 public_name) in
and+ pub_names =
field_o "public_names" (repeat1 (public_name ~dash_is_none:true))
in
(names, pub_names))
~f:(fun (names, public_names) ->
match (names, public_names) with
Expand All @@ -1130,10 +1132,12 @@ module Executables = struct
| names, public_names -> Ok (names, public_names))

let single_fields =
let* dune_syntax = Dune_lang.Syntax.get_exn Stanza.syntax in
let dash_is_none = dune_syntax >= (3, 8) in
let+ name = field_o "name" (located string)
and+ public_name = field_o "public_name" (located string) in
and+ public_name = field_o "public_name" (public_name ~dash_is_none) in
( Option.map name ~f:List.singleton
, Option.map public_name ~f:(fun (loc, s) -> [ (loc, Some s) ]) )
, Option.map public_name ~f:List.singleton )

let pluralize s ~multi = if multi then s ^ "s" else s

Expand Down
40 changes: 40 additions & 0 deletions test/blackbox-tests/test-cases/public-name-empty.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
This test is about the semantics of `(public_name -)`.

$ set_ver() {
> cat > dune-project << EOF
> (lang dune $1)
> (package
> (name e)
> (allow_empty))
> EOF
> }
$ cat > dune << EOF
> (executable
> (public_name -)
> (name e))
> EOF
$ touch e.ml

In 3.7, this declares a public name of "-":

$ set_ver 3.7
$ dune build @install
$ cat _build/default/e.install
lib: [
"_build/install/default/lib/e/META"
"_build/install/default/lib/e/dune-package"
]
bin: [
"_build/install/default/bin/-"
]

In 3.8, this is equivalent to no `(public_name)` field, consistently with what
happens with `(executables)`.

$ set_ver 3.8
$ dune build @install
$ cat _build/default/e.install
lib: [
"_build/install/default/lib/e/META"
"_build/install/default/lib/e/dune-package"
]

0 comments on commit 23c2389

Please sign in to comment.