Merge pull request #1048 from rgrinberg/jsoo-cctx
Refactor jsoo rules to use Compilation_context.t
This commit is contained in:
commit
a13325e389
|
@ -63,6 +63,8 @@ let includes t = t.includes
|
||||||
let preprocessing t = t.preprocessing
|
let preprocessing t = t.preprocessing
|
||||||
let no_keep_locs t = t.no_keep_locs
|
let no_keep_locs t = t.no_keep_locs
|
||||||
|
|
||||||
|
let context t = Super_context.context t.super_context
|
||||||
|
|
||||||
let create ~super_context ~scope ~dir ?(dir_kind=File_tree.Dune_file.Kind.Dune)
|
let create ~super_context ~scope ~dir ?(dir_kind=File_tree.Dune_file.Kind.Dune)
|
||||||
?(obj_dir=dir) ~modules ?alias_module ?lib_interface_module ~flags
|
?(obj_dir=dir) ~modules ?alias_module ?lib_interface_module ~flags
|
||||||
~requires ?(preprocessing=Preprocessing.dummy) ?(no_keep_locs=false) () =
|
~requires ?(preprocessing=Preprocessing.dummy) ?(no_keep_locs=false) () =
|
||||||
|
|
|
@ -6,7 +6,7 @@ open Import
|
||||||
|
|
||||||
A compilation context contains all the necessary information to
|
A compilation context contains all the necessary information to
|
||||||
preprocess and compile OCaml source files. Exactly one compilation
|
preprocess and compile OCaml source files. Exactly one compilation
|
||||||
context is associated to each library, executable and executbales
|
context is associated to each library, executable and executables
|
||||||
stanza.
|
stanza.
|
||||||
*)
|
*)
|
||||||
type t
|
type t
|
||||||
|
@ -32,6 +32,7 @@ val create
|
||||||
val for_alias_module : t -> t
|
val for_alias_module : t -> t
|
||||||
|
|
||||||
val super_context : t -> Super_context.t
|
val super_context : t -> Super_context.t
|
||||||
|
val context : t -> Context.t
|
||||||
val scope : t -> Scope.t
|
val scope : t -> Scope.t
|
||||||
val dir : t -> Path.t
|
val dir : t -> Path.t
|
||||||
val dir_kind : t -> File_tree.Dune_file.Kind.t
|
val dir_kind : t -> File_tree.Dune_file.Kind.t
|
||||||
|
|
|
@ -157,7 +157,7 @@ let link_exe
|
||||||
]);
|
]);
|
||||||
if linkage.ext = ".bc" then
|
if linkage.ext = ".bc" then
|
||||||
let rules =
|
let rules =
|
||||||
Js_of_ocaml_rules.build_exe sctx ~dir ~js_of_ocaml ~src:exe ~requires
|
Js_of_ocaml_rules.build_exe cctx ~js_of_ocaml ~src:exe
|
||||||
in
|
in
|
||||||
let cm_and_flags =
|
let cm_and_flags =
|
||||||
Build.fanout
|
Build.fanout
|
||||||
|
|
|
@ -342,7 +342,7 @@ module Gen(P : Install_rules.Params) = struct
|
||||||
SC.add_rules sctx (
|
SC.add_rules sctx (
|
||||||
let src = Library.archive lib ~dir ~ext:(Mode.compiled_lib_ext Mode.Byte) in
|
let src = Library.archive lib ~dir ~ext:(Mode.compiled_lib_ext Mode.Byte) in
|
||||||
let target = Path.extend_basename src ~suffix:".js" in
|
let target = Path.extend_basename src ~suffix:".js" in
|
||||||
Js_of_ocaml_rules.build_cm sctx ~scope ~dir
|
Js_of_ocaml_rules.build_cm cctx
|
||||||
~js_of_ocaml:lib.buildable.js_of_ocaml ~src ~target);
|
~js_of_ocaml:lib.buildable.js_of_ocaml ~src ~target);
|
||||||
|
|
||||||
if ctx.natdynlink_supported then
|
if ctx.natdynlink_supported then
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
let build_cm _ ~scope:_ ~dir:_ ~js_of_ocaml:_ ~src:_ ~target:_ = []
|
let build_cm _ ~js_of_ocaml:_ ~src:_ ~target:_ = []
|
||||||
|
|
||||||
let build_exe _ ~dir:_ ~js_of_ocaml:_ ~src:_ ~requires:_ = []
|
let build_exe _ ~js_of_ocaml:_ ~src:_ = []
|
||||||
|
|
||||||
let setup_separate_compilation_rules _ _ = ()
|
let setup_separate_compilation_rules _ _ = ()
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,10 @@ let runtime_file ~sctx fname =
|
||||||
"js_of_ocaml-compiler")
|
"js_of_ocaml-compiler")
|
||||||
| Ok f -> Arg_spec.Dep f
|
| Ok f -> Arg_spec.Dep f
|
||||||
|
|
||||||
let js_of_ocaml_rule ~sctx ~dir ~flags ~spec ~target =
|
let js_of_ocaml_rule sctx ~dir ~flags ~spec ~target =
|
||||||
let jsoo = SC.resolve_program sctx ~hint:install_jsoo_hint "js_of_ocaml" in
|
let jsoo = SC.resolve_program sctx ~hint:install_jsoo_hint "js_of_ocaml" in
|
||||||
let runtime = runtime_file ~sctx "runtime.js" in
|
let runtime = runtime_file ~sctx "runtime.js" in
|
||||||
Build.run ~context:(SC.context sctx) ~dir
|
Build.run ~context:(Super_context.context sctx) ~dir
|
||||||
jsoo
|
jsoo
|
||||||
[ Arg_spec.Dyn flags
|
[ Arg_spec.Dyn flags
|
||||||
; Arg_spec.A "-o"; Target target
|
; Arg_spec.A "-o"; Target target
|
||||||
|
@ -43,36 +43,42 @@ let js_of_ocaml_rule ~sctx ~dir ~flags ~spec ~target =
|
||||||
; spec
|
; spec
|
||||||
]
|
]
|
||||||
|
|
||||||
let standalone_runtime_rule ~sctx ~dir ~javascript_files ~target ~requires =
|
let standalone_runtime_rule cc ~javascript_files ~target =
|
||||||
let spec =
|
let spec =
|
||||||
Arg_spec.S
|
Arg_spec.S
|
||||||
[ Arg_spec.of_result_map requires ~f:(fun libs ->
|
[ Arg_spec.of_result_map (Compilation_context.requires cc) ~f:(fun libs ->
|
||||||
Arg_spec.Deps (Lib.L.jsoo_runtime_files libs))
|
Arg_spec.Deps (Lib.L.jsoo_runtime_files libs))
|
||||||
; Arg_spec.Deps javascript_files
|
; Arg_spec.Deps javascript_files
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
Build.arr (fun (cm_files, flags) -> (cm_files, "--runtime-only" :: flags))
|
Build.arr (fun (cm_files, flags) -> (cm_files, "--runtime-only" :: flags))
|
||||||
>>>
|
>>>
|
||||||
js_of_ocaml_rule ~sctx ~dir ~flags:(fun (_,flags) -> As flags) ~target ~spec
|
js_of_ocaml_rule
|
||||||
|
(Compilation_context.super_context cc)
|
||||||
|
~dir:(Compilation_context.dir cc)
|
||||||
|
~flags:(fun (_,flags) -> As flags) ~target ~spec
|
||||||
|
|
||||||
let exe_rule ~sctx ~dir ~javascript_files ~src ~target ~requires =
|
let exe_rule cc ~javascript_files ~src ~target =
|
||||||
|
let dir = Compilation_context.dir cc in
|
||||||
|
let sctx = Compilation_context.super_context cc in
|
||||||
let spec =
|
let spec =
|
||||||
Arg_spec.S
|
Arg_spec.S
|
||||||
[ Arg_spec.of_result_map requires ~f:(fun libs ->
|
[ Arg_spec.of_result_map (Compilation_context.requires cc)
|
||||||
Arg_spec.Deps (Lib.L.jsoo_runtime_files libs))
|
~f:(fun libs -> Arg_spec.Deps (Lib.L.jsoo_runtime_files libs))
|
||||||
; Arg_spec.Deps javascript_files
|
; Arg_spec.Deps javascript_files
|
||||||
; Arg_spec.Dep src
|
; Arg_spec.Dep src
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
js_of_ocaml_rule ~sctx ~dir ~flags:(fun (_,flags) -> As flags) ~spec ~target
|
js_of_ocaml_rule sctx ~dir ~flags:(fun (_,flags) -> As flags) ~spec ~target
|
||||||
|
|
||||||
let jsoo_archives lib =
|
let jsoo_archives lib =
|
||||||
List.map (Lib.archives lib).byte ~f:(Path.extend_basename ~suffix:".js")
|
List.map (Lib.archives lib).byte ~f:(Path.extend_basename ~suffix:".js")
|
||||||
|
|
||||||
let link_rule ~sctx ~dir ~runtime ~target ~requires =
|
let link_rule cc ~runtime ~target =
|
||||||
let ctx = SC.context sctx in
|
let sctx = Compilation_context.super_context cc in
|
||||||
|
let ctx = Compilation_context.context cc in
|
||||||
let get_all (cm, _) =
|
let get_all (cm, _) =
|
||||||
Arg_spec.of_result_map requires ~f:(fun libs ->
|
Arg_spec.of_result_map (Compilation_context.requires cc) ~f:(fun libs ->
|
||||||
let all_libs =
|
let all_libs =
|
||||||
List.concat_map libs ~f:(fun (lib : Lib.t) ->
|
List.concat_map libs ~f:(fun (lib : Lib.t) ->
|
||||||
let jsoo_archives = jsoo_archives lib in
|
let jsoo_archives = jsoo_archives lib in
|
||||||
|
@ -93,7 +99,7 @@ let link_rule ~sctx ~dir ~runtime ~target ~requires =
|
||||||
Arg_spec.Deps (List.concat [all_libs;all_other_modules]))
|
Arg_spec.Deps (List.concat [all_libs;all_other_modules]))
|
||||||
in
|
in
|
||||||
let jsoo_link = SC.resolve_program sctx ~hint:install_jsoo_hint "jsoo_link" in
|
let jsoo_link = SC.resolve_program sctx ~hint:install_jsoo_hint "jsoo_link" in
|
||||||
Build.run ~context:(SC.context sctx) ~dir
|
Build.run ~context:ctx ~dir:(Compilation_context.dir cc)
|
||||||
jsoo_link
|
jsoo_link
|
||||||
[ Arg_spec.A "-o"; Target target
|
[ Arg_spec.A "-o"; Target target
|
||||||
; Arg_spec.Dep runtime
|
; Arg_spec.Dep runtime
|
||||||
|
@ -101,19 +107,22 @@ let link_rule ~sctx ~dir ~runtime ~target ~requires =
|
||||||
; Arg_spec.Dyn get_all
|
; Arg_spec.Dyn get_all
|
||||||
]
|
]
|
||||||
|
|
||||||
let build_cm sctx ~scope ~dir ~(js_of_ocaml:Jbuild.Js_of_ocaml.t) ~src ~target =
|
let build_cm cc ~(js_of_ocaml:Jbuild.Js_of_ocaml.t) ~src ~target =
|
||||||
|
let sctx = Compilation_context.super_context cc in
|
||||||
|
let dir = Compilation_context.dir cc in
|
||||||
if separate_compilation_enabled sctx
|
if separate_compilation_enabled sctx
|
||||||
then
|
then
|
||||||
let itarget = Path.extend_basename src ~suffix:".js" in
|
let itarget = Path.extend_basename src ~suffix:".js" in
|
||||||
let spec = Arg_spec.Dep src in
|
let spec = Arg_spec.Dep src in
|
||||||
let flags =
|
let flags =
|
||||||
|
let scope = Compilation_context.scope cc in
|
||||||
SC.expand_and_eval_set sctx ~scope ~dir js_of_ocaml.flags
|
SC.expand_and_eval_set sctx ~scope ~dir js_of_ocaml.flags
|
||||||
~standard:(Build.return (standard sctx))
|
~standard:(Build.return (standard sctx))
|
||||||
in
|
in
|
||||||
[ flags
|
[ flags
|
||||||
>>>
|
>>>
|
||||||
js_of_ocaml_rule ~sctx ~dir ~flags:(fun flags ->
|
js_of_ocaml_rule sctx ~dir ~flags:(fun flags -> As flags) ~spec ~target:itarget
|
||||||
As flags) ~spec ~target:itarget ]
|
]
|
||||||
@ (if target = itarget then
|
@ (if target = itarget then
|
||||||
[]
|
[]
|
||||||
else
|
else
|
||||||
|
@ -149,20 +158,19 @@ let setup_separate_compilation_rules sctx components =
|
||||||
SC.add_rule sctx
|
SC.add_rule sctx
|
||||||
(Build.return (standard sctx)
|
(Build.return (standard sctx)
|
||||||
>>>
|
>>>
|
||||||
js_of_ocaml_rule ~sctx ~dir ~flags:(fun flags ->
|
js_of_ocaml_rule sctx ~dir ~flags:(fun flags ->
|
||||||
As flags) ~spec ~target)
|
As flags) ~spec ~target))
|
||||||
)
|
|
||||||
|
|
||||||
let build_exe sctx ~dir ~js_of_ocaml ~src ~requires =
|
let build_exe cc ~js_of_ocaml ~src =
|
||||||
let {Jbuild.Js_of_ocaml.javascript_files; _} = js_of_ocaml in
|
let {Jbuild.Js_of_ocaml.javascript_files; _} = js_of_ocaml in
|
||||||
let javascript_files = List.map javascript_files ~f:(Path.relative dir) in
|
let javascript_files =
|
||||||
|
List.map javascript_files ~f:(Path.relative (Compilation_context.dir cc)) in
|
||||||
let mk_target ext = Path.extend_basename src ~suffix:ext in
|
let mk_target ext = Path.extend_basename src ~suffix:ext in
|
||||||
let target = mk_target ".js" in
|
let target = mk_target ".js" in
|
||||||
let standalone_runtime = mk_target ".runtime.js" in
|
let standalone_runtime = mk_target ".runtime.js" in
|
||||||
if separate_compilation_enabled sctx then
|
if separate_compilation_enabled (Compilation_context.super_context cc) then
|
||||||
[ link_rule ~sctx ~dir ~runtime:standalone_runtime ~target ~requires
|
[ link_rule cc ~runtime:standalone_runtime ~target
|
||||||
; standalone_runtime_rule ~sctx ~dir ~javascript_files
|
; standalone_runtime_rule cc ~javascript_files ~target:standalone_runtime
|
||||||
~target:standalone_runtime ~requires
|
|
||||||
]
|
]
|
||||||
else
|
else
|
||||||
[ exe_rule ~sctx ~dir ~javascript_files ~src ~target ~requires ]
|
[ exe_rule cc ~javascript_files ~src ~target ]
|
||||||
|
|
|
@ -4,20 +4,16 @@ open Import
|
||||||
open Jbuild
|
open Jbuild
|
||||||
|
|
||||||
val build_cm
|
val build_cm
|
||||||
: Super_context.t
|
: Compilation_context.t
|
||||||
-> scope:Scope.t
|
|
||||||
-> dir:Path.t
|
|
||||||
-> js_of_ocaml:Js_of_ocaml.t
|
-> js_of_ocaml:Js_of_ocaml.t
|
||||||
-> src:Path.t
|
-> src:Path.t
|
||||||
-> target:Path.t
|
-> target:Path.t
|
||||||
-> (unit, Action.t) Build.t list
|
-> (unit, Action.t) Build.t list
|
||||||
|
|
||||||
val build_exe
|
val build_exe
|
||||||
: Super_context.t
|
: Compilation_context.t
|
||||||
-> dir:Path.t
|
|
||||||
-> js_of_ocaml:Js_of_ocaml.t
|
-> js_of_ocaml:Js_of_ocaml.t
|
||||||
-> src:Path.t
|
-> src:Path.t
|
||||||
-> requires:Lib.t list Or_exn.t
|
|
||||||
-> (Path.t list * string list, Action.t) Build.t list
|
-> (Path.t list * string list, Action.t) Build.t list
|
||||||
|
|
||||||
val setup_separate_compilation_rules
|
val setup_separate_compilation_rules
|
||||||
|
|
|
@ -129,7 +129,6 @@ let build_module ?sandbox ?js_of_ocaml ?dynlink ~dep_graphs cctx m =
|
||||||
Option.iter js_of_ocaml ~f:(fun js_of_ocaml ->
|
Option.iter js_of_ocaml ~f:(fun js_of_ocaml ->
|
||||||
(* Build *.cmo.js *)
|
(* Build *.cmo.js *)
|
||||||
let sctx = CC.super_context cctx in
|
let sctx = CC.super_context cctx in
|
||||||
let scope = CC.scope cctx in
|
|
||||||
let dir = CC.dir cctx in
|
let dir = CC.dir cctx in
|
||||||
let obj_dir = CC.obj_dir cctx in
|
let obj_dir = CC.obj_dir cctx in
|
||||||
let src = Module.cm_file_unsafe m ~obj_dir Cm_kind.Cmo in
|
let src = Module.cm_file_unsafe m ~obj_dir Cm_kind.Cmo in
|
||||||
|
@ -138,7 +137,7 @@ let build_module ?sandbox ?js_of_ocaml ?dynlink ~dep_graphs cctx m =
|
||||||
~suffix:".js"
|
~suffix:".js"
|
||||||
in
|
in
|
||||||
SC.add_rules sctx
|
SC.add_rules sctx
|
||||||
(Js_of_ocaml_rules.build_cm sctx ~scope ~dir ~js_of_ocaml ~src ~target))
|
(Js_of_ocaml_rules.build_cm cctx ~js_of_ocaml ~src ~target))
|
||||||
|
|
||||||
let build_modules ?sandbox ?js_of_ocaml ?dynlink ~dep_graphs cctx =
|
let build_modules ?sandbox ?js_of_ocaml ?dynlink ~dep_graphs cctx =
|
||||||
Module.Name.Map.iter
|
Module.Name.Map.iter
|
||||||
|
|
Loading…
Reference in New Issue