diff --git a/bin/exec.ml b/bin/exec.ml index d08c57c74f9..453721f361d 100644 --- a/bin/exec.ml +++ b/bin/exec.ml @@ -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 = diff --git a/doc/changes/12094.md b/doc/changes/12094.md new file mode 100644 index 00000000000..2b6594eb3e6 --- /dev/null +++ b/doc/changes/12094.md @@ -0,0 +1,2 @@ +- `dune exec` now accepts absolute paths inside the workspace. (#12094, + @Alizter) diff --git a/test/blackbox-tests/test-cases/exec/exec-abs.t b/test/blackbox-tests/test-cases/exec/exec-abs.t new file mode 100644 index 00000000000..e78258721cc --- /dev/null +++ b/test/blackbox-tests/test-cases/exec/exec-abs.t @@ -0,0 +1,38 @@ +Testing interaction of dune exec and absolute directories. + + $ cat > dune-project < (lang dune 3.20) + > EOF + + $ cat > dune < (executable + > (name foo)) + > EOF + + $ cat > foo.ml < 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] +