Skip to content

Commit 7dc7c8c

Browse files
committed
Add compilation test for the new META field
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
1 parent c2cdbb3 commit 7dc7c8c

File tree

4 files changed

+121
-102
lines changed

4 files changed

+121
-102
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
Check our handling of `exports` in META files. We begin with a test showing that
2+
we can *consume* META files containing an `exports` field.
3+
4+
To do this, first we create a Findlib hierarchy containing two installed
5+
packages, `foo` and `bar`. The package `foo` is empty and only exists to
6+
re-export `bar`. The package `bar` consists of a bytecode library, `bar.cma`.
7+
8+
$ mkdir -p _install/foo
9+
$ cat >_install/foo/META <<EOF
10+
> requires = "bar"
11+
> EOF
12+
13+
$ mkdir -p _install/bar
14+
$ cat >_install/bar/META <<EOF
15+
> archive(byte) = "bar.cma"
16+
> EOF
17+
$ cat >_install/bar/bar.ml <<EOF
18+
> let x = 42
19+
> EOF
20+
$ ocamlc -a -o _install/bar/bar.cma _install/bar/bar.ml
21+
22+
We now define a Dune project that will consume `foo`.
23+
24+
$ cat >dune-project <<EOF
25+
> (lang dune 3.0)
26+
> EOF
27+
28+
$ cat >dune <<EOF
29+
> (executable
30+
> (name main)
31+
> (modes byte)
32+
> (libraries foo))
33+
> EOF
34+
$ cat >main.ml <<EOF
35+
> let () = print_int Bar.x; print_newline ()
36+
> EOF
37+
38+
Compilation works with `(implicit_transitive_deps)`:
39+
40+
$ OCAMLPATH=$(pwd)/_install dune exec ./main.exe
41+
42
42+
43+
However, the compilation without `(implicit_transitive_deps)` fails:
44+
45+
$ cat >dune-project <<EOF
46+
> (lang dune 3.0)
47+
> (implicit_transitive_deps false)
48+
> EOF
49+
50+
$ OCAMLPATH=$(pwd)/_install dune exec ./main.exe
51+
File "main.ml", line 1, characters 19-24:
52+
1 | let () = print_int Bar.x; print_newline ()
53+
^^^^^
54+
Error: Unbound module Bar
55+
[1]
56+
57+
Next, we add the `exports` field to `foo`'s `META` file:
58+
59+
$ cat >_install/foo/META <<EOF
60+
> requires = "bar"
61+
> exports = "bar"
62+
> EOF
63+
64+
and compilation now works again:
65+
66+
$ OCAMLPATH=$(pwd)/_install dune exec ./main.exe
67+
42
68+
69+
----------------------------------------------------------------
70+
71+
Next, we check that we can *produce* META files with the `export` field. To do
72+
this, we define two Dune libraries `foo` and `bar`, where `foo` depends on `bar`
73+
using `(re_export)`.
74+
75+
$ cat >dune-project.gen <<'EOF'
76+
> cat <<EOF2
77+
> (lang dune $VERSION)
78+
> (package (name foo))
79+
> (package (name bar))
80+
> EOF2
81+
> EOF
82+
83+
$ cat >dune <<EOF
84+
> (library
85+
> (public_name bar)
86+
> (modules bar))
87+
> (library
88+
> (public_name foo)
89+
> (libraries (re_export bar))
90+
> (modules foo))
91+
> EOF
92+
$ true >bar.ml
93+
$ true >foo.ml
94+
95+
First we try with dune version 3.16 (it should not generate the `exports` field):
96+
97+
$ VERSION=3.16 sh dune-project.gen >dune-project
98+
$ dune build && dune install --libdir $(pwd)/_local
99+
$ cat _local/foo/META
100+
description = ""
101+
requires = "bar"
102+
archive(byte) = "foo.cma"
103+
archive(native) = "foo.cmxa"
104+
plugin(byte) = "foo.cma"
105+
plugin(native) = "foo.cmxs"
106+
107+
Now with dune version 3.17 (it should generate the `exports` field):
108+
109+
$ VERSION=3.17 sh dune-project.gen >dune-project
110+
$ dune build && dune install --libdir $(pwd)/_local
111+
$ cat _local/foo/META
112+
description = ""
113+
requires = "bar"
114+
exports = "bar"
115+
archive(byte) = "foo.cma"
116+
archive(native) = "foo.cmxa"
117+
plugin(byte) = "foo.cma"
118+
plugin(native) = "foo.cmxs"

test/blackbox-tests/test-cases/meta-gen.t/dune

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@
4141
(libraries foobar)
4242
(preprocess (pps foobar_rewriter)))
4343

44-
(rule
45-
(alias runtest)
44+
(alias
45+
(name runtest)
4646
(action (echo "%{read:META.foobar}")))
47-
48-
(library
49-
(name foobar2)
50-
(public_name foobar.foobar2)
51-
(libraries (re_export foobar) (re_export foobar_ppd) foobar_rewriter2))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.9)

