-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Fix pwsh compatibility bug #3590
Conversation
The command line needs a different formatting for pwsh compared to powershell
Looks good to me - great work! If you have it easy, please make the failing CI pass. Othewise we can cherry-pick + amend your commit. @ikappaki review also welcome. Thanks - V |
Not really sure how to |
Yes, commit and push |
;; please add more PowerShell quoting rules as necessary. | ||
(format "'%s'" (replace-regexp-in-string "\"" "\"\"" argument)) | ||
(shell-quote-argument argument))) | ||
(cond ((cider--jack-in-cmd-pwsh-p command) (format "'%s'" argument)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to add some comment explaining the need for the different escaping rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its important to clarify that this for me, is workaround for a bug that is either in the clojure cli tool or in powershell
clojure cli should behave the same on both shells, since as per powerhsell docs the quoting rules are the same
I created a question on ask clojure , suggesting that this is a bug in the clojure command line tool, since i cannot replicate this behavior with any other command
Are you ok with documenting this as a workaround, or do your prefer another solution, i think the calva vs code plugin in windows skips the cli tool and use the java command directly , so they dont seem to have this issue
they seem to run this command
; Starting Jack-in Terminal: pushd c:\dev\lang\clojure\project\ukg & java -jar ".calva\deps.clj.jar" -Sdeps "{:deps {nrepl/nrepl {:mvn/version,""1.0.0""},cider/cider-nrepl {:mvn/version,""0.28.5""}}}" -M -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]" & popd
for me the calva solution, seem a bit heavy handed, as the plugin on vs code, download his own cli jar files and i dont know what else, i like that cider doesnt install java jars and use the system cli tools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documenting this as a workaround is fine - e.g. I just learned what this is about and I imagine others reading the codebase will be in the same boat as me. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I thought powershell
and pwsh
were exactly the same thing)
Don't forget to add a changelog entry about this bugfix. |
Hi all I wanted to add some analysis on why we're seeing a different behavior with Here I'm using the GNU coreutils echo command to demonstrate the change in behaviour: powershell.exe treats # powershell
> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.22621.2428
PS> C:\local\msys64\usr\bin\echo.exe -Sdeps '{:deps {nrepl/nrepl {:mvn/version ""1.0.0""}}}'
-Sdeps {:deps {nrepl/nrepl {:mvn/version "1.0.0"}}} # pwsh
> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.0
PS > C:\local\msys64\usr\bin\echo.exe -Sdeps '{:deps {nrepl/nrepl {:mvn/version ""1.0.0""}}}'
-Sdeps {:deps {nrepl/nrepl {:mvn/version ""1.0.0""}}} @shishini's hack is good. There is also a one liner hack that forces pwsh.exe to the old behavior with Line 813 in 0134a0b
(defun cider--powershell-encode-command (cmd-params)
"Base64 encode the powershell command and jack-in CMD-PARAMS for clojure-cli."
(let* ((quoted-params cmd-params)
(command (format "$PSNativeCommandArgumentPassing = 'Legacy'; clojure %s" quoted-params))
(utf-16le-command (encode-coding-string command 'utf-16le)))
(format "-encodedCommand %s" (base64-encode-string utf-16le-command t)))) I've tested this to work with both powershell.exe and pwsh.exe. Perhaps this is a slightly better solution because we won't have to maintain two branches of logic for each powershell executable? Irrespective of the solution, i've stumbled upon a problem with
This is due to orchard having hardcoded Thus, if we only have a Thanks |
Thanks for another amazing analysis, @ikappaki 👏 Sounds like we should improve Orchard. This code looks overly complicated to me... Perhaps there's some pure-JVM approach we could use instead? Else we could try/catch and fallback to some other choice. But I wouldn't be keen on dynamically choosing one of |
Hi @ikappaki Well I could only temporarily hide powershell.exe from my path by modifying the $env:path variable Anyway, when I did i got this error, in my message buffer
And this line was one of the line in clojure-7741569257158880857.edn
So in short my patch doesnt fix this other issue, i think the orchard module should use |
It seems as if Out of curiosity, why are you opting for Thanks |
@ikappaki in retrospect, i probably should just have used powershell but my luck kinda, i installed clojure cli in pwsh, (in a folder only accessed by pwsh , only in pwsh module path) again in retrospect, i should have thought of this as bash vs sh situation, where they can coexist and some scripts might only be compatible wish sh and not bash but i just kinda thought pwsh should work its what i use |
This is a very good reason why we should support pwsh. It would also be nice if we can update the documentation at the below link with the above info? cider/doc/modules/ROOT/pages/basics/up_and_running.adoc Lines 211 to 215 in 0134a0b
To summarise
(I think we can also add an integration test with pwsh in CI... I can look into this once this is checked in) thanks |
I think I would prefer this approach - the code would have no branches. Do you agree @ikappaki ? |
Hi @vemv, I'd prefer the one line edit, but I don't want to deter @shishini in their first check in :) |
I see! I'd suggest @ikappaki , please create a PR with the fix, making sure it works as intended (if you have it at hand). Feel free to add |
The command line needs a different formatting for pwsh compared to powershell
More details can be found in this bug reports #3588
In summary, initializing a repl works when installing clojure-cli to Powershell 5.1 (Windows Powershell) but was failing when clojure-cli was installed in pwsh (when (setq cider-clojure-cli-command "pwsh") )