Skip to content

Commit f58b334

Browse files
committed
feat(ocamldep): add read_immediate_deps_raw_of for raw module names (issue #4572)
Add a new function `read_immediate_deps_raw_of` to the ocamldep module that returns raw module names (as Module_name.Set.t) from ocamldep output, without resolving them to Module.t values. This function will be used to determine which external library modules a module actually references, enabling finer-grained dependency tracking where modules are only recompiled when libraries they actually use change. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
1 parent de8c864 commit f58b334

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/dune_rules/ocamldep.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,18 @@ let read_immediate_deps_of ~obj_dir ~modules ~ml_kind ~for_ unit =
199199
|> parse_module_names ~dir:(Obj_dir.dir obj_dir) ~unit ~modules)
200200
|> Action_builder.memoize (Path.Build.to_string ocamldep_output)
201201
;;
202+
203+
let read_immediate_deps_raw_of ~obj_dir ~ml_kind ~for_ unit =
204+
match Module.source ~ml_kind unit with
205+
| None -> Action_builder.return Module_name.Set.empty
206+
| Some source ->
207+
let ocamldep_output =
208+
Obj_dir.Module.dep obj_dir ~for_ (Immediate (unit, ml_kind)) |> Option.value_exn
209+
in
210+
Action_builder.lines_of (Path.build ocamldep_output)
211+
|> Action_builder.map ~f:(fun lines ->
212+
parse_deps_exn ~file:(Module.File.path source) lines
213+
|> List.map ~f:Module_name.of_checked_string
214+
|> Module_name.Set.of_list)
215+
|> Action_builder.memoize (Path.Build.to_string ocamldep_output ^ "-raw")
216+
;;

src/dune_rules/ocamldep.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,15 @@ val read_immediate_deps_of
3232
-> for_:Compilation_mode.t
3333
-> Module.t
3434
-> Module.t list Action_builder.t
35+
36+
(** [read_immediate_deps_raw_of ~obj_dir ~ml_kind ~for_ unit] returns the raw
37+
module names (unresolved) from ocamldep output for the file with kind
38+
[ml_kind] of the module [unit]. This includes ALL module references, both
39+
intra-stanza and external library modules. If there is no such file with
40+
kind [ml_kind], an empty set is returned. *)
41+
val read_immediate_deps_raw_of
42+
: obj_dir:Path.Build.t Obj_dir.t
43+
-> ml_kind:Ml_kind.t
44+
-> for_:Compilation_mode.t
45+
-> Module.t
46+
-> Module_name.Set.t Action_builder.t

0 commit comments

Comments
 (0)