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.
genmeblog 2019-02-22T08:32:05.002500Z

Hi. It's not a solution for a problem. But when you use Cygwin it's quite easy to adapt linux version of scripts.

genmeblog 2019-02-22T08:34:33.003200Z

install_dir=`realpath.exe --relative-to=. /usr/local/lib/clojure`

genmeblog 2019-02-22T08:39:27.004500Z

after installation find a line in /usr/local/bin/clojure which defines install_dir and change to the above one.

genmeblog 2019-02-22T09:12:47.005Z

oops, also line where config-path is set

genmeblog 2019-02-22T09:12:54.005400Z

config_dir="`realpath --relative-to=. $HOME`/.clojure"

genmeblog 2019-02-22T09:13:58.006600Z

maybe it's good to set them conditionally based on OSTYPE env variable?

alexmiller 2019-02-22T13:49:24.007100Z

I don’t think that’s enough to make everything work

genmeblog 2019-02-22T14:40:00.010500Z

The only issue is to have relative paths in the script to ensure that Java and Cygwin/bash see the same. I found only two places which are $HOME and install_dir. Of course you may be right since I didn't test every case.

alexmiller 2019-02-22T14:42:10.011Z

there are also paths inside deps.edn and paths to the various deps.edn

alexmiller 2019-02-22T14:43:03.011700Z

and ultimately we're making a classpath which is made of paths

alexmiller 2019-02-22T14:43:38.012500Z

I've looked at this and others have as well and my memory is that it fell apart, but I don't remember where exactly

genmeblog 2019-02-22T14:46:10.013700Z

I'm working through the guide from the clojure site and I'll let you know if something is wrong

genmeblog 2019-02-22T14:50:42.015200Z

if classpaths are created only by a make-classpath it should be ok, since bash script doesn't rely on it.

alexmiller 2019-02-22T14:56:54.015900Z

they are. tools.deps.alpha uses Java platform file and path separators so not sure if that's good or bad for cygwin

genmeblog 2019-02-22T15:25:33.018400Z

from what I see, bash script does not manipulate with files from classpath so it doesn't matter (separators etc.). The only point is when bash produces path for java it should be relative one. And when java produces any path for bash file operations it should be translated to cygwin one.

genmeblog 2019-02-22T15:25:50.018900Z

anyway, I checked almost all examples from the guide

genmeblog 2019-02-22T15:26:05.019300Z

the last one doesn't work, I'm getting following error

genmeblog 2019-02-22T15:26:32.019500Z

ubuntu@ml1:~$ vim deps.edn
ubuntu@ml1:~$ vim src/my_class.clj
ubuntu@ml1:~$ vim src/hello.clj
ubuntu@ml1:~$ clj -e "(compile 'hello)"
hello
ubuntu@ml1:~$ clj -m hello
Exception in thread "main" clojure.lang.ArityException: Wrong number of args (1) passed to: my-class/-hello
        at clojure.lang.AFn.throwArity(AFn.java:429)
        at clojure.lang.AFn.invoke(AFn.java:32)
        at my_class.MyClass.hello(Unknown Source)
        at hello$_main.invokeStatic(hello.clj:7)
        at hello$_main.doInvoke(hello.clj:5)

genmeblog 2019-02-22T15:26:56.020Z

the same under cygwin and under linux (ubuntu)

genmeblog 2019-02-22T15:29:09.020700Z

my deps.edn consists of single line {:paths ["src" "classes"]}

genmeblog 2019-02-22T15:29:51.021Z

so it's not cygwin related problem

alexmiller 2019-02-22T15:31:13.021300Z

if you add -Spath it will dump the classpath it's using

genmeblog 2019-02-22T15:32:07.021900Z

src:classes:/home/ubuntu/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar:/home/ubuntu/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/home/ubuntu/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar

genmeblog 2019-02-22T15:32:31.022500Z

classes are there (in both: ubuntu and cygwin)

alexmiller 2019-02-22T15:33:09.023200Z

the error implies that the hello class is being called with something after it as args, when it expects no args

genmeblog 2019-02-22T15:34:40.024Z

content is copied from the guide

genmeblog 2019-02-22T15:34:44.024200Z

ubuntu@ml1:~/cljt/src$ cat hello.clj
(ns hello
  (:require [my-class])
  (:import (my_class MyClass)))

(defn -main [& args]
  (let [inst (MyClass.)]
    (println (.hello inst))))

ubuntu@ml1:~/cljt/src$ cat my_class.clj
(ns my-class)

(gen-class
  :name my_class.MyClass
  :methods [[hello [] String]])

(defn -hello []
  "Hello, World!")

genmeblog 2019-02-22T15:35:02.024500Z

the code looks ok

alexmiller 2019-02-22T15:35:39.025100Z

it should basically be running java -cp src:classes:/home/ubuntu/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar:/home/ubuntu/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/home/ubuntu/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar clojure.main -m hello

genmeblog 2019-02-22T15:36:20.025300Z

the same exception

alexmiller 2019-02-22T15:37:48.025900Z

this seems like some mismatch in this code (which I'm not seeing), not a path error

alexmiller 2019-02-22T15:39:52.026200Z

I get the same

genmeblog 2019-02-22T15:40:15.026600Z

maybe something is wrong with class generation

alexmiller 2019-02-22T15:40:27.026900Z

yeah, I think there is some bug in the genclass

genmeblog 2019-02-22T15:41:12.027300Z

compilation produces bunch of internal classes for MyClass

genmeblog 2019-02-22T15:42:20.028Z

I don't know compilation process though

genmeblog 2019-02-22T15:43:22.029100Z

anyway, regardless this case, after aformentioned modifications cygwin version works with all provided examples

alexmiller 2019-02-22T15:46:45.029400Z

yeah, should be

(defn -hello [this]
  "Hello, World!")

alexmiller 2019-02-22T15:47:27.029900Z

while I don't think we want cygwin to be "the" way to do things, would be happy to make it work for people that want to go that path

alexmiller 2019-02-22T15:48:08.030500Z

would be happy to consider os-targeting changes to install script

alexmiller 2019-02-22T15:48:16.030800Z

patch welcome...

genmeblog 2019-02-22T15:48:48.031500Z

ah this, ok, now works 🙂

genmeblog 2019-02-22T15:49:31.032500Z

cygwin is always kind of workaround

alexmiller 2019-02-22T15:49:41.033200Z

fixed the example on the site, will redeploy later

genmeblog 2019-02-22T15:50:17.034Z

great

genmeblog 2019-02-22T15:51:08.034400Z

for patch, I assume I have to be contributor, right?

alexmiller 2019-02-22T15:58:13.034700Z

yes

alexmiller 2019-02-22T15:58:48.035300Z

if you're not up for that, even filing a jira ticket so someone else can do so would be great (don't need to be a contributor to file tickets)

genmeblog 2019-02-22T16:00:13.035700Z

I think I can do this.

alexmiller 2019-02-22T16:07:44.035900Z

cool

genmeblog 2019-02-22T17:32:06.036400Z

@alexmiller where can I find clj/clojure scripts?

genmeblog 2019-02-22T17:32:13.036700Z

I mean which github repo?

alexmiller 2019-02-22T17:33:09.036900Z

https://github.com/clojure/brew-install

genmeblog 2019-02-22T17:38:30.037300Z

thanks