-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect when a module is used by several stanzas (#532)
- print a warning - don't generate several rules for the .d files - Added tests for multiple rules for .ml.d
- Loading branch information
1 parent
19f1c6f
commit 2a531c5
Showing
14 changed files
with
173 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
open Import | ||
|
||
type t = | ||
{ dir : Path.t | ||
; all_modules : Module.t String_map.t | ||
; mutable used : Loc.t list String_map.t | ||
} | ||
|
||
let create ~dir ~all_modules = | ||
{ dir | ||
; all_modules | ||
; used = String_map.empty | ||
} | ||
|
||
let acknowledge t ~loc ~modules = | ||
let already_used = | ||
String_map.merge modules t.used ~f:(fun _name x l -> | ||
Option.some_if (Option.is_some x && Option.is_some l) ()) | ||
|> String_map.keys | ||
|> String_set.of_list | ||
in | ||
t.used <- | ||
String_map.merge modules t.used ~f:(fun _name x l -> | ||
match x with | ||
| None -> l | ||
| Some _ -> Some (loc :: Option.value l ~default:[])); | ||
already_used | ||
|
||
let emit_warnings t = | ||
let loc = | ||
Utils.jbuild_file_in ~dir:t.dir | ||
|> Path.to_string | ||
|> Loc.in_file | ||
in | ||
String_map.iter t.used ~f:(fun ~key:name ~data:locs -> | ||
if List.length locs > 1 then | ||
Loc.warn loc | ||
"Module %S is used in several stanzas:@\n\ | ||
@[<v>%a@]@\n\ | ||
This will become an error in the future." | ||
name | ||
(Fmt.list (Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line)) | ||
locs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(** Checks modules partitioning inside a directory *) | ||
|
||
open Import | ||
|
||
type t | ||
|
||
val create | ||
: dir:Path.t | ||
-> all_modules:Module.t String_map.t | ||
-> t | ||
|
||
(** [acknowledge t ~loc ~modules] registers the fact that [modules] | ||
are associated with [loc]. | ||
Returns the set of modules that are already used at another | ||
location. | ||
*) | ||
val acknowledge | ||
: t | ||
-> loc:Loc.t | ||
-> modules:Module.t String_map.t | ||
-> String_set.t | ||
|
||
(** To be called after processing a directory. Emit warnings about | ||
detected problems *) | ||
val emit_warnings : t -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/blackbox-tests/test-cases/ocamldep-multi-stanzas/run.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
$ $JBUILDER exec ./test.exe -j1 --debug-dep --display short --root . | ||
File "jbuild", line 1, characters 0-0: | ||
Warning: Module "Lib" is used in several stanzas: | ||
- jbuild:8 | ||
- jbuild:4 | ||
This will become an error in the future. | ||
Multiple rules generated for _build/default/lib.o: | ||
- <internal location> | ||
- <internal location> | ||
[1] | ||
|
||
$ $JBUILDER build src/a.cma -j1 --debug-dep --display short --root . | ||
File "src/jbuild", line 1, characters 0-0: | ||
Warning: Module "X" is used in several stanzas: | ||
- src/jbuild:4 | ||
- src/jbuild:3 | ||
This will become an error in the future. | ||
ocamldep src/x.ml.d | ||
ocamlc src/.a.objs/a.{cmi,cmo,cmt} | ||
ocamlc src/.a.objs/a__X.{cmi,cmo,cmt} | ||
ocamlc src/a.cma |
4 changes: 4 additions & 0 deletions
4
test/blackbox-tests/test-cases/ocamldep-multi-stanzas/src/jbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(jbuild_version 1) | ||
|
||
(library ((name a))) | ||
(library ((name b))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x = 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters