I'd like to announce python-pods https://github.com/judepayne/python-pods. This is a faithful port of babashka pods to python, so you can use any pod from python. Enjoy!
I'm trying to understand a change that seems to have happened with the release of Babashka 1.12.197.
I'm using Babashka in part via a very minimal rules_babashka module for Bazel that I've written so that we can run script tests etc through the same Bazel tooling we use for the rest of our code (and also build to run bb in AWS lambdas easily through Bazel): https://github.com/griffinbank/rules_babashka
Babashka up to 1.12.196 works fine. From 1.12.197 onwards, all my attempts to run bb uberjar are failing. From the stacktrace, it seems that it no longer likes the value of JAVA_HOME which, as with all things in Bazel, really wants to be a relative path.
The way Bazel actions work is to cd to a specific sandbox subdirectory, and have all symlinks and files set up by Bazel so that env vars, file links etc can all be relative to that base dir. But that only works as long as processes don't move away from that directory (or at least, if they do, are aware of running within Bazel and the relative path changes that must now be applied).
It looks like bb 1.12.196 and before treated a relative JAVA_HOME as being relative to the directory the command was executed from, which was 'correct' from the point of view of what Bazel expected and worked fine. bb 1.12.197 and above seem to treat it as relative from the directory of any target bb.edn provided via --config, which is completely breaking my tooling as Bazel puts that into a different path under the same root.
I'm trying to work out how to change my tooling to work around this, but I'd also like to understand how/why this change occurred, as I can't see any mention of it in the release notes for 1.12.197 or for the deps.clj submodule (which I would assume as the most likely source of the change in behaviour, and also seems to have been updated several times between 1.12.196 and 1.12.197).
Hmm. I will give it a go. The thing is in our case we're not baking in a java version from a specific toolchain reference, we're using Bazel functions from @bazel_tools to say "Find me whatever Java toolchain the user has configured and use that", so as I understand it we can't be sure of the name to hard code (e.g. tar_dev_env in your link).
Bazel's documentation is IMO shocking. It's very opinionated, but horrible about specifying those opinions or how you're supposed to work within them anywhere. Every time I have to touch it I spend hours trying to work out how Bazel wants me to do something when if I was just writing my own standalone shell script that didn't have to deal with Bazel I could have it done in minutes.
I had the same experience, which is a big part of why I haven't touched it for ~2 years 🙂
deps.clj would be the most likely place
if you can make a small repro without all the bazel details, to show the difference, it would probably be easy to find and fix for me
perhaps in a Docker container would be easiest
Should be pretty easy to repro. Give me a sec
(docker is optional)
could be related to this one: https://github.com/borkdude/deps.clj/commit/7067271120664c4de805191c2ff867bb3b382e28
I tried to repro with a relative path like:
$ JAVA_HOME=../../Users/borkdude/.sdkman/candidates/java/current /Users/borkdude/dev/babashka/bb -Sforce -Sdeps '{:deps {medley/medley {:mvn/version "1.0.0"}}}' -e "(require '[medley.core]) (prn :dude)"
:dude
but this worked on my machine...(while removing java from the PATH)
Hmm. I can remove java from my PATH and not set JAVA_HOME or any other JAVA_, JDK_ etc env vars, and bb seemingly still finds it. Claude thinks /usr/libexec/java_home might be the culprit, which is still correctly identifying it on Mac. Let me move it somewhere else.
The logic in deps.clj is JAVA_CMD, then java on the path, then JAVA_HOME
OK, hmm, where is java in the babashka/babashka docker container? I can't find it on the path nor with find / -name java, and yet bb uberjar foo.jar with a basic hello world namespace works, whereas if I try it somewhere that I know has no Java it fails saying couldn't locate java and please set JAVA_HOME
there's no java in the babashka/babashka container. probably easiest to start with a java container and then add bb to it via curl
e.g. FROM clojure:temurin-21-tools-deps or so
(any java container would do)
But if there's no java in the babashka container, why is bb uberjar not erroring like it does elsewhere and telling me it needs java?
it depends on your bb.edn I guess
if there are no deps, you don't need java
Aaah
I will try adding one
Hmm, I am also unable to replicate this externally, so it must be something to do with other properties I am changing elsewhere in bazel affecting the behaviour. I will clearly have to do some deeper digging.
Thank you for coming back to me so fast, and apologies for not getting a minimal example first!
No worries, hope you’ll find it!
If Babashka looks for java in PATH first, can't you tell Bazel to put java on the PATH with a tool dependency?
And work around JAVA_HOME altogether.
This order is dictated by how the clojure CLI works btw, I didn't make it up
deps.clj is a direct port of the clojure CLI bash script
@gaverhae You'd think, but I've never managed to make that work.
As far as I can tell, defining tools doesn't actually set their locations in the PATH env var or similar, it just makes them available from the sandbox root. It's still up to the application to work out how to find them, or be told where they are by bazel parameters being passed in
Indeed, but I seem to remember — I haven't touched a Bazel build in about two years, give or take — that we used to wrap some executables in a tiny Bash script that takes positional arguments and sets the PATH and other env vars using that.
Yeah, I have that for bb already, but it doesn't set JAVA_HOME or any of the java path stuff because I want to be able to set that dynamically based on whatever Java toolchain is being used at a given time
I made it work by turning ctx.actions.run into ctx.actions.run_shell and having the wrapper there export JAVA_HOME=$(pwd)/... before anything else
If you have a shell script somewhere already it should be possible to do something like
export PATH="$(rlocation jdk/bin/java):$PATH"
maybe? I'm working of very remote memories at this point. Here's an example of using rlocation, though not for setting PATH specifically: https://github.com/digital-asset/daml/blob/5ed01acd6086f3d77259b2b32684021c6f9cd2dc/sdk/bazel_tools/sh/mktar.sh#L29