From cffb68cfe06f6ba6500283d4130f8c218c7f5b89 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 23 Jan 2023 14:56:21 +0100 Subject: [PATCH 1/2] refactor(jsoo): more robust flag parsing Signed-off-by: Hugo Heuzard --- src/dune_rules/jsoo/jsoo_rules.ml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index 28cf2c46d0d..1be05d7307e 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -61,7 +61,17 @@ end = struct let rec loop acc = function | [] -> acc | "--enable" :: name :: rest -> loop (set acc name true) rest + | maybe_enable :: rest + when String.is_prefix maybe_enable ~prefix:"--enable=" -> ( + match String.drop_prefix maybe_enable ~prefix:"--enable=" with + | Some name -> loop (set acc name true) rest + | _ -> assert false) | "--disable" :: name :: rest -> loop (set acc name false) rest + | maybe_disable :: rest + when String.is_prefix maybe_disable ~prefix:"--disable=" -> ( + match String.drop_prefix maybe_disable ~prefix:"--disable=" with + | Some name -> loop (set acc name false) rest + | _ -> assert false) | _ :: rest -> loop acc rest in loop default l From 2bc75b659c9ebe60b2ed3b2c71c0555e8cd992e3 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 23 Jan 2023 14:58:02 +0100 Subject: [PATCH 2/2] feature(jsoo): recognize toplevel variant Signed-off-by: Hugo Heuzard --- CHANGES.md | 2 +- src/dune_rules/jsoo/jsoo_rules.ml | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f0f298f7c00..5a1f22cd9ae 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -85,7 +85,7 @@ Unreleased enabled (#6645, @hhugo) - Fix *js_of_ocaml* separate compilation rules when `--enable=effects` - or `--enable=use-js-string` is used. (#6714, #6828, @hhugo) + ,`--enable=use-js-string` or `--toplevel` is used. (#6714, #6828, #6920, @hhugo) - Fix *js_of_ocaml* separate compilation in presence of linkall (#6832, #6916, @hhugo) diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index 1be05d7307e..51db00206d1 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -16,19 +16,25 @@ end = struct type t = { js_string : bool option ; effects : bool option + ; toplevel : bool option } - let default = { js_string = None; effects = None } + let default = { js_string = None; effects = None; toplevel = None } let bool_opt = [ None; Some true; Some false ] let all = List.concat_map bool_opt ~f:(fun js_string -> - List.concat_map bool_opt ~f:(fun effects -> [ { js_string; effects } ])) + List.concat_map bool_opt ~f:(fun effects -> + List.concat_map bool_opt ~f:(fun toplevel -> + [ { js_string; effects; toplevel } ]))) let get t = List.filter_map - [ ("use-js-string", t.js_string); ("effects", t.effects) ] + [ ("use-js-string", t.js_string) + ; ("effects", t.effects) + ; ("toplevel", t.toplevel) + ] ~f:(fun (n, v) -> match v with | None -> None @@ -38,6 +44,7 @@ end = struct match name with | "use-js-string" -> { acc with js_string = Some v } | "effects" -> { acc with effects = Some v } + | "toplevel" -> { acc with toplevel = Some v } | _ -> acc let path t = @@ -72,12 +79,15 @@ end = struct match String.drop_prefix maybe_disable ~prefix:"--disable=" with | Some name -> loop (set acc name false) rest | _ -> assert false) + | "--toplevel" :: rest -> loop (set acc "toplevel" true) rest | _ :: rest -> loop acc rest in loop default l let to_flags t = List.concat_map (get t) ~f:(function + | "toplevel", true -> [ "--toplevel" ] + | "toplevel", false -> [] | name, true -> [ "--enable"; name ] | name, false -> [ "--disable"; name ]) end