Fixed all binaries using cmdliner to avoid newly deprecated functions

This commit is contained in:
rand00 2022-02-21 14:46:57 +01:00 committed by Reynir Björnsson
parent 7bb9e2d8fe
commit f68f383ba6
5 changed files with 152 additions and 101 deletions

View file

@ -478,87 +478,111 @@ let setup_log =
in in
Cmdliner.Term.(const setup_log $ Logs_cli.level ()) Cmdliner.Term.(const setup_log $ Logs_cli.level ())
open Cmdliner
let migrate_cmd = let migrate_cmd =
let doc = "create database and add tables" in let doc = "create database and add tables" in
Cmdliner.Term.(pure migrate $ setup_log $ dbpath_new), let term = Term.(const migrate $ setup_log $ dbpath_new) in
Cmdliner.Term.info ~doc "migrate" let info = Cmd.info ~doc "migrate" in
Cmd.v info term
let user_add_cmd = let user_add_cmd =
let doc = "add a user" in let doc = "add a user" in
(Cmdliner.Term.(pure user_add $ setup_log $ dbpath $ scrypt_n $ scrypt_r $ scrypt_p $ username $ unrestricted), let term = Term.(
Cmdliner.Term.info ~doc "user-add") const user_add $ setup_log $ dbpath $ scrypt_n $ scrypt_r $ scrypt_p
$ username $ unrestricted) in
let info = Cmd.info ~doc "user-add" in
Cmd.v info term
let user_update_cmd = let user_update_cmd =
let doc = "update a user password" in let doc = "update a user password" in
(Cmdliner.Term.(pure user_update $ setup_log $ dbpath $ scrypt_n $ scrypt_r $ scrypt_p $ username $ unrestricted), let term = Term.(
Cmdliner.Term.info ~doc "user-update") const user_update $ setup_log $ dbpath $ scrypt_n $ scrypt_r $ scrypt_p
$ username $ unrestricted) in
let info = Cmd.info ~doc "user-update" in
Cmd.v info term
let user_remove_cmd = let user_remove_cmd =
let doc = "remove a user" in let doc = "remove a user" in
(Cmdliner.Term.(pure user_remove $ setup_log $ dbpath $ username), let term = Term.(const user_remove $ setup_log $ dbpath $ username) in
Cmdliner.Term.info ~doc "user-remove") let info = Cmd.info ~doc "user-remove" in
Cmd.v info term
let user_disable_cmd = let user_disable_cmd =
let doc = "disable a user" in let doc = "disable a user" in
(Cmdliner.Term.(pure user_disable $ setup_log $ dbpath $ username), let term = Term.(const user_disable $ setup_log $ dbpath $ username) in
Cmdliner.Term.info ~doc "user-disable") let info = Cmd.info ~doc "user-disable" in
Cmd.v info term
let user_list_cmd = let user_list_cmd =
let doc = "list all users" in let doc = "list all users" in
(Cmdliner.Term.(pure user_list $ setup_log $ dbpath), let term = Term.(const user_list $ setup_log $ dbpath) in
Cmdliner.Term.info ~doc "user-list") let info = Cmd.info ~doc "user-list" in
Cmd.v info term
let access_add_cmd = let access_add_cmd =
let doc = "grant access to user and job" in let doc = "grant access to user and job" in
(Cmdliner.Term.(pure access_add $ setup_log $ dbpath $ username $ job), let term = Term.(const access_add $ setup_log $ dbpath $ username $ job) in
Cmdliner.Term.info ~doc "access-add") let info = Cmd.info ~doc "access-add" in
Cmd.v info term
let access_remove_cmd = let access_remove_cmd =
let doc = "remove access to user and job" in let doc = "remove access to user and job" in
(Cmdliner.Term.(pure access_remove $ setup_log $ dbpath $ username $ job), let term = Term.(const access_remove $ setup_log $ dbpath $ username $ job) in
Cmdliner.Term.info ~doc "access-remove") let info = Cmd.info ~doc "access-remove" in
Cmd.v info term
let job_remove_cmd = let job_remove_cmd =
let doc = "remove job and its associated builds and artifacts" in let doc = "remove job and its associated builds and artifacts" in
(Cmdliner.Term.(pure job_remove $ setup_log $ datadir $ jobname), let term = Term.(const job_remove $ setup_log $ datadir $ jobname) in
Cmdliner.Term.info ~doc "job-remove") let info = Cmd.info ~doc "job-remove" in
Cmd.v info term
let extract_full_cmd = let extract_full_cmd =
let doc = "extract a build from the database" in let doc = "extract a build from the database" in
(Cmdliner.Term.(pure extract_full $ setup_log $ datadir $ full_dest $ build), let term = Term.(
Cmdliner.Term.info ~doc "extract-build") const extract_full $ setup_log $ datadir $ full_dest $ build) in
let info = Cmd.info ~doc "extract-build" in
Cmd.v info term
let verify_input_id_cmd = let verify_input_id_cmd =
let doc = "verify that the main binary hash of all builds with the same input are equal" in let doc = "verify that the main binary hash of all builds with the same \
(Cmdliner.Term.(pure verify_input_id $ setup_log $ dbpath), input are equal" in
Cmdliner.Term.info ~doc "verify-input-id") let term = Term.(const verify_input_id $ setup_log $ dbpath) in
let info = Cmd.info ~doc "verify-input-id" in
Cmd.v info term
let verify_data_dir_cmd = let verify_data_dir_cmd =
let doc = "verify that the data directory is consistent with the build_artifact table" in let doc = "verify that the data directory is consistent with the \
(Cmdliner.Term.(pure verify_data_dir $ setup_log $ datadir), build_artifact table" in
Cmdliner.Term.info ~doc "verify-data-dir") let term = Term.(const verify_data_dir $ setup_log $ datadir) in
let info = Cmd.info ~doc "verify-data-dir" in
Cmd.v info term
let help_cmd = let help_cmd =
let topic = let topic =
let doc = "Command to get help on" in let doc = "Command to get help on" in
Cmdliner.Arg.(value & pos 0 (some string) None & info ~doc ~docv:"COMMAND" []) Arg.(value & pos 0 (some string) None & info ~doc ~docv:"COMMAND" [])
in in
let doc = "Builder database help" in let doc = "Builder database help" in
Cmdliner.Term.(ret (const help $ man_format $ choice_names $ topic)), let term = Term.(ret (const help $ Arg.man_format $ choice_names $ topic)) in
Cmdliner.Term.info ~doc "help" let info = Cmd.info ~doc "help" in
Cmd.v info term
let default_cmd = let default_cmd, default_info =
let doc = "Builder database command" in let doc = "Builder database command" in
Cmdliner.Term.(ret (const help $ man_format $ choice_names $ const None)), Term.(ret (const help $ Arg.man_format $ choice_names $ const None)),
Cmdliner.Term.info ~doc "builder-db" Cmd.info ~doc "builder-db"
let () = let () =
Mirage_crypto_rng_unix.initialize (); Mirage_crypto_rng_unix.initialize ();
Cmdliner.Term.eval_choice Cmdliner.Cmd.group
default_cmd ~default:default_cmd default_info
[ help_cmd; migrate_cmd; [ help_cmd; migrate_cmd;
user_add_cmd; user_update_cmd; user_remove_cmd; user_list_cmd; user_disable_cmd; user_add_cmd; user_update_cmd; user_remove_cmd; user_list_cmd;
user_disable_cmd;
access_add_cmd; access_remove_cmd; job_remove_cmd; access_add_cmd; access_remove_cmd; job_remove_cmd;
verify_input_id_cmd; verify_data_dir_cmd; verify_input_id_cmd; verify_data_dir_cmd;
extract_full_cmd ] extract_full_cmd ]
|> Cmdliner.Term.exit |> Cmdliner.Cmd.eval
|> exit

