This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1 @@
|
|||
(executable (name main))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.1)
|
||||
|
|
@ -0,0 +1 @@
|
|||
print_endline "foobar";;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ DUNE_BUILD_DIR="$PWD/_custom" dune exec ./main.exe
|
||||
foobar
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
$ cat > dune-project << EOF
|
||||
> (lang dune 1.1)
|
||||
>
|
||||
> (package
|
||||
> (name e))
|
||||
> EOF
|
||||
$ cat > dune << EOF
|
||||
> (executable
|
||||
> (public_name e))
|
||||
> EOF
|
||||
|
||||
The executable just displays "Hello" and its arguments.
|
||||
|
||||
$ cat > e.ml << EOF
|
||||
> let () =
|
||||
> print_endline "Hello";
|
||||
> Array.iteri (fun i s ->
|
||||
> Printf.printf "argv[%d] = %s\n" i s
|
||||
> ) Sys.argv
|
||||
> EOF
|
||||
|
||||
By default, e is executed with the program name and arguments in argv.
|
||||
|
||||
$ dune exec ./e.exe a b c
|
||||
Hello
|
||||
argv[0] = ./_build/default/e.exe
|
||||
argv[1] = a
|
||||
argv[2] = b
|
||||
argv[3] = c
|
||||
|
||||
The special form %{bin:public_name} is supported.
|
||||
|
||||
$ dune exec %{bin:e} a b c
|
||||
Hello
|
||||
argv[0] = ./_build/install/default/bin/e
|
||||
argv[1] = a
|
||||
argv[2] = b
|
||||
argv[3] = c
|
||||
|
||||
This wrapper parses its own arguments and executes the rest.
|
||||
|
||||
$ cat > wrap.sh << 'EOF'
|
||||
> #!/bin/sh
|
||||
> while getopts "xy" o; do
|
||||
> echo "Got option: $o"
|
||||
> done
|
||||
> shift $((OPTIND-1))
|
||||
> echo Before
|
||||
> "$@"
|
||||
> echo After
|
||||
> EOF
|
||||
$ chmod +x wrap.sh
|
||||
|
||||
It is possible to put the %{bin:...} pform in arguments rather than first.
|
||||
|
||||
$ dune exec -- ./wrap.sh -x -y %{bin:e} a b c
|
||||
Got option: x
|
||||
Got option: y
|
||||
Before
|
||||
Hello
|
||||
argv[0] = _build/install/default/bin/e
|
||||
argv[1] = a
|
||||
argv[2] = b
|
||||
argv[3] = c
|
||||
After
|
||||
|
||||
The first item is still looked up in PATH.
|
||||
|
||||
$ dune exec ls %{bin:e}
|
||||
_build/install/default/bin/e
|
||||
|
||||
Pforms can appear several times.
|
||||
|
||||
$ dune exec ls %{bin:e} %{bin:e}
|
||||
_build/install/default/bin/e
|
||||
_build/install/default/bin/e
|
||||
|
||||
It should also be possible to call another program that is also supposed to be
|
||||
built if referenced, for this we create a new binary that calls its first
|
||||
argument:
|
||||
|
||||
$ cat > call_arg.ml << EOF
|
||||
> let () =
|
||||
> let first = Sys.argv.(1) in
|
||||
> Printf.printf "Calling my first arg, %S:\n" first;
|
||||
> let inch, outch = Unix.open_process_args first [|first|] in
|
||||
> print_endline (input_line inch);
|
||||
> let status = Unix.close_process (inch, outch) in
|
||||
> match status with
|
||||
> | Unix.WEXITED 0 -> print_endline "All good"
|
||||
> | _ -> print_endline "Something is Rotten in the State of Dune"
|
||||
> EOF
|
||||
$ cat > called.ml << EOF
|
||||
> let () = print_endline "I was called"
|
||||
> EOF
|
||||
$ cat > dune << EOF
|
||||
> (executables
|
||||
> (public_names e call_arg called)
|
||||
> (libraries unix))
|
||||
> EOF
|
||||
|
||||
If we then ask it to execute, both `call_arg` and `called` should be compiled
|
||||
and run, successfully.
|
||||
|
||||
$ dune exec %{bin:call_arg} %{bin:called}
|
||||
Calling my first arg, "_build/install/default/bin/called":
|
||||
I was called
|
||||
All good
|
||||
|
|
@ -0,0 +1 @@
|
|||
print_endline "Bar";
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(executable
|
||||
(modules foo)
|
||||
(name foo))
|
||||
|
||||
(executable
|
||||
(modules bar)
|
||||
(name bar)
|
||||
(public_name dunetestbar))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.0)
|
||||
|
|
@ -0,0 +1 @@
|
|||
print_endline "Foo";
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
$ dune clean
|
||||
$ dune exec --no-build ./foo.exe
|
||||
Error: Program './foo.exe' isn't built yet. You need to build it first or
|
||||
remove the '--no-build' option.
|
||||
[1]
|
||||
$ dune exec ./foo.exe
|
||||
Foo
|
||||
$ dune exec --profile release ./foo.exe
|
||||
Foo
|
||||
$ dune exec dunetestbar --no-build
|
||||
Error: Program 'dunetestbar' isn't built yet. You need to build it first or
|
||||
remove the '--no-build' option.
|
||||
[1]
|
||||
$ dune exec dunetestbar
|
||||
Bar
|
||||
|
||||
#Test the at exit bookkeeping of dune is done in the right directory
|
||||
$ dune clean
|
||||
|
||||
$ mkdir test
|
||||
|
||||
$ mkdir test/_build
|
||||
|
||||
$ (cd test; dune exec --root .. -- dunetestbar)
|
||||
Entering directory '..'
|
||||
Leaving directory '..'
|
||||
Bar
|
||||
|
||||
$ ls -a test/_build
|
||||
.
|
||||
..
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
Testing how dune exec handles errors in the program being run.
|
||||
|
||||
$ cat > dune-project <<EOF
|
||||
> (lang dune 3.18)
|
||||
> EOF
|
||||
|
||||
$ cat > dune <<EOF
|
||||
> (executable
|
||||
> (name foo))
|
||||
> EOF
|
||||
|
||||
If a program exits with a non-zero exit code, we should return that code.
|
||||
|
||||
$ cat > foo.ml <<EOF
|
||||
> let () =
|
||||
> Printf.eprintf "oh no!\n";
|
||||
> exit 1
|
||||
> ;;
|
||||
> EOF
|
||||
|
||||
$ dune exec -- ./foo.exe
|
||||
oh no!
|
||||
[1]
|
||||
|
||||
If a program encounters an exception, we should return a non-zero exit code.
|
||||
|
||||
$ cat > foo.ml <<EOF
|
||||
> let () =
|
||||
> raise (Failure "oh no!")
|
||||
> ;;
|
||||
> EOF
|
||||
|
||||
$ dune exec -- ./foo.exe
|
||||
Fatal error: exception Failure("oh no!")
|
||||
[2]
|
||||
|
||||
Disable shell monitoring (of jobs) so that we do not get spurious messages
|
||||
about signals.
|
||||
$ set +m
|
||||
|
||||
If a program segfaults, we should return a non-zero exit code.
|
||||
|
||||
$ cat > foo.ml <<EOF
|
||||
> let () =
|
||||
> let f = Obj.magic 0 in
|
||||
> f 1
|
||||
> [@@warning "-20"]
|
||||
> ;;
|
||||
> EOF
|
||||
|
||||
Note that 128 + 11 (SEGV) = 139
|
||||
$ { dune exec -- ./foo.exe; } 2> /dev/null
|
||||
[139]
|
||||
|
||||
If a program is killed by a signal before it terminates, we should return a non-zero exit
|
||||
code.
|
||||
|
||||
$ cat > dune <<EOF
|
||||
> (executable
|
||||
> (name foo)
|
||||
> (libraries unix))
|
||||
> EOF
|
||||
|
||||
$ cat > foo.ml <<EOF
|
||||
> let () =
|
||||
> let pid = Unix.getpid () in
|
||||
> Printf.printf "Killing self";
|
||||
> Unix.kill pid Sys.sigkill
|
||||
> ;;
|
||||
> EOF
|
||||
|
||||
$ { dune exec -- ./foo.exe; } 2> /dev/null
|
||||
[137]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name x)
|
||||
(libraries does-not-exist))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 1.0)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
When using dune exec, the external-lib-deps command refers to the executable:
|
||||
|
||||
$ dune exec ./x.exe
|
||||
File "dune", line 3, characters 12-26:
|
||||
3 | (libraries does-not-exist))
|
||||
^^^^^^^^^^^^^^
|
||||
Error: Library "does-not-exist" not found.
|
||||
-> required by _build/default/x.exe
|
||||
[1]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(executable
|
||||
(name foo))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 2.0)
|
||||
|
|
@ -0,0 +1 @@
|
|||
print_string "foo"
|
||||
|
|
@ -0,0 +1 @@
|
|||
print_string "foo/bar"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
(executable
|
||||
(name bar))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 2.0)
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
when user tries to execute a current-dir-defined
|
||||
executable without './' we suggest it
|
||||
|
||||
$ dune exec foo.exe --no-build
|
||||
Error: Program 'foo.exe' not found!
|
||||
Hint: did you mean ./foo.exe?
|
||||
[1]
|
||||
|
||||
$ dune exec foo.exe
|
||||
Error: Program 'foo.exe' not found!
|
||||
Hint: did you mean ./foo.exe?
|
||||
[1]
|
||||
|
||||
$ dune exec ./foo.exe
|
||||
foo
|
||||
|
||||
$ (cd foo && dune exec bar.exe --no-build)
|
||||
Error: Program 'bar.exe' not found!
|
||||
Hint: did you mean ./bar.exe?
|
||||
[1]
|
||||
|
||||
$ (cd foo && dune exec bar.exe)
|
||||
Error: Program 'bar.exe' not found!
|
||||
Hint: did you mean ./bar.exe?
|
||||
[1]
|
||||
|
||||
$ (cd foo && dune exec ./bar.exe)
|
||||
foo/bar
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name example)
|
||||
(public_name shaihulud))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(lang dune 2.8)
|
||||
(generate_opam_files true)
|
||||
(package
|
||||
(name mypackage)
|
||||
(synopsis "My first Dune package!")
|
||||
(description "\| This is my first attempt at creating
|
||||
"\| a project with Dune.
|
||||
))
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
# This file is generated by dune, edit dune-project instead
|
||||
opam-version: "2.0"
|
||||
synopsis: "My first Dune package!"
|
||||
description: """
|
||||
This is my first attempt at creating
|
||||
a project with Dune.
|
||||
"""
|
||||
depends: [
|
||||
"dune" {>= "2.8"}
|
||||
"odoc" {with-doc}
|
||||
]
|
||||
build: [
|
||||
["dune" "subst"] {dev}
|
||||
[
|
||||
"dune"
|
||||
"build"
|
||||
"-p"
|
||||
name
|
||||
"-j"
|
||||
jobs
|
||||
"@install"
|
||||
"@runtest" {with-test}
|
||||
"@doc" {with-doc}
|
||||
]
|
||||
]
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
Test case for https://github.com/ocaml/dune/issues/3322
|
||||
"dune exec needs to add .exe on Windows"
|
||||
|
||||
$ os_type=$(ocamlc -config-var os_type)
|
||||
$ echo 'let () = print_endline "Hello, World!"' > example.ml
|
||||
|
||||
Test that on Windows `dune exec -- public_name` and
|
||||
`dune exec -- public_name.exe` have the same effect.
|
||||
|
||||
With extension
|
||||
==============
|
||||
|
||||
$ dune clean
|
||||
$ dune build @install
|
||||
$ if [ $os_type = Win32 ]; then dune exec -- shaihulud.exe; else echo "Hello, World!"; fi
|
||||
Hello, World!
|
||||
|
||||
Without extension, prebuild
|
||||
=================
|
||||
|
||||
$ dune clean
|
||||
$ dune build @install
|
||||
$ dune exec -- shaihulud
|
||||
Hello, World!
|
||||
|
||||
|
||||
Test that `dune exec -- public_name` (omitting the .exe) works from a
|
||||
clean state.
|
||||
|
||||
Without extension, clean state
|
||||
==============================
|
||||
|
||||
$ dune clean
|
||||
$ dune exec -- shaihulud
|
||||
Hello, World!
|
||||
|
||||
|
||||
Test that the public name resolves well to the actual executable file
|
||||
when a dependency changes. On platforms where there are no symlinks,
|
||||
updating the public_name executable matters.
|
||||
|
||||
With extension, prebuild
|
||||
==============
|
||||
|
||||
$ dune clean
|
||||
$ dune build @install
|
||||
|
||||
$ if [ $os_type = Win32 ]; then dune exec -- shaihulud.exe; else echo "Hello, World!"; fi
|
||||
Hello, World!
|
||||
$ dune exec -- ./example.exe
|
||||
Hello, World!
|
||||
$ sed -i.bak 's/World/Arrakis/' example.ml
|
||||
$ if [ $os_type = Win32 ]; then dune exec -- shaihulud.exe; else echo "Hello, Arrakis!"; fi
|
||||
Hello, Arrakis!
|
||||
$ dune exec -- ./example.exe
|
||||
Hello, Arrakis!
|
||||
|
||||
Without extension, prebuild
|
||||
=================
|
||||
|
||||
$ sed -i.bak 's/Arrakis/World/' example.ml
|
||||
$ dune clean
|
||||
$ dune build @install
|
||||
|
||||
$ dune exec -- shaihulud
|
||||
Hello, World!
|
||||
$ dune exec -- ./example.exe
|
||||
Hello, World!
|
||||
$ sed -i.bak 's/World/Arrakis/' example.ml
|
||||
$ dune exec -- shaihulud
|
||||
Hello, Arrakis!
|
||||
$ dune exec -- ./example.exe
|
||||
Hello, Arrakis!
|
||||
|
||||
Without extension, clean state
|
||||
==============================
|
||||
|
||||
$ sed -i.bak 's/Arrakis/World/' example.ml
|
||||
$ dune clean
|
||||
|
||||
$ dune exec -- shaihulud
|
||||
Hello, World!
|
||||
$ dune exec -- ./example.exe
|
||||
Hello, World!
|
||||
$ sed -i.bak 's/World/Arrakis/' example.ml
|
||||
$ dune exec -- shaihulud
|
||||
Hello, Arrakis!
|
||||
$ dune exec -- ./example.exe
|
||||
Hello, Arrakis!
|
||||
Loading…
Add table
Add a link
Reference in a new issue