From 5d6e919f0451d00e40e1705dc7cfba87f1cc6a0b Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Tue, 12 Jun 2018 18:57:14 +0100 Subject: [PATCH] Turn warning about modules being used multiple times into errors Signed-off-by: Jeremie Dimino --- src/gen_rules.ml | 4 +- src/modules_partitioner.ml | 54 ++++++++++++------ src/modules_partitioner.mli | 8 +-- .../ocamldep-multi-stanzas/{ => dune}/dune | 0 .../{ => dune}/dune-project | 0 .../ocamldep-multi-stanzas/{ => dune}/lib.ml | 0 .../{ => dune}/src/dune | 0 .../{ => dune}/src/x.ml | 0 .../ocamldep-multi-stanzas/{ => dune}/test.ml | 0 .../ocamldep-multi-stanzas/jbuild/jbuild | 7 +++ .../ocamldep-multi-stanzas/jbuild/lib.ml | 1 + .../ocamldep-multi-stanzas/jbuild/src/jbuild | 2 + .../ocamldep-multi-stanzas/jbuild/src/x.ml | 1 + .../ocamldep-multi-stanzas/jbuild/test.ml | 1 + .../test-cases/ocamldep-multi-stanzas/run.t | 57 ++++++++++++------- 15 files changed, 92 insertions(+), 43 deletions(-) rename test/blackbox-tests/test-cases/ocamldep-multi-stanzas/{ => dune}/dune (100%) rename test/blackbox-tests/test-cases/ocamldep-multi-stanzas/{ => dune}/dune-project (100%) rename test/blackbox-tests/test-cases/ocamldep-multi-stanzas/{ => dune}/lib.ml (100%) rename test/blackbox-tests/test-cases/ocamldep-multi-stanzas/{ => dune}/src/dune (100%) rename test/blackbox-tests/test-cases/ocamldep-multi-stanzas/{ => dune}/src/x.ml (100%) rename test/blackbox-tests/test-cases/ocamldep-multi-stanzas/{ => dune}/test.ml (100%) create mode 100644 test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/jbuild create mode 100644 test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/lib.ml create mode 100644 test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/jbuild create mode 100644 test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/x.ml create mode 100644 test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/test.ml diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 56b7fcff..8806b885 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -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 diff --git a/src/modules_partitioner.ml b/src/modules_partitioner.ml index c0ce4802..e944c31a 100644 --- a/src/modules_partitioner.ml +++ b/src/modules_partitioner.ml @@ -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,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 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 - Loc.warn loc - "Module %a is used in several stanzas:@\n\ - @[%a@]@\n\ - @[%a@]@\n\ - This warning will become an error in the future." - Module.Name.pp_quote name - (Fmt.list (Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line)) - locs - Format.pp_print_text - "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.") + match t.dir_kind with + | Jbuild -> + Loc.warn loc + "Module %a is used in several stanzas:@\n\ + @[%a@]@\n\ + @[%a@]@\n\ + This warning will become an error in the future." + Module.Name.pp_quote name + (Fmt.list (Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line)) + locs + Format.pp_print_text + "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." + | Dune -> + Loc.fail loc + "Module %a is used in several stanzas:@\n\ + @[%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.") diff --git a/src/modules_partitioner.mli b/src/modules_partitioner.mli index ae05eb15..af3cdae8 100644 --- a/src/modules_partitioner.mli +++ b/src/modules_partitioner.mli @@ -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 diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/dune similarity index 100% rename from test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune rename to test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/dune diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune-project b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/dune-project similarity index 100% rename from test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune-project rename to test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/dune-project diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/lib.ml b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/lib.ml similarity index 100% rename from test/blackbox-tests/test-cases/ocamldep-multi-stanzas/lib.ml rename to test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/lib.ml diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/src/dune b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/src/dune similarity index 100% rename from test/blackbox-tests/test-cases/ocamldep-multi-stanzas/src/dune rename to test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/src/dune diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/src/x.ml b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/src/x.ml similarity index 100% rename from test/blackbox-tests/test-cases/ocamldep-multi-stanzas/src/x.ml rename to test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/src/x.ml diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/test.ml b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/test.ml similarity index 100% rename from test/blackbox-tests/test-cases/ocamldep-multi-stanzas/test.ml rename to test/blackbox-tests/test-cases/ocamldep-multi-stanzas/dune/test.ml diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/jbuild b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/jbuild new file mode 100644 index 00000000..50ed67e5 --- /dev/null +++ b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/jbuild @@ -0,0 +1,7 @@ +(library + ((name lib) + (modules (:standard \ test)))) + +(executable + ((name test) + (libraries (lib)))) diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/lib.ml b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/lib.ml new file mode 100644 index 00000000..ccd9b7a1 --- /dev/null +++ b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/lib.ml @@ -0,0 +1 @@ +let run () = print_endline "foo bar" diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/jbuild b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/jbuild new file mode 100644 index 00000000..d0a1b57d --- /dev/null +++ b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/jbuild @@ -0,0 +1,2 @@ +(library ((name a))) +(library ((name b))) diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/x.ml b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/x.ml new file mode 100644 index 00000000..7fecab12 --- /dev/null +++ b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/src/x.ml @@ -0,0 +1 @@ +let x = 42 diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/test.ml b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/test.ml new file mode 100644 index 00000000..058934e5 --- /dev/null +++ b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/jbuild/test.ml @@ -0,0 +1 @@ +Lib.run ();; diff --git a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/run.t b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/run.t index 7e59b5e9..8da97ce4 100644 --- a/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/run.t +++ b/test/blackbox-tests/test-cases/ocamldep-multi-stanzas/run.t @@ -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: + - + - + [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]