This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,27 @@
$ cat > dune-workspace << EOF
> (lang dune 3.13)
> (context default)
> (context
> (default
> (name log)))
> EOF
$ dune build
File "dune-workspace", line 5, characters 8-11:
5 | (name log)))
^^^
Error: "log" is an invalid context name.
[1]
$ cat > dune-workspace << EOF
> (lang dune 3.13)
> (context default)
> (context
> (default
> (name install)))
> EOF
$ dune build 2>&1 | grep "must not crash"
I must not crash. Uncertainty is the mind-killer. Exceptions are the

View file

@ -0,0 +1,3 @@
(alias
(name runtest)
(action (echo "build profile: %{profile}")))

View file

@ -0,0 +1,3 @@
(lang dune 1.0)
(context (default (profile foobar)))

View file

@ -0,0 +1,4 @@
Workspaces let you set custom profiles
$ dune runtest
build profile: foobar

View file

@ -0,0 +1,3 @@
(lang dune 1.0)
(context (default))

View file

@ -0,0 +1,3 @@
specifying the workspace file is possible:
$ dune build --workspace dune-workspace.dev

View file

@ -0,0 +1,3 @@
(cram
(applies_to multiple-merlin-contexts opam)
(deps %{bin:opam}))

View file

@ -0,0 +1,9 @@
dune uses a versioned file. If the version is missing, then we get an error.
$ dune build
File "dune-workspace", line 1, characters 0-19:
1 | (context (default))
^^^^^^^^^^^^^^^^^^^
Error: Invalid first line, expected: (lang <lang> <version>)
[1]

View file

@ -0,0 +1,3 @@
dune ignores jbuild-workspace files:
$ dune build

View file

@ -0,0 +1,12 @@
(lang dune 1.0)
(context
(default
(merlin)))
(context
(opam
(switch foo-switch)
(name foo-name)
(profile foo-profile)
(merlin)))

View file

@ -0,0 +1,11 @@
Only a single context may be marked for merlin
$ dune build
File "dune-workspace", lines 8-12, characters 1-82:
8 | (opam
9 | (switch foo-switch)
10 | (name foo-name)
11 | (profile foo-profile)
12 | (merlin)))
Error: you can only have one context for merlin
[1]

View file

@ -0,0 +1,8 @@
(lang dune 1.0)
(context
(opam
(switch foo-switch)
(name foo-name)
(profile foo-profile)
(merlin false)))

View file

@ -0,0 +1,4 @@
A workspace context can be defined using an opam switch. This test is disabled
because we don't really have a way to mock an opam switch.
# $ dune build --display quiet 2>&1

View file

@ -0,0 +1,2 @@
(executable (name foo))

View file

@ -0,0 +1,3 @@
(lang dune 1.0)
(context (default (targets native)))

View file

@ -0,0 +1 @@
print_endline "message from targets-native test";;

View file

@ -0,0 +1,6 @@
Workspaces also allow you to set "target" for cross compilation. This feature is
a bit hard to test since it requires mocking more than one context. But we can
see how we can set a "native" target. Which is the default.
$ dune exec ./foo.exe
message from targets-native test

View file

@ -0,0 +1,13 @@
(lang dune 1.7)
(env
(default
(ocamlc_flags (:standard -verbose))
(c_flags ())
(cxx_flags ())))
(context
(default
(env
(default
(flags (:standard -machin))))))

View file

@ -0,0 +1,23 @@
Workspaces also allow you to set the env for a context:
$ dune printenv --profile default
(flags
(-w -40 -machin))
(ocamlc_flags
(-g -verbose))
(ocamlopt_flags (-g))
(melange.compile_flags (-g))
(c_flags ())
(cxx_flags ())
(link_flags ())
(menhir_flags ())
(menhir_explain ())
(coq_flags (-q))
(coqdep_flags ())
(coqdoc_flags (--toc))
(js_of_ocaml_flags ())
(js_of_ocaml_build_runtime_flags ())
(js_of_ocaml_link_flags ())
(wasm_of_ocaml_flags ())
(wasm_of_ocaml_build_runtime_flags ())
(wasm_of_ocaml_link_flags ())

View file

@ -0,0 +1,3 @@
(executable
(name hello)
(promote (until-clean)))

View file

@ -0,0 +1,2 @@
let () =
Printf.printf "Hello: %s\n%!" (Sys.getenv "FOO")

View file

@ -0,0 +1,8 @@
(alias
(name default)
(deps bin/hello.exe)
(action (run hello.exe)))
;; Note that if you try the above on Windows it will fail because the program in
;; the (run ...) action is supposed to **not** contain the .exe extension, but
;; if we remove it then it will fail on Unix systems.

View file

@ -0,0 +1,5 @@
(lang dune 1.12)
(context
(default
(paths (PATH bin :standard) (FOO a b /c \ b))))

View file

@ -0,0 +1,27 @@
Duplicate hello.exe before writing to it, as modifying a produced file
is prohibited.
$ cp bin/hello.exe.source bin/hello.exe
$ chmod u+w bin/hello.exe
$ dune build
Hello: $TESTCASE_ROOT/a:/c
$ mkdir sub
$ cat > sub/dune-workspace <<EOF
> (lang dune 1.12)
> (context
> (default
> (paths (FOO a) (FOO b))))
> EOF
$ cat > sub/dune-project <<EOF
> (lang dune 1.12)
> EOF
$ dune build --root sub
Entering directory 'sub'
File "dune-workspace", line 4, characters 19-22:
4 | (paths (FOO a) (FOO b))))
^^^
Error: the variable "FOO" can appear at most once in this stanza.
Leaving directory 'sub'
[1]