let path_separator = ':' let terminal_supports_color_without_term = false let inherit_streaming_terminal_stdin = false let configure_standard_streams () = () let clean_symbol = "🧹 " let parse_symbol = "🧱 " let build_symbol = "🤺 " let success_symbol = "✅ " let warning_symbol = "⚠️ " let error_symbol = "❌ " let normalize_path_for_comparison value = value let directory_identity ~path:_ metadata = Printf.sprintf "%d:%d" metadata.Unix.st_dev metadata.Unix.st_ino let canonicalize_path = Unix.realpath let executable_extensions ~program:_ = [""] let executable_is_usable candidate = try (Unix.stat candidate).Unix.st_kind = Unix.S_REG && try Unix.access candidate [Unix.X_OK]; true with Unix.Unix_error _ -> false with Unix.Unix_error _ -> false let resolve_program = Platform_common.resolve_program ~path_separator ~executable_extensions ~normalize_directory:Fun.id ~executable_is_usable type command = {env: Spawn.Env.t option; program: string; args: string list} let post_build_command ~command ~output = { env = None; program = "/bin/sh"; args = ["-c"; command ^ " " ^ Filename.quote output]; } let shell_command command = {env = None; program = "/bin/sh"; args = ["-c"; command]} type process = int let spawn ~env ~cwd ~program ~args ~stdin ~stdout ~stderr = let program = resolve_program ~cwd program in Spawn.spawn ?env ~cwd:(Spawn.Working_dir.Path cwd) ~prog:program ~argv:(program :: args) ~stdin ~stdout ~stderr ~setpgid:Spawn.Pgid.new_process_group () let null_device = "/dev/null" let current_process_id = Unix.getpid let process_id process = process let release_process _process = () let signal_process_tree process signal = try Unix.kill (-process) signal; Ok () with (* A missing group is already in the requested terminal state. Other errors must prevent the caller from waiting indefinitely for an undelivered signal. *) | Unix.Unix_error (Unix.ESRCH, _, _) -> Ok () | Unix.Unix_error (error, operation, _) -> Error (Printf.sprintf "%s while sending signal %d to process group %d: %s" operation signal process (Unix.error_message error)) (* Children run in their own process groups, so a closing terminal's SIGHUP and a SIGQUIT reach only rescript. Handling them like SIGTERM keeps those children from outliving the build and leaving its lock behind. *) let termination_signals = [Sys.sigint; Sys.sigterm; Sys.sighup; Sys.sigquit] let escalate_process_groups = true let process_name_from_ps ~run pid = match run "/bin/ps" ["-p"; string_of_int pid; "-o"; "comm="] with | Some (Unix.WEXITED 0, output) -> output |> String.trim |> Filename.basename |> Platform_common.is_lock_owner_name | Some (Unix.WEXITED _, _) -> false | Some (Unix.WSIGNALED _, _) | Some (Unix.WSTOPPED _, _) | None -> true let probe_process ~run pid = Unix.kill pid 0; let executable = Printf.sprintf "/proc/%d/exe" pid in if Sys.file_exists executable then try Unix.realpath executable |> Filename.basename |> Platform_common.is_lock_owner_name with Unix.Unix_error _ -> true else (* macOS has no procfs. `ps` supplies the same executable-name check so a reused PID from an abandoned lock is not mistaken for this tool. A failed probe remains conservative because stealing a live build's lock is worse than asking the user to remove an inconclusive stale lock. *) process_name_from_ps ~run pid let process_is_active ~run value = Platform_common.process_is_active ~probe:(probe_process ~run) value