dune icon indicating copy to clipboard operation
dune copied to clipboard

Fix locating program in exec watch mode

Open gridbugs opened this issue 1 year ago • 2 comments

This fixes a bug where running an executable from the current project with dune exec --watch would be unable to find the executable unless the command was run from the project's root directory.

The problem was introduced when we started setting the cwd of processes spawned by exec in watch mode to the user's current directory (https://github.com/ocaml/dune/pull/10262). If the program argument to exec refers to a file to be built in the current project (such as an executable implemented in the current project) then the path to the executable to spawn will be a path inside the _build directory relative to the project root. Since the cwd of the new process was set to the user's current directory, this relative path was being resolved within the current directory, whereas it should have been resolved relative to the project root.

The fix was to convert relative paths into absolute paths relative to the project root (this was already being done for exec when not in watch mode).

gridbugs avatar Apr 04 '24 10:04 gridbugs

what happens with cd path && dune exec -- echo hello?

IIUC, echo would pass the Filename.is_relative check and get a prefix when it shouldn't?

dune exec converts paths with no slashes into absolute paths by looking them up in PATH, so any program names will be represented by their absolute path here.

gridbugs avatar Apr 05 '24 02:04 gridbugs

Just making sure that we don't forget to merge this. Are any other changes necessary?

gridbugs avatar May 29 '24 01:05 gridbugs

Fixed in another PR

rgrinberg avatar Oct 18 '24 15:10 rgrinberg