Skip to content

Commit 136f99b

Browse files
Use OCaml implementation of exec -a
Signed-off-by: Marek Kubica <marek@tarides.com>
1 parent deaec3d commit 136f99b

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

test/blackbox-tests/test-cases/pkg/different-dune-in-path.t

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,26 @@ Make a project that depends on the test packages:
2525
> (lang dune 3.13)
2626
> (package
2727
> (name x)
28-
> (allow_empty)
2928
> (depends foo bar))
3029
> EOF
3130

3231
$ cat > dune <<EOF
33-
> (data_only_dirs bin)
32+
> (executable
33+
> (name exec_a)
34+
> (public_name exec-a)
35+
> (libraries unix))
36+
> EOF
37+
38+
Small helper binary to implement `exec -a` in a portable way
39+
40+
$ cat > exec_a.ml <<EOF
41+
> let () =
42+
> let desired_argv0 = Sys.argv.(1) in
43+
> let prog = Sys.argv.(2) in
44+
> let args = Array.length Sys.argv in
45+
> let new_args = Array.init (args - 2) (fun i -> Sys.argv.(i+2)) in
46+
> new_args.(0) <- desired_argv0;
47+
> Unix.execvp prog new_args
3448
> EOF
3549

3650
Make lockfiles for the packages.
@@ -65,13 +79,25 @@ Make lockfiles for the packages.
6579
Test that the project can be built normally.
6680
$ build_pkg foo
6781

82+
6883
Make a fake dune exe:
69-
$ mkdir bin
70-
$ cat > bin/dune <<EOF
84+
85+
$ mkdir .bin
86+
$ cat > .bin/dune <<EOF
7187
> #!/bin/sh
7288
> echo "Fake dune! (args: \$@)"
7389
> EOF
74-
$ chmod a+x bin/dune
90+
$ chmod a+x .bin/dune
91+
92+
$ dune build @install
93+
$ mkdir .temp
94+
$ dune install --prefix $PWD/.temp
95+
$ cp .temp/bin/exec-a $PWD/.bin/
96+
97+
Show that the binary works like `exec -a` would work
98+
99+
$ .bin/exec-a "desired-argv0" sh -c 'echo $0'
100+
desired-argv0
75101

76102
$ dune clean
77103

@@ -88,16 +114,16 @@ Remember the digests, to not to have to call nested Dunes:
88114

89115
Call Dune with an absolute PATH as argv[0]:
90116

91-
$ PATH=$PWD/bin:$PATH $DUNE build $pkg_root/$foo_digest/target/
92-
$ PATH=$PWD/bin:$PATH $DUNE build $pkg_root/$bar_digest/target/
117+
$ PATH=$PWD/.bin:$PATH $DUNE build $pkg_root/$foo_digest/target/
118+
$ PATH=$PWD/.bin:$PATH $DUNE build $pkg_root/$bar_digest/target/
93119
Fake dune! (args: build -p bar @install)
94120

95121
Call Dune with argv[0] set to a relative PATH. Make sure "dune" in PATH refers
96122
to the fake dune:
97123

98-
$ (PATH=$PWD/bin:$PATH exec -a "dune" sh -c "which dune")
99-
$TESTCASE_ROOT/bin/dune
124+
$ (PATH=$PWD/.bin:$PATH $PWD/.bin/exec-a "dune" sh -c "which dune")
125+
$TESTCASE_ROOT/.bin/dune
100126

101127
Make sure that fake dune is not picked up when dune is called with argv[0] = "dune":
102128

103-
$ (PATH=$PWD/bin:$PATH exec -a "dune" $DUNE build $pkg_root/$foo_digest/target/)
129+
$ (PATH=$PWD/bin:$PATH $PWD/.bin/exec-a "dune" $DUNE build $pkg_root/$foo_digest/target/)

0 commit comments

Comments
 (0)