Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline tests: add node_flags #7957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dune_rules/env_node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ let make ~dir ~inherit_from ~scope ~config_stanza ~profile ~expander
; flags =
Js_of_ocaml.Flags.make ~spec:local.flags ~default:jsoo.flags
~eval:(Expander.expand_and_eval_set expander)
; node_flags =
Expander.expand_and_eval_set expander local.node_flags
~standard:jsoo.node_flags
})
in
let foreign_flags lang =
Expand Down
7 changes: 6 additions & 1 deletion src/dune_rules/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ include Sub_system.Register_end_point (struct
else Sandbox_config.needs_sandboxing
in
let deps, sandbox = Dep_conf_eval.unnamed ~sandbox info.deps ~expander in
let* runner_flags =
Super_context.js_of_ocaml_node_flags sctx ~dir ~flags:info.node_flags
in
let action (mode : Mode_conf.t) (flags : string list Action_builder.t) :
Action.t Action_builder.t =
(* [action] needs to run from [dir] as we use [dir] to resolve
Expand All @@ -246,9 +249,11 @@ include Sub_system.Register_end_point (struct
let* prog =
Action_builder.of_memo
(Super_context.resolve_program ~dir sctx ~loc:(Some loc) runner)
and* runner_flags = runner_flags
and* flags = flags in
let action =
Action.run prog (Path.reach exe ~from:(Path.build dir) :: flags)
Action.run prog
(runner_flags @ (Path.reach exe ~from:(Path.build dir) :: flags))
in
(* jeremiedimino: it feels like this pattern should be pushed
into [resolve_program] directly *)
Expand Down
3 changes: 3 additions & 0 deletions src/dune_rules/inline_tests_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module Tests = struct
; deps : Dep_conf.t list
; modes : Mode_conf.Set.t
; flags : Ordered_set_lang.Unexpanded.t
; node_flags : Ordered_set_lang.Unexpanded.t
; executable_ocaml_flags : Ocaml_flags.Spec.t
; executable_link_flags : Ordered_set_lang.Unexpanded.t
; backend : (Loc.t * Lib_name.t) option
Expand All @@ -145,6 +146,7 @@ module Tests = struct
(let+ loc = loc
and+ deps = field "deps" (repeat Dep_conf.decode) ~default:[]
and+ flags = Ordered_set_lang.Unexpanded.field "flags"
and+ node_flags = Ordered_set_lang.Unexpanded.field "node_flags"
and+ executable_ocaml_flags, executable_link_flags =
field "executable"
~default:
Expand Down Expand Up @@ -172,6 +174,7 @@ module Tests = struct
{ loc
; deps
; flags
; node_flags
; executable_ocaml_flags
; executable_link_flags
; backend
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/inline_tests_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Tests : sig
; deps : Dep_conf.t list
; modes : Mode_conf.Set.t
; flags : Ordered_set_lang.Unexpanded.t
; node_flags : Ordered_set_lang.Unexpanded.t
; executable_ocaml_flags : Ocaml_flags.Spec.t
; executable_link_flags : Ordered_set_lang.Unexpanded.t
; backend : (Loc.t * Lib_name.t) option
Expand Down
24 changes: 18 additions & 6 deletions src/dune_rules/jsoo/js_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,43 @@ module Env = struct
{ compilation_mode : Compilation_mode.t option
; runtest_alias : Alias.Name.t option
; flags : 'a Flags.t
; node_flags : 'a
}

let decode =
fields
@@ let+ compilation_mode =
field_o "compilation_mode" Compilation_mode.decode
and+ runtest_alias = field_o "runtest_alias" Dune_lang.Alias.decode
and+ flags = Flags.decode in
and+ flags = Flags.decode
and+ node_flags = field_oslu "node_flags" in
Option.iter ~f:Alias.register_as_standard runtest_alias;
{ compilation_mode; runtest_alias; flags }
{ compilation_mode; runtest_alias; flags; node_flags }

let equal { compilation_mode; runtest_alias; flags } t =
let equal { compilation_mode; runtest_alias; flags; node_flags } t =
Option.equal Compilation_mode.equal compilation_mode t.compilation_mode
&& Option.equal Alias.Name.equal runtest_alias t.runtest_alias
&& Flags.equal Ordered_set_lang.Unexpanded.equal flags t.flags
&& Ordered_set_lang.Unexpanded.equal node_flags t.node_flags

let map ~f { compilation_mode; runtest_alias; flags } =
{ compilation_mode; runtest_alias; flags = Flags.map ~f flags }
let map ~f { compilation_mode; runtest_alias; flags; node_flags } =
{ compilation_mode
; runtest_alias
; flags = Flags.map ~f flags
; node_flags = f node_flags
}

let empty =
{ compilation_mode = None; runtest_alias = None; flags = Flags.standard }
{ compilation_mode = None
; runtest_alias = None
; flags = Flags.standard
; node_flags = Ordered_set_lang.Unexpanded.standard
}

let default ~profile =
{ compilation_mode = None
; runtest_alias = None
; flags = Flags.default ~profile
; node_flags = []
}
end
1 change: 1 addition & 0 deletions src/dune_rules/jsoo/js_of_ocaml.mli
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module Env : sig
{ compilation_mode : Compilation_mode.t option
; runtest_alias : Alias.Name.t option
; flags : 'a Flags.t
; node_flags : 'a
}

val map : f:('a -> 'b) -> 'a t -> 'b t
Expand Down
5 changes: 5 additions & 0 deletions src/dune_rules/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ let js_of_ocaml_flags t ~dir (spec : Js_of_ocaml.Flags.Spec.t) =
Js_of_ocaml.Flags.make ~spec ~default:js_of_ocaml.flags
~eval:(Expander.expand_and_eval_set expander)

let js_of_ocaml_node_flags t ~dir ~flags =
let+ expander = Env_tree.expander t ~dir
and+ js_of_ocaml = Env_tree.get_node t ~dir >>= Env_node.js_of_ocaml in
Expander.expand_and_eval_set expander flags ~standard:js_of_ocaml.node_flags

let default_foreign_flags t ~dir ~language =
Env_tree.get_node t ~dir >>| Env_node.foreign_flags
>>| (fun dict -> Foreign_language.Dict.get dict language)
Expand Down
6 changes: 6 additions & 0 deletions src/dune_rules/super_context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ val js_of_ocaml_flags :
-> Js_of_ocaml.Flags.Spec.t
-> string list Action_builder.t Js_of_ocaml.Flags.t Memo.t

val js_of_ocaml_node_flags :
t
-> dir:Path.Build.t
-> flags:Ordered_set_lang.Unexpanded.t
-> string list Action_builder.t Memo.t

val default_foreign_flags :
t
-> dir:Path.Build.t
Expand Down