11(* lib/dune_ai_context.ml
22 This module provides functionality to parse Dune stanza files
33 (bin/dune, lib/dune, test/dune) and extract the list of library dependencies.
4- It then prints the dependencies, searches for the corresponding .cmi files
5- in the OPAM_SWITCH_PREFIX/lib directory, and prints the paths of any found
6- .cmi files .
4+ It then prints each vendor library name, and for each library prints the
5+ paths of any corresponding .cmi files found under the OPAM_SWITCH_PREFIX/lib
6+ directory .
77
88 Missing Dune files are ignored, so the code works for projects that only
99 have a lib, only have a bin, or have additional test stanzas.
@@ -77,9 +77,9 @@ let rec find_cmi_files (dir : string) (target : string) : string list =
7777
7878(* * [print_vendor_dependencies ()] parses the project's Dune files (bin/dune,
7979 lib/dune, test/dune), extracts the library dependencies, deduplicates them,
80- prints each dependency, then looks for the corresponding .cmi files in the
81- OPAM_SWITCH_PREFIX/lib directory and prints any found paths. Missing files
82- are silently ignored . *)
80+ and for each dependency prints the library name followed by any found .cmi
81+ file paths (one per line). If no .cmi file is found for a library, only the
82+ library name is printed . *)
8383let print_vendor_dependencies () =
8484 let dune_files = [ " bin/dune" ; " lib/dune" ; " test/dune" ] in
8585 let deps =
@@ -91,15 +91,19 @@ let print_vendor_dependencies () =
9191 [] dune_files
9292 in
9393 let uniq_deps = dedup deps in
94- (* Print the vendor library names *)
95- List. iter (printf " %s\n " ) uniq_deps;
96- (* Locate and print .cmi files if OPAM_SWITCH_PREFIX is set *)
9794 match Sys. getenv_opt " OPAM_SWITCH_PREFIX" with
98- | None -> ()
95+ | None ->
96+ (* No OPAM switch prefix; just print the library names *)
97+ List. iter (printf " %s\n " ) uniq_deps
9998 | Some prefix ->
10099 let lib_dir = Filename. concat prefix " lib" in
101100 List. iter
102101 (fun dep ->
103102 let cmi_paths = find_cmi_files lib_dir dep in
104- List. iter (fun p -> printf " CMI: %s\n " p) cmi_paths)
103+ if cmi_paths = [] then
104+ (* No .cmi found – print only the library name *)
105+ printf " %s\n " dep
106+ else
107+ (* Print one line per found .cmi, prefixed by the library name *)
108+ List. iter (fun p -> printf " %s %s\n " dep p) cmi_paths)
105109 uniq_deps
0 commit comments