Skip to content

Commit d07fc07

Browse files
gridbugsAlizter
authored andcommitted
Fix package validation when portable lockdirs is enabled
The `dune pkg validate-lockdir` command checks that the lockdir contains the transitive dependency closure of all local packages. When run with portable lockdirs enabled, some packages were omitted from the dependency closure because the wrong solver environment was being treated as the current platform. This change fixes the issue by using the correct solver environment to represent the current platform, and does a minor refactor so the validation logic isn't juggling two different solver environments (the second environment is the one stored in the lockdir capturing the opam solver variables used to generate the solution). Signed-off-by: Stephen Sherratt <[email protected]>
1 parent 1f35103 commit d07fc07

File tree

2 files changed

+75
-13
lines changed

2 files changed

+75
-13
lines changed

src/dune_pkg/package_universe.ml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type t =
55
; lock_dir : Lock_dir.t
66
; platform : Solver_env.t
77
; version_by_package_name : Package_version.t Package_name.Map.t
8-
; solver_env : Solver_env.t
98
}
109

1110
let lockdir_regenerate_hints =
@@ -54,7 +53,10 @@ let concrete_dependencies_of_local_package t local_package_name ~with_test =
5453
|> Dependency_formula.to_filtered_formula
5554
|> Resolve_opam_formula.filtered_formula_to_package_names
5655
~with_test
57-
~env:(Solver_env.to_env t.solver_env)
56+
~env:
57+
(Solver_stats.Expanded_variable_bindings.to_solver_env
58+
t.lock_dir.expanded_solver_variable_bindings
59+
|> Solver_env.to_env)
5860
~packages:t.version_by_package_name
5961
with
6062
| Ok { regular; post = _ } -> regular
@@ -89,7 +91,6 @@ let all_non_local_dependencies_of_local_packages t =
8991
let check_for_unnecessary_packges_in_lock_dir
9092
~platform
9193
(lock_dir : Lock_dir.t)
92-
solver_env
9394
all_non_local_dependencies_of_local_packages
9495
=
9596
let packages = Lock_dir.Packages.pkgs_on_platform_by_name lock_dir.packages ~platform in
@@ -98,7 +99,7 @@ let check_for_unnecessary_packges_in_lock_dir
9899
match
99100
Lock_dir.transitive_dependency_closure
100101
lock_dir
101-
~platform:solver_env
102+
~platform
102103
all_non_local_dependencies_of_local_packages
103104
with
104105
| Ok x -> x
@@ -221,25 +222,21 @@ let validate_dependency_hash local_packages ~saved_dependency_hash =
221222
]
222223
;;
223224

224-
let validate ~platform t =
225+
let validate t =
225226
validate_dependency_hash
226227
t.local_packages
227228
~saved_dependency_hash:t.lock_dir.dependency_hash;
228229
all_non_local_dependencies_of_local_packages t
229-
|> check_for_unnecessary_packges_in_lock_dir ~platform t.lock_dir t.solver_env
230+
|> check_for_unnecessary_packges_in_lock_dir ~platform:t.platform t.lock_dir
230231
;;
231232

232233
let create ~platform local_packages lock_dir =
233234
try
234235
let version_by_package_name =
235236
version_by_package_name ~platform local_packages lock_dir
236237
in
237-
let solver_env =
238-
Solver_stats.Expanded_variable_bindings.to_solver_env
239-
lock_dir.expanded_solver_variable_bindings
240-
in
241-
let t = { local_packages; lock_dir; platform; version_by_package_name; solver_env } in
242-
validate ~platform t;
238+
let t = { local_packages; lock_dir; platform; version_by_package_name } in
239+
validate t;
243240
Ok t
244241
with
245242
| User_error.E e -> Error e
@@ -281,7 +278,7 @@ let transitive_dependency_closure_without_test t start =
281278
match
282279
Lock_dir.transitive_dependency_closure
283280
t.lock_dir
284-
~platform:t.solver_env
281+
~platform:t.platform
285282
Package_name.Set.(
286283
union
287284
non_local_immediate_dependencies_of_local_transitive_dependency_closure
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Exercise the `dune pkg validate-lockdir` command on portable lockdirs.
2+
3+
$ . ../helpers.sh
4+
$ mkrepo
5+
$ add_mock_repo_if_needed
6+
7+
Define some interdependent opam packages:
8+
$ mkpkg a 0.0.1 <<EOF
9+
> depends: [ "c" "d" ]
10+
> EOF
11+
$ mkpkg b 0.0.1 <<EOF
12+
> EOF
13+
$ mkpkg b 0.0.2 <<EOF
14+
> EOF
15+
$ mkpkg c <<EOF
16+
> depends: [ "e" ]
17+
> EOF
18+
$ mkpkg d <<EOF
19+
> EOF
20+
$ mkpkg e <<EOF
21+
> EOF
22+
23+
Define some local packages.
24+
$ cat >dune-project <<EOF
25+
> (lang dune 3.20)
26+
> (package (name foo) (depends a (b (>= 0.0.2))))
27+
> (package (name bar) (depends foo c))
28+
> EOF
29+
30+
Solve dependencies:
31+
$ DUNE_CONFIG__PORTABLE_LOCK_DIR=enabled dune pkg lock
32+
Solution for dune.lock
33+
34+
This solution supports the following platforms:
35+
- arch = x86_64; os = linux
36+
- arch = arm64; os = linux
37+
- arch = x86_64; os = macos
38+
- arch = arm64; os = macos
39+
- arch = x86_64; os = win32
40+
41+
Dependencies on all supported platforms:
42+
- a.0.0.1
43+
- b.0.0.2
44+
- c.0.0.1
45+
- d.0.0.1
46+
- e.0.0.1
47+
48+
Validate the lockdir. This will succeed because dune generates valid lockdirs.
49+
$ dune pkg validate-lockdir
50+
51+
Remove a package from the lockdir.
52+
$ rm ${source_lock_dir}/a.0.0.1.pkg
53+
54+
Validate the lockdir. This time dune detects that a required lockfile is missing.
55+
$ dune pkg validate-lockdir
56+
Lockdir dune.lock does not contain a solution for local packages:
57+
File "dune-project", line 2, characters 0-47:
58+
Error: The dependencies of local package "foo" could not be satisfied from
59+
the lockdir:
60+
Package "a" is missing
61+
Hint: The lockdir no longer contains a solution for the local packages in
62+
this project. Regenerate the lockdir by running: 'dune pkg lock'
63+
Error: Some lockdirs do not contain solutions for local packages:
64+
- dune.lock
65+
[1]

0 commit comments

Comments
 (0)