Change the type of Build.of_result and add Build.of_result_map
This commit is contained in:
parent
997d541c50
commit
09ff33951b
11
src/build.ml
11
src/build.ml
|
@ -172,9 +172,14 @@ let fail ?targets x =
|
||||||
| None -> Fail x
|
| None -> Fail x
|
||||||
| Some l -> Targets l >>> Fail x
|
| Some l -> Targets l >>> Fail x
|
||||||
|
|
||||||
let of_result = function
|
let of_result ?targets = function
|
||||||
| Ok x -> return x
|
| Ok x -> x
|
||||||
| Error e -> fail { fail = fun () -> raise e }
|
| 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 =
|
let memoize name t =
|
||||||
Memo { name; t; state = Unevaluated }
|
Memo { name; t; state = Unevaluated }
|
||||||
|
|
|
@ -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
|
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
|
(** Always fail when executed. We pass a function rather than an
|
||||||
backtrace *)
|
exception to get a proper backtrace *)
|
||||||
val fail : ?targets:Path.t list -> fail -> (_, _) t
|
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
|
(** [memoize name t] is an arrow that behaves like [t] except that its
|
||||||
result is computed only once. *)
|
result is computed only once. *)
|
||||||
|
|
|
@ -272,7 +272,10 @@ module Libs = struct
|
||||||
|
|
||||||
let requires t ~dir ~has_dot_merlin compile_info =
|
let requires t ~dir ~has_dot_merlin compile_info =
|
||||||
add_select_rules t ~dir (Lib.Compile.resolved_selects 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 =
|
let requires =
|
||||||
Build.record_lib_deps (Lib.Compile.user_written_deps compile_info)
|
Build.record_lib_deps (Lib.Compile.user_written_deps compile_info)
|
||||||
~kind:(if Lib.Compile.optional compile_info then
|
~kind:(if Lib.Compile.optional compile_info then
|
||||||
|
|
Loading…
Reference in New Issue