Skip to content

Commit

Permalink
Allow to pass custom "opam switch create" arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jan 20, 2023
1 parent 1fa2466 commit 97b7367
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/intf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/server_configfile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions server/backend/admin.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ 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.")
else
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
Expand Down
14 changes: 3 additions & 11 deletions server/backend/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -> []
Expand Down

0 comments on commit 97b7367

Please sign in to comment.