Skip to content

Commit 26491db

Browse files
Make the lockfile generation test mostly work
1 parent 1e5c577 commit 26491db

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/dune_rules/lock_dir.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ let get_workspace_lock_dir ctx =
174174

175175
let get_with_path ctx =
176176
let* path = get_path ctx >>| Option.value_exn in
177+
(* make sure the lock directory gets built before loading the lock directory *)
178+
let* () = Build_system.build_dir (Path.build path) in
177179
Load.load path
178180
>>= function
179181
| Error e -> Memo.return (Error e)

test/blackbox-tests/test-cases/pkg/helpers.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ show_pkg() {
2323
find $pkg_root/$1 | sort | sed "s#$pkg_root/$1##"
2424
}
2525

26+
# function to show the solver result of the default lock directory
27+
show_solution() {
28+
echo "Solution for dune.lock:"
29+
pkgs=$(ls ${default_lock_dir} | sort | grep -v lock.dune)
30+
for pkg in ${pkgs}; do
31+
version=$(sed -n "s/(version \(.*\))/\1/p" ${default_lock_dir}/${pkg})
32+
echo "- ${pkg%.pkg}.${version}"
33+
done
34+
}
35+
2636
strip_sandbox() {
2737
sed -E 's#[^ ]*.sandbox/[^/]+#$SANDBOX#g'
2838
}

test/blackbox-tests/test-cases/pkg/lockfile-generation.t/run.t

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,21 @@ Generate a `dune-project` file.
3333
Run the solver and generate a lock directory.
3434

3535
$ dune build @pkg-lock
36+
$ show_solution
3637
Solution for dune.lock:
3738
- bar.0.5.0
3839
- baz.0.1.0
3940
- foo.0.0.1
4041

4142
Helper to the name and contents of each file in the lock directory separated by
4243
"---", sorting by filename for consistency.
43-
$ print_all() { find ${default_lock_dir} -type f | sort | xargs -I{} sh -c "printf '{}:\n\n'; cat {}; printf '\n\n---\n\n'"; }
44+
45+
$ print_all() {
46+
> ls ${default_lock_dir} | sort | xargs -I{} sh -c "printf 'dune.lock/{}:\n\n'; cat ${default_lock_dir}/{}; printf '\n\n---\n\n'";
47+
> }
4448

4549
Print the contents of each file in the lockdir:
50+
4651
$ print_all
4752
dune.lock/bar.pkg:
4853

@@ -82,7 +87,8 @@ Print the contents of each file in the lockdir:
8287

8388

8489
Run the solver again preferring oldest versions of dependencies:
85-
$ dune pkg lock --version-preference=oldest
90+
$ dune build @pkg-lock --version-preference=oldest
91+
$ show_solution
8692
Solution for dune.lock:
8793
- bar.0.4.0
8894
- baz.0.1.0
@@ -138,9 +144,7 @@ Regenerate the `dune-project` file introducing an unsatisfiable constraint.
138144

139145
Run the solver again. This time it will fail.
140146
$ dune build @pkg-lock
141-
Error: Unable to solve dependencies for the following lock directories:
142-
Lock directory dune.lock:
143-
Couldn't solve the package dependency formula.
147+
Error: Couldn't solve the package dependency formula.
144148
Selected candidates: baz.0.1.0 foo.0.0.1 lockfile_generation_test.dev
145149
- bar -> (problem)
146150
No usable implementations:
@@ -153,6 +157,11 @@ Run the solver again. This time it will fail.
153157
bar.0.0.1:
154158
Package does not satisfy constraints of local package
155159
lockfile_generation_test
160+
-> required by _build/_private/default/.lock/dune.lock/content
161+
-> required by lock directory environment for context "default"
162+
-> required by base environment for context "default"
163+
-> required by loading findlib for context "default"
164+
-> required by loading the OCaml compiler for context "default"
156165
[1]
157166

158167
We'll also test how the lockfile generation works with alternate solutions.
@@ -173,10 +182,12 @@ After running this we expact a solution that has either `bar` or `baz` but not
173182
both.
174183

175184
$ dune build @pkg-lock
185+
$ show_solution
176186
Solution for dune.lock:
177-
- bar.0.5.0
178187
- bar-or-baz.0.0.1
179-
Top level or is simple, but does nested or work? nested-r defines nested or
188+
- bar.0.5.0
189+
190+
Top level OR is simple, but does nested OR work? `nested-or` defines nested OR
180191
patterns that can't be simplified
181192

182193
$ cat >dune-project <<EOF
@@ -197,11 +208,13 @@ After runninng we expect the solution to have quux and either baz or quz as
197208
well as bar or qux.
198209

199210
$ dune build @pkg-lock
211+
$ show_solution
200212
Solution for dune.lock:
201213
- bar.0.5.0
202214
- baz.0.1.0
203215
- nested-or.0.0.1
204216
- quux.0.0.1
217+
205218
In the dependency formulas, & should bind stronger than | so if we depend on
206219
bar and quux or baz, it should pick the first two or the last one, but nothing
207220
in between.
@@ -217,6 +230,7 @@ in between.
217230
> EOF
218231

219232
$ dune build @pkg-lock
233+
$ show_solution
220234
Solution for dune.lock:
221235
- bar.0.5.0
222236
- priorities.0.0.1
@@ -244,6 +258,7 @@ With versions 1 and 3 negated and version 4 removed via version constraint,
244258
we'd expect version 2 to be chosen:
245259

246260
$ dune build @pkg-lock
261+
$ show_solution
247262
Solution for dune.lock:
248263
- negation.0.0.1
249264
- pkg.2

0 commit comments

Comments
 (0)