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