Skip to content

Windows [find_executable] fixes - #16

Open
jonahbeckford wants to merge 1 commit into
janestreet:masterfrom
jonahbeckford:fix-find-executable-against-master
Open

Windows [find_executable] fixes#16
jonahbeckford wants to merge 1 commit into
janestreet:masterfrom
jonahbeckford:fix-find-executable-against-master

Conversation

@jonahbeckford

Copy link
Copy Markdown
  • Use ';' as PATH seperator on Windows.

  • On Windows Sys.file_exists can return true even if Sys.is_directory is true. And an executable ends in .exe

Before

utop # eval (find_executable_exn "git") ;;
Exception: Failure "command \"git\" not found".
Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
Called from Shexp_process__Process.map.(fun) in file "process-lib/src/process.ml", line 533, characters 40-45
Called from Shexp_process__Process.exec in file "process-lib/src/process.ml", line 173, characters 12-47
Re-raised at Shexp_process__Process.exec in file "process-lib/src/process.ml", line 176, characters 8-19
Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
Called from Topeval.load_lambda in file "toplevel/byte/topeval.ml", line 89, characters 4-153

And it has the same exception for git.exe.

After

utop # let open Shexp_process in eval (find_executable "git" ) ;;
- : string option = Some "C:\\Program Files\\Git\\cmd\\git.exe"

utop # let open Shexp_process in eval (find_executable "git.exe" ) ;;
- : string option = Some "C:\\Program Files\\Git\\cmd\\git.exe"

+ Use ';' as PATH seperator on Windows.

+ On Windows Sys.file_exists can return true even if Sys.is_directory is true. And an executable ends in `.exe`

Signed-off-by: Jonah Beckford <71855677+jonahbeckford@users.noreply.github.com>
@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label Feb 12, 2024
@mdelvecchio-jsc

Copy link
Copy Markdown

A couple notes:

  • Sys.file_exists also returns true on unix; why should we special-case it for windows?
  • Finding an executable from the path in windows involves checking the PATHEXT environment variable to determine what extensions to look for. I think it would be bad to "support" windows but not correctly use this environment variable.
  • The mli for this function explicitly says that it uses a unix environment. I think we should either 1) provide proper support for windows here (which involves some design questions that I don't quite have a good answer to); or 2) just leave the implementation as is (maybe change the name to make it more obvious it's unix-only?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants