Skip to content

Commit dbff7f5

Browse files
committed
feat(exec): support absolute paths
We add support for absolute paths passed to dune exec. There is quite some cleanup that needs to be done in the path handling in dune exec, but for now we have kept this change small and tried to record some of its behaviour. A current limitation is that if a watch mode dune is running then dune exec will connect via RPC and will not be able to correctly deal with an absolute path. Signed-off-by: Ali Caglayan <[email protected]>
1 parent 3a0f090 commit dbff7f5

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

bin/exec.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,19 @@ let get_path common sctx ~prog =
136136
| true -> Memo.return path
137137
| false -> not_found_with_suggestions ~dir ~prog)
138138
| Absolute ->
139-
(match
140-
let prog = Path.of_string prog in
141-
if Path.exists prog
142-
then Some prog
143-
else if not Sys.win32
144-
then None
145-
else (
146-
let prog = Path.extend_basename prog ~suffix:Bin.exe in
147-
Option.some_if (Path.exists prog) prog)
148-
with
149-
| Some prog -> Memo.return prog
150-
| None -> not_found_with_suggestions ~dir ~prog)
139+
let path =
140+
Path.of_string prog
141+
|> Path.Expert.try_localize_external
142+
|> Path.to_string
143+
|> Path.relative_to_source_in_build_or_external ~dir
144+
in
145+
if Path.equal (Path.external_ Path.External.root) path
146+
then not_found ~hints:[] ~prog
147+
else
148+
Build_system.file_exists path
149+
>>= (function
150+
| true -> Memo.return path
151+
| false -> not_found_with_suggestions ~dir ~prog)
151152
;;
152153

153154
let get_path_and_build_if_necessary common sctx ~no_rebuild ~prog =

doc/changes/12094.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `dune exec` now accepts absolute paths inside the workspace. (#12094,
2+
@Alizter)

test/blackbox-tests/test-cases/exec/exec-abs.t

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ Testing interaction of dune exec and absolute directories.
1616
$ dune exec ./foo.exe
1717
hi
1818

19+
Dune exec is able to handle absolute executable paths.
20+
1921
$ dune exec $PWD/foo.exe
20-
Error: Program
21-
'$TESTCASE_ROOT/foo.exe'
22-
not found!
22+
hi
23+
24+
Lets check some validation:
25+
26+
$ dune exec ..
27+
Error: Program '..' not found!
28+
[1]
29+
$ dune exec .
30+
Error: Program '.' not found!
31+
[1]
32+
$ dune exec /.
33+
Error: Program '/.' not found!
34+
[1]
35+
$ dune exec /
36+
Error: Program '/' not found!
2337
[1]
2438

0 commit comments

Comments
 (0)