Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passive watch mode for tests #4678

Merged
merged 31 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9706fd9
[RPC] fix result of dune rpc status
rgrinberg Jun 2, 2021
4629232
[RPC] use correct socket type
rgrinberg Jun 2, 2021
77f1f50
[RPC] destroy thread after connecting
rgrinberg Jun 2, 2021
588ac52
separate poll iteration into a separate function, introduce a standin…
aalekseyev Jun 1, 2021
5f039a2
add server-side support for passive watch mode
aalekseyev Jun 1, 2021
d88b6c4
add initial version of [dune rpc build]
aalekseyev Jun 1, 2021
d939b8c
flush
aalekseyev Jun 1, 2021
5eea6ec
fix a test, fix inotify sync
aalekseyev Jun 2, 2021
1259e61
build_outcome
aalekseyev Jun 2, 2021
fa24455
add a test
aalekseyev Jun 2, 2021
0627881
fix the test
aalekseyev Jun 2, 2021
0078118
tidier inotify sync
aalekseyev Jun 4, 2021
4a22394
merge
aalekseyev Jun 4, 2021
eef8236
make fmt
aalekseyev Jun 4, 2021
61dc663
Merge branch 'main' into dune-build-rpc-for-tests
aalekseyev Jun 7, 2021
3f3c441
disable test on macos
aalekseyev Jun 7, 2021
f02858a
Merge branch 'dune-build-rpc-for-tests' of github.com:aalekseyev/dune…
aalekseyev Jun 7, 2021
cce431a
Doc + API unification
jeremiedimino Jun 7, 2021
80f799c
tweak test
aalekseyev Jun 7, 2021
2eec898
Merge branch 'dune-build-rpc-for-tests' of github.com:aalekseyev/dune…
aalekseyev Jun 7, 2021
6eb1548
add comment about the '@' exclusion limitation, fix the exclude patte…
aalekseyev Jun 7, 2021
8a3bf97
Unify [poll] and [poll_passive] into poll_gen
aalekseyev Jun 8, 2021
a4af217
add to comment
aalekseyev Jun 8, 2021
8823055
make --wait work for [dune rpc build]
aalekseyev Jun 8, 2021
84bc17e
make fmt
aalekseyev Jun 8, 2021
8f78ce0
make -wpfoo mean 'watching build package foo' for backwards-compatibi…
aalekseyev Jun 8, 2021
d29b2e1
simplify build_cmd.ml
aalekseyev Jun 8, 2021
00d552b
add docs to poll_passive, make fmt
aalekseyev Jun 8, 2021
9486337
merge with main
aalekseyev Jun 10, 2021
5f7424a
get rid of is_polling
aalekseyev Jun 10, 2021
43e5c2e
share the [step] type definition
aalekseyev Jun 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 47 additions & 31 deletions bin/build_cmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,63 @@ let run_build_system ~common ~(request : unit Action_builder.t) () =
]));
Fiber.return ())

let run_build_command_poll ~(common : Common.t) ~config ~request ~setup =
let setup () = Import.Main.setup ()

let run_build_system ~common ~request =
let open Fiber.O in
let every =
Fiber.of_thunk (fun () ->
Cached_digest.invalidate_cached_timestamps ();
let* setup = setup () in
let* request =
match
let open Option.O in
let* rpc = Common.rpc common in
Dune_rpc_impl.Server.pending_build_action rpc
with
| None -> Fiber.return (request setup)
| Some (Build (targets, ivar)) ->
let+ () = Fiber.Ivar.fill ivar Accepted in
Target.interpret_targets (Common.root common) config setup targets
in
run_build_system ~common ~request ())
in
Scheduler.poll ~common ~config ~every ~finally:Hooks.End_of_build.run
Fiber.finalize
(fun () ->
Cached_digest.invalidate_cached_timestamps ();
let* setup = setup () in
let request = request setup in
run_build_system ~common ~request ())
~finally:(fun () ->
Hooks.End_of_build.run ();
Fiber.return ())

let run_build_command_poll_eager ~(common : Common.t) ~config ~request : unit =
Import.Scheduler.go_with_rpc_server_and_console_status_reporting ~common
~config (fun () -> Scheduler.Run.poll (run_build_system ~common ~request))

