Skip to content

Commit d3a4ed0

Browse files
committed
Actually move everything needed for promote_many into dune_rpc_private
* Demonstrate what moving everything into dune_rpc_private means * Previous commit was just copying, this is really moving things Signed-off-by: Ambre Austen Suhamy <[email protected]>
1 parent 78b83c8 commit d3a4ed0

33 files changed

+272
-271
lines changed

bin/promotion.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Import
22
module Diff_promotion = Promote.Diff_promotion
33

4-
let files_to_promote ~common files : Diff_promotion.files_to_promote =
4+
let files_to_promote ~common files : Dune_rpc.Files_to_promote.t =
55
match files with
66
| [] -> All
77
| _ ->
@@ -70,7 +70,7 @@ module Apply = struct
7070
(Rpc_common.fire_request
7171
~name:"promote_many"
7272
~wait:true
73-
Dune_rpc_impl.Decl.promote)
73+
Dune_rpc_private.Procedures.Public.promote_many)
7474
files_to_promote
7575
;;
7676

bin/rpc/rpc_build.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ let term =
2121
Rpc_common.fire_request ~name:"build" ~wait Dune_rpc_impl.Decl.build targets
2222
in
2323
match response with
24-
| Error (error : Dune_rpc_private.Response.Error.t) ->
25-
Printf.eprintf
26-
"Error: %s\n%!"
27-
(Dyn.to_string (Dune_rpc_private.Response.Error.to_dyn error))
24+
| Error (error : Dune_rpc.Response.Error.t) ->
25+
Printf.eprintf "Error: %s\n%!" (Dyn.to_string (Dune_rpc.Response.Error.to_dyn error))
2826
| Ok Success -> print_endline "Success"
2927
| Ok (Failure _) -> print_endline "Failure"
3028
;;

bin/rpc/rpc_build.mli

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ open! Import
77
val build
88
: wait:bool
99
-> Dune_lang.Dep_conf.t list
10-
-> ( Dune_rpc_impl.Decl.Build_outcome_with_diagnostics.t
11-
, Dune_rpc.Response.Error.t )
12-
result
13-
Fiber.t
10+
-> (Dune_rpc.Build_outcome_with_diagnostics.t, Dune_rpc.Response.Error.t) result Fiber.t
1411

1512
(** dune rpc build command *)
1613
val cmd : unit Cmdliner.Cmd.t

bin/rpc/rpc_common.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open Import
22
module Client = Dune_rpc_client.Client
3-
module Rpc_error = Dune_rpc_private.Response.Error
3+
module Rpc_error = Dune_rpc.Response.Error
44

55
let active_server () =
66
match Dune_rpc_impl.Where.get () with
@@ -28,7 +28,7 @@ let request_exn client witness n =
2828
let open Fiber.O in
2929
let* decl = Client.Versioned.prepare_request client witness in
3030
match decl with
31-
| Error e -> raise (Dune_rpc_private.Version_error.E e)
31+
| Error e -> raise (Dune_rpc.Version_error.E e)
3232
| Ok decl -> Client.request client decl n
3333
;;
3434

@@ -79,8 +79,7 @@ let fire_request ~name ~wait request arg =
7979
Dune_rpc_impl.Client.client
8080
connection
8181
(Dune_rpc.Initialize.Request.create ~id:(Dune_rpc.Id.make (Sexp.Atom name)))
82-
~f:(fun client ->
83-
request_exn client (Dune_rpc_private.Decl.Request.witness request) arg)
82+
~f:(fun client -> request_exn client (Dune_rpc.Decl.Request.witness request) arg)
8483
;;
8584

