From 97b7367cf29fb9b9d487ca447afb665574ed8887 Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 20 Jan 2023 22:45:53 +0000 Subject: [PATCH] Allow to pass custom "opam switch create" arguments --- lib/intf.ml | 4 ++-- lib/intf.mli | 4 ++-- lib/server_configfile.ml | 4 ++-- server/backend/admin.ml | 10 +++++----- server/backend/check.ml | 14 +++----------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/lib/intf.ml b/lib/intf.ml index d0802fd..7ebdeee 100644 --- a/lib/intf.ml +++ b/lib/intf.ml @@ -47,10 +47,10 @@ end module Switch = struct type t = Switch of Compiler.t * string - let create ~name ~switch = Switch (Compiler.from_string name, switch) + let create ~name ~args = Switch (Compiler.from_string name, args) let name (Switch (x, _)) = x - let switch (Switch (_, x)) = x + let args (Switch (_, x)) = x let equal (Switch (x, _)) (Switch (y, _)) = Compiler.equal x y let compare (Switch (x, _)) (Switch (y, _)) = Compiler.compare x y diff --git a/lib/intf.mli b/lib/intf.mli index 67553e7..e71b927 100644 --- a/lib/intf.mli +++ b/lib/intf.mli @@ -24,10 +24,10 @@ end module Switch : sig type t - val create : name:string -> switch:string -> t + val create : name:string -> args:string -> t val name : t -> Compiler.t - val switch : t -> string + val args : t -> string val equal : t -> t -> bool val compare : t -> t -> int diff --git a/lib/server_configfile.ml b/lib/server_configfile.ml index 0c9dfd4..1583261 100644 --- a/lib/server_configfile.ml +++ b/lib/server_configfile.ml @@ -59,7 +59,7 @@ let get_comp_str = function | _ -> failwith "string expected" let get_comp = function - | `O [name, `String switch] -> Intf.Switch.create ~name ~switch + | `O [name, `String args] -> Intf.Switch.create ~name ~args | _ -> failwith "key and value expected" let get_repo = function @@ -154,7 +154,7 @@ let yaml_of_extra_repositories l = `A (List.map (fun repo -> `O [Intf.Repository.name repo, aux repo]) l) let yaml_of_ocaml_switches l = - `A (List.map (fun s -> `O [Intf.(Compiler.to_string (Switch.name s)), `String (Intf.Switch.switch s)]) l) + `A (List.map (fun s -> `O [Intf.(Compiler.to_string (Switch.name s)), `String (Intf.Switch.args s)]) l) let yaml_of_slack_webhooks l = `A (List.map (fun s -> `String (Uri.to_string s)) l) diff --git a/server/backend/admin.ml b/server/backend/admin.ml index ce87d72..9803114 100644 --- a/server/backend/admin.ml +++ b/server/backend/admin.ml @@ -73,8 +73,8 @@ let admin_action ~on_finished ~conf ~run_trigger workdir body = else let%lwt () = Server_configfile.set_processes conf i in Lwt.return (fun () -> Lwt.return_none) - | ["add-ocaml-switch";name;switch] -> - let switch = Intf.Switch.create ~name ~switch in + | ["add-ocaml-switch";name;args] -> + let switch = Intf.Switch.create ~name ~args in let switches = Option.get_or ~default:[] (Server_configfile.ocaml_switches conf) in if List.mem ~eq:Intf.Switch.equal switch switches then Lwt.fail (Failure "Cannot have duplicate switches names.") @@ -82,15 +82,15 @@ let admin_action ~on_finished ~conf ~run_trigger workdir body = let switches = List.sort Intf.Switch.compare (switch :: switches) in let%lwt () = Server_configfile.set_ocaml_switches conf switches in Lwt.return (fun () -> Lwt.return_none) - | ["set-ocaml-switch";name;switch] -> - let switch = Intf.Switch.create ~name ~switch in + | ["set-ocaml-switch";name;args] -> + let switch = Intf.Switch.create ~name ~args in let switches = Option.get_or ~default:[] (Server_configfile.ocaml_switches conf) in let idx, _ = Option.get_exn_or "can't find switch name" (List.find_idx (Intf.Switch.equal switch) switches) in let switches = List.set_at_idx idx switch switches in let%lwt () = Server_configfile.set_ocaml_switches conf switches in Lwt.return (fun () -> Lwt.return_none) | ["rm-ocaml-switch";name] -> - let switch = Intf.Switch.create ~name ~switch:"(* TODO: remove this shit *)" in + let switch = Intf.Switch.create ~name ~args:"(* TODO: remove this shit *)" in let switches = Option.get_or ~default:[] (Server_configfile.ocaml_switches conf) in let switches = List.remove ~eq:Intf.Switch.equal ~key:switch switches in let%lwt () = Server_configfile.set_ocaml_switches conf switches in diff --git a/server/backend/check.ml b/server/backend/check.ml index 4c6106c..28fed5f 100644 --- a/server/backend/check.ml +++ b/server/backend/check.ml @@ -186,7 +186,7 @@ exit $res let run_job ~cap ~conf ~pool ~stderr ~base_obuilder ~switch ~num logdir pkg = Lwt_pool.use pool begin fun () -> - let%lwt () = Lwt_io.write_line stderr ("["^num^"] Checking "^pkg^" on "^Intf.Switch.switch switch^"…") in + let%lwt () = Lwt_io.write_line stderr ("["^num^"] Checking "^pkg^" on "^Intf.Compiler.to_string (Intf.Switch.name switch)^"…") in let switch = Intf.Switch.name switch in let logfile = Server_workdirs.tmplogfile ~pkg ~switch logdir in match%lwt @@ -255,20 +255,12 @@ let get_obuilder ~conf ~opam_repo ~opam_repo_commit ~extra_repos switch = ] ) extra_repos ) @ [ - run ~cache ~network "opam switch create --repositories=%sdefault '%s' '%s'" + run ~cache ~network "opam switch create --repositories=%sdefault '%s' %s" (List.fold_left (fun acc (repo, _) -> Intf.Repository.name repo^","^acc) "" extra_repos) (Intf.Compiler.to_string (Intf.Switch.name switch)) - (Intf.Switch.switch switch); + (Intf.Switch.args switch); run ~network "opam update --depexts"; ] @ - (* TODO: Should this be removed now that it is part of the base docker images? What about macOS? *) - (if OpamVersionCompare.compare (Intf.Switch.switch switch) "4.08" < 0 then - [run ~cache ~network "opam install -y ocaml-secondary-compiler"] - (* NOTE: See https://github.com/ocaml/opam-repository/pull/15404 - and https://github.com/ocaml/opam-repository/pull/15642 *) - else - [] - ) @ (match Server_configfile.extra_command conf with | Some c -> [run ~cache ~network "%s" c] | None -> []