babashka

Ryan 2025-09-24T13:34:03.165509Z

Hmm Iโ€™m having a bit of trouble with a bb script.. I manually remove the shadow-cljs build cache every time I build, and recently its been failing on that step because the directories arenโ€™t empty, even though Iโ€™m calling rm -rf. I think it might be OS related, but Iโ€™m not sure yet (mac os x) Any clues?

Ryan 2025-09-24T13:35:45.381779Z

util-clean-shadow-cache     {:task (shell (str "rm -rf ./.shadow-cljs/builds"))}
task definition in question

borkdude 2025-09-24T13:36:56.616159Z

@rdonahue You can use babashka.fs instead of you want to make it less OS-specific.

(babashka.fs/delete-tree ".shadow-cljs/builds")

Ryan 2025-09-24T13:37:29.323259Z

That sounds like a wonderful idea

Ryan 2025-09-24T13:39:32.040119Z

Ooh it definitely changed the error ๐Ÿ™‚

Type:     java.nio.file.DirectoryNotEmptyException
Message:  .shadow-cljs/builds/pnx/dev
Location: <expr>:26:1

borkdude 2025-09-24T13:42:54.932729Z

delete-tree should remove a directory recursively

borkdude 2025-09-24T13:43:06.774099Z

but perhaps there are files you don't have permission to delete?

Ryan 2025-09-24T13:43:46.651889Z

Maybe files that are in use by the shadow-cljs watch process?

Ryan 2025-09-24T13:43:52.968249Z

maybe my mac is trying to โ€œhelpโ€

borkdude 2025-09-24T13:44:13.803499Z

it could also be that files are being recreating during delete

borkdude 2025-09-24T13:44:28.312259Z

or something with symlinks

borkdude 2025-09-24T13:45:11.821689Z

you could try one more thing.

Deletes a file tree using walk-file-tree. Similar to rm -rf. Does not follow symlinks. force ensures read-only directories/files are deleted. Similar to chmod -R +wx + rm -rf

borkdude 2025-09-24T13:45:26.289819Z

(fs/delete-tree "...." {:force true})

borkdude 2025-09-24T13:45:36.879739Z

this will take care of file permissions being set right so you can delete

Ryan 2025-09-24T13:46:02.465409Z

I do love applying force to deletes

Ryan 2025-09-24T13:46:13.844929Z

its only bitten me.. like 3% of the time ๐Ÿ˜‰

Ryan 2025-09-24T13:49:14.281149Z

Ok, combining force with being more specific in the delete (.shadow-cljs/builds/{app}/release) seems to be doing the trick

Ryan 2025-09-24T13:49:53.760029Z

Thanks for the suggestions and you know, babashka, which is lovely.

borkdude 2025-09-24T13:51:42.515369Z

thanks :)

gaverhae 2025-09-26T08:28:29.090199Z

> Maybe files that are in use by the shadow-cljs watch process? On Unix systems files can be deleted while in use, and they are removed from the directory tree immediately, so that shouldn't be the issue. (They are kept as "detached" inodes in the file descriptors table, and the actual drive space is not freed, until they are properly closed.) As Michiel said, it's either files you didn't have permission to remove (but then you should have error messages about that somewhere), or files that are being created while you delete - rm -rf still has to walk down the tree one file at a time, so it is possible, if you have another concurrent process using that directory, that it "misses" the new files, and then when it moves back up to the directory level, the directory is not empty even though it's deleted all the files it knew about when it started.

socksy 2025-09-24T20:22:29.287359Z

if I run the static babashka linux build, it complains about the lack of java. In particular:

Exception in thread "main" java.lang.Exception: Couldn't find 'java'. Please set JAVA_HOME.
	at borkdude.deps$get_java_cmd.invokeStatic(deps.clj:283)
Is this expected behaviour? I find it surprising that I would need java (or indeed, any dependency) for a statically compiled binary

socksy 2025-09-24T20:46:14.935929Z

ah, I guess it's because I have a :deps in my bb.edn, so it's expected. Shame we can't package java directly in the bin ๐Ÿ™ƒ

borkdude 2025-09-24T20:46:17.945019Z

It only does this for fetching dependencies via tools.deps if you have any specified in bb.edn

borkdude 2025-09-24T20:48:28.788599Z

technically there is a way to do this without java. https://github.com/babashka/pod-registry/blob/master/examples/tools-deps-native.clj

socksy 2025-09-24T20:54:43.349649Z

hmm sorry for the noob question but does bb.edn have something similar to the deps.edn approach for having deps per alias? The singular dep I have here is only for a task I use in development, and I'm using the static binary for running in "prod" (ahem, a lima vm atm)

borkdude 2025-09-24T21:02:02.824249Z

you can have :extra-deps per task

socksy 2025-09-24T21:32:04.636749Z

thank you! I got it working! :D

๐Ÿ‘ 1
socksy 2025-09-24T22:21:23.207009Z

(what I was working on: https://github.com/socksy/bb-tower-deploy/)

borkdude 2025-09-25T08:24:00.860559Z

cool! just a small side-note: > which is a graalvm image so presumably has the entire JVM inside of it this isn't true, the smallest GraalVM image is only 5mb or so. The virtual machine that goes along with it is called Substrate VM - not a full JVM. But it is true that the bb binary isn't small, this is mostly due to the included libraries and Java classes. it's around 70-80mb in most cases. zipped 20mb or so.