Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions bin/exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,19 @@ let get_path common sctx ~prog =
| true -> Memo.return path
| false -> not_found_with_suggestions ~dir ~prog)
| Absolute ->
(match
let prog = Path.of_string prog in
if Path.exists prog
then Some prog
else if not Sys.win32
then None
else (
let prog = Path.extend_basename prog ~suffix:Bin.exe in
Option.some_if (Path.exists prog) prog)
with
| Some prog -> Memo.return prog
| None -> not_found_with_suggestions ~dir ~prog)
let path =
Path.of_string prog
|> Path.Expert.try_localize_external
|> Path.to_string
|> Path.relative_to_source_in_build_or_external ~dir
in
if Path.equal (Path.external_ Path.External.root) path
then not_found ~hints:[] ~prog
else
Build_system.file_exists path
>>= (function
| true -> Memo.return path
| false -> not_found_with_suggestions ~dir ~prog)
;;

let get_path_and_build_if_necessary common sctx ~no_rebuild ~prog =
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/12094.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `dune exec` now accepts absolute paths inside the workspace. (#12094,
@Alizter)
38 changes: 38 additions & 0 deletions test/blackbox-tests/test-cases/exec/exec-abs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Testing interaction of dune exec and absolute directories.

$ cat > dune-project <<EOF
> (lang dune 3.20)
> EOF

$ cat > dune <<EOF
> (executable
> (name foo))
> EOF

$ cat > foo.ml <<EOF
> let () = print_endline "hi" ;;
> EOF

$ dune exec ./foo.exe
hi

Dune exec is able to handle absolute executable paths.

$ dune exec $PWD/foo.exe
hi

Lets check some validation:

$ dune exec ..
Error: Program '..' not found!
[1]
$ dune exec .
Error: Program '.' not found!
[1]
$ dune exec /.
Error: Program '/.' not found!
[1]
$ dune exec /
Error: Program '/' not found!
[1]

Loading