Skip to content

Commit

Permalink
fix: improve message when foreign sources differ
Browse files Browse the repository at this point in the history
When executables with the same name have different `(foreign_stubs)`
attached, we would crash.

Fixes #10675

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Jun 28, 2024
1 parent 45dfef9 commit f3f15cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/dune_rules/foreign_sources.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,18 @@ let make stanzas ~(sources : Foreign.Sources.Unresolved.t) ~dune_version =
in
(* TODO: Make this more type-safe by switching to non-empty lists. *)
let executables =
String.Map.of_list_map_exn exes ~f:(fun (exes, m) ->
let first_exe = snd (Nonempty_list.hd exes.names) in
first_exe, m)
match
String.Map.of_list_map exes ~f:(fun (exes, m) ->
let first_exe = snd (Nonempty_list.hd exes.names) in
first_exe, m)
with
| Ok m -> m
| Error (exe_name, (exes1, _), _) ->
let loc = fst (Nonempty_list.hd exes1.names) in
User_error.raise
~loc
[ Pp.textf "Executables with same name %S use different foreign sources" exe_name
]
in
let libraries =
match Lib_name.Map.of_list_map libs ~f:(fun (lib, m) -> Library.best_name lib, m) with
Expand Down
10 changes: 6 additions & 4 deletions test/blackbox-tests/test-cases/github10675.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ stubs, dune should not crash. See #10675.
$ touch startup.c main.ml
$ dune build 2>&1 | head -n 3
Internal error, please report upstream including the contents of _build/log.
Description:
("Map.of_list_map_exn", { key = "main" })
$ dune build
File "dune", line 3, characters 7-11:
3 | (name main))
^^^^
Error: Executables with same name "main" use different foreign sources
[1]

0 comments on commit f3f15cc

Please sign in to comment.