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

'opam env' for directories with spaces #5205

Merged
merged 7 commits into from
Jul 29, 2022

Conversation

jonahbeckford
Copy link
Contributor

@jonahbeckford jonahbeckford commented Jul 26, 2022

  • Please update master_changes.md file with your changes.

Fixes #5204 .

It was not just a Windows problem, although only macOS of the *nix variants commonly uses spaces in their directory names.

Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

LGTM

@jonahbeckford
Copy link
Contributor Author

Err... DOS Command Prompt needs double-quotes. Sending a commit once I've built locally and tested it again.

src/state/opamEnv.ml Outdated Show resolved Hide resolved
@jonahbeckford
Copy link
Contributor Author

All fixed.

@dra27
Copy link
Member

dra27 commented Jul 27, 2022

Would it be OK - as with the set commands etc in opam env to do this only when it's necessary? i.e. to display --switch=foo rather than --switch='foo').

More importantly, I'd like to double-check the handling if Windows opam is called by another executable for --switch="foo" ... on the Unix shell that gets passed as the string --switch=foo in argv, but on Windows it's actually two parameters... I've got a feeling that's cmd-specific and I can't remember what cmdliner does if it actually receives the literal string --switch="foo" (the solution otherwise is to advice "--switch=foo")

@dbuenzli
Copy link
Contributor

on the Unix shell that gets passed as the string --switch=foo in argv,

But that must be your shell removing the quotes.

I can't remember what cmdliner does if it actually receives the literal string --switch="foo" (the solution otherwise is to advice "--switch=foo")

That depends on your argument converter. But if you use Arg.string you get "foo" of course. Everything after the = is the option's argument.

@rjbou
Copy link
Collaborator

rjbou commented Jul 27, 2022

updated with a test

@jonahbeckford
Copy link
Contributor Author

jonahbeckford commented Jul 27, 2022

The latest commit:

  1. Places the quotes around the entire argument. The examples I tested are:
  • for /f "tokens=*" %i in ('opam env "--switch=C:\Person 1"') do @%i in Command Prompt
  • eval $(opam env '--switch=C:\Person 1') in Bash
  • (& opam env "--switch=C:\Person 1") -split '\r?\n' | ForEach-Object { Invoke-Expression $_ } in PowerShell
  1. Uses quotes only when quotes are needed. An example is eval $(opam env --switch=default) in the GitHub PR CI: https://github.com/ocaml/opam/runs/7545056295?check_suite_focus=true#step:8:100

tests/reftests/env.test Outdated Show resolved Hide resolved
-> installed nv.1
Done.
# Run eval $(opam env --root='${BASEDIR}/root 2' --switch='${BASEDIR}/switch w spaces') to update the current shell environment
### opam env --sw "./$SW" | grep OPAM_SWITCH_PREFIX | ';' -> ':'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
### opam env --sw "./$SW" | grep OPAM_SWITCH_PREFIX | ';' -> ':'
### opam env --sw "./$SW" | grep OPAM_SWITCH_PREFIX | ';' -> ':' | '\\_opam\'' -> '/_opam\''

Copy link
Collaborator

@rjbou rjbou Jul 28, 2022

Choose a reason for hiding this comment

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

This should be handled by test engine, see

### opam env | grep "NV_VARS" | ';' -> ':'
NV_VARS='${BASEDIR}/OPAM/setenv/doc/nv:${BASEDIR}/OPAM/setenv/share/nv': export NV_VARS:

It passes windows ci too

Copy link
Collaborator

Choose a reason for hiding this comment

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

Anyway, this last test is not required for this PR (no extra escaping done in it)

Copy link
Member

Choose a reason for hiding this comment

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

ah, then I don’t know how to fix this properly

@kit-ty-kate
Copy link
Member

Thanks a lot!

@kit-ty-kate kit-ty-kate merged commit 4cfc265 into ocaml:master Jul 29, 2022
Leonidas-from-XIV pushed a commit to Leonidas-from-XIV/opam that referenced this pull request Mar 10, 2023
@rjbou rjbou added this to the 2.2.0~alpha milestone Sep 19, 2023
@rjbou rjbou added this to Done in Opam 2.2.0 Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Opam 2.2.0
  
Done
Development

Successfully merging this pull request may close these issues.

opam env --switch=SWITCHDIR is not quoted in PowerShell
5 participants