Skip to content

Commit e34eff0

Browse files
Make dev-tools aware of context name to lock in right place
1 parent 5217ced commit e34eff0

File tree

17 files changed

+104
-79
lines changed

17 files changed

+104
-79
lines changed

bin/fmt.ml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let man =
1313
]
1414
;;
1515
16-
let lock_ocamlformat () =
16+
let lock_ocamlformat ctx_name =
1717
if Lazy.force Lock_dev_tool.is_enabled
1818
then
1919
(* Note that generating the ocamlformat lockdir here means
@@ -22,15 +22,23 @@ let lock_ocamlformat () =
2222
this logic remain outside of `dune build`, as `dune
2323
build` is intended to only build targets, and generating
2424
a lockdir is not building a target. *)
25-
Lock_dev_tool.lock_dev_tool Ocamlformat |> Memo.run
26-
else Fiber.return ()
25+
(* TODO: adjust the above comment as with this PR it is no
26+
longer true *)
27+
Action_builder.of_memo (Lock_dev_tool.lock_dev_tool ctx_name Ocamlformat)
28+
else Action_builder.return ()
2729
;;
2830
2931
let run_fmt_command ~(common : Common.t) ~config =
3032
let open Fiber.O in
3133
let once () =
32-
let* () = lock_ocamlformat () in
3334
let request (setup : Import.Main.build_system) =
35+
let ctx_name =
36+
setup.contexts
37+
|> List.find_exn ~f:(fun ctx -> ctx |> Context.name |> Context_name.is_default)
38+
|> Context.name
39+
in
40+
let open Action_builder.O in
41+
let* () = lock_ocamlformat ctx_name in
3442
let dir = Path.(relative root) (Common.prefix_target common ".") in
3543
Alias.in_dir ~name:Dune_rules.Alias.fmt ~recursive:true ~contexts:setup.contexts dir
3644
|> Alias.request

bin/lock_dev_tool.ml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let make_local_package_wrapping_dev_tool ~dev_tool ~dev_tool_version ~extra_depe
6666
}
6767
;;
6868

69-
let solve ~dev_tool ~local_packages =
69+
let solve ctx_name ~dev_tool ~local_packages =
7070
let open Memo.O in
7171
let* solver_env_from_current_system =
7272
Pkg_common.poll_solver_env_from_current_system ()
@@ -79,7 +79,7 @@ let solve ~dev_tool ~local_packages =
7979
Workspace.add_repo workspace Dune_pkg.Pkg_workspace.Repository.binary_packages
8080
| `Disabled -> workspace
8181
in
82-
let lock_dir = Lock_dir.dev_tool_lock_dir_path dev_tool in
82+
let lock_dir = Lock_dir.dev_tool_lock_dir_path ctx_name dev_tool in
8383
Memo.of_reproducible_fiber
8484
@@ Lock.solve
8585
workspace
@@ -171,9 +171,9 @@ let extra_dependencies dev_tool =
171171
[ constraint_ ]
172172
;;
173173

174-
let lockdir_status dev_tool =
174+
let lockdir_status ctx_name dev_tool =
175175
let open Memo.O in
176-
let dev_tool_lock_dir = Lock_dir.dev_tool_lock_dir_path dev_tool in
176+
let dev_tool_lock_dir = Lock_dir.dev_tool_lock_dir_path ctx_name dev_tool in
177177
match Lock_dir.read_disk dev_tool_lock_dir with
178178
| Error _ -> Memo.return `No_lockdir
179179
| Ok { packages; _ } ->
@@ -205,14 +205,14 @@ let lockdir_status dev_tool =
205205
]))))
206206
;;
207207

208-
(* [lock_dev_tool_at_version dev_tool version] generates the lockdir for the
209-
dev tool [dev_tool]. If [version] is [Some v] then version [v] of the tool
210-
will be chosen by the solver. Otherwise the solver is free to choose the
211-
appropriate version of the tool to install. *)
212-
let lock_dev_tool_at_version dev_tool version =
208+
(* [lock_dev_tool_at_version ctx_name dev_tool version] generates the lockdir
209+
for the dev tool [dev_tool]. If [version] is [Some v] then version [v] of
210+
the tool will be chosen by the solver. Otherwise the solver is free to
211+
choose the appropriate version of the tool to install. *)
212+
let lock_dev_tool_at_version ctx_name dev_tool version =
213213
let open Memo.O in
214214
let* need_to_solve =
215-
lockdir_status dev_tool
215+
lockdir_status ctx_name dev_tool
216216
>>| function
217217
| `Lockdir_ok -> false
218218
| `No_lockdir -> true
@@ -238,17 +238,17 @@ let lock_dev_tool_at_version dev_tool version =
238238
~extra_dependencies
239239
in
240240
let local_packages = Package_name.Map.singleton local_pkg.name local_pkg in
241-
solve ~dev_tool ~local_packages
241+
solve ctx_name ~dev_tool ~local_packages
242242
else Memo.return ()
243243
;;
244244

245-
let lock_ocamlformat () =
245+
let lock_ocamlformat ctx_name () =
246246
let version = Dune_pkg.Ocamlformat.version_of_current_project's_ocamlformat_config () in
247-
lock_dev_tool_at_version Ocamlformat version
247+
lock_dev_tool_at_version ctx_name Ocamlformat version
248248
;;
249249

250-
let lock_dev_tool dev_tool =
250+
let lock_dev_tool ctx_name dev_tool =
251251
match (dev_tool : Dune_pkg.Dev_tool.t) with
252-
| Ocamlformat -> lock_ocamlformat ()
253-
| other -> lock_dev_tool_at_version other None
252+
| Ocamlformat -> lock_ocamlformat ctx_name ()
253+
| other -> lock_dev_tool_at_version ctx_name other None
254254
;;

bin/lock_dev_tool.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
open! Import
22

33
val is_enabled : bool Lazy.t
4-
val lock_dev_tool : Dune_pkg.Dev_tool.t -> unit Memo.t
4+
val lock_dev_tool : Context_name.t -> Dune_pkg.Dev_tool.t -> unit Memo.t

bin/ocaml/doc.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@ let man =
1313

1414
let info = Cmd.info "doc" ~doc ~man
1515

16-
let lock_odoc_if_dev_tool_enabled () =
16+
let lock_odoc_if_dev_tool_enabled ctx_name =
1717
match Lazy.force Lock_dev_tool.is_enabled with
1818
| false -> Action_builder.return ()
19-
| true -> Action_builder.of_memo (Lock_dev_tool.lock_dev_tool Odoc)
19+
| true -> Action_builder.of_memo (Lock_dev_tool.lock_dev_tool ctx_name Odoc)
2020
;;
2121

2222
let term =
2323
let+ builder = Common.Builder.term in
2424
let common, config = Common.init builder in
2525
let request (setup : Main.build_system) =
2626
let dir = Path.(relative root) (Common.prefix_target common ".") in
27+
let is_default ctx = ctx |> Context.name |> Dune_engine.Context_name.is_default in
28+
let doc_ctx = List.find_exn setup.contexts ~f:is_default in
29+
let ctx_name = Context.name doc_ctx in
2730
let open Action_builder.O in
28-
let* () = lock_odoc_if_dev_tool_enabled () in
31+
let* () = lock_odoc_if_dev_tool_enabled ctx_name in
2932
let+ () =
3033
Alias.in_dir ~name:Dune_rules.Alias.doc ~recursive:true ~contexts:setup.contexts dir
3134
|> Alias.request
3235
in
3336
let relative_toplevel_index_path =
34-
let toplevel_index_path =
35-
let is_default ctx = ctx |> Context.name |> Dune_engine.Context_name.is_default in
36-
let doc_ctx = List.find_exn setup.contexts ~f:is_default in
37-
Dune_rules.Odoc.Paths.toplevel_index doc_ctx
38-
in
37+
let toplevel_index_path = Dune_rules.Odoc.Paths.toplevel_index doc_ctx in
3938
Path.(toplevel_index_path |> build |> to_string_maybe_quoted)
4039
in
4140
Console.print

bin/ocaml/utop.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ let man =
1212

1313
let info = Cmd.info "utop" ~doc ~man
1414

15-
let lock_utop_if_dev_tool_enabled () =
15+
let lock_utop_if_dev_tool_enabled ctx_name =
1616
match Lazy.force Lock_dev_tool.is_enabled with
1717
| false -> Memo.return ()
18-
| true -> Lock_dev_tool.lock_dev_tool Utop
18+
| true -> Lock_dev_tool.lock_dev_tool ctx_name Utop
1919
;;
2020

2121
let term =
@@ -50,7 +50,7 @@ let term =
5050
[ Pp.textf "no library is defined in %s" (String.maybe_quoted dir) ]
5151
| true ->
5252
let* () = Build_system.build_file utop_exe in
53-
let* () = lock_utop_if_dev_tool_enabled () in
53+
let* () = lock_utop_if_dev_tool_enabled ctx_name in
5454
let* lock_dir_enabled = Dune_rules.Lock_dir.enabled in
5555
let* () =
5656
if lock_dir_enabled

bin/tools/tools_common.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ let build_dev_tool_via_rpc dev_tool =
2626
Build.build_via_rpc_server ~print_on_success:false ~targets:[ target ]
2727
;;
2828

29-
let lock_and_build_dev_tool ~common ~config dev_tool =
29+
let lock_and_build_dev_tool ctx_name ~common ~config dev_tool =
3030
let open Fiber.O in
3131
match Dune_util.Global_lock.lock ~timeout:None with
3232
| Error _lock_held_by ->
3333
Scheduler.go_without_rpc_server ~common ~config (fun () ->
34-
let* () = Lock_dev_tool.lock_dev_tool dev_tool |> Memo.run in
34+
let* () = Lock_dev_tool.lock_dev_tool ctx_name dev_tool |> Memo.run in
3535
build_dev_tool_via_rpc dev_tool)
3636
| Ok () ->
3737
Scheduler.go_with_rpc_server ~common ~config (fun () ->
38-
let* () = Lock_dev_tool.lock_dev_tool dev_tool |> Memo.run in
38+
let* () = Lock_dev_tool.lock_dev_tool ctx_name dev_tool |> Memo.run in
3939
build_dev_tool_directly common dev_tool)
4040
;;
4141

@@ -50,8 +50,8 @@ let run_dev_tool workspace_root dev_tool ~args =
5050
restore_cwd_and_execve workspace_root exe_path_string args Env.initial
5151
;;
5252

53-
let lock_build_and_run_dev_tool ~common ~config dev_tool ~args =
54-
lock_and_build_dev_tool ~common ~config dev_tool;
53+
let lock_build_and_run_dev_tool ctx_name ~common ~config dev_tool ~args =
54+
lock_and_build_dev_tool ctx_name ~common ~config dev_tool;
5555
run_dev_tool (Common.root common) dev_tool ~args
5656
;;
5757

@@ -92,9 +92,10 @@ let which_command dev_tool =
9292
let install_command dev_tool =
9393
let exe_name = Pkg_dev_tool.exe_name dev_tool in
9494
let term =
95-
let+ builder = Common.Builder.term in
95+
let+ builder = Common.Builder.term
96+
and+ ctx_name = Common.context_arg ~doc:"Build context to use." in
9697
let common, config = Common.init builder in
97-
lock_and_build_dev_tool ~common ~config dev_tool
98+
lock_and_build_dev_tool ctx_name ~common ~config dev_tool
9899
in
99100
let info =
100101
let doc = sprintf "Install %s as a dev tool" exe_name in
@@ -107,9 +108,10 @@ let exec_command dev_tool =
107108
let exe_name = Pkg_dev_tool.exe_name dev_tool in
108109
let term =
109110
let+ builder = Common.Builder.term
111+
and+ ctx_name = Common.context_arg ~doc:"Build_context to use."
110112
and+ args = Arg.(value & pos_all string [] (info [] ~docv:"ARGS")) in
111113
let common, config = Common.init builder in
112-
lock_build_and_run_dev_tool ~common ~config dev_tool ~args
114+
lock_build_and_run_dev_tool ctx_name ~common ~config dev_tool ~args
113115
in
114116
let info =
115117
let doc =

bin/tools/tools_common.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ open! Import
44
tool. If a step is unnecessary then it is skipped. This function does not
55
return, but starts running the dev tool in place of the current process. *)
66
val lock_build_and_run_dev_tool
7-
: common:Common.t
7+
: Context_name.t
8+
-> common:Common.t
89
-> config:Dune_config_file.Dune_config.t
910
-> Dune_pkg.Dev_tool.t
1011
-> args:string list

src/dune_pkg/lock_dir.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,11 +1085,14 @@ let create_latest_version
10851085
;;
10861086

10871087
let dev_tool_locks_name = "dev-tools.locks"
1088-
let dev_tools_path = Path.Build.(relative root dev_tool_locks_name)
10891088

1090-
let dev_tool_lock_dir_path dev_tool =
1089+
let dev_tools_path ctx_name =
1090+
Path.Build.relative (Dune_engine.Context_name.build_dir ctx_name) dev_tool_locks_name
1091+
;;
1092+
1093+
let dev_tool_lock_dir_path ctx_name dev_tool =
10911094
Path.Build.relative
1092-
dev_tools_path
1095+
(dev_tools_path ctx_name)
10931096
(Package_name.to_string (Dev_tool.package_name dev_tool))
10941097
;;
10951098

src/dune_pkg/lock_dir.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ val create_latest_version
130130

131131
(** Returns the path to the lockdir that will be used to lock the
132132
given dev tool *)
133-
val dev_tool_lock_dir_path : Dev_tool.t -> Path.Build.t
133+
val dev_tool_lock_dir_path : Dune_engine.Context_name.t -> Dev_tool.t -> Path.Build.t
134134

135135
(** Temporary hack to get the path of a dev tool lock directory in the source
136136
tree. Future versions will probably handle this differently and this

src/dune_rules/fetch_rules.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ let find_checksum, find_url =
188188
Dune_pkg.Dev_tool.all
189189
~init:(Checksum.Map.empty, Digest.Map.empty)
190190
~f:(fun acc dev_tool ->
191-
Lock_dir.of_dev_tool dev_tool >>| add_checksums_and_urls acc)
191+
(* TODO: better way to get this value? *)
192+
let ctx_name = Context_name.default in
193+
Lock_dir.of_dev_tool ctx_name dev_tool >>| add_checksums_and_urls acc)
192194
in
193195
Per_context.list ()
194196
>>= Memo.parallel_map ~f:Lock_dir.get

0 commit comments

Comments
 (0)