Skip to content

Commit

Permalink
Add compilation test for the new META field
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolás Ojeda Bär <n.oje.bar@gmail.com>
  • Loading branch information
nojb committed Aug 18, 2024
1 parent c2cdbb3 commit 7dc7c8c
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 102 deletions.
118 changes: 118 additions & 0 deletions test/blackbox-tests/test-cases/meta-exports.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Check our handling of `exports` in META files. We begin with a test showing that
we can *consume* META files containing an `exports` field.

To do this, first we create a Findlib hierarchy containing two installed
packages, `foo` and `bar`. The package `foo` is empty and only exists to
re-export `bar`. The package `bar` consists of a bytecode library, `bar.cma`.

$ mkdir -p _install/foo
$ cat >_install/foo/META <<EOF
> requires = "bar"
> EOF

$ mkdir -p _install/bar
$ cat >_install/bar/META <<EOF
> archive(byte) = "bar.cma"
> EOF
$ cat >_install/bar/bar.ml <<EOF
> let x = 42
> EOF
$ ocamlc -a -o _install/bar/bar.cma _install/bar/bar.ml

We now define a Dune project that will consume `foo`.

$ cat >dune-project <<EOF
> (lang dune 3.0)
> EOF

$ cat >dune <<EOF
> (executable
> (name main)
> (modes byte)
> (libraries foo))
> EOF
$ cat >main.ml <<EOF
> let () = print_int Bar.x; print_newline ()
> EOF

Compilation works with `(implicit_transitive_deps)`:

$ OCAMLPATH=$(pwd)/_install dune exec ./main.exe
42

However, the compilation without `(implicit_transitive_deps)` fails:

$ cat >dune-project <<EOF
> (lang dune 3.0)
> (implicit_transitive_deps false)
> EOF

$ OCAMLPATH=$(pwd)/_install dune exec ./main.exe
File "main.ml", line 1, characters 19-24:
1 | let () = print_int Bar.x; print_newline ()
^^^^^
Error: Unbound module Bar
[1]

Next, we add the `exports` field to `foo`'s `META` file:
$ cat >_install/foo/META <<EOF
> requires = "bar"
> exports = "bar"
> EOF
and compilation now works again:
$ OCAMLPATH=$(pwd)/_install dune exec ./main.exe
42
----------------------------------------------------------------
Next, we check that we can *produce* META files with the `export` field. To do
this, we define two Dune libraries `foo` and `bar`, where `foo` depends on `bar`
using `(re_export)`.
$ cat >dune-project.gen <<'EOF'
> cat <<EOF2
> (lang dune $VERSION)
> (package (name foo))
> (package (name bar))
> EOF2
> EOF

$ cat >dune <<EOF
> (library
> (public_name bar)
> (modules bar))
> (library
> (public_name foo)
> (libraries (re_export bar))
> (modules foo))
> EOF
$ true >bar.ml
$ true >foo.ml

First we try with dune version 3.16 (it should not generate the `exports` field):

$ VERSION=3.16 sh dune-project.gen >dune-project
$ dune build && dune install --libdir $(pwd)/_local
$ cat _local/foo/META
description = ""
requires = "bar"
archive(byte) = "foo.cma"
archive(native) = "foo.cmxa"
plugin(byte) = "foo.cma"
plugin(native) = "foo.cmxs"

Now with dune version 3.17 (it should generate the `exports` field):

$ VERSION=3.17 sh dune-project.gen >dune-project
$ dune build && dune install --libdir $(pwd)/_local
$ cat _local/foo/META
description = ""
requires = "bar"
exports = "bar"
archive(byte) = "foo.cma"
archive(native) = "foo.cmxa"
plugin(byte) = "foo.cma"
plugin(native) = "foo.cmxs"
9 changes: 2 additions & 7 deletions test/blackbox-tests/test-cases/meta-gen.t/dune
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
(libraries foobar)
(preprocess (pps foobar_rewriter)))

