Build information library for monopam tools.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "monopam-info: drop unused origin / is_virtual_implementation"

This reverts commit aec06451d4aeff9262c902a4a270756055e5689f.

+59 -7
+36 -6
lib/index/monopam_info_index.ml
··· 7 7 - [lib_to_pkg]: reverse index for fast [package_of] lookups, since 8 8 callers (e.g. monopam.lint dead-lib check) only have a library name. *) 9 9 10 + type origin = Local | Opam 11 + 10 12 type t = { 11 13 pkg_libs : (string, Dune.Lib_index.t) Hashtbl.t; 14 + pkg_origin : (string, origin) Hashtbl.t; 12 15 lib_to_pkg : (string, string) Hashtbl.t; 13 16 } 14 17 ··· 57 60 Hashtbl.replace t.pkg_libs pkg i; 58 61 i 59 62 60 - let scan_pkg_dir t pkg pkg_dir = 63 + let scan_pkg_dir ~origin t pkg pkg_dir = 64 + let registered = ref false in 65 + let register () = 66 + if not !registered then begin 67 + Hashtbl.replace t.pkg_origin pkg origin; 68 + registered := true 69 + end 70 + in 61 71 match load_eio_path Eio.Path.(pkg_dir / "dune-package") with 62 72 | Some content -> 73 + register (); 63 74 let i = pkg_index t pkg in 64 75 ignore (Dune.Lib_index.add_dune_package i content); 65 76 List.iter ··· 69 80 match cmi_modules_in_dir pkg_dir with 70 81 | [] -> () 71 82 | modules -> 83 + register (); 72 84 let i = pkg_index t pkg in 73 85 ignore (Dune.Lib_index.add_cmi_modules i ~pkg ~modules); 74 86 Hashtbl.replace t.lib_to_pkg pkg pkg) 75 87 76 88 let build ~fs ~monorepo = 77 - let t = { pkg_libs = Hashtbl.create 256; lib_to_pkg = Hashtbl.create 512 } in 78 - let scan root = 89 + let t = 90 + { 91 + pkg_libs = Hashtbl.create 256; 92 + pkg_origin = Hashtbl.create 256; 93 + lib_to_pkg = Hashtbl.create 512; 94 + } 95 + in 96 + let scan ~origin root = 79 97 let entries = try Eio.Path.read_dir root with Eio.Io _ -> [] in 80 - List.iter (fun pkg -> scan_pkg_dir t pkg Eio.Path.(root / pkg)) entries 98 + List.iter 99 + (fun pkg -> scan_pkg_dir ~origin t pkg Eio.Path.(root / pkg)) 100 + entries 81 101 in 82 102 let opam_lib = 83 103 Eio.Path.(fs / Fpath.to_string Fpath.(monorepo / "_opam" / "lib")) ··· 88 108 / Fpath.to_string 89 109 Fpath.(monorepo / "_build" / "install" / "default" / "lib")) 90 110 in 91 - scan opam_lib; 92 - scan build_lib; 111 + scan ~origin:Opam opam_lib; 112 + scan ~origin:Local build_lib; 93 113 t 94 114 115 + let origin t pkg = Hashtbl.find_opt t.pkg_origin pkg 116 + 95 117 let packages t = 96 118 Hashtbl.fold (fun k _ acc -> k :: acc) t.pkg_libs [] 97 119 |> List.sort String.compare ··· 111 133 match Hashtbl.find_opt t.pkg_libs pkg with 112 134 | None -> [] 113 135 | Some i -> Dune.Lib_index.modules i lib) 136 + 137 + let is_virtual_implementation t lib = 138 + match package_of t lib with 139 + | None -> false 140 + | Some pkg -> ( 141 + match Hashtbl.find_opt t.pkg_libs pkg with 142 + | None -> false 143 + | Some i -> Dune.Lib_index.is_virtual_implementation i lib)
+23 -1
lib/index/monopam_info_index.mli
··· 18 18 recover the [pkg.subpkg] tree, but that needs the [Meta] module to not 19 19 collide with [compiler-libs.Meta] in mdx-built executables. *) 20 20 21 + type origin = 22 + | Local 23 + | Opam 24 + (** Where a package was discovered: 25 + - [Local]: built locally and installed under 26 + [<monorepo>/_build/install/default/lib/]. Takes precedence over an 27 + opam-installed copy of the same package. 28 + - [Opam]: only present in [<monorepo>/_opam/lib/], i.e. an external 29 + opam dependency. *) 30 + 21 31 type t 22 32 (** Snapshot of the libraries available in a monorepo's opam switch. *) 23 33 ··· 25 35 (** [build ~fs ~monorepo] scans both [<monorepo>/_opam/lib/] and 26 36 [<monorepo>/_build/install/default/lib/] and aggregates everything into a 27 37 single index. The build-install root is scanned second so locally built 28 - packages override opam-installed ones. *) 38 + packages override opam-installed ones, and their {!origin} comes out as 39 + [Local]. *) 29 40 30 41 (** {1 Querying by opam package} *) 31 42 32 43 val packages : t -> string list 33 44 (** [packages t] is the sorted list of opam package names known to [t]. *) 45 + 46 + val origin : t -> string -> origin option 47 + (** [origin t pkg] is [Some Local] / [Some Opam] for known packages, or [None] 48 + if [pkg] is not in the index. *) 34 49 35 50 val libraries : t -> string -> string list 36 51 (** [libraries t pkg] is the sorted list of dune library names provided by opam ··· 46 61 (** [modules t lib] is the list of top-level module names exposed by dune 47 62 library [lib], or [[]] if [lib] is unknown. Module names are capitalised, in 48 63 the form [Dune.Package.Library.t.modules] returns. *) 64 + 65 + val is_virtual_implementation : t -> string -> bool 66 + (** [is_virtual_implementation t lib] is [true] iff [lib] has an 67 + [(implements X)] entry in its [dune-package]. Such libraries are link-time 68 + live even when none of their modules appear in source. Always [false] for 69 + libraries discovered via META, since findlib has no notion of virtual 70 + libraries. *)