Debian Codegraph @

otherlibs/dune-site/test/run.t

raw
1 Test embedding of sites locations information
2 -----------------------------------
3
4 $ mkdir -p a b c
5
6 $ mkdir -p a
7
8 $ cat >a/dune-project <<EOF
9 > (lang dune 3.0)
10 > (generate_opam_files true)
11 > (using dune_site 0.1)
12 > (name a)
13 > (version 0.a)
14 > (package (name a) (sites (share data)))
15 > EOF
16
17 $ for i in b d; do
18 > mkdir -p $i
19 > cat >$i/dune-project <<EOF
20 > (lang dune 3.0)
21 > (generate_opam_files true)
22 > (using dune_site 0.1)
23 > (name $i)
24 > (version 0.$i)
25 > (package (name $i) (sites (share data)) (depends c))
26 > EOF
27 > done
28
29 $ for i in c; do
30 > mkdir -p $i
31 > cat >$i/dune-project <<EOF
32 > (lang dune 3.0)
33 > (generate_opam_files true)
34 > (using dune_site 0.1)
35 > (name $i)
36 > (package (name $i) (sites (share data) (lib plugins)) (depends a))
37 > EOF
38 > done
39
40 $ cat >a/dune <<EOF
41 > (library
42 > (public_name a)
43 > (libraries dune-site))
44 > (generate_sites_module (module sites) (sites a))
45 > EOF
46
47 $ cat >a/a.ml <<EOF
48 > let v = "a"
49 > let () = Printf.printf "run a\n%!"
50 > let () = List.iter (Printf.printf "a: %s\n%!") Sites.Sites.data
51 > EOF
52
53 $ cat >b/dune <<EOF
54 > (library
55 > (public_name b.b.b)
56 > (name b)
57 > (libraries c.register dune-site))
58 > (generate_sites_module (module sites) (sites b))
59 > (plugin (name c-plugins-b) (libraries b.b.b) (site (c plugins)))
60 > (install (section (site (b data))) (files info.txt))
61 > EOF
62
63 $ cat >b/b.ml <<EOF
64 > let v = "b"
65 > let () = Printf.printf "run b\n%!"
66 > let () = C_register.registered := "b"::!C_register.registered
67 > let () = List.iter (Printf.printf "b: %s\n%!") Sites.Sites.data
68 > let () =
69 > let test d = Sys.file_exists (Filename.concat d "info.txt") in
70 > let found = List.exists test Sites.Sites.data in
71 > Printf.printf "info.txt is found: %b\n%!" found
72 > EOF
73
74 $ cat >b/info.txt <<EOF
75 > Lorem
76 > EOF
77
78 $ cat >d/dune <<EOF
79 > (library
80 > (public_name d)
81 > (libraries c.register dune-site non-existent-library)
82 > (optional))
83 > (generate_sites_module (module sites) (sites d))
84 > (plugin (name c-plugins-d) (libraries d) (site (c plugins)) (optional))
85 > (install (section (site (d data))) (files info.txt))
86 > EOF
87
88 $ cat >d/d.ml <<EOF
89 > let v = "d"
90 > let () = Printf.printf "run d\n%!"
91 > let () = C_register.registered := "d"::!C_register.registered
92 > let () = List.iter (Printf.printf "d: %s\n%!") Sites.Sites.data
93 > let () =
94 > let test d = Sys.file_exists (Filename.concat d "info.txt") in
95 > let found = List.exists test Sites.Sites.data in
96 > Printf.printf "info.txt is found: %d\n%!" found
97 > EOF
98
99 $ cat >d/info.txt <<EOF
100 > Lorem
101 > EOF
102
103
104 $ cat >c/dune <<EOF
105 > (executable
106 > (public_name c)
107 > (promote (until-clean))
108 > (modules c sites)
109 > (libraries a c.register dune-site dune-site.plugins))
110 > (library
111 > (public_name c.register)
112 > (name c_register)
113 > (modules c_register))
114 > (generate_sites_module (module sites) (sourceroot) (plugins (c plugins)))
115 > (rule
116 > (targets out.log)
117 > (deps (package c))
118 > (action (with-stdout-to out.log (run %{bin:c}))))
119 > EOF
120
121 $ cat >c/c_register.ml <<EOF
122 > let registered : string list ref = ref []
123 > EOF
124
125 $ cat >c/c.ml <<EOF
126 > let () = Printf.printf "run c: %s linked registered:%s.\n%!"
127 > A.v (String.concat "," !C_register.registered)
128 > let () = match Sites.sourceroot with
129 > | Some d -> Printf.printf "sourceroot is %S\n%!" d
130 > | None -> Printf.printf "no sourceroot\n%!"
131 > let () = List.iter (Printf.printf "c: %s\n%!") Sites.Sites.data
132 > let () = Printf.printf "b is available: %b\n%!" (Dune_site_plugins.V1.available "b")
133 > let () = Sites.Plugins.Plugins.load_all ()
134 > let () = Printf.printf "run c: registered:%s.\n%!" (String.concat "," !C_register.registered)
135 > EOF
136
137 $ cat > dune-project << EOF
138 > (lang dune 2.2)
139 > EOF
140
141
142 Test with an opam like installation
143 --------------------------------
144
145 $ dune build a/a.opam
146
147 #We print the generated file in order to update the following tests
148 $ cat a/a.opam
149 # This file is generated by dune, edit dune-project instead
150 opam-version: "2.0"
151 version: "0.a"
152 depends: [
153 "dune" {>= "3.0"}
154 "odoc" {with-doc}
155 ]
156 build: [
157 ["dune" "subst"] {dev}
158 [
159 "dune"
160 "build"
161 "-p"
162 name
163 "-j"
164 jobs
165 "--promote-install-files=false"
166 "@install"
167 "@runtest" {with-test}
168 "@doc" {with-doc}
169 ]
170 ["dune" "install" "-p" name "--create-install-files" name]
171 ]
172
173 $ dune build -p a --promote-install-files=false @install
174
175 $ test -e a/a.install
176 [1]
177
178 $ dune install -p a --create-install-files a --prefix "_destdir"
179
180 $ cat a/a.install
181 lib: [
182 "_destdir/_destdir/lib/a/META"
183 "_destdir/_destdir/lib/a/Sites.ml"
184 "_destdir/_destdir/lib/a/a.a"
185 "_destdir/_destdir/lib/a/a.cma"
186 "_build/install/default/lib/a/a.cmi"
187 "_build/install/default/lib/a/a.cmt"
188 "_build/install/default/lib/a/a.cmx"
189 "_build/install/default/lib/a/a.cmxa"
190 "_build/install/default/lib/a/a.ml"
191 "_build/install/default/lib/a/a__.cmi"
192 "_build/install/default/lib/a/a__.cmt"
193 "_build/install/default/lib/a/a__.cmx"
194 "_build/install/default/lib/a/a__.ml"
195 "_build/install/default/lib/a/a__Sites.cmi"
196 "_build/install/default/lib/a/a__Sites.cmt"
197 "_build/install/default/lib/a/a__Sites.cmx"
198 "_destdir/_destdir/lib/a/dune-package"
199 "_build/install/default/lib/a/opam"
200 ]
201 libexec: [
202 "_destdir/_destdir/lib/a/a.cmxs"
203 ]
204
205 Build everything
206 ----------------
207
208 $ dune build
209
210 Test with a normal installation
211 --------------------------------
212
213 $ dune install --prefix _install
214
215 Once installed, we have the sites information:
216
217 $ grep share/a _install/lib/a/dune-package
218 $TESTCASE_ROOT/_install/share/a))
219
220 $ OCAMLPATH=_install/lib:$OCAMLPATH _install/bin/c
221 run a
222 a: $TESTCASE_ROOT/_install/share/a/data
223 run c: a linked registered:.
224 no sourceroot
225 c: $TESTCASE_ROOT/_install/share/c/data
226 b is available: true
227 run b
228 b: $TESTCASE_ROOT/_install/share/b/data
229 info.txt is found: true
230 run c: registered:b.
231
232 Test with a relocatable installation
233 --------------------------------
234
235 $ dune install --prefix _install_relocatable --relocatable
236
237 Once installed, we have the sites information:
238
239 $ _install_relocatable/bin/c
240 run a
241 a: $TESTCASE_ROOT/_install_relocatable/share/a/data
242 run c: a linked registered:.
243 no sourceroot
244 c: $TESTCASE_ROOT/_install_relocatable/share/c/data
245 b is available: true
246 run b
247 b: $TESTCASE_ROOT/_install_relocatable/share/b/data
248 info.txt is found: true
249 run c: registered:b.
250
251 Test after moving a relocatable installation
252 --------------------------------
253
254 $ mv _install_relocatable _install_relocatable2
255
256 Once installed, we have the sites information:
257
258 $ _install_relocatable2/bin/c
259 run a
260 a: $TESTCASE_ROOT/_install_relocatable2/share/a/data
261 run c: a linked registered:.
262 no sourceroot
263 c: $TESTCASE_ROOT/_install_relocatable2/share/c/data
264 b is available: true
265 run b
266 b: $TESTCASE_ROOT/_install_relocatable2/share/b/data
267 info.txt is found: true
268 run c: registered:b.
269
270 Test substitution when promoting
271 --------------------------------
272
273 It is wrong that info.txt is not found, but to make it work it is an important
274 development because b is not promoted
275
276 $ c/c.exe
277 run a
278 a: $TESTCASE_ROOT/_build/install/default/share/a/data
279 run c: a linked registered:.
280 sourceroot is "$TESTCASE_ROOT"
281 c: $TESTCASE_ROOT/_build/install/default/share/c/data
282 b is available: true
283 run b
284 info.txt is found: false
285 run c: registered:b.
286
287 Test within dune rules
288 --------------------------------
289 $ dune build c/out.log
290
291 $ cat _build/default/c/out.log
292 run a
293 a: $TESTCASE_ROOT/_build/install/default/share/a/data
294 run c: a linked registered:.
295 sourceroot is "$TESTCASE_ROOT"
296 c: $TESTCASE_ROOT/_build/install/default/share/c/data
297 b is available: true
298 run b
299 b: $TESTCASE_ROOT/_build/install/default/share/b/data
300 info.txt is found: true
301 run c: registered:b.
302
303
304 Test with dune exec
305 --------------------------------
306 $ dune exec -- c/c.exe
307 run a
308 a: $TESTCASE_ROOT/_build/install/default/share/a/data
309 run c: a linked registered:.
310 sourceroot is "$TESTCASE_ROOT"
311 c: $TESTCASE_ROOT/_build/install/default/share/c/data
312 b is available: true
313 run b
314 b: $TESTCASE_ROOT/_build/install/default/share/b/data
315 info.txt is found: true
316 run c: registered:b.
317
318
319 Test compiling an external plugin
320 ---------------------------------
321 $ mkdir e
322 $ cat >e/dune-project <<EOF
323 > (lang dune 2.8)
324 > (using dune_site 0.1)
325 > (name e)
326 > (package (name e) (sites (share data)))
327 > EOF
328
329 $ cat >e/dune <<EOF
330 > (library
331 > (public_name e)
332 > (libraries c.register dune-site))
333 > (generate_sites_module (module sites) (sites e))
334 > (plugin (name c-plugins-e) (libraries e) (site (c plugins)))
335 > (install (section (site (e data))) (files info.txt))
336 > (rule (alias runtest) (deps (package a) (package b) (package c) (package d) (package e))
337 > (action (run %{bin:c})))
338 > EOF
339
340 $ cat >e/e.ml <<EOF
341 > let v = "e"
342 > let () = Printf.printf "run e\n%!"
343 > let () = C_register.registered := "e"::!C_register.registered
344 > let () = List.iter (Printf.printf "e: %s\n%!") Sites.Sites.data
345 > let () =
346 > let test d = Sys.file_exists (Filename.concat d "info.txt") in
347 > let found = List.exists test Sites.Sites.data in
348 > Printf.printf "info.txt is found: %b\n%!" found
349 > EOF
350
351 $ cat >e/info.txt <<EOF
352 > Lorem
353 > EOF
354
355 $ OCAMLPATH=$(pwd)/_install/lib:$OCAMLPATH dune build --root=e
356
357 $ OCAMLPATH=$(pwd)/_install/lib:$OCAMLPATH PATH=$(pwd)/_install/bin:$PATH dune exec --root=e -- c
358 run a
359 a: $TESTCASE_ROOT/_install/share/a/data
360 run c: a linked registered:.
361 no sourceroot
362 c: $TESTCASE_ROOT/_install/share/c/data
363 b is available: true
364 run b
365 b: $TESTCASE_ROOT/_install/share/b/data
366 info.txt is found: true
367 run e
368 e: $TESTCASE_ROOT/e/_build/install/default/share/e/data
369 info.txt is found: true
370 run c: registered:e,b.
371
372 $ OCAMLPATH=$(pwd)/_install/lib:$OCAMLPATH dune install --root=e --prefix $(pwd)/_install
373
374 $ OCAMLPATH=_install/lib:$OCAMLPATH _install/bin/c
375 run a
376 a: $TESTCASE_ROOT/_install/share/a/data
377 run c: a linked registered:.
378 no sourceroot
379 c: $TESTCASE_ROOT/_install/share/c/data
380 b is available: true
381 run b
382 b: $TESTCASE_ROOT/_install/share/b/data
383 info.txt is found: true
384 run e
385 e: $TESTCASE_ROOT/_install/share/e/data
386 info.txt is found: true
387 run c: registered:e,b.
388
389 $ OCAMLPATH=_install/lib:$OCAMLPATH dune build @runtest
390 run a
391 a: $TESTCASE_ROOT/_build/install/default/share/a/data
392 run c: a linked registered:.
393 sourceroot is "$TESTCASE_ROOT"
394 c: $TESTCASE_ROOT/_build/install/default/share/c/data
395 b is available: true
396 run b
397 b: $TESTCASE_ROOT/_build/install/default/share/b/data
398 info.txt is found: true
399 run e
400 e: $TESTCASE_ROOT/_build/install/default/share/e/data
401 info.txt is found: true
402 run c: registered:e,b.
403
404 Test %{version:installed-pkg}
405 -----------------------------
406
407 $ for i in f; do
408 > mkdir -p $i
409 > cat >$i/dune-project <<EOF
410 > (lang dune 3.0)
411 > (using dune_site 0.1)
412 > (name $i)
413 > (version 0.$i)
414 > (package (name $i) (sites (share data) (lib plugins)) (allow_empty))
415 > EOF
416 > done
417
418 $ cat >f/dune <<EOF
419 > (rule
420 > (target test.target)
421 > (action
422 > (with-stdout-to %{target}
423 > (progn
424 > (echo "a = %{version:a}\n")
425 > (echo "e = %{version:e}\n")))))
426 > EOF
427
428 $ OCAMLPATH=_install/lib:$OCAMLPATH dune build --root=f
429 $ cat $(pwd)/f/_build/default/test.target
430 a = 0.a
431 e =
432
433 $ cat f/dune | sed 's/version:a/version:a.test/' > f/dune.tmp && mv f/dune.tmp f/dune
434 $ OCAMLPATH=_install/lib:$OCAMLPATH dune build --root=f
435 Entering directory 'f'
436 File "dune", line 6, characters 15-32:
437 6 | (echo "a = %{version:a.test}\n")
438 ^^^^^^^^^^^^^^^^^
439 Error: Library names are not allowed in this position. Only package names are
440 allowed
441 Leaving directory 'f'
442 [1]
443
444 $ rm f/dune
445
446 Test error location
447 ---------------------------------
448
449 $ cat >>a/dune <<EOF
450 > (install
451 > (section (site (non-existent foo)))
452 > (files a.ml)
453 > )
454 > EOF
455
456 $ dune build @install
457 File "a/dune", line 6, characters 16-34:
458 6 | (section (site (non-existent foo)))
459 ^^^^^^^^^^^^^^^^^^
460 Error: The package non-existent is not found
461 [1]
462
463 $ cat >a/dune <<EOF
464 > (library
465 > (public_name a)
466 > (libraries dune-site))
467 > (generate_sites_module (module sites) (sites non-existent))
468 > EOF
469
470 $ dune build
471 File "a/dune", line 4, characters 45-57:
472 4 | (generate_sites_module (module sites) (sites non-existent))
473 ^^^^^^^^^^^^
474 Error: Unknown package
475 [1]