diff --git a/CHANGES.md b/CHANGES.md index 0c236840d01..e1b89129748 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) ------------------ diff --git a/doc/stanzas/executable.rst b/doc/stanzas/executable.rst index 2f39f2e3f1f..8edd42cccc0 100644 --- a/doc/stanzas/executable.rst +++ b/doc/stanzas/executable.rst @@ -54,6 +54,9 @@ files for executables. See `executables_implicit_empty_intf`_. (section bin) (files (.exe as ))) + As a special case, ``(public_name -)`` is the same as if the field was + absent. + .. _shared-exe-fields: - ``(package )`` if there is a ``(public_name ...)`` field, this diff --git a/src/dune_rules/dune_file.ml b/src/dune_rules/dune_file.ml index 4c9a5f31af8..3044a0489da 100644 --- a/src/dune_rules/dune_file.ml +++ b/src/dune_rules/dune_file.ml @@ -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 @@ -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 diff --git a/test/blackbox-tests/test-cases/public-name-empty.t b/test/blackbox-tests/test-cases/public-name-empty.t new file mode 100644 index 00000000000..85980df73fe --- /dev/null +++ b/test/blackbox-tests/test-cases/public-name-empty.t @@ -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" + ]