Skip to content

Commit

Permalink
add initial version of [dune rpc build]
Browse files Browse the repository at this point in the history
Signed-off-by: Arseniy Alekseyev <[email protected]>
  • Loading branch information
aalekseyev committed Jun 1, 2021
1 parent 5a3877b commit edf1cd8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
46 changes: 42 additions & 4 deletions bin/rpc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ module Init = struct
let term = (Term.Group.Term term, info)
end

let report_error error =
Printf.printf "Error: %s\n"
(Dyn.to_string (Dune_rpc_private.Response.Error.to_dyn error))

module Status = struct
let term =
let+ (common : Common.t) = Common.term in
Expand All @@ -149,20 +153,54 @@ module Status = struct
()
in
match response with
| Error _ -> assert false
(* TODO *)
| Error error -> report_error error
| Ok { clients } ->
List.iter clients ~f:(fun client ->
let sexp = Dune_rpc.Conv.to_sexp Dune_rpc.Id.sexp client in
Sexp.to_string sexp |> print_endline))

let info =
let doc = "shot active connections" in
let doc = "show active connections" in
Term.info "status" ~doc

let term = (Term.Group.Term term, info)
end

module Build = struct
let term =
let name_ = Arg.info [] ~docv:"TARGET" in
let+ (common : Common.t) = Common.term
and+ targets = Arg.(value & pos_all string [] name_) in
client_term common @@ fun common ->
let where = wait_for_server common in
printfn "Server is listening on %s" (Dune_rpc.Where.to_string where);
printfn "ID's of connected clients (include this one):";
Dune_rpc_impl.Run.client where
(Dune_rpc.Initialize.Request.create
~id:(Dune_rpc.Id.make (Sexp.Atom "build")))
~on_notification:(fun _ -> assert false)
~f:(fun session ->
let open Fiber.O in
let+ response =
Dune_rpc_impl.Client.request session Dune_rpc_impl.Server.Decl.build
targets
in
match response with
| Error (error : Dune_rpc_private.Response.Error.t) ->
report_error error
| Ok Rejected -> print_endline "wut"
| Ok Accepted -> print_endline "Accepted")

let info =
let doc =
"build a given target (requires dune to be running in passive watching \
mode)"
in
Term.info "build" ~doc

let term = (Term.Group.Term term, info)
end

let info =
let doc = "Dune's RPC mechanism. Experimental." in
let man =
Expand All @@ -173,4 +211,4 @@ let info =
in
Term.info "rpc" ~doc ~man

let group = (Term.Group.Group [ Init.term; Status.term ], info)
let group = (Term.Group.Group [ Init.term; Status.term; Build.term ], info)
2 changes: 2 additions & 0 deletions otherlibs/dune-rpc/private/dune_rpc_private.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module Response : sig

exception E of t

val to_dyn : t -> Stdune.Dyn.t

val of_conv : Conv.error -> t

val create : ?payload:Csexp.t -> kind:kind -> message:string -> unit -> t
Expand Down
2 changes: 2 additions & 0 deletions otherlibs/dune-rpc/private/types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ module Response : sig
; kind : kind
}

val to_dyn : t -> Dyn.t

val payload : t -> Sexp.t option

val message : t -> string
Expand Down

0 comments on commit edf1cd8

Please sign in to comment.