Skip to content

chore(cram): remove Sanitizer dead code #11568

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

Merged
merged 1 commit into from
Mar 25, 2025
Merged
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
89 changes: 0 additions & 89 deletions src/dune_rules/cram/cram_exec.ml
Original file line number Diff line number Diff line change
@@ -1,94 +1,5 @@
open Import

module Sanitizer : sig
[@@@ocaml.warning "-32"]

module Command : sig
type t =
{ output : string
; build_path_prefix_map : string
; script : Path.t
}
end

val impl_sanitizer : (Command.t -> string) -> in_channel -> out_channel -> unit

val run_sanitizer
: ?temp_dir:Path.t
-> prog:Path.t
-> argv:string list
-> Command.t list
-> string list Fiber.t
end = struct
module Command = struct
type t =
{ output : string
; build_path_prefix_map : string
; script : Path.t
}

let of_sexp script (csexp : Sexp.t) : t =
match csexp with
| List [ Atom build_path_prefix_map; Atom output ] ->
{ build_path_prefix_map; output; script }
| _ -> Code_error.raise "Command.of_csexp: invalid csexp" []
;;

let to_sexp { output; build_path_prefix_map; script } : Sexp.t =
List
[ Atom build_path_prefix_map
; Atom output
; Atom (Path.to_absolute_filename script)
]
;;
end

let run_sanitizer ?temp_dir ~prog ~argv commands =
let temp_dir =
match temp_dir with
| Some d -> d
| None -> Temp.create Dir ~prefix:"sanitizer" ~suffix:"unspecified"
in
let fname = Path.relative temp_dir in
let stdout_path = fname "sanitizer.stdout" in
let stdout_to = Process.Io.file stdout_path Process.Io.Out in
let stdin_from =
let path = fname "sanitizer.stdin" in
let csexp = List.map commands ~f:Command.to_sexp in
Io.with_file_out ~binary:true path ~f:(fun oc ->
List.iter csexp ~f:(Csexp.to_channel oc));
Process.Io.file path Process.Io.In
in
let open Fiber.O in
let+ () = Process.run ~display:Quiet ~stdin_from ~stdout_to Strict prog argv in
Io.with_file_in stdout_path ~f:(fun ic ->
let rec loop acc =
match Csexp.input_opt ic with
| Ok None -> List.rev acc
| Ok (Some (Sexp.Atom s)) -> loop (s :: acc)
| Error error -> Code_error.raise "invalid csexp" [ "error", String error ]
| Ok _ -> Code_error.raise "unexpected output" []
in
loop [])
;;

let impl_sanitizer f in_ out =
set_binary_mode_in in_ true;
set_binary_mode_out out true;
let rec loop () =
match Csexp.input_opt in_ with
| Error error -> Code_error.raise "unable to parse csexp" [ "error", String error ]
| Ok None -> ()
| Ok (Some sexp) ->
let command = Command.of_sexp (assert false) sexp in
Csexp.to_channel out (Atom (f command));
flush out;
loop ()
in
loop ()
;;
end

(* Translate a path for [sh]. On Windows, [sh] will come from Cygwin so if we
are a real windows program we need to pass the path through [cygpath] *)
let translate_path_for_sh =
Expand Down
Loading