forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This supports things like `dune exec time %{bin:e}`. The syntax is consistent with what support in `dune build` and backwards compatible in cases where no arguments start with `%`. The resolution mechanism is slightly different for the program and the rest of the arguments: - the program is always considered a possible dependency, either in pform syntax (`%{bin:e}` or in string syntax (`./path/to/e`, `_build/default/path/to/e`). - arguments are only interpreted as dependencies if they are in pform syntax. Closes ocaml#2691 Signed-off-by: Etienne Millon <me@emillon.org>
- Loading branch information
Showing
4 changed files
with
184 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
$ 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/bash | ||
> 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 |