diff --git a/doc/changes/10623.md b/doc/changes/10623.md new file mode 100644 index 000000000000..cdda785a1320 --- /dev/null +++ b/doc/changes/10623.md @@ -0,0 +1,2 @@ +- Correctly declare dependencies of indexes so that they are rebuilt when + needed. (#10623, @voodoos) diff --git a/src/dune_rules/merlin/ocaml_index.ml b/src/dune_rules/merlin/ocaml_index.ml index 58909d7ba18e..561f6a88099f 100644 --- a/src/dune_rules/merlin/ocaml_index.ml +++ b/src/dune_rules/merlin/ocaml_index.ml @@ -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" @@ -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 *) @@ -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 diff --git a/test/blackbox-tests/utils/ocaml_index.ml b/test/blackbox-tests/utils/ocaml_index.ml index 1c4507dc24d8..97448e7e0ea8 100644 --- a/test/blackbox-tests/utils/ocaml_index.ml +++ b/test/blackbox-tests/utils/ocaml_index.ml @@ -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 @@ -51,6 +51,11 @@ 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 @@ -58,6 +63,7 @@ module Aggregate = struct $ root $ Common.output_file $ build_path + $ no_cmt $ files $ Common.with_log) ;;