diff --git a/CHANGES.md b/CHANGES.md index 90419f67b2c7..976c82262f0b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,8 @@ Unreleased ---------- +- Fixes `dune exec` not adding .exe on Windows (#4371, fixes #3322, @MisterDA) + - Improve interpretation of ansi escape sequence when spawning processes (#4408, fixes #2665, @rgrinberg) diff --git a/bin/exec.ml b/bin/exec.ml index e137281d0b70..84d9acf5b030 100644 --- a/bin/exec.ml +++ b/bin/exec.ml @@ -26,7 +26,7 @@ let man = ; Common.examples [ ("Run the executable named `my_exec'", "dune exec my_exec") ; ( "Run the executable defined in `foo.ml' with the argument `arg'" - , "dune exec ./foo.exe -- arg" ) + , "dune exec -- ./foo.exe arg" ) ] ] @@ -66,11 +66,13 @@ let term = let open Memo.Build.O in (match prog_where with | `Search p -> - [ Path.Build.relative + let p = + Path.Build.relative (Local_install_path.bin_dir ~context:context.name) p |> Path.build - ] + in + [ p; Path.extend_basename p ~suffix:Bin.exe ] | `This_rel p when Sys.win32 -> [ p; Path.extend_basename p ~suffix:Bin.exe ] | `This_rel p -> [ p ] diff --git a/test/blackbox-tests/test-cases/public_name-exe.t/dune b/test/blackbox-tests/test-cases/public_name-exe.t/dune new file mode 100644 index 000000000000..15d32bd8916e --- /dev/null +++ b/test/blackbox-tests/test-cases/public_name-exe.t/dune @@ -0,0 +1,3 @@ +(executable + (name example) + (public_name shaihulud)) diff --git a/test/blackbox-tests/test-cases/public_name-exe.t/dune-project b/test/blackbox-tests/test-cases/public_name-exe.t/dune-project new file mode 100644 index 000000000000..07daf46607bf --- /dev/null +++ b/test/blackbox-tests/test-cases/public_name-exe.t/dune-project @@ -0,0 +1,8 @@ +(lang dune 2.8) +(generate_opam_files true) +(package + (name mypackage) + (synopsis "My first Dune package!") + (description "\| This is my first attempt at creating + "\| a project with Dune. +)) diff --git a/test/blackbox-tests/test-cases/public_name-exe.t/example.ml b/test/blackbox-tests/test-cases/public_name-exe.t/example.ml new file mode 100644 index 000000000000..7bf6048f46da --- /dev/null +++ b/test/blackbox-tests/test-cases/public_name-exe.t/example.ml @@ -0,0 +1 @@ +let () = print_endline "Hello, World!" diff --git a/test/blackbox-tests/test-cases/public_name-exe.t/mypackage.opam b/test/blackbox-tests/test-cases/public_name-exe.t/mypackage.opam new file mode 100644 index 000000000000..d94e2ca65ee1 --- /dev/null +++ b/test/blackbox-tests/test-cases/public_name-exe.t/mypackage.opam @@ -0,0 +1,25 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "My first Dune package!" +description: """ +This is my first attempt at creating +a project with Dune. +""" +depends: [ + "dune" {>= "2.8"} + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] diff --git a/test/blackbox-tests/test-cases/public_name-exe.t/run.t b/test/blackbox-tests/test-cases/public_name-exe.t/run.t new file mode 100644 index 000000000000..240f6682c7f0 --- /dev/null +++ b/test/blackbox-tests/test-cases/public_name-exe.t/run.t @@ -0,0 +1,88 @@ +Test case for https://github.com/ocaml/dune/issues/3322 +"dune exec needs to add .exe on Windows" + + $ os_type=$(ocamlc -config-var os_type) + +Test that on Windows `dune exec -- public_name` and +`dune exec -- public_name.exe` have the same effect. + +With extension +============== + + $ dune clean + $ dune build @install + $ if [ $os_type = Win32 ]; then dune exec -- shaihulud.exe; else echo "Hello, World!"; fi + Hello, World! + +Without extension, prebuild +================= + + $ dune clean + $ dune build @install + $ dune exec -- shaihulud + Hello, World! + + +Test that `dune exec -- public_name` (omitting the .exe) works from a +clean state. + +Without extension, clean state +============================== + + $ dune clean + $ dune exec -- shaihulud + Hello, World! + + +Test that the public name resolves well to the actual executable file +when a dependency changes. On platforms where there are no symlinks, +updating the public_name executable matters. + +With extension, prebuild +============== + + $ dune clean + $ dune build @install + + $ if [ $os_type = Win32 ]; then dune exec -- shaihulud.exe; else echo "Hello, World!"; fi + Hello, World! + $ dune exec -- ./example.exe + Hello, World! + $ sed -i.bak 's/World/Arrakis/' example.ml + $ if [ $os_type = Win32 ]; then dune exec -- shaihulud.exe; else echo "Hello, Arrakis!"; fi + Hello, Arrakis! + $ dune exec -- ./example.exe + Hello, Arrakis! + +Without extension, prebuild +================= + + $ sed -i.bak 's/Arrakis/World/' example.ml + $ dune clean + $ dune build @install + + $ dune exec -- shaihulud + Hello, World! + $ dune exec -- ./example.exe + Hello, World! + $ sed -i.bak 's/World/Arrakis/' example.ml + $ dune exec -- shaihulud + Hello, Arrakis! + $ dune exec -- ./example.exe + Hello, Arrakis! + +Without extention, clean state +============================== + + $ sed -i.bak 's/Arrakis/World/' example.ml + $ dune clean + + $ dune exec -- shaihulud + Hello, World! + $ dune exec -- ./example.exe + Hello, World! + $ sed -i.bak 's/World/Arrakis/' example.ml + $ dune exec -- shaihulud + Hello, Arrakis! + $ dune exec -- ./example.exe + Hello, Arrakis!