From 603279534704e8142357c2bd52f2891f8e6b635a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Tue, 16 Oct 2018 09:24:20 +0200 Subject: [PATCH 1/2] js_of_ocaml: look for runtime in the same dir as executable if ocamlfind pkg unavailable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- src/js_of_ocaml_rules.ml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/js_of_ocaml_rules.ml b/src/js_of_ocaml_rules.ml index 305bf7cd5c0..699fc44526e 100644 --- a/src/js_of_ocaml_rules.ml +++ b/src/js_of_ocaml_rules.ml @@ -19,24 +19,31 @@ let install_jsoo_hint = "try: opam install js_of_ocaml-compiler" let in_build_dir ~ctx args = Path.L.relative ctx.Context.build_dir (".js" :: args) -let runtime_file ~sctx file = +let jsoo ~dir sctx = + SC.resolve_program sctx ~dir ~loc:None ~hint:install_jsoo_hint + "js_of_ocaml" + +let runtime_file ~dir ~sctx file = match Artifacts.file_of_lib (SC.artifacts sctx) ~loc:Loc.none ~lib:(Lib_name.of_string_exn ~loc:None "js_of_ocaml-compiler") ~file with | Error _ -> - Arg_spec.Dyn (fun _ -> - Utils.library_not_found ~context:(SC.context sctx).name - ~hint:install_jsoo_hint - "js_of_ocaml-compiler") + begin match jsoo ~dir sctx with + | Ok path when Path.exists (Path.relative path file) -> + Arg_spec.Dep path + | _ -> + Arg_spec.Dyn (fun _ -> + Utils.library_not_found ~context:(SC.context sctx).name + ~hint:install_jsoo_hint + "js_of_ocaml-compiler") + end | Ok f -> Arg_spec.Dep f let js_of_ocaml_rule sctx ~dir ~flags ~spec ~target = - let jsoo = - SC.resolve_program sctx ~dir ~loc:None ~hint:install_jsoo_hint - "js_of_ocaml" in - let runtime = runtime_file ~sctx "runtime.js" in + let jsoo = jsoo ~dir sctx in + let runtime = runtime_file ~dir ~sctx "runtime.js" in Build.run ~dir jsoo [ Arg_spec.Dyn flags From 79327692f9d737f2373cd989e2c71df635b59b9e Mon Sep 17 00:00:00 2001 From: nojebar Date: Tue, 18 Dec 2018 23:45:33 +0100 Subject: [PATCH 2/2] Check if the runtime file exists inside the build arrow Signed-off-by: nojebar --- src/js_of_ocaml_rules.ml | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/js_of_ocaml_rules.ml b/src/js_of_ocaml_rules.ml index 699fc44526e..f78256190ac 100644 --- a/src/js_of_ocaml_rules.ml +++ b/src/js_of_ocaml_rules.ml @@ -30,25 +30,33 @@ let runtime_file ~dir ~sctx file = ~lib:(Lib_name.of_string_exn ~loc:None "js_of_ocaml-compiler") ~file with | Error _ -> - begin match jsoo ~dir sctx with - | Ok path when Path.exists (Path.relative path file) -> - Arg_spec.Dep path - | _ -> - Arg_spec.Dyn (fun _ -> + let fail = + let fail () = Utils.library_not_found ~context:(SC.context sctx).name ~hint:install_jsoo_hint - "js_of_ocaml-compiler") + "js_of_ocaml-compiler" + in + Build.fail {fail} + in + begin match jsoo ~dir sctx with + | Ok path -> + let path = Path.relative (Path.parent_exn path) file in + Build.if_file_exists path ~then_:(Build.arr (fun _ -> path)) ~else_:fail + | _ -> + fail end - | Ok f -> Arg_spec.Dep f + | Ok f -> + Build.arr (fun _ -> f) let js_of_ocaml_rule sctx ~dir ~flags ~spec ~target = let jsoo = jsoo ~dir sctx in - let runtime = runtime_file ~dir ~sctx "runtime.js" in + (Build.arr (fun x -> x) &&& runtime_file ~dir ~sctx "runtime.js") >>> Build.run ~dir jsoo - [ Arg_spec.Dyn flags + [ Arg_spec.Dyn (fun (x, _) -> flags x) ; Arg_spec.A "-o"; Target target - ; Arg_spec.A "--no-runtime"; runtime + ; Arg_spec.A "--no-runtime" + ; Arg_spec.Dyn (fun (_, runtime) -> Dep runtime) ; spec ]