Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/dune_rules/lock_dir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,23 @@ let get_source_path_for_context ctx_name =
| false -> None
| true -> Some ctx)
with
| None | Some (Default { lock_dir = None; _ }) -> Memo.return (Some default_source_path)
| Some (Default { lock_dir = Some lock_dir_selection; _ }) ->
let+ source_lock_dir = select_lock_dir lock_dir_selection in
Some source_lock_dir
| Some (Opam _) -> Memo.return None
| None | Some (Default { lock_dir = None; _ }) ->
(* CR-someday Alizter: The logic here is hard to follow. Improve the lock
directory selection logic so that it is harder to make a mistake. This
can be done by enforcing invariants about contexts and their lock
directories slightly earlier. *)
Memo.return
@@
(* Context doesn't specify a lock_dir, check if there's a top-level one *)
(match workspace.lock_dirs with
| [ lock_dir ] -> Some lock_dir.path
| [] | _ :: _ :: _ ->
(* No clear choice, fall back to default *)
Some default_source_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what if default_source_path is not in workspace.lock_dirs?

It might be correct; my question is more a behavioral: if the workspace specifies lock dirs, do they exist in addition to the default lock dir or replacing the default lock dir? Personally looking from a user perspective I would assume the latter, but I think it is worth being aware of the choice.

;;

let get_path ctx_name =
Expand Down
67 changes: 67 additions & 0 deletions test/blackbox-tests/test-cases/pkg/lockdir-switch.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
This test checks what happens when you lock with default directory then change
workspace to use a custom lock directory.

$ . ./helpers.sh
$ mkrepo
$ mkpkg foo
$ add_mock_repo_if_needed

$ cat > dune-project <<EOF
> (lang dune 3.21)
> (package
> (name myproject)
> (depends foo))
> EOF

Lock with default directory name:

$ dune pkg lock
Solution for dune.lock

Dependencies common to all supported platforms:
- foo.0.0.1

Now change the workspace to use a custom lock directory:

$ cat > dune-workspace <<EOF
> (lang dune 3.21)
> (lock_dir
> (path custom.lock)
> (repositories mock))
> (repository
> (name mock)
> (url "file://$PWD/mock-opam-repository"))
> EOF

$ cat > dune <<EOF
> (executable
> (public_name bar))
> EOF

$ cat > bar.ml <<EOF
> let () = print_endline "hello from bar" ;;
> EOF

$ dune exec -- bar
hello from bar

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

$ cat > dune-workspace <<EOF
> (lang dune 3.21)
> (context
> (default
> (lock_dir custom.lock)))
> (lock_dir
> (path custom.lock)
> (repositories mock))
> (repository
> (name mock)
> (url "file://$PWD/mock-opam-repository"))
> EOF

This is working as intended. The error is not relevant here.

$ dune exec -- bar
hello from bar