clj-on-windows

For those interested in making clj on Windows https://dev.clojure.org/jira/browse/TDEPS-67. Also see https://github.com/littleli/scoop-clojure.
lread 2019-06-15T17:49:34.058700Z

Added examples from our discussion on quote escaping to https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows

carkh 2019-06-15T18:09:37.059500Z

selecting powershell as a platform for the clj command line is strange, so many problems because of this.

borkdude 2019-06-15T18:15:20.060100Z

what about making a small GraalVM binary that is the replacement of the bash script

borkdude 2019-06-15T18:16:55.060500Z

same code for all platforms, with fast startup time

lread 2019-06-15T18:26:07.061500Z

hmmm… that sounds interesting @borkdude!

lread 2019-06-15T18:27:36.062900Z

@carkh I think that windows is a bit of a foreign beast to most clojure users? What do people normally do?

lread 2019-06-15T18:28:17.063700Z

Also I have enjoyed installing things via scoop. Would that work for clojure?

borkdude 2019-06-15T18:28:52.064200Z

leiningen uses a .bat script, which works fine from everywhere, if you place it on the path

lread 2019-06-15T18:29:29.064700Z

I guess that even works for Git Bash?

borkdude 2019-06-15T18:29:37.064900Z

it does

borkdude 2019-06-15T18:30:09.065700Z

Powershell also works, but I don’t understand the intricacies of it, like what it means to be a “command” instead of a script

lread 2019-06-15T18:30:49.067Z

Maybe GraalVM is overkill then?

borkdude 2019-06-15T18:30:52.067200Z

and the escape-hell when you call it from non-powershell

lread 2019-06-15T18:31:04.068100Z

yeah, it is not a nice experience.

borkdude 2019-06-15T18:31:21.069Z

I think one reason for Powershell was that writing .bat scripts is not fun. But with GraalVM you just get to write Clojure

lread 2019-06-15T18:32:00.070500Z

Yeah I am waist deep in bash scripts right now. Not the worst thing, but not fun either.

lread 2019-06-15T18:33:49.074200Z

Anyway, nice to have a starting point from which to get feedback and improve things.

ajoberstar 2019-06-15T18:35:15.076Z