View file

@ -102,7 +102,7 @@ let setup_app level influx port host datadir configdir =
open Cmdliner open Cmdliner
let ip_port : (Ipaddr.V4.t * int) Arg.converter = let ip_port : (Ipaddr.V4.t * int) Arg.conv =
let default_port = 8094 in let default_port = 8094 in
let parse s = let parse s =
match match
@ -114,12 +114,14 @@ let ip_port : (Ipaddr.V4.t * int) Arg.converter =
end end
| _ -> Error "multiple : found" | _ -> Error "multiple : found"
with with
| Error msg -> `Error msg | Error msg -> Error (`Msg msg)
| Ok (ip, port) -> match Ipaddr.V4.of_string ip with | Ok (ip, port) -> match Ipaddr.V4.of_string ip with
| Ok ip -> `Ok (ip, port) | Ok ip -> Ok (ip, port)
| Error `Msg msg -> `Error msg | Error `Msg msg -> Error (`Msg msg)
in in
parse, fun ppf (ip, port) -> Format.fprintf ppf "%a:%d" Ipaddr.V4.pp ip port let printer ppf (ip, port) =
Format.fprintf ppf "%a:%d" Ipaddr.V4.pp ip port in
Arg.conv (parse, printer)
let datadir = let datadir =
let doc = "data directory" in let doc = "data directory" in
@ -142,9 +144,8 @@ let influx =
Arg.(value & opt (some ip_port) None & info [ "influx" ] ~doc ~docv:"INFLUXHOST[:PORT]") Arg.(value & opt (some ip_port) None & info [ "influx" ] ~doc ~docv:"INFLUXHOST[:PORT]")
let () = let () =
let term = Term.(pure setup_app $ Logs_cli.level () $ influx $ port $ host $ datadir $ configdir) in let term = Term.(const setup_app $ Logs_cli.level () $ influx $ port $ host $ datadir $ configdir) in
let info = Term.info "Builder web" ~doc:"Builder web" ~man:[] in let info = Cmd.info "Builder web" ~doc:"Builder web" ~man:[] in
match Term.eval (term, info) with Cmd.v info term
| `Ok () -> exit 0 |> Cmd.eval
| `Error _ -> exit 1 |> exit
| _ -> exit 0

View file

@ -72,53 +72,69 @@ let setup_log =
in in
Cmdliner.Term.(const setup_log $ Logs_cli.level ()) Cmdliner.Term.(const setup_log $ Logs_cli.level ())
open Cmdliner
let actions (module M : MIGRATION) = let actions (module M : MIGRATION) =
let c s = s ^ "-" ^ M.identifier in let c s = s ^ "-" ^ M.identifier in
let v doc from_ver to_ver = Printf.sprintf "%s (DB version %Ld -> %Ld)" doc from_ver to_ver in let v doc from_ver to_ver = Printf.sprintf "%s (DB version %Ld -> %Ld)" doc from_ver to_ver in
[ let migrate_cmd =
(Cmdliner.Term.(const do_database_action $ const M.migrate $ setup_log $ datadir), let term = Term.(
Cmdliner.Term.info ~doc:(v M.migrate_doc M.old_version M.new_version) const do_database_action $ const M.migrate $ setup_log $ datadir) in
(c "migrate")); let info = Cmd.info ~doc:(v M.migrate_doc M.old_version M.new_version)
(Cmdliner.Term.(const do_database_action $ const M.rollback $ setup_log $ datadir), (c "migrate") in
Cmdliner.Term.info ~doc:(v M.rollback_doc M.new_version M.old_version) Cmd.v info term
(c "rollback")); in
] let rollback_cmd =
let term = Term.(
const do_database_action $ const M.rollback $ setup_log $ datadir) in
let info = Cmd.info ~doc:(v M.rollback_doc M.new_version M.old_version)
(c "rollback") in
Cmd.v info term
in
[ migrate_cmd; rollback_cmd ]
let f20210308 = let f20210308 =
let doc = "Remove broken builds as fixed in commit a57798f4c02eb4d528b90932ec26fb0b718f1a13. \ let doc = "Remove broken builds as fixed in commit a57798f4c02eb4d528b90932ec26fb0b718f1a13. \
Note that the files on disk have to be removed manually." in Note that the files on disk have to be removed manually." in
Cmdliner.Term.(const do_database_action $ const M20210308.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210308.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-03-08" let info = Cmd.info ~doc "fixup-2021-03-08" in
Cmd.v info term
let f20210707a = let f20210707a =
let doc = "Remove orb.deb and orb.txz that ended up in the build." in let doc = "Remove orb.deb and orb.txz that ended up in the build." in
Cmdliner.Term.(const do_database_action $ const M20210707a.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210707a.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-07-07a" let info = Cmd.info ~doc "fixup-2021-07-07a" in
Cmd.v info term
let f20210707b = let f20210707b =
let doc = "Move *.deb.debug to bin/*.deb and remove the earlier bin/*.deb. Adjust main_binary of build." in let doc = "Move *.deb.debug to bin/*.deb and remove the earlier bin/*.deb. Adjust main_binary of build." in
Cmdliner.Term.(const do_database_action $ const M20210707b.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210707b.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-07-07b" let info = Cmd.info ~doc "fixup-2021-07-07b" in
Cmd.v info term
let f20210707c = let f20210707c =
let doc = "Strip bin/*.{hvt,xen} if no *.{hvt,xen} exists. Adjust build_artifact table and main_binary of build." in let doc = "Strip bin/*.{hvt,xen} if no *.{hvt,xen} exists. Adjust build_artifact table and main_binary of build." in
Cmdliner.Term.(const do_database_action $ const M20210707c.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210707c.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-07-07c" let info = Cmd.info ~doc "fixup-2021-07-07c" in
Cmd.v info term
let f20210707d = let f20210707d =
let doc = "Remove ./ from filepath." in let doc = "Remove ./ from filepath." in
Cmdliner.Term.(const do_database_action $ const M20210707d.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210707d.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-07-07d" let info = Cmd.info ~doc "fixup-2021-07-07d" in
Cmd.v info term
let f20210712b = let f20210712b =
let doc = "Remove build-hashes and README from artifacts." in let doc = "Remove build-hashes and README from artifacts." in
Cmdliner.Term.(const do_database_action $ const M20210712b.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210712b.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-07-12b" let info = Cmd.info ~doc "fixup-2021-07-12b" in
Cmd.v info term
let f20210910 = let f20210910 =
let doc = "Undo builds with script and console mixed up." in let doc = "Undo builds with script and console mixed up." in
Cmdliner.Term.(const do_database_action $ const M20210910.fixup $ setup_log $ datadir), let term = Term.(const do_database_action $ const M20210910.fixup $ setup_log $ datadir) in
Cmdliner.Term.info ~doc "fixup-2021-09-10" let info = Cmd.info ~doc "fixup-2021-09-10" in
Cmd.v info term
let help_cmd = let help_cmd =
let topic = let topic =
@ -126,17 +142,16 @@ let help_cmd =
Cmdliner.Arg.(value & pos 0 (some string) None & info ~doc ~docv:"MIGRATION" []) Cmdliner.Arg.(value & pos 0 (some string) None & info ~doc ~docv:"MIGRATION" [])
in in
let doc = "Builder migration help" in let doc = "Builder migration help" in
Cmdliner.Term.(ret (const help $ man_format $ choice_names $ topic)), let term = Term.(ret (const help $ Arg.man_format $ choice_names $ topic)) in
Cmdliner.Term.info ~doc "help" let info = Cmd.info ~doc "help" in
Cmd.v info term
let default_cmd =
let doc = "Builder migration command" in
Cmdliner.Term.(ret (const help $ man_format $ choice_names $ const None)),
Cmdliner.Term.info ~doc "builder-migrations"
let () = let () =
Cmdliner.Term.eval_choice let doc = "Builder migration command" in
default_cmd let default_term = Term.(ret (const help $ Arg.man_format $ choice_names $ const None)) in
let default_info = Cmd.info ~doc "builder-migrations" in
Cmd.group
~default:default_term default_info
(List.concat [ (List.concat [
[ help_cmd ]; [ help_cmd ];
actions (module M20210126); actions (module M20210126);
@ -164,4 +179,5 @@ let () =
[ f20210910 ]; [ f20210910 ];
actions (module M20211105); actions (module M20211105);
]) ])
|> Cmdliner.Term.exit |> Cmd.eval
|> exit

View file

@ -86,9 +86,9 @@ let print_dependencies_html file =
let html = Render.Html.of_assoc ~override_css graph in let html = Render.Html.of_assoc ~override_css graph in
Format.printf "%a" Render.Html.pp html Format.printf "%a" Render.Html.pp html
module Cmd = struct module Cmd_aux = struct
module Arg = struct module Arg_aux = struct
let elf_path = let elf_path =
let doc = "The file-path of the debug-ELF to be analyzed" in let doc = "The file-path of the debug-ELF to be analyzed" in
@ -127,15 +127,19 @@ module Cmd = struct
end end
open Cmdliner
let treemap = let treemap =
let doc = "Dump treemap SVG and CSS wrapped in HTML" in let doc = "Dump treemap SVG and CSS wrapped in HTML" in
Cmdliner.Term.(pure print_treemap_html $ Arg.elf_path $ Arg.elf_size), let term = Term.(const print_treemap_html $ Arg_aux.elf_path $ Arg_aux.elf_size) in
Cmdliner.Term.info ~doc "treemap" let info = Cmd.info ~doc "treemap" in
Cmd.v info term
let dependencies = let dependencies =
let doc = "Dump opam dependencies SVG and CSS wrapped in HTML" in let doc = "Dump opam dependencies SVG and CSS wrapped in HTML" in
Cmdliner.Term.(pure print_dependencies_html $ Arg.opam_switch_path), let term = Term.(const print_dependencies_html $ Arg_aux.opam_switch_path) in
Cmdliner.Term.info ~doc "dependencies" let info = Cmd.info ~doc "dependencies" in
Cmd.v info term
let help = let help =
let topic = let topic =
@ -143,20 +147,26 @@ module Cmd = struct
Cmdliner.Arg.(value & pos 0 (some string) None & info ~doc ~docv:"COMMAND" []) Cmdliner.Arg.(value & pos 0 (some string) None & info ~doc ~docv:"COMMAND" [])
in in
let doc = "Builder database help" in let doc = "Builder database help" in
Cmdliner.Term.(ret (const Aux.help $ man_format $ choice_names $ topic)), let term = Term.(ret (const Aux.help $ Arg.man_format $ choice_names $ topic)) in
Cmdliner.Term.info ~doc "help" let info = Cmd.info ~doc "help" in
Cmd.v info term
let default = let default_info, default_cmd =
let doc = "Builder database command" in let doc = "Builder database command" in
Cmdliner.Term.(ret (const Aux.help $ man_format $ choice_names $ const None)), let term = Term.(ret (const Aux.help $ Arg.man_format $ choice_names $ const None)) in
Cmdliner.Term.info ~doc "builder-viz" let info = Cmd.info ~doc "builder-viz" in
info, term
end end
let () = let () =
Cmdliner.Term.eval_choice Cmd.default [ let open Cmdliner in
Cmd.help; Cmd.group
Cmd.treemap; ~default:Cmd_aux.default_cmd Cmd_aux.default_info
Cmd.dependencies; [
Cmd_aux.help;
Cmd_aux.treemap;
Cmd_aux.dependencies;
] ]
|> Cmdliner.Term.exit |> Cmd.eval
|> exit

View file

@ -43,7 +43,7 @@ depends: [
"mirage-crypto" "mirage-crypto"
"asn1-combinators" "asn1-combinators"
"logs" "logs"
"cmdliner" "cmdliner" {>= "1.1.0"}
"uri" "uri"
"fmt" {>= "0.8.7"} "fmt" {>= "0.8.7"}
"omd" "omd"