Fork me on GitHub
#babashka
<
2024-03-19
>
jjttjj14:03:02

Is there a reason the https://github.com/babashka/babashka/blob/655760d2a96a84f56a0e113933fe9a08d0e3883f/src/babashka/impl/clojure/core/server.clj#L156-L259 doesn't implement https://github.com/clojure/clojure/blob/92d86872d242d5176b0e616de91c339f79ff39cc/src/clj/clojure/core/server.clj#L298-L341? I've been idly wondering if I could do something like this: https://clojurians.slack.com/archives/CLX41ASCS/p1632220955376300 Except connecting to a remote prepl instead. In particular I'm wondering if I can use remote-prepl in babashka to connect to a remote "actual clojure" prepl, so that I could use little bb scripts to interact with a long running clojure process (I realize nrepl would probably work for this too)

borkdude14:03:21

You can probably copy paste that code somewhere and run it in bb, at first glance it seems fairly standalone

jjttjj14:03:47

Oh yeah, good point, thanks! Will try that later today and report back

jjttjj20:03:21

Seems to work nicely as is!

Fit Opene16:03:46

I have an executable script written in bb, and set it to a certain global shortcut key, it work fine. However, when I run bb inside it, bb seems not to run. test:

(shell {:out :write
        :out-file (io/file "/tmp/out.txt")}
       "which bb")
the output is: /usr/local/bin/bb
(shell {:out :write
        :out-file (io/file "/tmp/out.txt")}
       "bb --version") 
and /tmp/out.txt is empty What did I do wrong? Can bb run inside independent script?

borkdude16:03:53

Maybe the output goes to stderr? let me have a look

borkdude16:03:14

no it should work

borkdude16:03:22

let me try to repro

borkdude16:03:28

Hm yeah, this worked for me:

(require '[babashka.process :refer [shell]])
(require '[ :as io])

(shell {:out :write
        :out-file (io/file "/tmp/out.txt")}
       "bb --version")

(prn (slurp "/tmp/out.txt"))
Output: "babashka v1.3.190-SNAPSHOT\n"

borkdude16:03:34

What do you get for /usr/local/bin/bb --version ?

Fit Opene16:03:20

babashka v1.3.186

borkdude16:03:01

I don't see why it wouldn't work

Fit Opene16:03:42

I bind the script to a global shortcut, here is the shurtcut command: /home/.../bb_script

borkdude16:03:25

can you execute the above script as I wrote it, using bb /tmp/script.clj?

Fit Opene16:03:00

yes, that works fine

Fit Opene16:03:15

here is the whole script

#!/usr/bin/env bb
(require '[babashka.process :refer [shell]])
(require '[clojure.edn :as edn])


(def script-path "/home/scripts/")
(def config (edn/read-string (slurp (str script-path "src/bb/config.edn"))))

(shell "sleep 0.5")
(shell "xdotool key ctrl+c")
(shell "sleep 0.2")

(def text (-> (shell {:out :string} "xclip -o")
              :out))

(shell "sleep 0.1")
(def file (str (-> config :clip :path)
               (-> config :clip :default-file)))
(spit file text)

;; not work
(shell {:out :write
        :out-file (io/file "/tmp/out.txt")}
       "bb --version")  
It seems like the issue is related to how Ubuntu executes scripts, which is a bit beyond my knowledge area. I'm not quite clear about the differences between executing global scripts and command-line commands.

borkdude16:03:31

maybe add more logging to debug stuff?

Fit Opene17:03:36

as the global shortcut key is runs directly by ubuntu, I don't know where to check the logs. Maybe temporarily set aside this issue.

Fit Opene17:03:10

Thanks for taking the time to look into this. It's likely just a matter of my knowledge limitations.

borkdude17:03:18

you can log to a file

šŸ‘ 1
šŸ˜€ 1
Fit Opene18:03:24

change the shortcut command to /home/.../bb_script > /tmp/out.txt and magically works, outputting: babashka v1.3.186 .

m.q.warnock18:03:40

i'm setting up a new machine, and trying to be diligent about security; neither the output of sha256sum on babashka-1.3.189-linux-amd64-static.tar.gz or the bb inside it match the .sha256 file of the same base name I downloaded from the github releases. Am I missing something?

āœ… 1
borkdude18:03:58

I'm afk right now so I'll check up on this tomorrow

gratitude 2
Bob B19:03:48

these seem to match for me:

$ sha256sum babashka-1.3.189-linux-amd64-static.tar.gz
228e8ccee724ba8d66c66d8672161b991bb00b00e538e7aecd0b902330e5a712  babashka-1.3.189-linux-amd64-static.tar.gz

$ cat babashka-1.3.189-linux-amd64-static.tar.gz.sha256 
228e8ccee724ba8d66c66d8672161b991bb00b00e538e7aecd0b902330e5a712

gratitude-thank-you 1
m.q.warnock19:03:59

doh!

āžœ ī‚° ~/ļ€™  ī‚° sha224sum babashka-1.3.189-linux-amd64-static.tar.gz                            
f95ee73e63b363e280d6ecb49b6716f5986b25c6c11059b6d742290c  babashka-1.3.189-linux-amd64-static.tar.gz
                                                                            
āžœ ī‚° ~/ļ€™  ī‚° cat babashka-1.3.189-linux-amd64-static.tar.gz.sha256                           
228e8ccee724ba8d66c66d8672161b991bb00b00e538e7aecd0b902330e5a712āŽ  

m.q.warnock19:03:42

must have hit s-h-a-2-2-[tab]

Eugen21:03:52

I remember reading about custom babashka distributions, but I don't remember exaclty where it was described. I need some java libs (json schema validation mainly) to be included and probably build my own cli app from bb sources. I would like to build that for multiple OS / platforms - and reuse bb build scripts if possible. Not sure if this was all in the article I remember reading, but explained for context . (building a better docker swarm client - improved templating)

borkdude22:03:13

you could do that, but you could also just build your own GraalVM CLI without bb I guess. bb only adds value if your app needs to execute scripts

Eugen22:03:16

I guess it makes sense - until I need to execute scripts - and then I need bb šŸ™‚

Eugen22:03:24

I will give it a try

borkdude22:03:08

if startup isn't that important you could also just run it on the JVM of course, that would be the best way to iterate before you invest in all the graalvm native-image build stuff

borkdude22:03:26

but there's plenty examples around how to do that: bb, clj-kondo, jet, etc

Eugen22:03:30

I would like to distribute a single binary

Eugen22:03:41

without having to install a jvm

Eugen22:03:45

on multiple platforms

Eugen22:03:01

arm64 / amd64, Linux / Win and Mac

Eugen22:03:32

btw, how do you build and release for win and mac ?

Eugen22:03:54

I guess for Mac you are covered

borkdude22:03:37

Check the example projects I mentioned, it's all there

borkdude22:03:03

I use appveyor for windows and for mac x64 I use circleci, for mac aarch64 I use cirrus CI

Eugen22:03:47

found github actions in bb I got confused by circle ci dir

borkdude22:03:06

why so many different CIs? because those were the only ones that worked for those platforms at the time and I stuck with them. technically you could probably use Github Actions for most of them now, but I kinda dislike Github Actions in some ways, mostly their UI + performance

borkdude22:03:48

I don't use Github Actions for any of my binaries, but I have it as a backup solution

borkdude22:03:33

I believe that clojure-lsp does use Github Actions and their aarch64 linux build takes 1 hour because it runs in qemu facepalm