Skip to content

Commit 071f050

Browse files
committed
fix: default lock directory selection
Signed-off-by: Ali Caglayan <[email protected]>
1 parent 2f48ec3 commit 071f050

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/dune_rules/lock_dir.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,25 @@ 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+
| [] -> Some default_source_path
194+
| [ lock_dir ] -> Some lock_dir.path
195+
| _ :: _ :: _ ->
196+
(* Multiple lock dirs but context doesn't specify which one to use,
197+
fall back to default *)
198+
Some default_source_path)
185199
;;
186200

187201
let get_path ctx_name =

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ Now change the workspace to use a custom lock directory:
3232
> EOF
3333

3434
$ dune build
35-
Error: No rule found for default/.lock/dune.lock (context _private)
35+
Error: The package myproject does not have any user defined stanzas attached
36+
to it. If this is intentional, add (allow_empty) to the package definition in
37+
the dune-project file
38+
-> required by _build/default/myproject.install
39+
-> required by alias all
40+
-> required by alias default
3641
[1]
3742

3843
Now try with a context stanza that references the custom lock directory with a

0 commit comments

Comments
 (0)