Skip to content

Commit 7e67f02

Browse files
committed
fix: default lock directory selection
Signed-off-by: Ali Caglayan <[email protected]>
1 parent 1b91a6e commit 7e67f02

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/dune_rules/lock_dir.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,23 @@ let get_source_path_for_context ctx_name =
177177
| false -> None
178178
| true -> Some ctx)
179179
with
180-
| None | Some (Default { lock_dir = None; _ }) -> Memo.return (Some default_source_path)
181180
| Some (Default { lock_dir = Some lock_dir_selection; _ }) ->
182181
let+ source_lock_dir = select_lock_dir lock_dir_selection in
183182
Some source_lock_dir
184183
| Some (Opam _) -> Memo.return None
184+
| None | Some (Default { lock_dir = None; _ }) ->
185+
(* CR-someday Alizter: The logic here is hard to follow. Improve the lock
186+
directory selection logic so that it is harder to make a mistake. This
187+
can be done by enforcing invariants about contexts and their lock
188+
directories slightly earlier. *)
189+
Memo.return
190+
@@
191+
(* Context doesn't specify a lock_dir, check if there's a top-level one *)
192+
(match workspace.lock_dirs with
193+
| [ lock_dir ] -> Some lock_dir.path
194+
| [] | _ :: _ :: _ ->
195+
(* No clear choice, fall back to default *)
196+
Some default_source_path)
185197
;;
186198

187199
let get_path ctx_name =

test/blackbox-tests/test-cases/pkg/lockdir-switch.t

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ Now change the workspace to use a custom lock directory:
4343
> EOF
4444

4545
$ dune exec -- bar
46-
Error: No rule found for default/.lock/dune.lock (context _private)
47-
-> required by lock directory environment for context "default"
48-
-> required by base environment for context "default"
49-
-> required by loading findlib for context "default"
50-
-> required by creating installed environment for "default"
51-
[1]
46+
hello from bar
5247

5348
Now try with a context stanza that references the custom lock directory with a
5449
context stanza:

0 commit comments

Comments
 (0)