@@ -4,6 +4,7 @@ type effective =
44 { loc : Loc .t
55 ; alias : Alias.Name.Set .t
66 ; deps : unit Action_builder .t list
7+ ; shell : Path .t Cram_exec.Shell_spec .t Action_builder .t
78 ; sandbox : Sandbox_config .t
89 ; enabled_if : Blang .t list
910 ; locks : Path.Set .t
@@ -16,6 +17,7 @@ let empty_effective =
1617 ; enabled_if = [ Blang. true_ ]
1718 ; locks = Path.Set. empty
1819 ; deps = []
20+ ; shell = Action_builder. return Cram_exec.Shell_spec. default
1921 ; sandbox = Sandbox_config. needs_sandboxing
2022 ; packages = Package.Name.Set. empty
2123 }
@@ -59,12 +61,9 @@ let test_rule ~sctx ~expander ~dir (spec : effective)
5961 let script =
6062 Path.Build. append_source prefix_with (Cram_test. script test)
6163 in
62- let action =
64+ let action ~ shell_spec =
6365 Action. progn
64- [ Cram_exec. action
65- { script = Path. build script
66- ; shell_spec = Cram_exec.Shell_spec. default
67- }
66+ [ Cram_exec. action { script = Path. build script; shell_spec }
6867 ; Diff
6968 { Diff. optional = true
7069 ; mode = Text
@@ -87,8 +86,8 @@ let test_rule ~sctx ~expander ~dir (spec : effective)
8786 |> Path. build |> Source_deps. files
8887 in
8988 Action_builder. dyn_memo_deps deps
90- in
91- Action.Full. make action ~locks ~sandbox: spec.sandbox
89+ and + shell_spec = spec.shell in
90+ Action.Full. make ( action ~shell_spec ) ~locks ~sandbox: spec.sandbox
9291 in
9392 Memo. parallel_iter aliases ~f: (fun alias ->
9493 Alias_rules. add sctx ~alias ~loc cram))
@@ -149,15 +148,44 @@ let rules ~sctx ~expander ~dir tests =
149148 | false -> acc
150149 | true ->
151150 let * acc = acc in
152- let * deps, sandbox =
151+ let * expander = Super_context. expander sctx ~dir in
152+ let shell, deps, sandbox =
153+ let return ?shell_deps ?sandbox shell =
154+ let sandbox =
155+ match sandbox with
156+ | None -> acc.sandbox
157+ | Some s -> Sandbox_config. inter acc.sandbox s
158+ and deps =
159+ match shell_deps with
160+ | None -> acc.deps
161+ | Some dep -> dep :: acc.deps
162+ in
163+ (shell, deps, sandbox)
164+ in
165+ let open Cram_exec.Shell_spec in
166+ match spec.shell with
167+ | System_shell -> return (Action_builder. return System_shell )
168+ | Bash_shell -> return (Action_builder. return Bash_shell )
169+ | Exec_file_shell p ->
170+ let shell_deps, sandbox =
171+ Dep_conf_eval. unnamed ~expander [ File p ]
172+ in
173+ let shell =
174+ Expander. (
175+ With_deps_if_necessary. expand_single_path expander p
176+ |> Deps. action_builder)
177+ |> Action_builder. map ~f: (fun p -> Exec_file_shell p)
178+ in
179+ return ~shell_deps ~sandbox shell
180+ in
181+ let deps, sandbox =
153182 match spec.deps with
154- | None -> Memo. return (acc.deps, acc.sandbox)
155- | Some deps ->
156- let + (deps : unit Action_builder.t ), _, sandbox =
157- let + expander = Super_context. expander sctx ~dir in
158- Dep_conf_eval. named ~expander deps
183+ | None -> (deps, sandbox)
184+ | Some deps' ->
185+ let (deps' : unit Action_builder.t ), _, sandbox' =
186+ Dep_conf_eval. named ~expander deps'
159187 in
160- (deps :: acc. deps, Sandbox_config. inter acc. sandbox sandbox)
188+ (deps' :: deps, Sandbox_config. inter sandbox sandbox' )
161189 in
162190 let enabled_if = spec.enabled_if :: acc.enabled_if in
163191 let alias =
@@ -178,7 +206,15 @@ let rules ~sctx ~expander ~dir tests =
178206 Expander. expand_locks ~base expander spec.locks
179207 >> | Path.Set. of_list >> | Path.Set. union acc.locks
180208 in
181- { acc with enabled_if; locks; deps; alias; packages; sandbox })
209+ { acc with
210+ enabled_if
211+ ; locks
212+ ; deps
213+ ; shell
214+ ; alias
215+ ; packages
216+ ; sandbox
217+ })
182218 in
183219 let test_rule () = test_rule ~sctx ~expander ~dir effective test in
184220 Only_packages. get_mask () >> = function
0 commit comments