8685
let wrap_build_outcome_exn ~print_on_success f args () =
@@ -89,13 +88,13 @@ let wrap_build_outcome_exn ~print_on_success f args () =
8988
match response with
9089
| Error (error : Rpc_error.t) ->
9190
Printf.eprintf "Error: %s\n%!" (Dyn.to_string (Rpc_error.to_dyn error))
92-
| Ok Dune_rpc_impl.Decl.Build_outcome_with_diagnostics.Success ->
91+
| Ok Dune_rpc.Build_outcome_with_diagnostics.Success ->
9392
if print_on_success
9493
then
9594
Console.print_user_message
9695
(User_message.make [ Pp.text "Success" |> Pp.tag User_message.Style.Success ])
9796
| Ok (Failure errors) ->
98-
List.iter errors ~f:(fun { Dune_engine.Compound_user_error.main; _ } ->
97+
List.iter errors ~f:(fun { Dune_rpc.Compound_user_error.main; _ } ->
9998
Console.print_user_message main);
10099
User_error.raise
101100
[ (match List.length errors with

bin/rpc/rpc_common.mli

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ open Import
22

33
(** The current active RPC server, raising an exception if no RPC server is
44
currently running. *)
5-
val active_server_exn : unit -> Dune_rpc_private.Where.t
5+
val active_server_exn : unit -> Dune_rpc.Where.t
66

77
(** Raise an RPC response error. *)
8-
val raise_rpc_error : Dune_rpc_private.Response.Error.t -> 'a
8+
val raise_rpc_error : Dune_rpc.Response.Error.t -> 'a
99

1010
(** Make a request and raise an exception if the preparation for the request
1111
fails in any way. Returns an [Error] if the response errors. *)
1212
val request_exn
1313
: Dune_rpc_client.Client.t
14-
-> ('a, 'b) Dune_rpc_private.Decl.Request.witness
14+
-> ('a, 'b) Dune_rpc.Decl.Request.witness
1515
-> 'a
16-
-> ('b, Dune_rpc_private.Response.Error.t) result Fiber.t
16+
-> ('b, Dune_rpc.Response.Error.t) result Fiber.t
1717

1818
(** Cmdliner term for a generic RPC client. *)
1919
val client_term : Common.Builder.t -> (unit -> 'a Fiber.t) -> 'a
@@ -28,14 +28,12 @@ val fire_request
2828
-> wait:bool
2929
-> ('a, 'b) Dune_rpc.Decl.request
3030
-> 'a
31-
-> ('b, Dune_rpc_private.Response.Error.t) result Fiber.t
31+
-> ('b, Dune_rpc.Response.Error.t) result Fiber.t
3232

3333
val wrap_build_outcome_exn
3434
: print_on_success:bool
3535
-> ('a
36-
-> ( Dune_rpc_impl.Decl.Build_outcome_with_diagnostics.t
37-
, Dune_rpc_private.Response.Error.t )
38-
result
36+
-> (Dune_rpc.Build_outcome_with_diagnostics.t, Dune_rpc.Response.Error.t) result
3937
Fiber.t)
4038
-> 'a
4139
-> unit
@@ -48,9 +46,7 @@ val run_via_rpc
4846
-> config:Dune_config_file.Dune_config.t
4947
-> Dune_util.Global_lock.Lock_held_by.t
5048
-> ('a
51-
-> ( Dune_rpc_impl.Decl.Build_outcome_with_diagnostics.t
52-
, Dune_rpc_private.Response.Error.t )
53-
result
49+
-> (Dune_rpc.Build_outcome_with_diagnostics.t, Dune_rpc.Response.Error.t) result
5450
Fiber.t)
5551
-> 'a
5652
-> unit

boot/libs.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ let local_libraries =
164164
; include_subdirs_unqualified = false
165165
; special_builtin_support = None
166166
}
167+
; { path = "otherlibs/ocamlc-loc/src"
168+
; main_module_name = Some "Ocamlc_loc"
169+
; include_subdirs_unqualified = false
170+
; special_builtin_support = None
171+
}
167172
; { path = "otherlibs/dune-rpc/private"
168173
; main_module_name = Some "Dune_rpc_private"
169174
; include_subdirs_unqualified = false
@@ -194,11 +199,6 @@ let local_libraries =
194199
; include_subdirs_unqualified = false
195200
; special_builtin_support = None
196201
}
197-
; { path = "otherlibs/ocamlc-loc/src"
198-
; main_module_name = Some "Ocamlc_loc"
199-
; include_subdirs_unqualified = false
200-
; special_builtin_support = None
201-
}
202202
; { path = "src/fsevents"
203203
; main_module_name = Some "Fsevents"
204204
; include_subdirs_unqualified = false
@@ -324,11 +324,6 @@ let local_libraries =
324324
; include_subdirs_unqualified = false
325325
; special_builtin_support = None
326326
}
327-
; { path = "otherlibs/dune-site/src/private"
328-
; main_module_name = Some "Dune_site_private"
329-
; include_subdirs_unqualified = false
330-
; special_builtin_support = None
331-
}
332327
; { path = "src/dune_threaded_console"
333328
; main_module_name = Some "Dune_threaded_console"
334329
; include_subdirs_unqualified = false
@@ -369,8 +364,8 @@ let local_libraries =
369364
; include_subdirs_unqualified = false
370365
; special_builtin_support = None
371366
}
372-
; { path = "src/source"
373-
; main_module_name = Some "Source"
367+
; { path = "otherlibs/dune-site/src/private"
368+
; main_module_name = Some "Dune_site_private"
374369
; include_subdirs_unqualified = false
375370
; special_builtin_support = None
376371
}
@@ -379,6 +374,11 @@ let local_libraries =
379374
; include_subdirs_unqualified = false
380375
; special_builtin_support = None
381376
}
377+
; { path = "src/source"
378+
; main_module_name = Some "Source"
379+
; include_subdirs_unqualified = false
380+
; special_builtin_support = None
381+
}
382382
; { path = "src/dune_rules"
383383
; main_module_name = Some "Dune_rules"
384384
; include_subdirs_unqualified = true

otherlibs/dune-rpc/private/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(library
22
(name dune_rpc_private)
33
(public_name dune-rpc.private)
4-
(libraries stdune ordering pp csexp dyn xdg unix)
4+
(libraries csexp dyn ocamlc_loc ordering pp stdune unix xdg)
55
(synopsis "for internal use only"))
66

77
(ocamllex dbus_address)

otherlibs/dune-rpc/private/dune_rpc_private.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Public = struct
2121
let diagnostics = Procedures.Public.diagnostics.decl
2222
let format_dune_file = Procedures.Public.format_dune_file.decl
2323
let promote = Procedures.Public.promote.decl
24+
let promote_many = Procedures.Public.promote_many.decl
2425
let build_dir = Procedures.Public.build_dir.decl
2526
end
2627

@@ -642,6 +643,7 @@ module Client = struct
642643
Builder.declare_notification t Procedures.Public.shutdown;
643644
Builder.declare_request t Procedures.Public.format_dune_file;
644645
Builder.declare_request t Procedures.Public.promote;
646+
Builder.declare_request t Procedures.Public.promote_many;
645647
Builder.declare_request t Procedures.Public.build_dir;
646648
Builder.implement_notification t Procedures.Server_side.abort (fun () ->
647649
handler.abort);

otherlibs/dune-rpc/private/dune_rpc_private.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ module Procedures : sig
196196
val shutdown : unit Decl.Notification.t
197197
val format_dune_file : (Path.t * [ `Contents of string ], string) Decl.Request.t
198198
val promote : (Path.t, unit) Decl.Request.t
199+
200+
val promote_many
201+
: (Files_to_promote.t, Build_outcome_with_diagnostics.t) Decl.Request.t
202+
199203
val build_dir : (unit, Path.t) Decl.Request.t
200204
end
201205

@@ -240,6 +244,7 @@ module Public : sig
240244
val diagnostics : (unit, Diagnostic.t list) t
241245
val format_dune_file : (Path.t * [ `Contents of string ], string) t
242246
val promote : (Path.t, unit) t
247+
val promote_many : (Files_to_promote.t, Build_outcome_with_diagnostics.t) t
243248
val build_dir : (unit, Path.t) t
244249
end
245250

otherlibs/dune-rpc/private/exported_types.ml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,3 +703,137 @@ module Job = struct
703703
;;
704704
end
705705
end
706+
707+
module Compound_user_error = struct
708+
type t =
709+
{ main : User_message.t
710+
; related : User_message.t list
711+
}
712+
713+
let create ~main ~related =
714+
let () =
715+
List.iter related ~f:(fun (related : User_message.t) ->
716+
match related.loc with
717+
| Some _ -> ()
718+
| None ->
719+
Code_error.raise
720+
"related messages must have locations"
721+
[ "related", String (Stdune.User_message.to_string related) ])
722+
in
723+
{ main; related }
724+
;;
725+
726+
let sexp =
727+
let open Conv in
728+
let from { main; related } = main, related in
729+
let to_ (main, related) = create ~main ~related in
730+
let main = field "main" (required User_message.sexp_without_annots) in
731+
let related = field "related" (required (list User_message.sexp_without_annots)) in
732+
iso (record (both main related)) to_ from
733+
;;
734+
735+
let to_dyn { main; related } =
736+
let open Dyn in
737+
record
738+
[ "main", string (Stdune.User_message.to_string main)
739+
; "related", (list string) (List.map related ~f:Stdune.User_message.to_string)
740+
]
741+
;;
742+
743+
let annot =
744+
Stdune.User_message.Annots.Key.create ~name:"compound-user-error" (Dyn.list to_dyn)
745+
;;
746+
747+
let make ~main ~related = create ~main ~related
748+
749+
let make_loc ~dir { Ocamlc_loc.path; chars; lines } : Stdune.Loc.t =
750+
let pos_fname =
751+
let dir = Stdune.Path.drop_optional_build_context_maybe_sandboxed dir in
752+
Stdune.Path.to_absolute_filename (Stdune.Path.relative dir path)
753+
in
754+
let pos_lnum_start, pos_lnum_stop =
755+
match lines with
756+
| Single i -> i, i
757+
| Range (i, j) -> i, j
758+
in
759+
let pos_cnum_start, pos_cnum_stop =
760+
match chars with
761+
| None -> 0, 0
762+
| Some (x, y) -> x, y
763+
in
764+
let pos = { Lexing.pos_fname; pos_lnum = 0; pos_bol = 0; pos_cnum = 0 } in
765+
let start = { pos with pos_lnum = pos_lnum_start; pos_cnum = pos_cnum_start } in
766+
let stop = { pos with pos_lnum = pos_lnum_stop; pos_cnum = pos_cnum_stop } in
767+
Stdune.Loc.create ~start ~stop
768+
;;
769+
770+
let parse_output ~dir s =
771+
Ocamlc_loc.parse s
772+
|> List.map ~f:(fun (report : Ocamlc_loc.report) ->
773+
let make_message (loc, message) =
774+
let loc = make_loc ~dir loc in
775+
let message = Pp.verbatim message in
776+
Stdune.User_message.make ~loc [ message ]
777+
in
778+
let main = make_message (report.loc, report.message) in
779+
let related = List.map report.related ~f:make_message in
780+
make ~main ~related)
781+
;;
782+
end
783+
784+
module Build_outcome_with_diagnostics = struct
785+
type t =
786+
| Success
787+
| Failure of Compound_user_error.t list
788+
789+
let sexp_v1 =
790+
let open Conv in
791+
let success = constr "Success" unit (fun () -> Success) in
792+
let failure = constr "Failure" unit (fun () -> Failure []) in
793+
let variants = [ econstr success; econstr failure ] in
794+
sum variants (function
795+
| Success -> case () success
796+
| Failure _ -> case () failure)
797+
;;
798+
799+
let sexp_v2 =
800+
let open Conv in
801+
let success = constr "Success" unit (fun () -> Success) in
802+
let failure =
803+
constr "Failure" (list Compound_user_error.sexp) (fun errors -> Failure errors)
804+
in
805+
let variants = [ econstr success; econstr failure ] in
806+
sum variants (function
807+
| Success -> case () success
808+
| Failure errors -> case errors failure)
809+
;;
810+
811+
let sexp = sexp_v2
812+
end
813+
814+
module Files_to_promote = struct
815+
type t =
816+
| All
817+
| These of Stdune.Path.Source.t list * (Stdune.Path.Source.t -> unit)
818+
819+
let on_missing fn =
820+
Stdune.User_warning.emit
821+
[ Pp.paragraphf
822+
"Nothing to promote for %s."
823+
(Stdune.Path.Source.to_string_maybe_quoted fn)
824+
]
825+
;;
826+
827+
let sexp =
828+
let open Conv in
829+
let to_ = function
830+
| [] -> All
831+
| paths -> These (List.map ~f:Stdune.Path.Source.of_string paths, on_missing)
832+
in
833+
let from = function
834+
| All -> []
835+
| These (paths, _) -> List.map ~f:Stdune.Path.Source.to_string paths
836+
in
837+
iso (list Path.sexp) to_ from
838+
;;
839+
end

0 commit comments

Comments
 (0)