diff --git a/bin/build.ml b/bin/build.ml index 62fce29c983..1a6939b1ec5 100644 --- a/bin/build.ml +++ b/bin/build.ml @@ -143,14 +143,6 @@ let run_build_command ~(common : Common.t) ~config ~request = ~request ;; -let build_via_rpc_server ~print_on_success ~targets builder lock_held_by = - Rpc.Rpc_common.wrap_build_outcome_exn - ~print_on_success - (Rpc.Group.Build.build ~wait:true builder lock_held_by) - targets - () -;; - let build = let doc = "Build the given targets, or the default ones if none are given." in let man = @@ -203,10 +195,16 @@ let build = an RPC server in the background to schedule the fiber which will perform the RPC call. *) + let targets = Rpc.Rpc_common.prepare_targets targets in Rpc.Rpc_common.run_via_rpc ~common ~config - (Rpc.Group.Build.build ~wait:true builder lock_held_by) + (Rpc.Rpc_common.fire_request + ~name:"build" + ~wait:true + ~lock_held_by + builder + Dune_rpc_impl.Decl.build) targets | Ok () -> let request setup = diff --git a/bin/build.mli b/bin/build.mli index b7f2cf000c9..991de1711f3 100644 --- a/bin/build.mli +++ b/bin/build.mli @@ -1,17 +1,5 @@ open Import -(** Connect to an RPC server (waiting for the server to start if necessary) and - then send a request to the server to build the specified targets. If the - build fails then a diagnostic error message is printed. If - [print_on_success] is true then this function will also print a message - after the build succeeds. *) -val build_via_rpc_server - : print_on_success:bool - -> targets:Dune_lang.Dep_conf.t list - -> Common.Builder.t - -> Dune_util.Global_lock.Lock_held_by.t - -> unit Fiber.t - val run_build_system : common:Common.t -> request:(Dune_rules.Main.build_system -> unit Action_builder.t) diff --git a/bin/exec.ml b/bin/exec.ml index 810859d2818..7310511e9f7 100644 --- a/bin/exec.ml +++ b/bin/exec.ml @@ -225,11 +225,17 @@ let build_prog_via_rpc_if_necessary ~dir ~no_rebuild builder lock_held_by prog = Dune_lang.Dep_conf.File (Dune_lang.String_with_vars.make_text Loc.none (Path.to_string path)) in - Build.build_via_rpc_server + let targets = Rpc.Rpc_common.prepare_targets [ target ] in + Rpc.Rpc_common.wrap_build_outcome_exn ~print_on_success:false - ~targets:[ target ] - builder - lock_held_by) + (Rpc.Rpc_common.fire_request + ~name:"build" + ~wait:true + ~lock_held_by + builder + Dune_rpc_impl.Decl.build) + targets + ()) in Path.to_absolute_filename path | Absolute -> diff --git a/bin/rpc/rpc_build.ml b/bin/rpc/rpc_build.ml index a751c2b9042..89cc3850179 100644 --- a/bin/rpc/rpc_build.ml +++ b/bin/rpc/rpc_build.ml @@ -1,20 +1,5 @@ open Import -let build ~wait builder lock_held_by targets = - let targets = - List.map targets ~f:(fun target -> - let sexp = Dune_lang.Dep_conf.encode target in - Dune_lang.to_string sexp) - in - Rpc_common.fire_request - ~name:"build" - ~wait - ~lock_held_by - builder - Dune_rpc_impl.Decl.build - targets -;; - let term = let name_ = Arg.info [] ~docv:"TARGET" in let+ (builder : Common.Builder.t) = Common.Builder.term diff --git a/bin/rpc/rpc_build.mli b/bin/rpc/rpc_build.mli index 336f467c22a..4cd40300e56 100644 --- a/bin/rpc/rpc_build.mli +++ b/bin/rpc/rpc_build.mli @@ -1,15 +1,4 @@ open! Import -(** Sends a command to an RPC server to build the specified targets and wait - for the build to complete or fail. If [wait] is true then wait until an RPC - server is running before making the request. Otherwise if no RPC server is - running then raise a [User_error]. *) -val build - : wait:bool - -> Common.Builder.t - -> Dune_util.Global_lock.Lock_held_by.t - -> Dune_lang.Dep_conf.t list - -> (Dune_rpc.Build_outcome_with_diagnostics.t, Dune_rpc.Response.Error.t) result Fiber.t - (** dune rpc build command *) val cmd : unit Cmdliner.Cmd.t diff --git a/bin/rpc/rpc_common.ml b/bin/rpc/rpc_common.ml index 010b8bdfd97..4ed3aeecb6f 100644 --- a/bin/rpc/rpc_common.ml +++ b/bin/rpc/rpc_common.ml @@ -75,6 +75,12 @@ let establish_client_session ~wait = if wait then establish_connection_with_retry () else establish_connection_exn () ;; +let prepare_targets targets = + List.map targets ~f:(fun target -> + let sexp = Dune_lang.Dep_conf.encode target in + Dune_lang.to_string sexp) +;; + let warn_ignore_arguments lock_held_by = User_warning.emit [ Pp.paragraphf diff --git a/bin/rpc/rpc_common.mli b/bin/rpc/rpc_common.mli index cb370d2b291..afbc319b892 100644 --- a/bin/rpc/rpc_common.mli +++ b/bin/rpc/rpc_common.mli @@ -21,6 +21,10 @@ val client_term : Common.Builder.t -> (unit -> 'a Fiber.t) -> 'a (** Cmdliner argument for a wait flag. *) val wait_term : bool Cmdliner.Term.t +(** Encode the targets as [Dune_lang.t], and then as strings suitable to + be sent via RPC. *) +val prepare_targets : Dune_lang.Dep_conf.t list -> string list + (** Send a request to the RPC server. If [wait], it will poll forever until a server is listening. Should be scheduled by a scheduler that does not come with a RPC server on its own. diff --git a/bin/tools/tools_common.ml b/bin/tools/tools_common.ml index 6d1c2fd9bbc..821ee40994a 100644 --- a/bin/tools/tools_common.ml +++ b/bin/tools/tools_common.ml @@ -35,11 +35,17 @@ let build_dev_tool_directly common dev_tool = let build_dev_tool_via_rpc builder lock_held_by dev_tool = let target = dev_tool_build_target dev_tool in - Build.build_via_rpc_server + let targets = Rpc.Rpc_common.prepare_targets [ target ] in + Rpc.Rpc_common.wrap_build_outcome_exn ~print_on_success:false - ~targets:[ target ] - builder - lock_held_by + (Rpc.Rpc_common.fire_request + ~name:"build" + ~wait:true + ~lock_held_by + builder + Dune_rpc_impl.Decl.build) + targets + () ;; let lock_and_build_dev_tool ~common ~config builder dev_tool =