Skip to content

Commit 7861fb5

Browse files
authored
Allow running tests concurrently with watch server, again! (#12473)
* Allow running tests concurrently with watch server * Fix 'forwarding' warning appearing too early --------- Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
1 parent 8a38996 commit 7861fb5

24 files changed

Lines changed: 341 additions & 206 deletions

bin/build.ml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,16 @@ let poll_handling_rpc_build_requests ~(common : Common.t) ~config =
9292
in
9393
Dune_engine.Scheduler.Run.poll_passive
9494
~get_build_request:
95-
(let+ (Build (targets, ivar)) = Dune_rpc_impl.Server.pending_build_action rpc in
95+
(let+ { kind; outcome } = Dune_rpc_impl.Server.pending_action rpc in
9696
let request setup =
97-
Target.interpret_targets (Common.root common) config setup targets
97+
let root = Common.root common in
98+
match kind with
99+
| Build targets ->
100+
Target.interpret_targets (Common.root common) config setup targets
101+
| Runtest dir_or_cram_test_paths ->
102+
Runtest_common.make_request ~dir_or_cram_test_paths ~to_cwd:root.to_cwd setup
98103
in
99-
run_build_system ~common ~request, ivar)
104+
run_build_system ~common ~request, outcome)
100105
;;
101106

102107
let run_build_command_poll_eager ~(common : Common.t) ~config ~request : unit =
@@ -138,10 +143,10 @@ let run_build_command ~(common : Common.t) ~config ~request =
138143
~request
139144
;;
140145

141-
let build_via_rpc_server ~print_on_success ~targets =
146+
let build_via_rpc_server ~print_on_success ~targets builder lock_held_by =
142147
Rpc.Rpc_common.wrap_build_outcome_exn
143148
~print_on_success
144-
(Rpc.Group.Build.build ~wait:true)
149+
(Rpc.Group.Build.build ~wait:true builder lock_held_by)
145150
targets
146151
()
147152
;;
@@ -199,11 +204,9 @@ let build =
199204
perform the RPC call.
200205
*)
201206
Rpc.Rpc_common.run_via_rpc
202-
~builder
203207
~common
204208
~config
205-
lock_held_by
206-
(Rpc.Group.Build.build ~wait:true)
209+
(Rpc.Group.Build.build ~wait:true builder lock_held_by)
207210
targets
208211
| Ok () ->
209212
let request setup =

bin/build.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ open Import
88
val build_via_rpc_server
99
: print_on_success:bool
1010
-> targets:Dune_lang.Dep_conf.t list
11+
-> Common.Builder.t
12+
-> Dune_util.Global_lock.Lock_held_by.t
1113
-> unit Fiber.t
1214

1315
val run_build_system

bin/exec.ml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ let step ~prog ~args ~common ~no_rebuild ~context ~on_exit () =
187187
directory lock.
188188
189189
Returns the absolute path to the executable. *)
190-
let build_prog_via_rpc_if_necessary ~dir ~no_rebuild prog =
190+
let build_prog_via_rpc_if_necessary ~dir ~no_rebuild builder lock_held_by prog =
191191
match Filename.analyze_program_name prog with
192192
| In_path ->
193193
(* This case is reached if [dune exec] is passed the name of an
@@ -225,7 +225,11 @@ let build_prog_via_rpc_if_necessary ~dir ~no_rebuild prog =
225225
Dune_lang.Dep_conf.File
226226
(Dune_lang.String_with_vars.make_text Loc.none (Path.to_string path))
227227
in
228-
Build.build_via_rpc_server ~print_on_success:false ~targets:[ target ])
228+
Build.build_via_rpc_server
229+
~print_on_success:false
230+
~targets:[ target ]
231+
builder
232+
lock_held_by)
229233
in
230234
Path.to_absolute_filename path
231235
| Absolute ->
@@ -234,7 +238,7 @@ let build_prog_via_rpc_if_necessary ~dir ~no_rebuild prog =
234238
else not_found ~hints:[] ~prog
235239
;;
236240

