forked from ocurrent/opam-dune-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ml
28 lines (25 loc) · 1.09 KB
/
index.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Owner = Map.Make(String)
type t = OpamPackage.t Owner.t
(* Update the index to record that [changes] came from [pkg]. *)
let update_index t changes ~pkg =
OpamStd.String.Map.fold (fun file op acc ->
match op with
| OpamDirTrack.Added _ ->
begin match String.split_on_char '/' file with
| ["lib"; lib; "META"] -> Owner.add lib pkg acc
| _ -> acc
end
| _ -> acc
) changes t
let create () =
let root = OpamStateConfig.opamroot () in
ignore (OpamStateConfig.load_defaults ~lock_kind:`Lock_read root);
OpamGlobalState.with_ `Lock_none @@ fun gt ->
let switch = OpamStateConfig.get_switch () in
let installed = (OpamSwitchState.load_selections ~lock_kind:`Lock_read gt switch).sel_installed in
OpamPackage.Set.fold (fun pkg acc ->
let changes = OpamPath.Switch.changes gt.root switch (OpamPackage.name pkg) in
match OpamFile.Changes.read_opt changes with
| None -> Fmt.pr "WARNING: no .changes found for %S!@." (OpamPackage.to_string pkg); acc
| Some changes -> update_index acc changes ~pkg
) installed Owner.empty