Skip to content

Commit 165b4d4

Browse files
authored
test: verify library file deps in compilation rules and sandboxed builds (#4572) (#14100)
## Summary - Add baseline tests documenting existing behavior before the refactor that moves `Hidden_deps` from `Includes` to per-module in `build_cm` - `lib-deps-preserved.t`: every non-alias module declares glob deps on its library dependencies' `.cmi` files - `sandbox-lib-deps.t`: sandboxed package builds have dependency libraries' `.cmi` files available when a library depends on another library These tests pass on `main` today and establish a baseline for the refactor in #14030. Ref: #4572 Signed-off-by: Robin Bate Boerop <me@robinbb.com>
1 parent 7711a49 commit 165b4d4

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Verify that library file deps are declared for module compilation rules.
2+
3+
Every non-alias module should declare glob deps on its library
4+
dependencies' .cmi files.
5+
6+
$ cat > dune-project <<EOF
7+
> (lang dune 3.23)
8+
> EOF
9+
10+
$ mkdir lib
11+
$ cat > lib/dune <<EOF
12+
> (library (name mylib))
13+
> EOF
14+
$ cat > lib/mylib.ml <<EOF
15+
> let value = 42
16+
> EOF
17+
$ cat > lib/mylib.mli <<EOF
18+
> val value : int
19+
> EOF
20+
21+
$ cat > dune <<EOF
22+
> (executable (name main) (libraries mylib))
23+
> EOF
24+
$ cat > uses_lib.ml <<EOF
25+
> let get () = Mylib.value
26+
> EOF
27+
$ cat > uses_lib.mli <<EOF
28+
> val get : unit -> int
29+
> EOF
30+
$ cat > main.ml <<EOF
31+
> let () = print_int (Uses_lib.get ())
32+
> EOF
33+
34+
$ dune build ./main.exe
35+
36+
Both modules declare glob deps on mylib's .cmi files:
37+
38+
$ dune rules --deps _build/default/.main.eobjs/native/dune__exe__Uses_lib.cmx 2>&1 | grep 'predicate'
39+
(predicate *.cmi)
40+
41+
$ dune rules --deps _build/default/.main.eobjs/native/dune__exe__Main.cmx 2>&1 | grep 'predicate'
42+
(predicate *.cmi)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Sandboxed package builds need library file deps declared properly.
2+
3+
When building with DUNE_SANDBOX=symlink and -p (release/package mode),
4+
dependency libraries' .cmi files must be available in the sandbox. If
5+
library file deps are not declared, the sandbox won't contain them and
6+
compilation will fail.
7+
8+
$ cat > dune-project <<EOF
9+
> (lang dune 3.23)
10+
> (package (name mypkg) (allow_empty))
11+
> EOF
12+
13+
$ mkdir types_lib
14+
$ cat > types_lib/dune <<EOF
15+
> (library (name types_lib) (public_name mypkg.types_lib))
16+
> EOF
17+
$ cat > types_lib/types_lib.ml <<EOF
18+
> type expr = Int of int | Add of expr * expr
19+
> EOF
20+
21+
$ mkdir consumer_lib
22+
$ cat > consumer_lib/dune <<EOF
23+
> (library
24+
> (name consumer_lib)
25+
> (public_name mypkg.consumer_lib)
26+
> (libraries types_lib))
27+
> EOF
28+
$ cat > consumer_lib/consumer_lib.ml <<EOF
29+
> let make_int i : Types_lib.expr = Int i
30+
> let make_add a b : Types_lib.expr = Add (a, b)
31+
> EOF
32+
33+
The build must succeed — the sandbox must contain types_lib's .cmi files:
34+
35+
$ DUNE_SANDBOX=symlink dune build -p mypkg 2>&1 | grep -i error
36+
[1]

0 commit comments

Comments
 (0)