237-
let exec_building_via_rpc_server ~common ~prog ~args ~no_rebuild =
241+
let exec_building_via_rpc_server ~common ~prog ~args ~no_rebuild builder lock_held_by =
238242
let open Fiber.O in
239243
let ensure_terminal v =
240244
match (v : Cmd_arg.t) with
@@ -252,7 +256,9 @@ let exec_building_via_rpc_server ~common ~prog ~args ~no_rebuild =
252256
let dir = Context_name.build_dir context in
253257
let prog = ensure_terminal prog in
254258
let args = List.map args ~f:ensure_terminal in
255-
let+ prog = build_prog_via_rpc_if_necessary ~dir ~no_rebuild prog in
259+
let+ prog =
260+
build_prog_via_rpc_if_necessary ~dir ~no_rebuild builder lock_held_by prog
261+
in
256262
restore_cwd_and_execve (Common.root common) prog args Env.initial
257263
;;
258264

@@ -311,18 +317,9 @@ let term : unit Term.t =
311317
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
312318
]
313319
| No ->
314-
if not (Common.Builder.equal builder Common.Builder.default)
315-
then
316-
User_warning.emit
317-
[ Pp.textf
318-
"Your build request is being forwarded to a running Dune instance%s. Note \
319-
that certain command line arguments may be ignored."
320-
(match lock_held_by with
321-
| Unknown -> ""
322-
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
323-
];
324320
Scheduler.go_without_rpc_server ~common ~config
325-
@@ fun () -> exec_building_via_rpc_server ~common ~prog ~args ~no_rebuild)
321+
@@ fun () ->
322+
exec_building_via_rpc_server ~common ~prog ~args ~no_rebuild builder lock_held_by)
326323
| Ok () -> exec_building_directly ~common ~config ~context ~prog ~args ~no_rebuild
327324
;;
328325

bin/fmt.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let lock_ocamlformat () =
2626
else Fiber.return ()
2727
;;
2828

29-
let run_fmt_command ~common ~config ~preview =
29+
let run_fmt_command ~common ~config ~preview builder =
3030
let open Fiber.O in
3131
let once () =
3232
let* () = lock_ocamlformat () in
@@ -50,6 +50,9 @@ let run_fmt_command ~common ~config ~preview =
5050
Rpc.Rpc_common.fire_request
5151
~name:"format"
5252
~wait:true
53+
~warn_forwarding:false
54+
~lock_held_by
55+
builder
5356
Dune_rpc.Procedures.Public.format
5457
())
5558
in
@@ -81,7 +84,7 @@ let command =
8184
Common.Builder.set_promote builder (if preview then Never else Automatically)
8285
in
8386
let common, config = Common.init builder in
84-
run_fmt_command ~common ~config ~preview
87+
run_fmt_command ~common ~config ~preview builder
8588
in
8689
Cmd.v (Cmd.info "fmt" ~doc ~man ~envs:Common.envs) term
8790
;;

bin/promotion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ module Apply = struct
6363
Diff_promotion.promote_files_registered_in_last_run files_to_promote)
6464
| Error lock_held_by ->
6565
Rpc.Rpc_common.run_via_rpc
66-
~builder
6766
~common
6867
~config
69-
lock_held_by
7068
(Rpc.Rpc_common.fire_request
7169
~name:"promote_many"
7270
~wait:true
71+
~lock_held_by
72+
builder
7373
Dune_rpc_private.Procedures.Public.promote_many)
7474
files_to_promote
7575
;;

bin/rpc/rpc_build.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
open Import
22

3-
let build ~wait targets =
3+
let build ~wait builder lock_held_by targets =
44
let targets =
55
List.map targets ~f:(fun target ->
66
let sexp = Dune_lang.Dep_conf.encode target in
77
Dune_lang.to_string sexp)
88
in
9-
Rpc_common.fire_request ~name:"build" ~wait Dune_rpc_impl.Decl.build targets
9+
Rpc_common.fire_request
10+
~name:"build"
11+
~wait
12+
~lock_held_by
13+
builder
14+
Dune_rpc_impl.Decl.build
15+
targets
1016
;;
1117

1218
let term =
@@ -18,7 +24,7 @@ let term =
1824
@@ fun () ->
1925
let open Fiber.O in
2026
let+ response =
21-
Rpc_common.fire_request ~name:"build" ~wait Dune_rpc_impl.Decl.build targets
27+
Rpc_common.fire_request ~name:"build" ~wait builder Dune_rpc_impl.Decl.build targets
2228
in
2329
match response with
2430
| Error (error : Dune_rpc.Response.Error.t) ->

bin/rpc/rpc_build.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ open! Import
66
running then raise a [User_error]. *)
77
val build
88
: wait:bool
9+
-> Common.Builder.t
10+
-> Dune_util.Global_lock.Lock_held_by.t
911
-> Dune_lang.Dep_conf.t list
1012
-> (Dune_rpc.Build_outcome_with_diagnostics.t, Dune_rpc.Response.Error.t) result Fiber.t
1113

