Skip to content
Draft
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
23 changes: 14 additions & 9 deletions src/dune_rules/ml_sources.ml
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,25 @@ let find_origin (t : t) ~libs path =
| origins -> raise_module_conflict_error origins ~module_path:path)
;;

let modules_and_obj_dir t ~libs ~for_ =
match
match for_ with
| Library lib_id -> Lib_id.Local.Map.find t.modules.libraries lib_id
| Exe { first_exe } -> String.Map.find t.modules.executables first_exe
| Melange { target } -> String.Map.find t.modules.melange_emits target
with
| Some (Library _, modules, obj_dir) ->
let* () =
let find_and_validate_modules t ~libs ~for_ =
(match for_ with
| Library lib_id -> Lib_id.Local.Map.find t.modules.libraries lib_id
| Exe { first_exe } -> String.Map.find t.modules.executables first_exe
| Melange { target } -> String.Map.find t.modules.melange_emits target)
|> Memo.Option.map ~f:(fun (origin, modules, obj_dir) ->
let+ () =
Modules.fold_user_written modules ~init:[] ~f:(fun m acc -> Module.path m :: acc)
|> Memo.List.iter ~f:(fun module_path ->
let+ (_origin : Origin.t option) = find_origin t ~libs module_path in
())
in
origin, modules, obj_dir)
;;

let modules_and_obj_dir t ~libs ~for_ =
find_and_validate_modules t ~libs ~for_
>>= function
| Some (Library _, modules, obj_dir) ->
(match
Path.Build.Map.find_exn t.modules.libraries_by_obj_dir (Obj_dir.obj_dir obj_dir)
with
Expand Down
69 changes: 69 additions & 0 deletions test/blackbox-tests/test-cases/overlapping-modules.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
When executables have overlapping modules we should tell the user this is the
case.

$ cat > dune-project <<EOF
> (lang dune 3.21)
> EOF

$ cat > dune <<EOF
> (executable
> (name baz))
> (executable
> (name bar))
> EOF
$ cat > baz.ml
$ cat > bar.ml

Currently this check is missing for overlapping executable(s) stanzas.

$ dune build @check
File "dune", line 1, characters 0-0:
Error: Module "Baz" is used in several stanzas:
- dune:1
- dune:3
To fix this error, you must specify an explicit "modules" field in every
library, executable, and executables stanzas in this dune file. Note that
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.
[1]

Overlapping executable and library:

$ cat > dune <<EOF
> (executable
> (name baz))
> (library
> (name bar))
> EOF

$ dune build @check
File "dune", line 1, characters 0-0:
Error: Module "Baz" is used in several stanzas:
- dune:1
- dune:3
To fix this error, you must specify an explicit "modules" field in every
library, executable, and executables stanzas in this dune file. Note that
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.
[1]

Overlapping libraries:

$ cat > dune <<EOF
> (library
> (name baz))
> (library
> (name bar))
> EOF

$ dune build @check
File "dune", line 1, characters 0-0:
Error: Module "Baz" is used in several stanzas:
- dune:1
- dune:3
To fix this error, you must specify an explicit "modules" field in every
library, executable, and executables stanzas in this dune file. Note that
each module cannot appear in more than one "modules" field - it must belong
to a single library or executable.
[1]

Loading