C build tool of the 21st century
1type 'a t = { checked : (string, bool) Hashtbl.t; mgr : 'a Eio.Process.mgr }
2
3let v mgr = { checked = Hashtbl.create 16; mgr }
4
5let path mgr cmd =
6 try
7 let result = Eio.Process.parse_out mgr Eio.Buf_read.line [ "which"; cmd ] in
8 let path = String.trim result in
9 Some path
10 with _ -> None
11
12let is_available t cmd =
13 match Hashtbl.find_opt t.checked cmd with
14 | Some result -> result
15 | None ->
16 let available = path t.mgr cmd |> Option.is_some in
17 Hashtbl.add t.checked cmd available;
18 available
19
20let check_command t cmd =
21 if not (is_available t cmd) then
22 Fmt.failwith "command '%s' not found. Please install it and try again." cmd
23
24let check_commands t cmds =
25 let missing =
26 List.fold_left
27 (fun acc cmd -> if not (is_available t cmd) then cmd :: acc else acc)
28 [] cmds
29 in
30 if not (List.is_empty missing) then
31 Fmt.failwith "missing commands: %a@."
32 (Fmt.list ~sep:(Fmt.any ", ") Fmt.string)
33 (List.rev missing)