IMO, a lot of the PowerShell issues are overblown. If you're in Git Bash feels like the bash script should get used instead. PowerShell has the momentum on Windows, so cmd isn't super compelling from my side. Also many of the quoting issues are tied to two things. A lack of "embrace the host" by trying to use more Posix style arguments (granted that's for consistency between Linux/Windows) that PowerShell doesn't handle as well. And that we call tools.deps inside the scripts which prints out arguments it expects you to put back on the cmd line when calling clojure. Those args work fine for bash, but require some translation for PowerShell.

ajoberstar 2019-06-15T18:36:35.077800Z

If I ever have time I'd like to make a more native PowerShell feeling version of this, which wouldn't be fit for merging back in as it would drop consistency with Linux clj arguments.

lread 2019-06-15T18:39:45.079200Z

I installed leiningen via scoop. It seems to support the 3 major shells:

PS C:\Users\lee> ls .\scoop\shims\lein*

    Directory: C:\Users\lee\scoop\shims

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         6/4/2019   6:48 PM            104 lein
-a----         6/4/2019   6:48 PM             59 lein.cmd
-a----         6/4/2019   6:48 PM            270 lein.ps1

PS C:\Users\lee>

lread 2019-06-15T18:40:09.079800Z

Isn’t that a more friendly approach?

borkdude 2019-06-15T18:40:18.080Z

are those scripts generated by lein or scoop?

lread 2019-06-15T18:40:40.080500Z

hmmm… I do not know!

lread 2019-06-15T18:43:31.081200Z

Let’s look at something you might be more familiar with:

PS C:\Users\lee> ls .\scoop\shims\clj-kondo*

    Directory: C:\Users\lee\scoop\shims

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         6/4/2019   4:29 PM           7680 clj-kondo.exe
-a----        6/15/2019   2:41 PM            275 clj-kondo.ps1
-a----        6/15/2019   2:41 PM             67 clj-kondo.shim

PS C:\Users\lee>

borkdude 2019-06-15T18:43:53.081700Z

I certainly did not write the .ps1 script

lread 2019-06-15T18:44:29.082400Z

well scoop is doing a good deed then

lread 2019-06-15T18:47:00.083100Z

hmmm… I not sure that scoop installed clj-kondo works from Git Bash.

lee@LEEREAD594C MINGW64 ~
$ clj-kondo

lee@LEEREAD594C MINGW64 ~
$

borkdude 2019-06-15T18:47:32.083300Z

maybe do which clj-kondo

lread 2019-06-15T18:48:56.083600Z

$ which clj-kondo
/c/Users/lee/scoop/shims/clj-kondo

borkdude 2019-06-15T18:49:43.084100Z

and it does work from PS, cmd and WSL?

lread 2019-06-15T18:50:26.084700Z

Yes to cmd and PowerShell. Have not tried WSL at all yet.

lread 2019-06-15T18:52:39.086100Z

If we look at lein shim:

#!/bin/sh
MSYS2_ARG_CONV_EXCL=/C cmd.exe /C "C:\Users\lee\scoop\apps\leiningen\current\lein.bat"  "$@"
We see specific support for Git Bash (or Git Bash-like) shell.

borkdude 2019-06-15T18:54:52.086500Z

I don’t see anything specific here: https://github.com/ScoopInstaller/Main/blob/master/bucket/leiningen.json but maybe it does that because it’s a .bat script automatically

lread 2019-06-15T19:06:07.087300Z

Looks like scoop generates it but not for exes for some reason: https://github.com/lukesampson/scoop/blob/6a39221036f3d52562d21c907a98b41fa748140e/lib/core.ps1#L393

carkh 2019-06-15T19:13:26.087500Z

I disagree with your premise that powershell has the momentum

carkh 2019-06-15T19:13:42.087700Z

the quoting issues are indeed the main issue

carkh 2019-06-15T19:14:27.087900Z

also we have trouble with tools trying to call into clj without hitting powershell at all

carkh 2019-06-15T19:14:45.088100Z

so no powershell, no clj command

carkh 2019-06-15T19:16:05.088300Z

in the end, we'll still need to have a bat or exe file to call into it

carkh 2019-06-15T19:16:39.088500Z

so what was the gain in having the thing implemented in powershell ?

ajoberstar 2019-06-15T19:17:09.088700Z

It's a much better language than batch.

carkh 2019-06-15T19:17:23.088900Z

great, but now we have problems

carkh 2019-06-15T19:17:43.089100Z

my guess is that the real reason is the services provided by powerhsell

carkh 2019-06-15T19:17:53.089300Z

downloading, verifying

carkh 2019-06-15T19:18:05.089500Z

(didn't look very hard at the source)

carkh 2019-06-15T19:19:10.089700Z

but if this comes at that, fire up a c compiler or whatever language, anything .net is good too, and what we need from powershell is all included in .net

carkh 2019-06-15T19:19:20.089900Z

and .net is available on every windows computer

carkh 2019-06-15T19:19:27.090100Z

and it works from cmd

carkh 2019-06-15T19:19:38.090300Z

i mean a .net exe works from cmd

carkh 2019-06-15T19:20:37.090500Z

powershell was a bizarre choice

carkh 2019-06-15T19:25:29.092Z

the solution to quoting issues is to generate a ps1 file, that way you deal with only 2 escaping syntaxes instead of the 3 (java, poweshell and your shell)

carkh 2019-06-15T19:26:38.092700Z

i have this very brittle batch file that at least let tools call into clj

carkh 2019-06-15T19:31:01.093200Z

carkh 2019-06-15T19:31:54.094300Z

it is brittle because it's not using a temp file (there is no good facility in cmd for that) for the launch.ps1 script

carkh 2019-06-15T19:32:24.094900Z

also the quote escaping was only worked on until it was "working for me", not many tests were made

carkh 2019-06-15T19:33:03.095300Z

i have the same code for clj.cmd and clojure.cmd

carkh 2019-06-15T19:35:22.096Z

@borkdude i like your idea about making a graalvm executable