Skip to content

Commit a5d8945

Browse files
rgrinbergAlizter
authored andcommitted
fix: root module should have no dependencies
The root module is generated and only depends on the entry modules of the libraries field. Signed-off-by: Rudi Grinberg <[email protected]>
1 parent ed7214c commit a5d8945

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

doc/changes/12227.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Don't run ocamldep to compute false dependencies on the `root_module`
2+
(#12227, @rgrinberg)

src/dune_rules/dep_rules.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ let rec deps_of
137137
~ml_kind
138138
(m : Modules.Sourced_module.t)
139139
=
140-
let is_alias =
140+
let is_alias_or_root =
141141
match m with
142142
| Impl_of_virtual_module _ -> false
143143
| Imported_from_vlib m | Normal m ->
144144
(match Module.kind m with
145-
| Alias _ -> true
145+
| Root | Alias _ -> true
146146
| _ -> false)
147147
in
148-
if is_alias
148+
if is_alias_or_root
149149
then Memo.return (Action_builder.return [])
150150
else (
151151
let skip_if_source_absent f sourced_module =
@@ -176,7 +176,7 @@ let has_single_file modules = Option.is_some @@ Modules.With_vlib.as_singleton m
176176

177177
let immediate_deps_of unit modules ~obj_dir ~ml_kind =
178178
match Module.kind unit with
179-
| Alias _ -> Action_builder.return []
179+
| Root | Alias _ -> Action_builder.return []
180180
| Wrapped_compat ->
181181
let interface_module =
182182
match Modules.With_vlib.lib_interface modules with

src/dune_rules/obj_dir.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ module Module = struct
618618
match (dep : Dep.t) with
619619
| Immediate (m, _) | Transitive (m, _) ->
620620
(match Module.kind m with
621-
| Module.Kind.Alias _ -> None
621+
| Module.Kind.Alias _ | Root -> None
622622
| _ ->
623623
let dir = obj_dir t in
624624
let name = Dep.basename dep in

src/dune_rules/ocamldep.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let parse_deps_exn =
109109
let transitive_deps =
110110
let transive_dep obj_dir m =
111111
(match Module.kind m with
112-
| Alias _ -> None
112+
| Root | Alias _ -> None
113113
| _ -> if Module.has m ~ml_kind:Intf then Some Ml_kind.Intf else Some Impl)
114114
|> Option.map ~f:(fun ml_kind ->
115115
Obj_dir.Module.dep obj_dir (Transitive (m, ml_kind))

test/blackbox-tests/test-cases/root-module/root-module-ocamldep.t

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ compilation unit.
2626
_build/default/.foo.objs/byte/foo__Root.cmi
2727
_build/default/.foo.objs/byte/foo__Root.cmo
2828
_build/default/.foo.objs/byte/foo__Root.cmt
29-
_build/default/.foo.objs/foo__Root.impl.all-deps
30-
_build/default/.foo.objs/foo__Root.impl.d
3129

3230
Not only is running ocamldep wasteful, but it can also lead to cycles:
3331

@@ -36,10 +34,3 @@ Not only is running ocamldep wasteful, but it can also lead to cycles:
3634
> EOF
3735

3836
$ dune build foo.cma
39-
Error: Dependency cycle between:
40-
_build/default/.foo.objs/foo__Bar.impl.all-deps
41-
-> _build/default/.foo.objs/foo__Root.impl.all-deps
42-
-> _build/default/.foo.objs/foo__Bar.impl.all-deps
43-
-> required by _build/default/.foo.objs/byte/foo__Bar.cmo
44-
-> required by _build/default/foo.cma
45-
[1]

0 commit comments

Comments
 (0)