diff --git a/src/build.ml b/src/build.ml index 60a5fb1e..78ae7c9d 100644 --- a/src/build.ml +++ b/src/build.ml @@ -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 } diff --git a/src/build.mli b/src/build.mli index 7a73a3c1..188bc29c 100644 --- a/src/build.mli +++ b/src/build.mli @@ -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. *) diff --git a/src/super_context.ml b/src/super_context.ml index 0387b65b..1e31c7bb 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -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