@@ -25,12 +25,27 @@ 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 _a = Sys. argv. (1 ) in
43+ > let desired_argv0 = Sys. argv. (2 ) in
44+ > let prog = Sys. argv. (3 ) in
45+ > let args = Array . length Sys. argv in
46+ > let new_args = Array . init (args - 3 ) (fun i -> Sys. argv. (i+ 3)) in
47+ > new_args. (0 ) < - desired_argv0;
48+ > Unix. execvp prog new_args
3449 > EOF
3550
3651Make lockfiles for the packages.
@@ -65,13 +80,25 @@ Make lockfiles for the packages.
6580Test that the project can be built normally.
6681 $ build_pkg foo
6782
83+
6884Make a fake dune exe:
69- $ mkdir bin
70- $ cat > bin/ dune << EOF
85+
86+ $ mkdir . bin
87+ $ cat > . bin/ dune << EOF
7188 > # !/bin/sh
7289 > echo " Fake dune! (args: \$@)"
7390 > EOF
74- $ chmod a+ x bin/ dune
91+ $ chmod a+ x . bin/ dune
92+
93+ $ dune build @ install
94+ $ mkdir . temp
95+ $ dune install -- prefix $ PWD /. temp
96+ $ cp . temp / bin/ exec-a $ PWD /. bin/
97+
98+ Show that the binary works like `exec -a` would work
99+
100+ $ . bin/ exec-a -a " desired-argv0" sh -c ' echo $0'
101+ desired-argv0
75102
76103 $ dune clean
77104
@@ -88,16 +115,16 @@ Remember the digests, to not to have to call nested Dunes:
88115
89116Call Dune with an absolute PATH as argv[0 ]:
90117
91- $ PATH= $ PWD / bin: $ PATH $ DUNE build $ pkg_root / $ foo_digest / target/
92- $ PATH= $ PWD / bin: $ PATH $ DUNE build $ pkg_root / $ bar_digest / target/
118+ $ PATH= $ PWD /. bin: $ PATH $ DUNE build $ pkg_root / $ foo_digest / target/
119+ $ PATH= $ PWD /. bin: $ PATH $ DUNE build $ pkg_root / $ bar_digest / target/
93120 Fake dune! (args: build -p bar @ install )
94121
95122Call Dune with argv[0 ] set to a relative PATH. Make sure " dune" in PATH refers
96123to the fake dune:
97124
98- $ (PATH= $ PWD / bin: $ PATH exec -a " dune" sh -c " which dune" )
99- $ TESTCASE_ROOT / bin/ dune
125+ $ (PATH= $ PWD /. bin: $ PATH $ PWD /. bin / exec-a -a " dune" sh -c " which dune" )
126+ $ TESTCASE_ROOT /. bin/ dune
100127
101128Make sure that fake dune is not picked up when dune is called with argv[0 ] = " dune" :
102129
103- $ (PATH= $ PWD / bin: $ PATH exec -a " dune" $ DUNE build $ pkg_root / $ foo_digest / target/ )
130+ $ (PATH= $ PWD / bin: $ PATH $ PWD /. bin / exec-a -a " dune" $ DUNE build $ pkg_root / $ foo_digest / target/ )
0 commit comments