Build information library for monopam tools.
0
fork

Configure Feed

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

monopam-info: drop unused origin / is_virtual_implementation

Found via [prune clean]. The [type origin = Local | Opam] tag plus the
[origin] and [is_virtual_implementation] queries had no callers — neither
in production nor tests. Removing them cascaded into the [pkg_origin]
hashtable and the [register/registered] scaffolding inside [scan_pkg_dir]
that only existed to populate it.

+7 -59
+6 -36
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 - 12 10 type t = { 13 11 pkg_libs : (string, Dune.Lib_index.t) Hashtbl.t; 14 - pkg_origin : (string, origin) Hashtbl.t; 15 12 lib_to_pkg : (string, string) Hashtbl.t; 16 13 } 17 14 ··· 60 57 Hashtbl.replace t.pkg_libs pkg i; 61 58 i 62 59 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 60 + let scan_pkg_dir t pkg pkg_dir = 71 61 match load_eio_path Eio.Path.(pkg_dir / "dune-package") with 72 62 | Some content -> 73 - register (); 74 63 let i = pkg_index t pkg in 75 64 ignore (Dune.Lib_index.add_dune_package i content); 76 65 List.iter ··· 80 69 match cmi_modules_in_dir pkg_dir with 81 70 | [] -> () 82 71 | modules -> 83 - register (); 84 72 let i = pkg_index t pkg in 85 73 ignore (Dune.Lib_index.add_cmi_modules i ~pkg ~modules); 86 74 Hashtbl.replace t.lib_to_pkg pkg pkg) 87 75 88 76 let build ~fs ~monorepo = 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 = 77 + let t = { pkg_libs = Hashtbl.create 256; lib_to_pkg = Hashtbl.create 512 } in 78 + let scan root = 97 79 let entries = try Eio.Path.read_dir root with Eio.Io _ -> [] in 98 - List.iter 99 - (fun pkg -> scan_pkg_dir ~origin t pkg Eio.Path.(root / pkg)) 100 - entries 80 + List.iter (fun pkg -> scan_pkg_dir t pkg Eio.Path.(root / pkg)) entries 101 81 in 102 82 let opam_lib = 103 83 Eio.Path.(fs / Fpath.to_string Fpath.(monorepo / "_opam" / "lib")) ··· 108 88 / Fpath.to_string 109 89 Fpath.(monorepo / "_build" / "install" / "default" / "lib")) 110 90 in 111 - scan ~origin:Opam opam_lib; 112 - scan ~origin:Local build_lib; 91 + scan opam_lib; 92 + scan build_lib; 113 93 t 114 94 115 - let origin t pkg = Hashtbl.find_opt t.pkg_origin pkg 116 - 117 95 let packages t = 118 96 Hashtbl.fold (fun k _ acc -> k :: acc) t.pkg_libs [] 119 97 |> List.sort String.compare ··· 133 111 match Hashtbl.find_opt t.pkg_libs pkg with 134 112 | None -> [] 135 113 | 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)
+1 -23
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 - 31 21 type t 32 22 (** Snapshot of the libraries available in a monorepo's opam switch. *) 33 23 ··· 35 25 (** [build ~fs ~monorepo] scans both [<monorepo>/_opam/lib/] and 36 26 [<monorepo>/_build/install/default/lib/] and aggregates everything into a 37 27 single index. The build-install root is scanned second so locally built 38 - packages override opam-installed ones, and their {!origin} comes out as 39 - [Local]. *) 28 + packages override opam-installed ones. *) 40 29 41 30 (** {1 Querying by opam package} *) 42 31 43 32 val packages : t -> string list 44 33 (** [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. *) 49 34 50 35 val libraries : t -> string -> string list 51 36 (** [libraries t pkg] is the sorted list of dune library names provided by opam ··· 61 46 (** [modules t lib] is the list of top-level module names exposed by dune 62 47 library [lib], or [[]] if [lib] is unknown. Module names are capitalised, in 63 48 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. *)