Skip to content

Commit

Permalink
Indexing rules: correctly declare indexes dependencies (ocaml#10623)
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
  • Loading branch information
voodoos authored and anmonteiro committed Nov 17, 2024
1 parent d5cf0c8 commit 3630a84
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/changes/10623.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Correctly declare dependencies of indexes so that they are rebuilt when
needed. (#10623, @voodoos)
20 changes: 19 additions & 1 deletion src/dune_rules/merlin/ocaml_index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ let ocaml_index sctx ~dir =
Super_context.resolve_program ~loc:None ~dir sctx "ocaml-index"
;;

let index_file_name = "cctx.ocaml-index"

let index_path_in_obj_dir obj_dir =
let dir = Obj_dir.obj_dir obj_dir in
Path.Build.relative dir "cctx.ocaml-index"
Path.Build.relative dir index_file_name
;;

let project_index ~build_dir = Path.Build.relative build_dir "project.ocaml-index"
Expand Down Expand Up @@ -36,12 +38,27 @@ let cctx_rules cctx =
in
Lib_flags.L.include_flags non_compile_libs (Lib_mode.Ocaml Byte)
in
(* Indexing depends (recursively) on [required_compile] libs:
- These libs's cmt files should be built before indexing starts
- If these libs are rebuilt a re-indexation is needed *)
let other_indexes_deps =
let open Resolve.Memo.O in
let+ requires_compile = Compilation_context.requires_compile cctx in
let deps =
List.filter_map requires_compile ~f:(fun l ->
match Lib.info l |> Lib_info.obj_dir |> Obj_dir.obj_dir with
| In_build_dir dir -> Some (Path.relative (Path.build dir) index_file_name)
| _ -> None)
in
Command.Args.Hidden_deps (Dep.Set.of_files deps)
in
let context_dir =
Compilation_context.context cctx
|> Context.name
|> Context_name.build_dir
|> Path.build
in
(* Indexation also depends on the current stanza's modules *)
let modules_deps =
let cm_kind = Lib_mode.Cm_kind.(Ocaml Cmi) in
(* We only index occurrences in user-written modules *)
Expand All @@ -64,6 +81,7 @@ let cctx_rules cctx =
; Target fn
; Deps modules_deps
; Dyn (Resolve.Memo.read additional_libs)
; Dyn (Resolve.Memo.read other_indexes_deps)
]
in
Super_context.add_rule sctx ~dir aggregate
Expand Down
8 changes: 7 additions & 1 deletion test/blackbox-tests/utils/ocaml_index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Common = struct
end

module Aggregate = struct
let from_files _ _ output_file _ _ () = touch output_file
let from_files _ _ output_file _ _ _ () = touch output_file

let root =
let doc = "if provided all locations will be appended to that path" in
Expand All @@ -51,13 +51,19 @@ module Aggregate = struct
Arg.(value & flag & info [ "store-shapes" ] ~doc)
;;

let no_cmt =
let doc = "" in
Arg.(value & flag & info [ "no-cmt-load-path" ] ~doc)
;;

let term =
Term.(
const from_files
$ store_shapes
$ root
$ Common.output_file
$ build_path
$ no_cmt
$ files
$ Common.with_log)
;;
Expand Down

0 comments on commit 3630a84

Please sign in to comment.