Skip to content

Commit 5ad7cad

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 5ad7cad

File tree

4 files changed

+121
-93
lines changed

4 files changed

+121
-93
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)
Lines changed: 0 additions & 86 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"
@@ -81,88 +80,3 @@
8180
plugin(byte) = "foobar_sub.cma"
8281
plugin(native) = ""
8382
)
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-
)
112-
package "ppd" (
113-
directory = "ppd"
114-
description = "pp'd with a rewriter"
115-
requires = "foobar foobar.baz foobar.runtime-lib2"
116-
archive(byte) = "foobar_ppd.cma"
117-
archive(native) = "foobar_ppd.cmxa"
118-
plugin(byte) = "foobar_ppd.cma"
119-
plugin(native) = "foobar_ppd.cmxs"
120-
)
121-
package "rewriter" (
122-
directory = "rewriter"
123-
description = "ppx rewriter"
124-
requires(ppx_driver) = "foobar foobar.rewriter2"
125-
archive(ppx_driver,byte) = "foobar_rewriter.cma"
126-
archive(ppx_driver,native) = "foobar_rewriter.cmxa"
127-
plugin(ppx_driver,byte) = "foobar_rewriter.cma"
128-
plugin(ppx_driver,native) = "foobar_rewriter.cmxs"
129-
# This is what dune uses to find out the runtime dependencies of
130-
# a preprocessor
131-
ppx_runtime_deps = "foobar.baz"
132-
# This line makes things transparent for people mixing preprocessors
133-
# and normal dependencies
134-
requires(-ppx_driver) = "foobar.baz foobar.runtime-lib2"
135-
ppx(-ppx_driver,-custom_ppx) = "./ppx.exe --as-ppx"
136-
library_kind = "ppx_rewriter"
137-
)
138-
package "rewriter2" (
139-
directory = "rewriter2"
140-
description = "ppx rewriter expander"
141-
requires = "foobar"
142-
archive(byte) = "foobar_rewriter2.cma"
143-
archive(native) = "foobar_rewriter2.cmxa"
144-
plugin(byte) = "foobar_rewriter2.cma"
145-
plugin(native) = "foobar_rewriter2.cmxs"
146-
# This is what dune uses to find out the runtime dependencies of
147-
# a preprocessor
148-
ppx_runtime_deps = "foobar.runtime-lib2"
149-
)
150-
package "runtime-lib2" (
151-
directory = "runtime-lib2"
152-
description = "runtime library for foobar.rewriter2"
153-
requires = ""
154-
archive(byte) = "foobar_runtime_lib2.cma"
155-
archive(native) = "foobar_runtime_lib2.cmxa"
156-
plugin(byte) = "foobar_runtime_lib2.cma"
157-
plugin(native) = "foobar_runtime_lib2.cmxs"
158-
jsoo_runtime = "foobar_runtime.js foobar_runtime2.js"
159-
)
160-
package "sub" (
161-
directory = "sub"
162-
description = "sub library in a sub dir"
163-
requires = "bytes"
164-
archive(byte) = "foobar_sub.cma"
165-
archive(native) = ""
166-
plugin(byte) = "foobar_sub.cma"
167-
plugin(native) = ""
168-
)

0 commit comments

Comments
 (0)