···117117 let findlib_init _ = ()
118118 let get_stdlib_dcs _uri = []
119119120120- let require () packages =
120120+ let require _ () packages =
121121 try
122122 let eff_packages =
123123 Findlib.package_deep_ancestors !Topfind.predicates packages
+3-3
idl/js_top_worker_client.ml
···6868module Wraw = Toplevel_api_gen.Make (Rpc_lwt.GenClient ())
69697070module W : sig
7171- type init_libs = Toplevel_api_gen.init_libs
7171+ type init_config = Toplevel_api_gen.init_config
7272 type err = Toplevel_api_gen.err
7373 type exec_result = Toplevel_api_gen.exec_result
74747575 val init :
7676 rpc ->
7777- Toplevel_api_gen.init_libs ->
7777+ Toplevel_api_gen.init_config ->
7878 (unit, Toplevel_api_gen.err) result Lwt.t
79798080 val setup :
···105105 string ->
106106 (string, Toplevel_api_gen.err) result Lwt.t
107107end = struct
108108- type init_libs = Toplevel_api_gen.init_libs
108108+ type init_config = Toplevel_api_gen.init_config
109109 type err = Toplevel_api_gen.err
110110 type exec_result = Toplevel_api_gen.exec_result
111111
+2-2
idl/js_top_worker_client.mli
···24242525 The following types are redeclared here for convenience. *)
26262727- type init_libs = Toplevel_api_gen.init_libs
2727+ type init_config = Toplevel_api_gen.init_config
2828 type err = Toplevel_api_gen.err
2929 type exec_result = Toplevel_api_gen.exec_result
3030···3535 worker by the timeout set in the {!val-start} call, the {!Lwt} thread will
3636 be {{!Lwt.fail}failed}. *)
37373838- val init : rpc -> init_libs -> (unit, err) result Lwt.t
3838+ val init : rpc -> init_config -> (unit, err) result Lwt.t
3939 (** Initialise the toplevel. This must be called before any other API. *)
40404141 val setup : rpc -> unit -> (exec_result, err) result Lwt.t
+1-1
idl/js_top_worker_client_fut.ml
···7373module Wraw = Toplevel_api_gen.Make (Rpc_fut.GenClient ())
74747575module W = struct
7676- type init_libs = Toplevel_api_gen.init_libs
7676+ type init_config = Toplevel_api_gen.init_config
7777 type err = Toplevel_api_gen.err
7878 type exec_result = Toplevel_api_gen.exec_result
7979
+8-5
idl/toplevel_api.ml
···183183}
184184[@@deriving rpcty]
185185186186-type init_libs = { path : string; cmis : cmis; cmas : cma list; findlib_index : string; findlib_requires : string list; stdlib_dcs : string } [@@deriving rpcty]
186186+type init_config = {
187187+ findlib_index : string; (** URL to the findlib index file *)
188188+ findlib_requires : string list; (** Findlib packages to require *)
189189+ stdlib_dcs : string; (** URL to the dynamic cmis for the OCaml standard library *)
190190+ execute : bool (** Whether this session should support execution or not. *)
191191+} [@@deriving rpcty]
187192type err = InternalError of string [@@deriving rpcty]
188193189194type opt_id = string option [@@deriving rpcty]
···241246 Param.mk ~name:"init_libs"
242247 ~description:
243248 [
244244- "Libraries to load during the initialisation of the toplevel. ";
245245- "If the stdlib cmis have not been compiled into the worker this ";
246246- "MUST include the urls from which they may be fetched";
249249+ "Configuration for the toplevel.";
247250 ]
248248- init_libs
251251+ init_config
249252250253 let init =
251254 declare "init"
+66-102
idl/toplevel_api_gen.ml
···19691969 and _ = typ_of_cma
19701970 and _ = cma
19711971 end[@@ocaml.doc "@inline"][@@merlin.hide ]
19721972-type init_libs =
19721972+type init_config =
19731973 {
19741974- path: string ;
19751975- cmis: cmis ;
19761976- cmas: cma list ;
19771977- findlib_index: string ;
19781978- findlib_requires: string list ;
19791979- stdlib_dcs: string }[@@deriving rpcty]
19741974+ findlib_index: string [@ocaml.doc " URL to the findlib index file "];
19751975+ findlib_requires: string list [@ocaml.doc " Findlib packages to require "];
19761976+ stdlib_dcs: string
19771977+ [@ocaml.doc " URL to the dynamic cmis for the OCaml standard library "];
19781978+ execute: bool
19791979+ [@ocaml.doc " Whether this session should support execution or not. "]}
19801980+[@@deriving rpcty]
19801981include
19811982 struct
19821982- let _ = fun (_ : init_libs) -> ()
19831983- let rec init_libs_path : (_, init_libs) Rpc.Types.field =
19841984- {
19851985- Rpc.Types.fname = "path";
19861986- Rpc.Types.field = (let open Rpc.Types in Basic String);
19871987- Rpc.Types.fdefault = None;
19881988- Rpc.Types.fdescription = [];
19891989- Rpc.Types.fversion = None;
19901990- Rpc.Types.fget = (fun _r -> _r.path);
19911991- Rpc.Types.fset = (fun v _s -> { _s with path = v })
19921992- }
19931993- and init_libs_cmis : (_, init_libs) Rpc.Types.field =
19941994- {
19951995- Rpc.Types.fname = "cmis";
19961996- Rpc.Types.field = typ_of_cmis;
19971997- Rpc.Types.fdefault = None;
19981998- Rpc.Types.fdescription = [];
19991999- Rpc.Types.fversion = None;
20002000- Rpc.Types.fget = (fun _r -> _r.cmis);
20012001- Rpc.Types.fset = (fun v _s -> { _s with cmis = v })
20022002- }
20032003- and init_libs_cmas : (_, init_libs) Rpc.Types.field =
20042004- {
20052005- Rpc.Types.fname = "cmas";
20062006- Rpc.Types.field = (Rpc.Types.List typ_of_cma);
20072007- Rpc.Types.fdefault = None;
20082008- Rpc.Types.fdescription = [];
20092009- Rpc.Types.fversion = None;
20102010- Rpc.Types.fget = (fun _r -> _r.cmas);
20112011- Rpc.Types.fset = (fun v _s -> { _s with cmas = v })
20122012- }
20132013- and init_libs_findlib_index : (_, init_libs) Rpc.Types.field =
19831983+ let _ = fun (_ : init_config) -> ()
19841984+ let rec init_config_findlib_index : (_, init_config) Rpc.Types.field =
20141985 {
20151986 Rpc.Types.fname = "findlib_index";
20161987 Rpc.Types.field = (let open Rpc.Types in Basic String);
20171988 Rpc.Types.fdefault = None;
20182018- Rpc.Types.fdescription = [];
19891989+ Rpc.Types.fdescription = ["URL to the findlib index file"];
20191990 Rpc.Types.fversion = None;
20201991 Rpc.Types.fget = (fun _r -> _r.findlib_index);
20211992 Rpc.Types.fset = (fun v _s -> { _s with findlib_index = v })
20221993 }
20232023- and init_libs_findlib_requires : (_, init_libs) Rpc.Types.field =
19941994+ and init_config_findlib_requires : (_, init_config) Rpc.Types.field =
20241995 {
20251996 Rpc.Types.fname = "findlib_requires";
20261997 Rpc.Types.field =
20271998 (Rpc.Types.List (let open Rpc.Types in Basic String));
20281999 Rpc.Types.fdefault = None;
20292029- Rpc.Types.fdescription = [];
20002000+ Rpc.Types.fdescription = ["Findlib packages to require"];
20302001 Rpc.Types.fversion = None;
20312002 Rpc.Types.fget = (fun _r -> _r.findlib_requires);
20322003 Rpc.Types.fset = (fun v _s -> { _s with findlib_requires = v })
20332004 }
20342034- and init_libs_stdlib_dcs : (_, init_libs) Rpc.Types.field =
20052005+ and init_config_stdlib_dcs : (_, init_config) Rpc.Types.field =
20352006 {
20362007 Rpc.Types.fname = "stdlib_dcs";
20372008 Rpc.Types.field = (let open Rpc.Types in Basic String);
20382009 Rpc.Types.fdefault = None;
20392039- Rpc.Types.fdescription = [];
20102010+ Rpc.Types.fdescription =
20112011+ ["URL to the dynamic cmis for the OCaml standard library"];
20402012 Rpc.Types.fversion = None;
20412013 Rpc.Types.fget = (fun _r -> _r.stdlib_dcs);
20422014 Rpc.Types.fset = (fun v _s -> { _s with stdlib_dcs = v })
20432015 }
20442044- and typ_of_init_libs =
20162016+ and init_config_execute : (_, init_config) Rpc.Types.field =
20172017+ {
20182018+ Rpc.Types.fname = "execute";
20192019+ Rpc.Types.field = (let open Rpc.Types in Basic Bool);
20202020+ Rpc.Types.fdefault = None;
20212021+ Rpc.Types.fdescription =
20222022+ ["Whether this session should support execution or not."];
20232023+ Rpc.Types.fversion = None;
20242024+ Rpc.Types.fget = (fun _r -> _r.execute);
20252025+ Rpc.Types.fset = (fun v _s -> { _s with execute = v })
20262026+ }
20272027+ and typ_of_init_config =
20452028 Rpc.Types.Struct
20462029 ({
20472030 Rpc.Types.fields =
20482048- [Rpc.Types.BoxedField init_libs_path;
20492049- Rpc.Types.BoxedField init_libs_cmis;
20502050- Rpc.Types.BoxedField init_libs_cmas;
20512051- Rpc.Types.BoxedField init_libs_findlib_index;
20522052- Rpc.Types.BoxedField init_libs_findlib_requires;
20532053- Rpc.Types.BoxedField init_libs_stdlib_dcs];
20542054- Rpc.Types.sname = "init_libs";
20312031+ [Rpc.Types.BoxedField init_config_findlib_index;
20322032+ Rpc.Types.BoxedField init_config_findlib_requires;
20332033+ Rpc.Types.BoxedField init_config_stdlib_dcs;
20342034+ Rpc.Types.BoxedField init_config_execute];
20352035+ Rpc.Types.sname = "init_config";
20552036 Rpc.Types.version = None;
20562037 Rpc.Types.constructor =
20572038 (fun getter ->
20582039 let open Rresult.R in
20592059- (getter.Rpc.Types.field_get "stdlib_dcs"
20602060- (let open Rpc.Types in Basic String))
20402040+ (getter.Rpc.Types.field_get "execute"
20412041+ (let open Rpc.Types in Basic Bool))
20612042 >>=
20622062- (fun init_libs_stdlib_dcs ->
20632063- (getter.Rpc.Types.field_get "findlib_requires"
20642064- (Rpc.Types.List
20652065- (let open Rpc.Types in Basic String)))
20432043+ (fun init_config_execute ->
20442044+ (getter.Rpc.Types.field_get "stdlib_dcs"
20452045+ (let open Rpc.Types in Basic String))
20662046 >>=
20672067- (fun init_libs_findlib_requires ->
20682068- (getter.Rpc.Types.field_get "findlib_index"
20692069- (let open Rpc.Types in Basic String))
20472047+ (fun init_config_stdlib_dcs ->
20482048+ (getter.Rpc.Types.field_get "findlib_requires"
20492049+ (Rpc.Types.List
20502050+ (let open Rpc.Types in Basic String)))
20702051 >>=
20712071- (fun init_libs_findlib_index ->
20722072- (getter.Rpc.Types.field_get "cmas"
20732073- (Rpc.Types.List typ_of_cma))
20522052+ (fun init_config_findlib_requires ->
20532053+ (getter.Rpc.Types.field_get "findlib_index"
20542054+ (let open Rpc.Types in Basic String))
20742055 >>=
20752075- (fun init_libs_cmas ->
20762076- (getter.Rpc.Types.field_get "cmis"
20772077- typ_of_cmis)
20782078- >>=
20792079- (fun init_libs_cmis ->
20802080- (getter.Rpc.Types.field_get "path"
20812081- (let open Rpc.Types in
20822082- Basic String))
20832083- >>=
20842084- (fun init_libs_path ->
20852085- return
20862086- {
20872087- path = init_libs_path;
20882088- cmis = init_libs_cmis;
20892089- cmas = init_libs_cmas;
20902090- findlib_index =
20912091- init_libs_findlib_index;
20922092- findlib_requires =
20932093- init_libs_findlib_requires;
20942094- stdlib_dcs =
20952095- init_libs_stdlib_dcs
20962096- })))))))
20972097- } : init_libs Rpc.Types.structure)
20982098- and init_libs =
20562056+ (fun init_config_findlib_index ->
20572057+ return
20582058+ {
20592059+ findlib_index =
20602060+ init_config_findlib_index;
20612061+ findlib_requires =
20622062+ init_config_findlib_requires;
20632063+ stdlib_dcs = init_config_stdlib_dcs;
20642064+ execute = init_config_execute
20652065+ })))))
20662066+ } : init_config Rpc.Types.structure)
20672067+ and init_config =
20992068 {
21002100- Rpc.Types.name = "init_libs";
20692069+ Rpc.Types.name = "init_config";
21012070 Rpc.Types.description = [];
21022102- Rpc.Types.ty = typ_of_init_libs
20712071+ Rpc.Types.ty = typ_of_init_config
21032072 }
21042104- let _ = init_libs_path
21052105- and _ = init_libs_cmis
21062106- and _ = init_libs_cmas
21072107- and _ = init_libs_findlib_index
21082108- and _ = init_libs_findlib_requires
21092109- and _ = init_libs_stdlib_dcs
21102110- and _ = typ_of_init_libs
21112111- and _ = init_libs
20732073+ let _ = init_config_findlib_index
20742074+ and _ = init_config_findlib_requires
20752075+ and _ = init_config_stdlib_dcs
20762076+ and _ = init_config_execute
20772077+ and _ = typ_of_init_config
20782078+ and _ = init_config
21122079 end[@@ocaml.doc "@inline"][@@merlin.hide ]
21132080type err =
21142081 | InternalError of string [@@deriving rpcty]
···22272194 let exec_toplevel_result_p = Param.mk exec_toplevel_result
22282195 let init_libs =
22292196 Param.mk ~name:"init_libs"
22302230- ~description:["Libraries to load during the initialisation of the toplevel. ";
22312231- "If the stdlib cmis have not been compiled into the worker this ";
22322232- "MUST include the urls from which they may be fetched"]
22332233- init_libs
21972197+ ~description:["Configuration for the toplevel."] init_config
22342198 let init =
22352199 declare "init"
22362200 ["Initialise the toplevel. This must be called before any other API."]
+2-2
lib/findlibish.ml
···150150 None)
151151 metas |> flatten_libs
152152153153-let require v packages =
153153+let require cmi_only v packages =
154154 let rec require dcss package :
155155 Js_top_worker_rpc.Toplevel_api_gen.dynamic_cmis list =
156156 match List.find (fun lib -> lib.name = package) v with
···179179 let archive_js =
180180 Fpath.(dir / (archive ^ ".cma.js") |> to_string)
181181 in
182182- if List.mem lib.name preloaded then ()
182182+ if List.mem lib.name preloaded || cmi_only then ()
183183 else
184184 Js_of_ocaml.Worker.import_scripts
185185 [ Uri.with_path uri archive_js |> Uri.to_string ];
+5-24
lib/impl.ml
···9696 val init_function : string -> unit -> unit
9797 val get_stdlib_dcs : string -> Toplevel_api_gen.dynamic_cmis list
9898 val findlib_init : string -> findlib_t
9999- val require : findlib_t -> string list -> Toplevel_api_gen.dynamic_cmis list
9999+ val require : bool -> findlib_t -> string list -> Toplevel_api_gen.dynamic_cmis list
100100end
101101102102module Make (S : S) = struct
···104104 let requires : string list ref = ref []
105105 let path : string option ref = ref None
106106 let findlib_v : S.findlib_t option ref = ref None
107107+ let execution_allowed = ref true
107108108109 let refill_lexbuf s p ppf buffer len =
109110 if !p = String.length s then 0
···338339 let old_loader = !load in
339340 load := new_load ~s:"merl" ~old_loader
340341341341- let init (init_libs : Toplevel_api_gen.init_libs) =
342342+ let init (init_libs : Toplevel_api_gen.init_config) =
342343 try
343344 Logs.info (fun m -> m "init()");
344344- path := Some init_libs.path;
345345+ path := Some "/static/cmis";
345346346347 findlib_v := Some (S.findlib_init init_libs.findlib_index);
347348···349350 | [ dcs ] -> add_dynamic_cmis dcs
350351 | _ -> ());
351352 Clflags.no_check_prims := true;
352352- List.iter
353353- (fun { Toplevel_api_gen.sc_name; sc_content } ->
354354- let filename =
355355- Printf.sprintf "%s.cmi" (String.uncapitalize_ascii sc_name)
356356- in
357357- let name = Filename.(concat init_libs.path filename) in
358358- S.create_file ~name ~content:sc_content)
359359- init_libs.cmis.static_cmis;
360360- List.iter add_dynamic_cmis init_libs.cmis.dynamic_cmis;
361361-362362- S.import_scripts
363363- (List.map (fun cma -> cma.Toplevel_api_gen.url) init_libs.cmas);
364353365354 requires := init_libs.findlib_requires;
366366- functions :=
367367- Some
368368- (List.map
369369- (fun func_name ->
370370- Logs.info (fun m -> m "Function: %s" func_name);
371371- S.init_function func_name)
372372- (List.map (fun cma -> cma.Toplevel_api_gen.fn) init_libs.cmas));
373373- (* *)
374355 functions := Some [];
375356 Logs.info (fun m -> m "init() finished");
376357···400381 in
401382402383 let dcs =
403403- match !findlib_v with Some v -> S.require v !requires | None -> []
384384+ match !findlib_v with Some v -> S.require (not !execution_allowed) v !requires | None -> []
404385 in
405386 List.iter add_dynamic_cmis dcs;
406387
+2-2
lib/worker.ml
···5757 let import_scripts = Js_of_ocaml.Worker.import_scripts
5858 let findlib_init = Findlibish.init
59596060- let require v = function
6060+ let require b v = function
6161 | [] -> []
6262- | packages -> Findlibish.require v packages
6262+ | packages -> Findlibish.require b v packages
63636464 let init_function func_name =
6565 let open Js_of_ocaml in
+2-21
test/node/node_test.ml
···4444 let findlib_init _ = ()
4545 let get_stdlib_dcs _uri = []
46464747- let require () packages =
4747+ let require _ () packages =
4848 try
4949 let eff_packages =
5050 Findlib.package_deep_ancestors !Topfind.predicates packages
···9696 let rpc = start_server () in
9797 Printf.printf "Starting worker...\n%!";
9898 let ( let* ) = IdlM.ErrM.bind in
9999- let dcs =
100100- Js_top_worker_rpc.Toplevel_api_gen.
101101- {
102102- dcs_url = "cmis/";
103103- dcs_toplevel_modules =
104104- [
105105- "CamlinternalOO";
106106- "Stdlib";
107107- "CamlinternalFormat";
108108- "Std_exit";
109109- "CamlinternalMod";
110110- "CamlinternalFormatBasics";
111111- "CamlinternalLazy";
112112- ];
113113- dcs_file_prefixes = [ "stdlib__" ];
114114- }
115115- in
11699 let init =
117100 Js_top_worker_rpc.Toplevel_api_gen.
118101 {
119119- path = "/tmp/static/cmis";
120120- cmas = [];
121121- cmis = { dynamic_cmis = [ dcs ]; static_cmis = [] };
122102 stdlib_dcs = "/lib/ocaml/dynamic_cmis.json";
123103 findlib_index = "/lib/findlib_index";
124104 findlib_requires = [];
105105+ execute = true;
125106 }
126107 in
127108 let x =
+2-21
test/unix/unix_test.ml
···7575 let findlib_init _ = ()
7676 let get_stdlib_dcs _uri = []
77777878- let require () packages =
7878+ let require _ () packages =
7979 try
8080 let eff_packages =
8181 Findlib.package_deep_ancestors !Topfind.predicates packages
···127127 let rpc = start_server () in
128128 Printf.printf "Starting worker...\n%!";
129129 let ( let* ) = IdlM.ErrM.bind in
130130- let dcs =
131131- Js_top_worker_rpc.Toplevel_api_gen.
132132- {
133133- dcs_url = "cmis/";
134134- dcs_toplevel_modules =
135135- [
136136- "CamlinternalOO";
137137- "Stdlib";
138138- "CamlinternalFormat";
139139- "Std_exit";
140140- "CamlinternalMod";
141141- "CamlinternalFormatBasics";
142142- "CamlinternalLazy";
143143- ];
144144- dcs_file_prefixes = [ "stdlib__" ];
145145- }
146146- in
147130 let init =
148131 Js_top_worker_rpc.Toplevel_api_gen.
149132 {
150150- path = "/tmp/static/cmis";
151151- cmas = [];
152152- cmis = { dynamic_cmis = [ dcs ]; static_cmis = [] };
153133 stdlib_dcs = "/lib/ocaml/dynamic_cmis.json";
154134 findlib_index = "/lib/findlib_index";
155135 findlib_requires = [];
136136+ execute = true;
156137 }
157138 in
158139 let x =