Better signature for Artifacts.file_of_lib (#418)

This commit is contained in:
Jérémie Dimino 2018-01-16 13:40:04 +00:00 committed by GitHub
parent 49edf8ed65
commit 314da72d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 28 deletions

View File

@ -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)

View File

@ -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 "<lib>:<file>". Raises immediately if it is not
the case. Returns "<lib>" 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

View File

@ -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

View File

@ -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