Turn warning about modules being used multiple times into errors
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
This commit is contained in:
parent
de26077d28
commit
5d6e919f04
|
@ -960,7 +960,7 @@ module Gen(P : Install_rules.Params) = struct
|
|||
(* This interprets "rule" and "copy_files" stanzas. *)
|
||||
let files = text_files ~dir:ctx_dir in
|
||||
let all_modules = modules_by_dir ~dir:ctx_dir in
|
||||
let modules_partitioner = Modules_partitioner.create () in
|
||||
let modules_partitioner = Modules_partitioner.create ~dir_kind:kind in
|
||||
let merlins =
|
||||
List.filter_map stanzas ~f:(fun stanza ->
|
||||
let dir = ctx_dir in
|
||||
|
@ -1008,7 +1008,7 @@ module Gen(P : Install_rules.Params) = struct
|
|||
in
|
||||
Menhir_rules.gen_rules cctx m
|
||||
| _ -> ());
|
||||
Modules_partitioner.emit_warnings modules_partitioner
|
||||
Modules_partitioner.emit_errors modules_partitioner
|
||||
|
||||
let gen_rules ~dir components : Build_system.extra_sub_directories_to_keep =
|
||||
(match components with
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
open Import
|
||||
|
||||
type 'a t =
|
||||
{ mutable used : ('a * Loc.t list) Module.Name.Map.t
|
||||
{ dir_kind : File_tree.Dune_file.Kind.t
|
||||
; mutable used : ('a * Loc.t list) Module.Name.Map.t
|
||||
}
|
||||
|
||||
let create () =
|
||||
{ used = Module.Name.Map.empty
|
||||
let create ~dir_kind =
|
||||
{ dir_kind
|
||||
; used = Module.Name.Map.empty
|
||||
}
|
||||
|
||||
let acknowledge t part ~loc ~modules =
|
||||
|
@ -28,12 +30,14 @@ let acknowledge t part ~loc ~modules =
|
|||
|
||||
let find t name = Option.map (Module.Name.Map.find t.used name) ~f:fst
|
||||
|
||||
let emit_warnings t =
|
||||
let emit_errors t =
|
||||
Module.Name.Map.iteri t.used ~f:(fun name (_, locs) ->
|
||||
match locs with
|
||||
| [] | [_] -> ()
|
||||
| loc :: _ ->
|
||||
let loc = Loc.in_file loc.start.pos_fname in
|
||||
match t.dir_kind with
|
||||
| Jbuild ->
|
||||
Loc.warn loc
|
||||
"Module %a is used in several stanzas:@\n\
|
||||
@[<v>%a@]@\n\
|
||||
|
@ -47,4 +51,18 @@ let emit_warnings t =
|
|||
field in every library, executable, and executables stanzas in \
|
||||
this jbuild file. Note that each module cannot appear in more \
|
||||
than one \"modules\" field - it must belong to a single library \
|
||||
or executable."
|
||||
| Dune ->
|
||||
Loc.fail loc
|
||||
"Module %a is used in several stanzas:@\n\
|
||||
@[<v>%a@]@\n\
|
||||
@[%a@]"
|
||||
Module.Name.pp_quote name
|
||||
(Fmt.list (Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line))
|
||||
locs
|
||||
Format.pp_print_text
|
||||
"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.")
|
||||
|
|
|
@ -4,7 +4,7 @@ open! Stdune
|
|||
|
||||
type 'a t
|
||||
|
||||
val create : unit -> 'a t
|
||||
val create : dir_kind:File_tree.Dune_file.Kind.t -> 'a t
|
||||
|
||||
(** [acknowledge t partition ~loc ~modules] registers the fact that [modules]
|
||||
are associated with [loc].
|
||||
|
@ -22,6 +22,6 @@ val acknowledge
|
|||
(** Find which partition a module is part of *)
|
||||
val find : 'a t -> Module.Name.t -> 'a option
|
||||
|
||||
(** To be called after processing a directory. Emit warnings about
|
||||
detected problems *)
|
||||
val emit_warnings : _ t -> unit
|
||||
(** To be called after processing a directory. Emit errors or warnings
|
||||
about detected problems *)
|
||||
val emit_errors : _ t -> unit
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
(library
|
||||
((name lib)
|
||||
(modules (:standard \ test))))
|
||||
|
||||
(executable
|
||||
((name test)
|
||||
(libraries (lib))))
|
|
@ -0,0 +1 @@
|
|||
let run () = print_endline "foo bar"
|
|
@ -0,0 +1,2 @@
|
|||
(library ((name a)))
|
||||
(library ((name b)))
|
|
@ -0,0 +1 @@
|
|||
let x = 42
|
|
@ -0,0 +1 @@
|
|||
Lib.run ();;
|
|
@ -1,30 +1,25 @@
|
|||
$ dune exec ./test.exe --debug-dep --display short
|
||||
File "dune", line 1, characters 0-0:
|
||||
$ dune exec ./test.exe --debug-dep --display short --root jbuild
|
||||
Entering directory 'jbuild'
|
||||
File "jbuild", line 1, characters 0-0:
|
||||
Warning: Module "Lib" is used in several stanzas:
|
||||
- dune:6
|
||||
- dune:2
|
||||
- jbuild:6
|
||||
- jbuild:2
|
||||
To remove this warning, you must specify an explicit "modules" field in every
|
||||
library, executable, and executables stanzas in this jbuild file. Note that
|
||||
each module cannot appear in more than one "modules" field - it must belong
|
||||
to a single library or executable.
|
||||
This warning will become an error in the future.
|
||||
ocamldep lib.ml.d
|
||||
ocamlc .lib.objs/lib.{cmi,cmo,cmt}
|
||||
ocamlopt .lib.objs/lib.{cmx,o}
|
||||
ocamlopt lib.{a,cmxa}
|
||||
ocamldep test.ml.d
|
||||
ocamlc .test.eobjs/lib.{cmi,cmo,cmt}
|
||||
ocamlopt .test.eobjs/lib.{cmx,o}
|
||||
ocamlc .test.eobjs/test.{cmi,cmo,cmt}
|
||||
ocamlopt .test.eobjs/test.{cmx,o}
|
||||
ocamlopt test.exe
|
||||
foo bar
|
||||
Multiple rules generated for _build/default/lib$ext_obj:
|
||||
- <internal location>
|
||||
- <internal location>
|
||||
[1]
|
||||
|
||||
$ dune build src/a.cma --debug-dep --display short
|
||||
File "src/dune", line 1, characters 0-0:
|
||||
$ dune build src/a.cma --debug-dep --display short --root jbuild
|
||||
Entering directory 'jbuild'
|
||||
File "src/jbuild", line 1, characters 0-0:
|
||||
Warning: Module "X" is used in several stanzas:
|
||||
- src/dune:2
|
||||
- src/dune:1
|
||||
- src/jbuild:2
|
||||
- src/jbuild:1
|
||||
To remove this warning, you must specify an explicit "modules" field in every
|
||||
library, executable, and executables stanzas in this jbuild file. Note that
|
||||
each module cannot appear in more than one "modules" field - it must belong
|
||||
|
@ -34,3 +29,27 @@
|
|||
ocamlc src/.a.objs/a.{cmi,cmo,cmt}
|
||||
ocamlc src/.a.objs/a__X.{cmi,cmo,cmt}
|
||||
ocamlc src/a.cma
|
||||
|
||||
$ dune exec ./test.exe --debug-dep --display short --root dune
|
||||
Entering directory 'dune'
|
||||
File "dune", line 1, characters 0-0:
|
||||
Error: Module "Lib" is used in several stanzas:
|
||||
- dune:6
|
||||
- dune:2
|
||||
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]
|
||||
|
||||
$ dune build src/a.cma --debug-dep --display short --root dune
|
||||
Entering directory 'dune'
|
||||
File "src/dune", line 1, characters 0-0:
|
||||
Error: Module "X" is used in several stanzas:
|
||||
- src/dune:2
|
||||
- src/dune:1
|
||||
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…
Reference in New Issue