(rule
(alias runtest)
(alias
(name runtest)
(action (echo "%{read:META.foobar}")))

(library
(name foobar2)
(public_name foobar.foobar2)
(libraries (re_export foobar) (re_export foobar_ppd) foobar_rewriter2))
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/meta-gen.t/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.9)
95 changes: 0 additions & 95 deletions test/blackbox-tests/test-cases/meta-gen.t/run.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$ echo '(lang dune 2.0)' > dune-project
$ dune runtest --force
description = "contains \"quotes\""
requires = "bytes"
Expand All @@ -15,100 +14,6 @@
plugin(byte) = "foobar_baz.cma"
plugin(native) = ""
)
package "foobar2" (
directory = "foobar2"
description = ""
requires = "foobar foobar.ppd foobar.rewriter2"
archive(byte) = "foobar2.cma"
archive(native) = "foobar2.cmxa"
plugin(byte) = "foobar2.cma"
plugin(native) = "foobar2.cmxs"
)
package "ppd" (
directory = "ppd"
description = "pp'd with a rewriter"
requires = "foobar foobar.baz foobar.runtime-lib2"
archive(byte) = "foobar_ppd.cma"
archive(native) = "foobar_ppd.cmxa"
plugin(byte) = "foobar_ppd.cma"
plugin(native) = "foobar_ppd.cmxs"
)
package "rewriter" (
directory = "rewriter"
description = "ppx rewriter"
requires(ppx_driver) = "foobar foobar.rewriter2"
archive(ppx_driver,byte) = "foobar_rewriter.cma"
archive(ppx_driver,native) = "foobar_rewriter.cmxa"
plugin(ppx_driver,byte) = "foobar_rewriter.cma"
plugin(ppx_driver,native) = "foobar_rewriter.cmxs"
# This is what dune uses to find out the runtime dependencies of
# a preprocessor
ppx_runtime_deps = "foobar.baz"
# This line makes things transparent for people mixing preprocessors
# and normal dependencies
requires(-ppx_driver) = "foobar.baz foobar.runtime-lib2"
ppx(-ppx_driver,-custom_ppx) = "./ppx.exe --as-ppx"
library_kind = "ppx_rewriter"
)
package "rewriter2" (
directory = "rewriter2"
description = "ppx rewriter expander"
requires = "foobar"
archive(byte) = "foobar_rewriter2.cma"
archive(native) = "foobar_rewriter2.cmxa"
plugin(byte) = "foobar_rewriter2.cma"
plugin(native) = "foobar_rewriter2.cmxs"
# This is what dune uses to find out the runtime dependencies of
# a preprocessor
ppx_runtime_deps = "foobar.runtime-lib2"
)
package "runtime-lib2" (
directory = "runtime-lib2"
description = "runtime library for foobar.rewriter2"
requires = ""
archive(byte) = "foobar_runtime_lib2.cma"
archive(native) = "foobar_runtime_lib2.cmxa"
plugin(byte) = "foobar_runtime_lib2.cma"
plugin(native) = "foobar_runtime_lib2.cmxs"
jsoo_runtime = "foobar_runtime.js foobar_runtime2.js"
)
package "sub" (
directory = "sub"
description = "sub library in a sub dir"
requires = "bytes"
archive(byte) = "foobar_sub.cma"
archive(native) = ""
plugin(byte) = "foobar_sub.cma"
plugin(native) = ""
)

$ echo '(lang dune 3.17)' > dune-project
$ dune runtest --force
description = "contains \"quotes\""
requires = "bytes"
archive(byte) = "foobar.cma"
archive(native) = "foobar.cmxa"
plugin(byte) = "foobar.cma"
plugin(native) = "foobar.cmxs"
package "baz" (
directory = "baz"
description = "sub library with modes set to byte"
requires = "bytes"
archive(byte) = "foobar_baz.cma"
archive(native) = ""
plugin(byte) = "foobar_baz.cma"
plugin(native) = ""
)
package "foobar2" (
directory = "foobar2"
description = ""
requires = "foobar foobar.ppd foobar.rewriter2"
exports = "foobar foobar.ppd"
archive(byte) = "foobar2.cma"
archive(native) = "foobar2.cmxa"
plugin(byte) = "foobar2.cma"
plugin(native) = "foobar2.cmxs"
)
package "ppd" (
directory = "ppd"
description = "pp'd with a rewriter"
Expand Down

0 comments on commit 7dc7c8c

Please sign in to comment.