Change the type of Build.of_result and add Build.of_result_map

This commit is contained in:
Jeremie Dimino 2018-03-01 20:16:16 +00:00
parent 997d541c50
commit 09ff33951b
3 changed files with 24 additions and 7 deletions

View File

@ -172,9 +172,14 @@ let fail ?targets x =
| None -> Fail x
| Some l -> Targets l >>> Fail x
let of_result = function
| Ok x -> return x
| Error e -> fail { fail = fun () -> raise e }
let of_result ?targets = function
| Ok x -> x
| Error e -> fail ?targets { fail = fun () -> raise e }
let of_result_map ?targets res ~f =
match res with
| Ok x -> f x
| Error e -> fail ?targets { fail = fun () -> raise e }
let memoize name t =
Memo { name; t; state = Unevaluated }

View File

@ -110,11 +110,20 @@ val if_file_exists : Path.t -> then_:('a, 'b) t -> else_:('a, 'b) t -> ('a, 'b)
*)
val file_exists_opt : Path.t -> ('a, 'b) t -> ('a, 'b option) t
(** Always fail when executed. We pass a function rather than an exception to get a proper
backtrace *)
(** Always fail when executed. We pass a function rather than an
exception to get a proper backtrace *)
val fail : ?targets:Path.t list -> fail -> (_, _) t
val of_result : ('a, exn) Result.t -> (unit, 'a) t
val of_result
: ?targets:Path.t list
-> (('a, 'b) t, exn) Result.t
-> ('a, 'b) t
val of_result_map
: ?targets:Path.t list
-> ('a, exn) Result.t
-> f:('a -> ('b, 'c) t)
-> ('b, 'c) t
(** [memoize name t] is an arrow that behaves like [t] except that its
result is computed only once. *)

View File

@ -272,7 +272,10 @@ module Libs = struct
let requires t ~dir ~has_dot_merlin compile_info =
add_select_rules t ~dir (Lib.Compile.resolved_selects compile_info);
let requires = Build.of_result (Lib.Compile.requires compile_info) in
let requires =
Build.of_result_map (Lib.Compile.requires compile_info)
~f:Build.return
in
let requires =
Build.record_lib_deps (Lib.Compile.user_written_deps compile_info)
~kind:(if Lib.Compile.optional compile_info then