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. *)
|
(* This interprets "rule" and "copy_files" stanzas. *)
|
||||||
let files = text_files ~dir:ctx_dir in
|
let files = text_files ~dir:ctx_dir in
|
||||||
let all_modules = modules_by_dir ~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 =
|
let merlins =
|
||||||
List.filter_map stanzas ~f:(fun stanza ->
|
List.filter_map stanzas ~f:(fun stanza ->
|
||||||
let dir = ctx_dir in
|
let dir = ctx_dir in
|
||||||
|
@ -1008,7 +1008,7 @@ module Gen(P : Install_rules.Params) = struct
|
||||||
in
|
in
|
||||||
Menhir_rules.gen_rules cctx m
|
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 =
|
let gen_rules ~dir components : Build_system.extra_sub_directories_to_keep =
|
||||||
(match components with
|
(match components with
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
open Import
|
open Import
|
||||||
|
|
||||||
type 'a t =
|
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 () =
|
let create ~dir_kind =
|
||||||
{ used = Module.Name.Map.empty
|
{ dir_kind
|
||||||
|
; used = Module.Name.Map.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
let acknowledge t part ~loc ~modules =
|
let acknowledge t part ~loc ~modules =
|
||||||
|
@ -28,23 +30,39 @@ let acknowledge t part ~loc ~modules =
|
||||||
|
|
||||||
let find t name = Option.map (Module.Name.Map.find t.used name) ~f:fst
|
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) ->
|
Module.Name.Map.iteri t.used ~f:(fun name (_, locs) ->
|
||||||
match locs with
|
match locs with
|
||||||
| [] | [_] -> ()
|
| [] | [_] -> ()
|
||||||
| loc :: _ ->
|
| loc :: _ ->
|
||||||
let loc = Loc.in_file loc.start.pos_fname in
|
let loc = Loc.in_file loc.start.pos_fname in
|
||||||
Loc.warn loc
|
match t.dir_kind with
|
||||||
"Module %a is used in several stanzas:@\n\
|
| Jbuild ->
|
||||||
@[<v>%a@]@\n\
|
Loc.warn loc
|
||||||
@[%a@]@\n\
|
"Module %a is used in several stanzas:@\n\
|
||||||
This warning will become an error in the future."
|
@[<v>%a@]@\n\
|
||||||
Module.Name.pp_quote name
|
@[%a@]@\n\
|
||||||
(Fmt.list (Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line))
|
This warning will become an error in the future."
|
||||||
locs
|
Module.Name.pp_quote name
|
||||||
Format.pp_print_text
|
(Fmt.list (Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line))
|
||||||
"To remove this warning, you must specify an explicit \"modules\" \
|
locs
|
||||||
field in every library, executable, and executables stanzas in \
|
Format.pp_print_text
|
||||||
this jbuild file. Note that each module cannot appear in more \
|
"To remove this warning, you must specify an explicit \"modules\" \
|
||||||
than one \"modules\" field - it must belong to a single library \
|
field in every library, executable, and executables stanzas in \
|
||||||
or executable.")
|
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
|
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]
|
(** [acknowledge t partition ~loc ~modules] registers the fact that [modules]
|
||||||
are associated with [loc].
|
are associated with [loc].
|
||||||
|
@ -22,6 +22,6 @@ val acknowledge
|
||||||
(** Find which partition a module is part of *)
|
(** Find which partition a module is part of *)
|
||||||
val find : 'a t -> Module.Name.t -> 'a option
|
val find : 'a t -> Module.Name.t -> 'a option
|
||||||
|
|
||||||
(** To be called after processing a directory. Emit warnings about
|
(** To be called after processing a directory. Emit errors or warnings
|
||||||
detected problems *)
|
about detected problems *)
|
||||||
val emit_warnings : _ t -> unit
|
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
|
$ dune exec ./test.exe --debug-dep --display short --root jbuild
|
||||||
File "dune", line 1, characters 0-0:
|
Entering directory 'jbuild'
|
||||||
|
File "jbuild", line 1, characters 0-0:
|
||||||
Warning: Module "Lib" is used in several stanzas:
|
Warning: Module "Lib" is used in several stanzas:
|
||||||
- dune:6
|
- jbuild:6
|
||||||
- dune:2
|
- jbuild:2
|
||||||
To remove this warning, you must specify an explicit "modules" field in every
|
To remove this warning, you must specify an explicit "modules" field in every
|
||||||
library, executable, and executables stanzas in this jbuild file. Note that
|
library, executable, and executables stanzas in this jbuild file. Note that
|
||||||
each module cannot appear in more than one "modules" field - it must belong
|
each module cannot appear in more than one "modules" field - it must belong
|
||||||
to a single library or executable.
|
to a single library or executable.
|
||||||
This warning will become an error in the future.
|
This warning will become an error in the future.
|
||||||
ocamldep lib.ml.d
|
Multiple rules generated for _build/default/lib$ext_obj:
|
||||||
ocamlc .lib.objs/lib.{cmi,cmo,cmt}
|
- <internal location>
|
||||||
ocamlopt .lib.objs/lib.{cmx,o}
|
- <internal location>
|
||||||
ocamlopt lib.{a,cmxa}
|
[1]
|
||||||
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
|
|
||||||
|
|
||||||
$ dune build src/a.cma --debug-dep --display short
|
$ dune build src/a.cma --debug-dep --display short --root jbuild
|
||||||
File "src/dune", line 1, characters 0-0:
|
Entering directory 'jbuild'
|
||||||
|
File "src/jbuild", line 1, characters 0-0:
|
||||||
Warning: Module "X" is used in several stanzas:
|
Warning: Module "X" is used in several stanzas:
|
||||||
- src/dune:2
|
- src/jbuild:2
|
||||||
- src/dune:1
|
- src/jbuild:1
|
||||||
To remove this warning, you must specify an explicit "modules" field in every
|
To remove this warning, you must specify an explicit "modules" field in every
|
||||||
library, executable, and executables stanzas in this jbuild file. Note that
|
library, executable, and executables stanzas in this jbuild file. Note that
|
||||||
each module cannot appear in more than one "modules" field - it must belong
|
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.{cmi,cmo,cmt}
|
||||||
ocamlc src/.a.objs/a__X.{cmi,cmo,cmt}
|
ocamlc src/.a.objs/a__X.{cmi,cmo,cmt}
|
||||||
ocamlc src/a.cma
|
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