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

Cygpath the PATH from opam env #4844

Merged
merged 2 commits into from
Jul 23, 2022

Conversation

jonahbeckford
Copy link
Contributor

@jonahbeckford jonahbeckford commented Sep 23, 2021

When using a native Windows opam.exe the PATH from opam env is in Windows format.

PowerShell output from opam env: $env:PATH = 'Z:\source\opam\_opam\bin;...'
CMD.exe output from opam env: SET PATH=Z:\source\opam\_opam\bin;...

With this change both MSYS2 and Cygwin will Unix-ize the PATH with essentially cygpath --path $PATH.

Cygwin output from opam env: PATH='/cygdrive/c/Users/beckf/AppData/Local/opam/diskuv-boot-DO-NOT-DELETE/bin:...'
MSYS2 output from opam env: PATH='/z/source/opam/_opam/bin:...'

cygpath --path on an already Unix PATH is idempotent, so a Cygwin opam.exe will still work after this change. That is, the following says "MATCHES" on both Cygwin and MSYS2:

if [[ "$(cygpath --path '$PATH')" = $(cygpath --path "$(cygpath --path '$PATH')") ]]; then echo MATCHES; fi

This PR gets eval $(opam env) working from a native Windows opam.exe into a MSYS2 shell. However the same command in a Cygwin shell chokes with -bash: $'\r': command not found because native Windows opam.exe prints carriage returns (which MSYS2 eval can handle, but not Cygwin). I don't actually know a clean fix for that, and I suspect removing carriage returns when in MSYS2/Cygwin probably belongs in another PR.

@jonahbeckford jonahbeckford force-pushed the feature-win32-env-cygpath branch 2 times, most recently from dbe720f to 19a7daa Compare September 23, 2021 03:02
@jonahbeckford jonahbeckford marked this pull request as ready for review September 23, 2021 03:15
@jonahbeckford jonahbeckford force-pushed the feature-win32-env-cygpath branch from 19a7daa to f202567 Compare May 3, 2022 17:30
@jonahbeckford
Copy link
Contributor Author

Rebased.

@dra27 dra27 self-assigned this Jun 27, 2022
Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit uneasy about this one, to be honest - mostly, I think if you want to use a Cygwin or MSYS2 shell, then it's better to use a Cygwin or MSYS2 opam, but our cross-compilation and tooling story isn't good enough for me to insist on that yet!

A thought for the \r issue - I expect this can be fixed by detecting that stdout is not a tty (i.e. you're inside $(eval )) and detecting the parent as being a Cygwin-ish shell (it's in the same class of shim that the OCaml toplevel uses to display colour in mintty, etc.). That depends on your other PR and also on a further bit of work on top of that which I've done which gives the full path to the parent process, so perhaps it would be worth opening an issue to track that.

This can be merged once the "--" part is added, thanks!

Co-authored-by: David Allsopp <[email protected]>
Copy link
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge when CI finishes, thanks!

@kit-ty-kate
Copy link
Member

CI is green. Thanks!

@kit-ty-kate kit-ty-kate merged commit 6875b92 into ocaml:master Jul 23, 2022
@dra27 dra27 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants