Skip to content

Commit 5b6d2a6

Browse files
Use Path type
Signed-off-by: Marek Kubica <[email protected]>
1 parent b69d172 commit 5b6d2a6

File tree

13 files changed

+60
-49
lines changed

13 files changed

+60
-49
lines changed

bin/lock_dev_tool.ml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ let solve ~dev_tool ~local_packages =
8080
| `Disabled -> workspace
8181
in
8282
(* as we want to write to the source, we're using the source lock dir here *)
83-
let lock_dir = Dune_rules.Lock_dir.dev_tool_source_lock_dir dev_tool |> Path.source in
83+
let lock_dir = Dune_rules.Lock_dir.dev_tool_untracked_lock_dir dev_tool in
8484
Memo.of_reproducible_fiber
8585
@@ Pkg.Lock.solve
8686
workspace
@@ -174,14 +174,11 @@ let extra_dependencies dev_tool =
174174

175175
let lockdir_status dev_tool =
176176
let open Memo.O in
177-
let dev_tool_lock_dir = Dune_rules.Lock_dir.dev_tool_source_lock_dir dev_tool in
178-
let* lock_dir_exists =
179-
Dune_engine.Fs_memo.dir_exists (In_source_dir dev_tool_lock_dir)
180-
in
177+
let dev_tool_lock_dir = Dune_rules.Lock_dir.dev_tool_untracked_lock_dir dev_tool in
178+
let lock_dir_exists = Path.exists dev_tool_lock_dir in
181179
match lock_dir_exists with
182180
| false -> Memo.return `No_lockdir
183181
| true ->
184-
let dev_tool_lock_dir = Path.source dev_tool_lock_dir in
185182
(match Lock_dir.read_disk dev_tool_lock_dir with
186183
| Error _ -> Memo.return `No_lockdir
187184
| Ok { packages; _ } ->

bin/ocaml/utop.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ let term =
5858
[ Pp.textf "no library is defined in %s" (String.maybe_quoted dir) ]
5959
| true ->
6060
let* () = Build_system.build_file utop_exe in
61-
let* utop_dev_tool_lock_dir_exists =
62-
Memo.Lazy.force Utop.utop_dev_tool_lock_dir_exists
61+
let utop_dev_tool_lock_dir_exists =
62+
Lazy.force Utop.utop_dev_tool_lock_dir_exists
6363
in
6464
let* () =
6565
if utop_dev_tool_lock_dir_exists

src/dune_pkg/lock_dir.ml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,20 @@ let in_source_tree path =
524524
(match Path.Source.explode in_source with
525525
| "default" :: ".lock" :: components ->
526526
Path.Source.L.relative Path.Source.root components
527-
| _otherwise ->
528-
Code_error.raise
529-
"Unexpected location of lock directory in build directory"
530-
[ "path", Path.Build.to_dyn b; "in_source", Path.Source.to_dyn in_source ])
527+
| source_components ->
528+
(match Path.Build.explode b with
529+
| ".dev-tools.locks" :: dev_tool :: components ->
530+
Path.Source.L.relative
531+
Path.Source.root
532+
([ "_build"; ".dev-tools.locks"; dev_tool ] @ components)
533+
| build_components ->
534+
Code_error.raise
535+
"Unexpected location of lock directory in build directory"
536+
[ "path", Path.Build.to_dyn b
537+
; "in_source", Path.Source.to_dyn in_source
538+
; "source_components", Dyn.(list string) source_components
539+
; "build_components", Dyn.(list string) build_components
540+
]))
531541
| External e ->
532542
Code_error.raise
533543
"External path returned when loading a lock dir"
@@ -1789,7 +1799,7 @@ let loc_in_source_tree loc =
17891799
loc
17901800
|> Loc.map_pos ~f:(fun ({ pos_fname; _ } as pos) ->
17911801
let path = Path.of_string pos_fname in
1792-
match Path.of_string pos_fname with
1802+
match path with
17931803
| External _ | In_source_tree _ -> pos
17941804
| In_build_dir b ->
17951805
(match Path.Build.explode b with

src/dune_rules/fetch_rules.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ let find_checksum, find_url =
189189
Dune_pkg.Dev_tool.all
190190
~init:(Checksum.Map.empty, Digest.Map.empty)
191191
~f:(fun acc dev_tool ->
192-
let dir = Lock_dir.dev_tool_source_lock_dir dev_tool in
192+
let dir = Lock_dir.dev_tool_untracked_lock_dir dev_tool in
193193
let exists =
194194
(* Note we use [Path.Untracked] here rather than [Fs_memo] because a tool's
195195
lockdir may be generated part way through a build. *)
196-
Path.Untracked.exists (Path.source dir)
196+
Path.Untracked.exists dir
197197
in
198198
match exists with
199199
| false -> Memo.return acc

src/dune_rules/format_rules.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end
3333

3434
module Ocamlformat = struct
3535
let dev_tool_lock_dir_exists () =
36-
Lock_dir.dev_tool_source_lock_dir Ocamlformat |> Path.source |> Path.Untracked.exists
36+
Lock_dir.dev_tool_untracked_lock_dir Ocamlformat |> Path.Untracked.exists
3737
;;
3838

3939
(* Config files for ocamlformat. When these are changed, running

src/dune_rules/lock_dir.ml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,16 @@ let dev_tool_to_path_segment dev_tool =
147147
dev_tool |> Dev_tool.package_name |> Package_name.to_string |> Path.Local.of_string
148148
;;
149149

150-
let dev_tool_source_lock_dir dev_tool =
151-
let dev_tools_path =
152-
Path.Source.L.relative Path.Source.root [ "_build"; ".dev-tools.locks" ]
153-
in
150+
(* This function returns the lock dir that is created outside the build system. *)
151+
let dev_tool_untracked_lock_dir dev_tool =
152+
let dev_tools_path = Path.Build.relative Path.Build.root ".dev-tools.locks" in
154153
let dev_tool_segment = dev_tool_to_path_segment dev_tool in
155-
Path.Source.append_local dev_tools_path dev_tool_segment
154+
Path.Build.append_local dev_tools_path dev_tool_segment |> Path.build
156155
;;
157156

157+
(* This function returns the lock dir location where the build system can create
158+
the lock directory. This is where lock files should be loaded from and it
159+
is populated either by copy rules or the solver running. *)
158160
let dev_tool_lock_dir dev_tool =
159161
(* dev tools always live in default *)
160162
let ctx_name = Context_name.default |> Context_name.to_string in
@@ -228,20 +230,20 @@ let get ctx = get_with_path ctx >>| Result.map ~f:snd
228230
let get_exn ctx = get ctx >>| User_error.ok_exn
229231

230232
let of_dev_tool dev_tool =
231-
let source_path = dev_tool_source_lock_dir dev_tool in
232-
Load.load_exn (Path.source source_path)
233+
let path = dev_tool_untracked_lock_dir dev_tool in
234+
Load.load_exn path
233235
;;
234236

235237
let of_dev_tool_if_lock_dir_exists dev_tool =
236-
let source_path = dev_tool_source_lock_dir dev_tool in
238+
let path = dev_tool_untracked_lock_dir dev_tool in
237239
let exists =
238240
(* Note we use [Path.Untracked] here rather than [Fs_memo] because a tool's
239241
lockdir may be generated part way through a build. *)
240-
Path.Untracked.exists (Path.source source_path)
242+
Path.Untracked.exists path
241243
in
242244
if exists
243245
then
244-
let+ t = Load.load_exn (Path.source source_path) in
246+
let+ t = Load.load_exn path in
245247
Some t
246248
else Memo.return None
247249
;;

src/dune_rules/lock_dir.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ val default_path : Path.t
2121
val default_source_path : Path.Source.t
2222

2323
(** The location in the source tree where a dev tool lock dir is expected *)
24-
val dev_tool_source_lock_dir : Dune_pkg.Dev_tool.t -> Path.Source.t
24+
val dev_tool_untracked_lock_dir : Dune_pkg.Dev_tool.t -> Path.t
2525

2626
(** Returns the path to the lock_dir that will be used to lock the
2727
given dev tool *)

src/dune_rules/lock_rules.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,10 @@ let copy_lock_dir ~target ~lock_dir ~deps ~files =
394394
let open Action_builder.O in
395395
Action_builder.deps deps
396396
>>> (Path.Set.to_list_map files ~f:(fun src ->
397-
let dst =
398-
Path.drop_prefix_exn src ~prefix:(Path.source lock_dir)
399-
|> Path.Build.append_local target
400-
in
401-
Action.progn [ Action.mkdir (Path.Build.parent_exn dst); Action.copy src dst ])
397+
let suffix = Path.drop_prefix_exn src ~prefix:lock_dir in
398+
let dst = Path.Build.append_local target suffix in
399+
let parent = Path.Build.parent_exn dst in
400+
Action.progn [ Action.mkdir parent; Action.copy src dst ])
402401
|> Action.concurrent
403402
|> Action.Full.make
404403
|> Action_builder.return)
@@ -453,7 +452,7 @@ let files dir =
453452

454453
let setup_copy_rules ~dir:target ~assume_src_exists ~lock_dir =
455454
let+ () = Memo.return () in
456-
let deps, files = files (Path.source lock_dir) in
455+
let deps, files = files lock_dir in
457456
let directory_targets, rules =
458457
match Path.Set.is_empty files with
459458
| true -> Path.Build.Map.empty, Rules.empty
@@ -484,15 +483,15 @@ let setup_lock_rules_with_source (workspace : Workspace.t) ~dir ~lock_dir =
484483
match source with
485484
| `Source_tree lock_dir ->
486485
let dir = Path.Build.append_source dir lock_dir in
487-
setup_copy_rules ~assume_src_exists:false ~dir ~lock_dir
486+
setup_copy_rules ~assume_src_exists:false ~dir ~lock_dir:(Path.source lock_dir)
488487
| `Generated -> Memo.return (setup_lock_rules ~dir ~lock_dir)
489488
;;
490489

491490
let setup_dev_tool_lock_rules ~dir dev_tool =
492491
let package_name = Dev_tool.package_name dev_tool in
493492
let dev_tool_name = Dune_lang.Package_name.to_string package_name in
494493
let dir = Path.Build.relative dir dev_tool_name in
495-
let lock_dir = Lock_dir.dev_tool_source_lock_dir dev_tool in
494+
let lock_dir = Lock_dir.dev_tool_untracked_lock_dir dev_tool in
496495
(* dev tool lock files are created in _build outside of the build system
497496
so we have to tell the build system not to try to create them *)
498497
setup_copy_rules ~dir ~assume_src_exists:true ~lock_dir

src/dune_rules/merlin/ocaml_index.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let ocaml_index_dev_tool_exe_path_building_if_necessary () =
99
;;
1010

1111
let ocaml_index_dev_tool_exists () =
12-
Lock_dir.dev_tool_source_lock_dir Ocaml_index |> Path.source |> Path.Untracked.exists
12+
Lock_dir.dev_tool_untracked_lock_dir Ocaml_index |> Path.Untracked.exists
1313
;;
1414

1515
let ocaml_index sctx ~dir =

src/dune_rules/pkg_rules.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ module Package_universe = struct
8686
| Dependencies ctx -> Lock_dir.get_path ctx
8787
| Dev_tool dev_tool ->
8888
(* CR-Leonidas-from-XIV: It probably isn't always [Some] *)
89-
dev_tool
90-
|> Lock_dir.dev_tool_source_lock_dir
91-
|> Path.source
92-
|> Option.some
93-
|> Memo.return
89+
dev_tool |> Lock_dir.dev_tool_untracked_lock_dir |> Option.some |> Memo.return
9490
;;
9591
end
9692

0 commit comments

Comments
 (0)