parent
804822ef68
commit
05581ed8bc
12
src/build.ml
12
src/build.ml
|
@ -17,6 +17,11 @@ type lib_dep_kind =
|
|||
| Required
|
||||
type lib_deps = lib_dep_kind String_map.t
|
||||
|
||||
let merge_lib_dep_kind a b =
|
||||
match a, b with
|
||||
| Optional, Optional -> Optional
|
||||
| _ -> Required
|
||||
|
||||
module Repr = struct
|
||||
type ('a, 'b) t =
|
||||
| Arr : ('a -> 'b) -> ('a, 'b) t
|
||||
|
@ -44,10 +49,7 @@ let merge_lib_deps a b =
|
|||
match a, b with
|
||||
| None, None -> None
|
||||
| x, None | None, x -> x
|
||||
| Some a, Some b ->
|
||||
Some (match a, b with
|
||||
| Optional, Optional -> Optional
|
||||
| _ -> Required))
|
||||
| Some a, Some b -> Some (merge_lib_dep_kind a b))
|
||||
|
||||
let arr f = Arr f
|
||||
let return x = Arr (fun () -> x)
|
||||
|
@ -65,7 +67,7 @@ let record_lib_deps ~dir ~kind lib_deps =
|
|||
List.filter_map c.Jbuild_types.Lib_dep.lits ~f:(function
|
||||
| Pos d -> Some (d, Optional)
|
||||
| Neg _ -> None)))
|
||||
|> String_map.of_alist_exn)
|
||||
|> String_map.of_alist_reduce ~f:merge_lib_dep_kind)
|
||||
|
||||
module O = struct
|
||||
let ( >>> ) a b =
|
||||
|
|
|
@ -118,6 +118,7 @@ module Map = struct
|
|||
val of_alist : (key * 'a) list -> ('a t, key * 'a * 'a) result
|
||||
val of_alist_exn : (key * 'a) list -> 'a t
|
||||
val of_alist_multi : (key * 'a) list -> 'a list t
|
||||
val of_alist_reduce : (key * 'a) list -> f:('a -> 'a -> 'a) -> 'a t
|
||||
val keys : 'a t -> key list
|
||||
val values : 'a t -> 'a list
|
||||
end
|
||||
|
@ -156,6 +157,12 @@ module Map = struct
|
|||
else
|
||||
Ok (add t ~key ~data))
|
||||
|
||||
let of_alist_reduce l ~f =
|
||||
List.fold_left l ~init:empty ~f:(fun acc (key, data) ->
|
||||
match find key acc with
|
||||
| None -> add acc ~key ~data
|
||||
| Some x -> add acc ~key ~data:(f x data))
|
||||
|
||||
let of_alist_exn l =
|
||||
match of_alist l with
|
||||
| Ok x -> x
|
||||
|
|
Loading…
Reference in New Issue