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
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
installed-package
no-transitive-through-targets
ocamlfind
transitive-closure
virtual-without-default)
(deps %{bin:ocamlfind}))
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,112 @@ Test that (deps (package ...)) works with externally installed packages.
Installed packages (found via findlib) go through the Installed codepath,
not the layout. The layout only applies to Local (workspace) packages.

Install package "a" into a prefix:
Install packages "a" and "b" into a prefix. Library `a` depends on library
`b`, so its installed metadata records `b` as a requirement.

$ mkdir a consumer prefix

$ cat >a/dune-project <<EOF
> (lang dune 3.24)
> (package (name a))
> (package (name b))
> EOF

$ cat >a/dune <<EOF
> (library (public_name a))
> (library
> (public_name a)
> (libraries b))
> EOF

$ cat >a/a.ml <<EOF
> let msg = "hello from lib a"
> let value = B.value + 1
> EOF

$ mkdir a/b

$ cat >a/b/dune <<EOF
> (library (public_name b))
> EOF

$ cat >a/b/b.ml <<EOF
> let value = 1
> EOF

$ dune build --root a @install
$ dune install --root a --prefix $PWD/prefix 2>/dev/null
$ test -f prefix/lib/a/META
$ test -f prefix/lib/b/META

Now create a consumer project that depends on the installed package.
The consumer uses (deps (package a)) and ocamlfind to verify the
package is findable:
The consumer uses `(deps (package a))` and external OCaml tooling to verify
that both `a` and its library dependency are findable:

$ cat >consumer/dune-project <<EOF
> (lang dune 3.24)
> EOF

$ cat >consumer/main.ml <<EOF
> let () = print_int A.value
> EOF

$ cat >consumer/dune <<'EOF'
> (rule
> (deps (package a))
> (action (with-stdout-to out
> (run ocamlfind query a))))
> (target main.exe)
> (deps
> main.ml
> (package a))
> (action
> (run ocamlfind ocamlc -package a -linkpkg -o %{target} main.ml)))
> EOF

$ OCAMLPATH=$PWD/prefix/lib dune build --root consumer main.exe
$ consumer/_build/default/main.exe
2

When `--only-packages` masks a workspace library in the closure, library
resolution falls back to its installed copy. The installed library remains on
the inherited `OCAMLPATH`; it is not rematerialized as workspace support.

$ mkdir masked masked/a-src masked/b-src

$ cat >masked/dune-project <<EOF
> (lang dune 3.24)
> (package (name a))
> (package (name b))
> EOF

$ cat >masked/a-src/dune <<EOF
> (library
> (public_name a)
> (libraries b))
> EOF

$ cat >masked/a-src/a.ml <<EOF
> let value = B.value + 10
> EOF

$ cat >masked/b-src/dune <<EOF
> (library (public_name b))
> EOF

$ cat >masked/b-src/b.ml <<EOF
> let value = 100
> EOF

$ cat >masked/main.ml <<EOF
> let () = print_int A.value
> EOF

$ cat >masked/dune <<'EOF'
> (rule
> (target main.exe)
> (deps
> main.ml
> (package a))
> (action
> (run %{bin:ocamlfind} ocamlc -package a -linkpkg -o %{target} main.ml)))
> EOF

$ OCAMLPATH=$PWD/prefix/lib/:$OCAMLPATH dune build --root consumer out
$ cat consumer/_build/default/out
$TESTCASE_ROOT/prefix/lib/a
$ OCAMLPATH=$PWD/prefix/lib dune build --root masked --only-packages a main.exe
$ masked/_build/default/main.exe
11
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ the query against the layout's OCAMLPATH.

$ dune build out

Immediate-deps-only: myutil is mylib's declared opam dependency but is
NOT in the layout for (deps (package mylib)). ocamlfind fails to find
it.
Current-behavior snapshot: myutil is mylib's declared opam dependency but is
not in the immediate-only layout for (deps (package mylib)), so ocamlfind
cannot find it.

$ cat >dune <<'EOF'
> (rule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Test that (strict_package_deps) does not affect the install layout. The
layout always uses immediate deps only. strict_package_deps controls
validation in install_rules, not layout closure.
layout currently uses immediate package dependencies only.
strict_package_deps controls validation in install_rules, not the layout.

$ cat >dune-project <<EOF
> (lang dune 3.24)
Expand All @@ -13,15 +13,19 @@ validation in install_rules, not layout closure.
$ mkdir foo-src bar-src baz-src

$ cat >foo-src/dune <<EOF
> (library (public_name foo))
> (library
> (public_name foo)
> (libraries bar))
> EOF

$ cat >foo-src/foo.ml <<EOF
> let x = 1
> EOF

$ cat >bar-src/dune <<EOF
> (library (public_name bar))
> (library
> (public_name bar)
> (libraries baz))
> EOF

$ cat >bar-src/bar.ml <<EOF
Expand All @@ -44,7 +48,8 @@ validation in install_rules, not layout closure.

$ dune build out

Only foo appears, same as without strict_package_deps:
The missing library closure is unchanged by strict_package_deps, so only foo
appears:

$ dune rules --format=json _build/default/out | jq_dune '.[] | ruleDepFilePaths' | censor | grep dune-package | sort
"_build/install/default/.packages/$DIGEST/lib/foo/dune-package"
Loading
Loading