This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-21
Channels
- # ai (1)
- # announcements (18)
- # aws (7)
- # babashka (54)
- # babashka-sci-dev (6)
- # beginners (22)
- # calva (57)
- # cider (3)
- # clj-http (1)
- # clojure (144)
- # clojure-austin (1)
- # clojure-dev (38)
- # clojure-europe (34)
- # clojure-gamedev (4)
- # clojure-norway (8)
- # clojure-uk (5)
- # clojurescript (12)
- # clr (20)
- # conjure (4)
- # data-science (1)
- # emacs (30)
- # events (1)
- # graphql (9)
- # helix (7)
- # hyperfiddle (22)
- # introduce-yourself (4)
- # jobs (1)
- # leiningen (7)
- # malli (3)
- # off-topic (26)
- # polylith (26)
- # portal (5)
- # random (14)
- # shadow-cljs (113)
- # tools-deps (6)
- # xtdb (9)
Is there a way to create a mock of java classes so that Babashka does not say Unable to resolve classname
when this class is not included in Babashka? 🧵
I’m trying to port a library to Babashka, but somewhere deep in the code java.util.concurrent.ConcurrentHashMap
is being used. This class is not available in Babahska so I tried something like
(ns java.util.concurrent)
(deftype ConcurrentHashMap [a])
But this doesn’t work it seemsThe other option would be to adapt the library to not use this class, but I feel that this would be more work than to create a mock version of this particular class.
FYI, I was trying to port https://github.com/polyfy/polylith which relies on https://github.com/clojure/tools.deps which uses https://github.com/clojure/tools.deps/blob/be30a1ae275eabfd1eba571080e039451c122c69/src/main/clojure/clojure/tools/deps/util/session.clj#L16
Maybe it is easier to override that particular ns instead
Ok still need this mocking idea I think, the next class that it doesn’t like is https://github.com/clojure/tools.deps/blob/be30a1ae275eabfd1eba571080e039451c122c69/src/main/clojure/clojure/tools/deps.clj#L21 Or I have to port tools.deps
itself of course 😅
iirc, the mocking thing wouldn't really work, because deftype doesn't create a class in bb (because of the limitations of graal with regards to reflection)
I've used the same mocking trick in bb. It doesn't really matter that it's not a real class since interop stuff should also work on "fake" classes
you should be able to use tools deps in bb using this https://github.com/babashka/tools-deps-native but it's very experimental so be warned.
ah cool, i’ll try that repo
it's also used in this (experimental!) project https://github.com/babashka/tools.bbuild
Ah great, I just tried it and it does get me to a new (unrelated!) error message of a missing class. Might be tricky to port polylith
org.eclipse.aether.util.version.GenericVersionScheme
I guess I could find a workaround here as well. Maybe for another day 🙂
Made some progress and have it (partially) working. Last hurdle is the missing resolve-symbol
from clojure.tools.reader
(https://github.com/polyfy/polylith/blob/1209a81e6b8f70987050d65d106e99d1a902969a/components/file/src/polylith/clj/core/file/core.clj#L6). I see Babashka https://github.com/babashka/babashka/blob/056254dc9da23e9088f171c53a6e0363b1215323/src/babashka/impl/clojure/tools/reader.clj#L56
We can add that, issue welcome, but you can probably fake it using intern
right now
I’ll try intern and create an issue. Thanks!
Added the issue here https://github.com/babashka/babashka/issues/1579
This wasn't what I meant. I meant:
(intern 'clojure.tools.reader 'resolve-symbol your-version-of-resolve-symbol)
ah I yeah I didn’t think it through properly. Not sure how to do a custom version I think
Something like this should work?
(intern 'clojure.tools.reader 'resolve-symbol (fn [sym] (eval sym)))
why not just copy the function from tools reader and use that? https://github.com/clojure/tools.reader/blob/bb5885b8417c493cf7fb3d7f9544c3565f16370e/src/main/clojure/clojure/tools/reader.clj#L649
in the var?
case I would substitute just calling symbol on the var directly:
user=> (symbol #'inc)
clojure.core/inc
resolve-symbol also contains resolve-ns which has other dependencies. Not sure if this is right. Since the parser should not load code from the polylith project itself
after https://github.com/polyfy/polylith/commit/e4d3f0e67bf1082d686b3049682b3f811cb1925a#diff-4bb26aa3114413f0d9ef22a944af3a5754db2b9e9e5f048492a04a77595d4379L122 without edamame and the use of resolve-symbol I get better results
(relies on read-string
)
hmmm ok not too familiar with all of this I guess
I have a private project where
bb --config ../../Github/polyfy/polylith/projects/poly-bb/bb.edn --debug -m polylith.clj.core.poly-cli.core info
works.
On the polylith project itself I still get an error. and note that these can return nil
indeed, when something can't be resolved, so maybe log an error to see what could not be resolved
I went for a nil
clause at var?
So with Edamame it works on the polylith project itself. Didn’t check if the output is the same with the normal polylith tool, but it looks like something
ah true 😅
that's what I was trying to say here https://clojurians.slack.com/archives/CLX41ASCS/p1687374672568619?thread_ts=1687355757.823539&cid=CLX41ASCS :)
Ok I guess too many things at once happening 😬
Thanks for your help as always 🙂
sure :) perhaps tools-deps-native could be replaced by shelling out using the babashka.tasks/clojure function or so, not sure.
ah doesn’t ring a bell yet, I’ll have a look tomorrow with fresh eyes
I didn’t try to replace tools-deps-native, but I did use it from the https://github.com/polyfy/polylith/commit/0cf1cb6ce1911dbe64b0c58d7460374590c258c4 For now pretty happy with the result