bin/rpc/rpc_common.ml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,30 @@ let establish_client_session ~wait =
7575
if wait then establish_connection_with_retry () else establish_connection_exn ()
7676
;;
7777

78-
let fire_request ~name ~wait request arg =
78+
let warn_ignore_arguments lock_held_by =
79+
User_warning.emit
80+
[ Pp.paragraphf
81+
"Your build request is being forwarded to a running Dune instance%s. Note that \
82+
certain command line arguments may be ignored."
83+
(match lock_held_by with
84+
| Dune_util.Global_lock.Lock_held_by.Unknown -> ""
85+
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
86+
]
87+
;;
88+
89+
let fire_request
90+
~name
91+
~wait
92+
?(warn_forwarding = true)
93+
?(lock_held_by = Dune_util.Global_lock.Lock_held_by.Unknown)
94+
builder
95+
request
96+
arg
97+
=
7998
let open Fiber.O in
8099
let* connection = establish_client_session ~wait in
100+
if warn_forwarding && not (Common.Builder.equal builder Common.Builder.default)
101+
then warn_ignore_arguments lock_held_by;
81102
Dune_rpc_impl.Client.client
82103
connection
83104
(Dune_rpc.Initialize.Request.create ~id:(Dune_rpc.Id.make (Sexp.Atom name)))
@@ -107,20 +128,7 @@ let wrap_build_outcome_exn ~print_on_success f args () =
107128
Console.print [ error_msg |> Pp.tag User_message.Style.Error ]
108129
;;
109130

110-
let warn_ignore_arguments lock_held_by =
111-
User_warning.emit
112-
[ Pp.paragraphf
113-
"Your build request is being forwarded to a running Dune instance%s. Note that \
114-
certain command line arguments may be ignored."
115-
(match lock_held_by with
116-
| Dune_util.Global_lock.Lock_held_by.Unknown -> ""
117-
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
118-
]
119-
;;
120-
121-
let run_via_rpc ~builder ~common ~config lock_held_by f args =
122-
if not (Common.Builder.equal builder Common.Builder.default)
123-
then warn_ignore_arguments lock_held_by;
131+
let run_via_rpc ~common ~config f args =
124132
Scheduler.go_without_rpc_server
125133
~common
126134
~config

bin/rpc/rpc_common.mli

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ val client_term : Common.Builder.t -> (unit -> 'a Fiber.t) -> 'a
2222
val wait_term : bool Cmdliner.Term.t
2323

2424
(** Send a request to the RPC server. If [wait], it will poll forever until a server is listening.
25-
Should be scheduled by a scheduler that does not come with a RPC server on its own. *)
25+
Should be scheduled by a scheduler that does not come with a RPC server on its own.
26+
27+
[warn_forwarding] defaults to true, warns the user that since a RPC server is running, some arguments are ignored.
28+
[lock_held_by] defaults to [Unknown], is only used to allow error messages to print the PID. *)
2629
val fire_request
2730
: name:string
2831
-> wait:bool
32+
-> ?warn_forwarding:bool
33+
-> ?lock_held_by:Dune_util.Global_lock.Lock_held_by.t
34+
-> Common.Builder.t
2935
-> ('a, 'b) Dune_rpc.Decl.request
3036
-> 'a
3137
-> ('b, Dune_rpc.Response.Error.t) result Fiber.t
@@ -44,10 +50,8 @@ val warn_ignore_arguments : Dune_util.Global_lock.Lock_held_by.t -> unit
4450

4551
(** Schedule a fiber to run via RPC, wrapping any errors. *)
4652
val run_via_rpc
47-
: builder:Common.Builder.t
48-
-> common:Common.t
53+
: common:Common.t
4954
-> config:Dune_config_file.Dune_config.t
50-
-> Dune_util.Global_lock.Lock_held_by.t
5155
-> ('a
5256
-> (Dune_rpc.Build_outcome_with_diagnostics.t, Dune_rpc.Response.Error.t) result
5357
Fiber.t)

bin/rpc/rpc_ping.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ let term =
1818
Rpc_common.fire_request
1919
~name:"ping_cmd"
2020
~wait
21+
builder
2122
Dune_rpc_private.Procedures.Public.ping
2223
()
2324
>>| function

0 commit comments

Comments
 (0)