test/blackbox-tests/test-cases/meta-gen.t/run.t

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
$ echo '(lang dune 2.0)' > dune-project
21
$ dune runtest --force
32
description = "contains \"quotes\""
43
requires = "bytes"
@@ -15,100 +14,6 @@
1514
plugin(byte) = "foobar_baz.cma"
1615
plugin(native) = ""
1716
)
18-
package "foobar2" (
19-
directory = "foobar2"
20-
description = ""
21-
requires = "foobar foobar.ppd foobar.rewriter2"
22-
archive(byte) = "foobar2.cma"
23-
archive(native) = "foobar2.cmxa"
24-
plugin(byte) = "foobar2.cma"
25-
plugin(native) = "foobar2.cmxs"
26-
)
27-
package "ppd" (
28-
directory = "ppd"
29-
description = "pp'd with a rewriter"
30-
requires = "foobar foobar.baz foobar.runtime-lib2"
31-
archive(byte) = "foobar_ppd.cma"
32-
archive(native) = "foobar_ppd.cmxa"
33-
plugin(byte) = "foobar_ppd.cma"
34-
plugin(native) = "foobar_ppd.cmxs"
35-
)
36-
package "rewriter" (
37-
directory = "rewriter"
38-
description = "ppx rewriter"
39-
requires(ppx_driver) = "foobar foobar.rewriter2"
40-
archive(ppx_driver,byte) = "foobar_rewriter.cma"
41-
archive(ppx_driver,native) = "foobar_rewriter.cmxa"
42-
plugin(ppx_driver,byte) = "foobar_rewriter.cma"
43-
plugin(ppx_driver,native) = "foobar_rewriter.cmxs"
44-
# This is what dune uses to find out the runtime dependencies of
45-
# a preprocessor
46-
ppx_runtime_deps = "foobar.baz"
47-
# This line makes things transparent for people mixing preprocessors
48-
# and normal dependencies
49-
requires(-ppx_driver) = "foobar.baz foobar.runtime-lib2"
50-
ppx(-ppx_driver,-custom_ppx) = "./ppx.exe --as-ppx"
51-
library_kind = "ppx_rewriter"
52-
)
53-
package "rewriter2" (
54-
directory = "rewriter2"
55-
description = "ppx rewriter expander"
56-
requires = "foobar"
57-
archive(byte) = "foobar_rewriter2.cma"
58-
archive(native) = "foobar_rewriter2.cmxa"
59-
plugin(byte) = "foobar_rewriter2.cma"
60-
plugin(native) = "foobar_rewriter2.cmxs"
61-
# This is what dune uses to find out the runtime dependencies of
62-
# a preprocessor
63-
ppx_runtime_deps = "foobar.runtime-lib2"
64-
)
65-
package "runtime-lib2" (
66-
directory = "runtime-lib2"
67-
description = "runtime library for foobar.rewriter2"
68-
requires = ""
69-
archive(byte) = "foobar_runtime_lib2.cma"
70-
archive(native) = "foobar_runtime_lib2.cmxa"
71-
plugin(byte) = "foobar_runtime_lib2.cma"
72-
plugin(native) = "foobar_runtime_lib2.cmxs"
73-
jsoo_runtime = "foobar_runtime.js foobar_runtime2.js"
74-
)
75-
package "sub" (
76-
directory = "sub"
77-
description = "sub library in a sub dir"
78-
requires = "bytes"
79-
archive(byte) = "foobar_sub.cma"
80-
archive(native) = ""
81-
plugin(byte) = "foobar_sub.cma"
82-
plugin(native) = ""
83-
)
84-
85-
$ echo '(lang dune 3.17)' > dune-project
86-
$ dune runtest --force
87-
description = "contains \"quotes\""
88-
requires = "bytes"
89-
archive(byte) = "foobar.cma"
90-
archive(native) = "foobar.cmxa"
91-
plugin(byte) = "foobar.cma"
92-
plugin(native) = "foobar.cmxs"
93-
package "baz" (
94-
directory = "baz"
95-
description = "sub library with modes set to byte"
96-
requires = "bytes"
97-
archive(byte) = "foobar_baz.cma"
98-
archive(native) = ""
99-
plugin(byte) = "foobar_baz.cma"
100-
plugin(native) = ""
101-
)
102-
package "foobar2" (
103-
directory = "foobar2"
104-
description = ""
105-
requires = "foobar foobar.ppd foobar.rewriter2"
106-
exports = "foobar foobar.ppd"
107-
archive(byte) = "foobar2.cma"
108-
archive(native) = "foobar2.cmxa"
109-
plugin(byte) = "foobar2.cma"
110-
plugin(native) = "foobar2.cmxs"
111-
)
11217
package "ppd" (
11318
directory = "ppd"
11419
description = "pp'd with a rewriter"

0 commit comments

Comments
 (0)