Skip to content

Commit

Permalink
Exec watch mode spawns processes with initial cwd
Browse files Browse the repository at this point in the history
Fixes a bug where commands run from `dune exec -w` would have the cwd of
the project root rather than the directory where the command was run.

Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
  • Loading branch information
gridbugs committed Mar 14, 2024
1 parent e45ac2f commit f072bb5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bin/exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ module Command_to_exec = struct
let path = Path.to_string path in
let env = Env.to_unix env |> Spawn.Env.of_list in
let argv = path :: args in
Spawn.spawn ~prog:path ~env ~argv ()
let cwd = Spawn.Working_dir.Path Fpath.initial_cwd in
Spawn.spawn ~prog:path ~env ~cwd ~argv ()
in
Pid.of_int pid
;;
Expand Down
1 change: 1 addition & 0 deletions doc/changes/10262.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix bug with `dune exec --watch` where the working directory would always be set to the project root rather than the directory where the command was run (#10262, @gridbugs)
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/exec-watch/exec-pwd.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In normal (non-watching) mode, pwd is the folder from which dune is launched
$ rm -rf $OUTPUT
$ cd ..

While in watch mode, pwd is always the root project folder
In watch mode, pwd is also the folder from which dune is launched.
$ cd bin
$ dune exec --root .. -w -- pwd > $OUTPUT &
Entering directory '..'
Expand All @@ -20,6 +20,6 @@ While in watch mode, pwd is always the root project folder
$ until test -s $OUTPUT; do sleep 0.1; done;
$ kill $PID
$ cat $OUTPUT
$TESTCASE_ROOT
$TESTCASE_ROOT/bin
$ rm -rf $OUTPUT
$ cd ..

0 comments on commit f072bb5

Please sign in to comment.