11open Import
22
3+ module Shell_spec = struct
4+ type 'path t =
5+ | System_shell
6+ | Bash_shell
7+ | Exec_file_shell of 'path
8+
9+ let default = System_shell
10+
11+ let conv f = function
12+ | System_shell -> System_shell
13+ | Bash_shell -> Bash_shell
14+ | Exec_file_shell p -> Exec_file_shell (f p)
15+ end
16+
317module Sanitizer : sig
418 [@@@ ocaml.warning " -32" ]
519
@@ -376,7 +390,7 @@ let create_sh_script cram_stanzas ~temp_dir : sh_script Fiber.t =
376390let _display_with_bars s =
377391 List. iter (String. split_lines s) ~f: (Printf. eprintf " | %s\n " )
378392
379- let run ~env ~script lexbuf : string Fiber.t =
393+ let run ~env ~script ~ shell_spec lexbuf : string Fiber.t =
380394 let temp_dir =
381395 let suffix =
382396 let basename = Path. basename script in
@@ -414,8 +428,14 @@ let run ~env ~script lexbuf : string Fiber.t =
414428 let open Fiber.O in
415429 let + () =
416430 let sh =
417- let path = Env_path. path Env. initial in
418- Option. value_exn (Bin. which ~path " sh" )
431+ let which shell_name =
432+ let path = Env_path. path Env. initial in
433+ Option. value_exn (Bin. which ~path shell_name)
434+ in
435+ match shell_spec with
436+ | Shell_spec. System_shell -> which " sh"
437+ | Bash_shell -> which " bash"
438+ | Exec_file_shell sh -> sh
419439 in
420440 let metadata =
421441 let name =
@@ -436,24 +456,38 @@ let run ~env ~script lexbuf : string Fiber.t =
436456 let sanitized = sanitize ~parent_script: sh_script.script raw in
437457 compose_cram_output sanitized
438458
439- let run ~env ~script =
440- run_expect_test script ~f: (fun lexbuf -> run ~env ~script lexbuf)
459+ let run ~env ~script ~shell_spec =
460+ run_expect_test script ~f: (fun lexbuf -> run ~env ~script ~shell_spec lexbuf)
461+
462+ type ('path, _) spec =
463+ { script : 'path
464+ ; shell_spec : 'path Shell_spec .t
465+ }
441466
442467module Spec = struct
443- type ('path, _ ) t = 'path
468+ type ('path, 'target ) t = ( 'path , 'target ) spec
444469
445470 let name = " cram"
446471
447472 let version = 1
448473
449- let bimap path f _ = f path
474+ let bimap spec f _ =
475+ { script = f spec.script; shell_spec = Shell_spec. conv f spec.shell_spec }
450476
451477 let is_useful_to ~distribute :_ ~memoize :_ = true
452478
453- let encode script path _ : Dune_lang.t =
454- List [ Dune_lang. atom_or_quoted_string " cram" ; path script ]
479+ let encode { script; shell_spec } path _ : Dune_sexp.t =
480+ let atom = Dune_lang. atom_or_quoted_string in
481+ let sh : Dune_lang.t =
482+ match shell_spec with
483+ | System_shell -> List [ atom " system" ]
484+ | Bash_shell -> List [ atom " bash" ]
485+ | Exec_file_shell p -> List [ atom " executable" ; path p ]
486+ in
487+ List [ atom " cram" ; path script; List [ atom " shell" ; sh ] ]
455488
456- let action script ~ectx :_ ~(eenv : Action.Ext.env ) = run ~env: eenv.env ~script
489+ let action { script; shell_spec } ~ectx :_ ~(eenv : Action.Ext.env ) =
490+ run ~env: eenv.env ~script ~shell_spec
457491end
458492
459493let action script =
0 commit comments