let run_build_command_poll_passive ~(common : Common.t) ~config ~request:_ :
unit =
(* CR-someday aalekseyev: It would've been better to complain if [request] is
non-empty, but we can't check that here because [request] is a function.*)
let open Fiber.O in
match Common.rpc common with
| None ->
Code_error.raise
"Attempted to start a passive polling mode without an RPC server" []
| Some rpc ->
Import.Scheduler.go_with_rpc_server_and_console_status_reporting ~common
~config (fun () ->
Scheduler.Run.poll_passive
~get_build_request:
(let+ (Build (targets, ivar)) =
Dune_rpc_impl.Server.pending_build_action rpc
in
let request setup =
Target.interpret_targets (Common.root common) config setup
targets
in
(run_build_system ~common ~request, ivar)))

let run_build_command_once ~(common : Common.t) ~config ~request ~setup =
let run_build_command_once ~(common : Common.t) ~config ~request =
let open Fiber.O in
let once () =
let* setup = setup () in
let+ res = run_build_system ~common ~request:(request setup) () in
let+ res = run_build_system ~common ~request in
match res with
| Error `Already_reported ->
(* to ensure non-zero exit code *)
raise Dune_util.Report_error.Already_reported
| Error `Already_reported -> raise Dune_util.Report_error.Already_reported
| Ok () -> ()
in
Scheduler.go ~common ~config once

let run_build_command ~(common : Common.t) ~config ~request =
let setup () = Import.Main.setup () in
(if Common.watch common then
run_build_command_poll
else
run_build_command_once)
~setup ~common ~config ~request
(match Common.watch common with
| Yes Eager -> run_build_command_poll_eager
| Yes Passive -> run_build_command_poll_passive
| No -> run_build_command_once)
~common ~config ~request

let runtest =
let doc = "Run tests." in
Expand Down
31 changes: 18 additions & 13 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type t =
orig_args : string list
; rpc : Dune_rpc_impl.Server.t option
; default_target : Arg.Dep.t (* For build & runtest only *)
; watch : bool
; watch : Dune_engine.Watch_mode_config.t
; print_metrics : bool
; stats_trace_file : string option
; always_show_command_line : bool
Expand Down Expand Up @@ -525,6 +525,11 @@ let display_term =
{|Control the display mode of Dune.
See $(b,dune-config\(5\)) for more details.|})

let simple_arg_conv ~to_string ~of_string =
Arg.conv
( (fun s -> Result.map_error (of_string s) ~f:(fun s -> `Msg s))
, fun pp x -> Format.pp_print_string pp (to_string x) )

let shared_with_config_file =
let docs = copts_sect in
let+ concurrency =
Expand All @@ -542,12 +547,8 @@ let shared_with_config_file =
~doc:{|Run no more than $(i,JOBS) commands simultaneously.|})
and+ sandboxing_preference =
let arg =
Arg.conv
( (fun s ->
Result.map_error (Dune_engine.Sandbox_mode.of_string s) ~f:(fun s ->
`Msg s))
, fun pp x ->
Format.pp_print_string pp (Dune_engine.Sandbox_mode.to_string x) )
simple_arg_conv ~of_string:Dune_engine.Sandbox_mode.of_string
~to_string:Dune_engine.Sandbox_mode.to_string
in
Arg.(
value
Expand Down Expand Up @@ -799,9 +800,14 @@ let term =
"Force actions associated to aliases to be re-executed even\n\
\ if their dependencies haven't changed.")
and+ watch =
let watch_arg_name = "watch" in
Arg.(
value & flag
& info [ "watch"; "w" ]
value
& opt ~vopt:(Dune_engine.Watch_mode_config.Yes Eager)
(simple_arg_conv ~to_string:Dune_engine.Watch_mode_config.to_string
~of_string:Dune_engine.Watch_mode_config.of_string)
Dune_engine.Watch_mode_config.No
& info [ watch_arg_name; "w" ]
~doc:
"Instead of terminating build after completion, wait continuously \
for file changes.")
Expand Down Expand Up @@ -928,10 +934,9 @@ let term =
let build_dir = Option.value ~default:default_build_dir build_dir in
let root = Workspace_root.create ~specified_by_user:root in
let rpc =
if watch then
Some (Dune_rpc_impl.Server.create ())
else
None
match watch with
| Yes _ -> Some (Dune_rpc_impl.Server.create ())
| No -> None
in
let stats =
Option.map stats_trace_file ~f:(fun f ->
Expand Down
2 changes: 1 addition & 1 deletion bin/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ val stats : t -> Dune_stats.t option

val print_metrics : t -> bool

val watch : t -> bool
val watch : t -> Dune_engine.Watch_mode_config.t

val file_watcher : t -> Dune_engine.Scheduler.Run.file_watcher

Expand Down
17 changes: 9 additions & 8 deletions bin/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ include Common.Let_syntax

let in_group (t, info) = (Term.Group.Term t, info)

module Main = struct
module Main : sig
include module type of struct
include Dune_rules.Main
end

val setup : unit -> build_system Fiber.t
end = struct
include Dune_rules.Main

let setup () =
Expand Down Expand Up @@ -92,18 +98,13 @@ module Scheduler = struct
let config = Dune_config.for_scheduler dune_config None stats in
Scheduler.Run.go config ~on_event:(on_event dune_config) f

let poll ~(common : Common.t) ~config:dune_config ~every ~finally =
let go_with_rpc_server_and_console_status_reporting ~(common : Common.t)
~config:dune_config run =
let stats = Common.stats common in
let rpc_where = Some (Dune_rpc_private.Where.default ()) in
let config = Dune_config.for_scheduler dune_config rpc_where stats in
let file_watcher = Common.file_watcher common in
let run =
let run () =
Scheduler.Run.poll
(Fiber.finalize
(fun () -> every)
~finally:(fun () -> Fiber.return (finally ())))
in
match Common.rpc common with
| None -> run
| Some rpc ->
Expand Down
Loading