Fork me on GitHub
#babashka
<
2022-03-30
>
borkdude12:03:40

A neat babashka script to give an overview of column width in your project: https://twitter.com/ghoseb/status/1509129173683834884

🆒 4
borkdude15:03:02

Tomorrow is the last day to complete the babashka survey! Please take it if you're using bb! https://docs.google.com/forms/d/e/1FAIpQLScQ13ZKsXzN594uvzxOTV8juaoETIHDk-T1XBizwe-fVh8Gyw/viewform

tatut15:03:03

I tried to see if clj-chrome-devtools would run with babashka, got

clojure.lang.ExceptionInfo: Could not resolve symbol: monitor-enter
{:type :sci/error, :line nil, :column nil, :file "clojure/spec/gen/alpha.clj", :phase "analysis"} 

borkdude15:03:38

oooh... monitor-enter that's a pretty low level thing.

tatut15:03:48

but I didn't try to upgrade, the project is using some old libraries anyway... this is coming as a transitive dep

borkdude15:03:48

but why does a chrome devtools tool use spec gen alpha at runtime... that seems to be mostly for testing

tatut15:03:21

it doesn't but something else requires it

tatut15:03:07

but as monitors are so low level, I guess graalvm stuff should support it

borkdude15:03:15

you can see this with (binding [clojure.core/*loading-verbosely* true] (require '[...]) (in clojure)

borkdude15:03:36

yes, it is supported by graalvm compilation, just not as a special form in interpreted SCI code right now

tatut15:03:41

hmm, doesn't say anything about spec related things

borkdude15:03:02

I'm in the middle of something clj-kondo right now, but I can check later today

tatut15:03:44

no worries

borkdude19:03:38

ok let's take a look

borkdude19:03:37

So how I'm testing this: I checked out the project. Then ran:

$ lein classpath > .classpath

borkdude19:03:53

and then I ran:

$ bb --classpath $(cat .classpath) -e "(require '[clj-chrome-devtools.core])"

borkdude19:03:05

Which resulted in:

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: org.eclipse.jetty.websocket.client.ClientUpgradeRequest
Location: gniazdo/core.clj:2:3

----- Context ------------------------------------------------------------------
1: (ns gniazdo.core
2:   (:import java.net.URI
     ^--- Unable to resolve classname: org.eclipse.jetty.websocket.client.ClientUpgradeRequest
3:            java.nio.ByteBuffer
4:            java.util.List
5:            (org.eclipse.jetty.websocket.client ClientUpgradeRequest
6:                                                WebSocketClient)
7:            (org.eclipse.jetty.util.ssl SslContextFactory)

borkdude19:03:33

You could try to replace org.eclipse.jetty.websocket client by the java.net.http stuff.

borkdude19:03:38

which is supported by bb

borkdude19:03:36

Also this library works with bb, if you want to include a dep: https://github.com/schmee/java-http-clj#websockets

tatut04:03:17

thanks, I'll try that

tatut16:03:11

got rid of the jetty in favor of java http, that's a good idea in any case to shed some dependencies

tatut16:03:03

❯ bb --classpath $(cat .classpath) -e "(require '[clj-chrome-devtools.core])"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Protocol not found: java.lang.AutoCloseable
does bb defrecord have some limitations wrt java interfaces?

borkdude16:03:04

yes unfortunately, only protocols are supported at the moment

tatut16:03:48

is there a bb specific reader conditional that could be used to omit that? It would be best if the same code worked in jvm clojure and bb

borkdude16:03:08

:bb - must come before :clj , else :clj wins

tatut16:03:27

thanks, I'll try that

tatut16:03:13

that fixed the core namespace require

tatut16:03:35

another ns still has problems

bb --classpath $(cat .classpath) -e "(require '[clj-chrome-devtools.automation.launcher])"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Unable to resolve classname: clojure.lang.Var
Phase:    analysis
will investigate

borkdude16:03:13

Dinner time, will be back

tatut16:03:57

it is again the require of clojure.spec.alpha ns

tatut16:03:01

got over the spec stuff... next up is core.async... as go is not supported I think I'll need some bigger changes

tatut16:03:04

the go blocks in use are very simple, maybe I could just rip out core.async as well and use java.util.concurrent stuff instead

borkdude18:03:09

well go is supported, but it just maps to <!! behind the scenes a sort of polyfill

borkdude18:03:39

you shouldn't really get an error with those, if you're not using millions of go blocks

tatut04:04:14

for some reason I was

Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: clj-chrome-devtools.events/go
Phase:    analysis

tatut04:04:11

but I already started with replacing core.async use, it will actually be simpler to use promises and an executor service for listeners

Alex Miller (Clojure team)17:03:05

I'm pretty sure that I'm an idiot but I can't figure out what is going wrong here (using Java 8, but does not seem to matter)

% bb 

1.9.0 src:/Users/alex.miller/.m2/repository/org/clojure/clojure/1.9.0/clojure-1.9.0.jar:/Users/alex.miller/.m2/repository/org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar:/Users/alex.miller/.m2/repository/org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar

clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;


1.8.0 src:/Users/alex.miller/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar

1
borkdude17:03:54

@U064X3EF3 I've tried your script, but had to delete some weird whitespace symbols, after that it worked for me...

borkdude17:03:42

1.9:

clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;
1.8:
clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;

cldwalker17:03:36

Hey. On 0.7.8 bb, I also get a blank. Looks like the last process call is failing. Change that last go line to (println (:err @(process ["serialver" "-classpath" cp c] {:err :string}))) to see Class clojure.lang.Symbol not found.

Alex Miller (Clojure team)17:03:10

and then the question is ... why?

borkdude17:03:47

Which OS are you on?

Gunnar17:03:03

0.7.6 Linux here. Prints the src: output for both 1.9.0 and 1.8.0 but no serialVersionUID after 1.8.0

borkdude17:03:47

bb version?

borkdude17:03:32

Can you try this?

(require '[babashka.process :refer [process
                                    check]])

(defn go
  [clj-ver]
  (let [c "clojure.lang.Symbol"
        cp (:out (check (process
                         ["clj" "-Spath" "-Sdeps"
                          (format "{:deps {org.clojure/clojure {:mvn/version \"%s\"}}}" clj-ver)]
                         {:out :string})))]
    (println)
    (println clj-ver cp)
    (println (:out @(process ["serialver" "-classpath" cp c] {:out :string})))))

(go "1.9.0") ;; works as expected
(go "1.8.0") ;; no output, not sure why

borkdude17:03:50

As I said, I had to remove a couple of weird whitespace symbols, perhaps it was that?

Alex Miller (Clojure team)17:03:31

does not seem like it, same original output for me

cldwalker17:03:49

@U04V15CAJ I was only able to repro in a fresh directory. When I ran it in an existing clj project, I got your results. I'm also 0.7.8 osx

borkdude17:03:35

Also try:

(println (:out (check (process ["serialver" "-classpath" cp c] {:out :string}))))
for 1.8, then you will see the error output at least. Not sure why this happens yet

borkdude17:03:50

Maybe it's the trailing newline in the classpath

borkdude17:03:18

Yeah, that was it

borkdude17:03:36

(require '[babashka.process :refer [process
                                    check]]
         '[clojure.string :as str])

(defn go
  [clj-ver]
  (let [c "clojure.lang.Symbol"
        cp (str/trim (:out (check (process
                                  ["clj" "-Spath" "-Sdeps"
                                   (format "{:deps {org.clojure/clojure {:mvn/version \"%s\"}}}" clj-ver)]
                                  {:out :string}))))]
    (println)
    (println clj-ver cp)
    (println (:out (check (process ["serialver" "-classpath" cp c] {:out :string}))))))

(go "1.9.0") ;; works as expected
(go "1.8.0") ;; no output, not sure why

borkdude17:03:41

^ that should work

Alex Miller (Clojure team)17:03:30

but why is it different between 1.8 and 1.9?

1
borkdude17:03:03

I'm getting:

clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;
clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;

Alex Miller (Clojure team)17:03:08

maybe that's a Clojure CLI question, no idea

Alex Miller (Clojure team)17:03:30

yeah, works now for me so that was it, just unclear why it's different

borkdude17:03:17

I'm getting the same one?

$ bb -e '(= "1191039485148212259L" "1191039485148212259L")'
true

borkdude17:03:42

oh you mean the newline

Alex Miller (Clojure team)17:03:46

don't care about the particular answer here at all, this is subset of much larger script

Alex Miller (Clojure team)17:03:30

for me, this failed for all clojure versions through 1.8, worked on 1.9-1.11

Alex Miller (Clojure team)17:03:50

I guess that's the spec switchover so more jars so maybe classpath construction is different

borkdude17:03:52

I suspect having more deps than only clojure (like clojure.spec) accidentally fixed it

Alex Miller (Clojure team)17:03:57

probably something in tools.deps

borkdude17:03:09

Let's print the classpath as seen from the clojure process

borkdude17:03:44

Hmm, I don't see anything strange there, so yes, this could be a CLI issue

borkdude17:03:31

Or rather, a serialver issue

Alex Miller (Clojure team)17:03:33

same version of serialver

borkdude17:03:04

I mean, when you feed serialver a classpath with a newline, maybe it behaves sometimes correct, sometimes not

borkdude17:03:13

The error clojure.lang.Symbol not found was coming from serialver

borkdude18:03:06

$ serialver -classpath "src:/Users/borkdude/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar" clojure.lang.Symbol
clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;

borkdude18:03:12

$ serialver -classpath "src:/Users/borkdude/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar\n" clojure.lang.Symbol
Class clojure.lang.Symbol not found.

Alex Miller (Clojure team)18:03:44

Another question - can I make serialver a bg process ?

Alex Miller (Clojure team)18:03:11

Right now it foregrounds and steals focus

borkdude18:03:24

Putting something before newline fixes it:

$ serialver -classpath "src:/Users/borkdude/.m2/repository/org/clojure/clojure/1.8.0/clojure-1.8.0.jar:\n" clojure.lang.Symbol
clojure.lang.Symbol:    private static final long serialVersionUID = 1191039485148212259L;
So I guess it was that. Yes, just don't dereference the process and it runs in the background.

borkdude18:03:22

What do you mean with steals focus?

Alex Miller (Clojure team)18:03:12

I mean, I see a serialver task show up in the task manager and it gets focus, then the process dies and it goes away, for every call (I'm running this in a nested loop over every clojure release and class)

Alex Miller (Clojure team)18:03:40

don't I need to deref to get the string output? or should I slurp the stream

borkdude18:03:00

That's weird :) I'm not sure why this happens, why is serialver a GUI program?

borkdude18:03:20

I'm not seeing that

borkdude18:03:53

$ java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)

Alex Miller (Clojure team)18:03:53

ah, does it on 1.8, but not on newer

Alex Miller (Clojure team)18:03:01

I switched as I was debugging

wilkerlucio18:03:41

hello, does someone have an example of how to setup babashka on Gitlab?

1
borkdude18:03:56

Maybe it could be as simple as:

bash <(curl ) 

dakra20:03:55

It is. E.g. this is the build step in one of my .gitlab-ci.yml configs that builds a webapp with shadow-cljs and then runs a bb script that reads the manifest.edn output from shadow and points the index.html to the correct js file:

build:webapp:
  stage: build:webapp
  image: clojure:latest
  tags:
    - docker-runner
  artifacts:
    paths:
      - public/
  script:
    - apt-get update && apt-get -y install nodejs npm curl unzip
    - npm install
    - npx shadow-cljs release app
    - bash < <(curl -s )
    - bb update-index.clj

👍 1
🙏 1