Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`findExecutable "ghc-9.10.1" behaves surprisingly on windows #188

Open
hasufell opened this issue Aug 17, 2024 · 2 comments
Open

`findExecutable "ghc-9.10.1" behaves surprisingly on windows #188

hasufell opened this issue Aug 17, 2024 · 2 comments

Comments

@hasufell
Copy link
Member

hasufell commented Aug 17, 2024

ghci> findExecutable "ghc-9.10.1"
Nothing
ghci> findExecutable "ghc-9.10.1.exe"
Just "C:\\ghcup\\bin\\ghc-9.10.1.exe"

This is because "ghc-9.10.1" is considered to contain a file extension. The documentation on SearchPathW states under lpExtension:

The extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension.

@hasufell
Copy link
Member Author

hasufell commented Aug 17, 2024

So I think, the way we need is this:

searchPathEnvForExes :: OsString -> IO (Maybe OsPath)
searchPathEnvForExes (OsString binary) =
  let binary' = if takeExtension binary == exeExtension then binary else binary <.> exeExtension
  in fmap OsString <$> Win32.searchPath Nothing binary' Nothing

ignoring the lpExtension parameter.

But that would not allow us to search for e.g. foo.bat or other executable-like formats.

@Rufflewind
Copy link
Member

I don't see a way to work around this quirk of SearchPathW without breaking existing use cases. I think the caller will just have to intentionally add the .exe suffix in this situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants