From 314da72d3cc9a5835f406c5a892ddcafcafd6273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dimino?= Date: Tue, 16 Jan 2018 13:40:04 +0000 Subject: [PATCH] Better signature for Artifacts.file_of_lib (#418) --- src/artifacts.ml | 9 --------- src/artifacts.mli | 13 +++++-------- src/js_of_ocaml_rules.ml | 9 ++++----- src/super_context.ml | 22 ++++++++++++++++------ 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/artifacts.ml b/src/artifacts.ml index 02df3fd3..8c166400 100644 --- a/src/artifacts.ml +++ b/src/artifacts.ml @@ -100,12 +100,3 @@ let file_of_lib t ~from ~lib ~file = : Findlib.package); assert false } - -let file_of_lib t ~loc ~from name = - let lib, file = - match String.lsplit2 name ~on:':' with - | None -> - Loc.fail loc "invalid ${lib:...} form: %s" name - | Some x -> x - in - (lib, file_of_lib t ~from ~lib ~file) diff --git a/src/artifacts.mli b/src/artifacts.mli index f5447d42..fa4d525e 100644 --- a/src/artifacts.mli +++ b/src/artifacts.mli @@ -18,14 +18,11 @@ val binary -> string -> Action.Prog.t -(** [file_of_lib t ~from name] a named artifact that is looked up in the given library. - - [name] is expected to be of the form ":". Raises immediately if it is not - the case. Returns "" as well as the resolved artifact. -*) +(** [file_of_lib t ~from ~lib ~file] returns the path to a file in the directory of the + given library. *) val file_of_lib : t - -> loc:Loc.t -> from:Path.t - -> string - -> string * (Path.t, fail) result + -> lib:string + -> file:string + -> (Path.t, fail) result diff --git a/src/js_of_ocaml_rules.ml b/src/js_of_ocaml_rules.ml index b9fe89a8..245a091a 100644 --- a/src/js_of_ocaml_rules.ml +++ b/src/js_of_ocaml_rules.ml @@ -18,11 +18,10 @@ let in_build_dir ~ctx = List.fold_left ~init ~f:Path.relative let runtime_file ~sctx ~dir fname = - let _lib, file = - Artifacts.file_of_lib (SC.artifacts sctx) ~loc:Loc.none ~from:dir - (sprintf "js_of_ocaml-compiler:%s" fname) - in - match file with + match + Artifacts.file_of_lib (SC.artifacts sctx) ~from:dir + ~lib:"js_of_ocaml-compiler" ~file:fname + with | Error _ -> Arg_spec.Dyn (fun _ -> Utils.library_not_found ~context:(SC.context sctx).name ~hint:install_jsoo_hint diff --git a/src/super_context.ml b/src/super_context.ml index 2e1f1989..8600c0ac 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -534,6 +534,12 @@ module Action = struct Path.append host.context.build_dir exe | _ -> exe + let parse_lib_file ~loc s = + match String.lsplit2 s ~on:':' with + | None -> + Loc.fail loc "invalid ${lib:...} form: %s" s + | Some x -> x + let expand_step1 sctx ~dir ~dep_kind ~scope ~targets_written_by_user ~map_exe t = let acc = { failures = [] @@ -566,19 +572,23 @@ module Action = struct (* "findlib" for compatibility with Jane Street packages which are not yet updated to convert "findlib" to "lib" *) | Some (("lib"|"findlib"), s) -> begin - let lib_dep, res = - Artifacts.file_of_lib (artifacts sctx) ~loc ~from:dir s in + let lib_dep, file = parse_lib_file ~loc s in add_lib_dep acc lib_dep dep_kind; - match res with + match + Artifacts.file_of_lib (artifacts sctx) ~from:dir + ~lib:lib_dep ~file + with | Ok path -> static_dep_exp acc path | Error fail -> add_fail acc fail end | Some ("libexec" , s) -> begin let sctx = host_sctx sctx in - let lib_dep, res = - Artifacts.file_of_lib (artifacts sctx) ~loc ~from:dir s in + let lib_dep, file = parse_lib_file ~loc s in add_lib_dep acc lib_dep dep_kind; - match res with + match + Artifacts.file_of_lib (artifacts sctx) ~from:dir + ~lib:lib_dep ~file + with | Error fail -> add_fail acc fail | Ok path -> if not Sys.win32 || Filename.extension s = ".exe" then begin