Fork me on GitHub
#babashka
<
2023-08-22
>
Matthew Downey01:08:40

Curious if anyone has a Makefile shim laying around that sneakily installs babashka and forwards other make invocations to the bb task runner? Basically I'd like to have a Makefile in my repo and a disclaimer that it installs this tool called babashka, but without making users actually install it themselves. Then I want them to be able to call e.g. make build and have it use bb build. I know, I know: this is dimb because babashka is easy to set up, and make is doing nothing in my scenario. But in practice, I feel like having the install fully automated and exposing functionality via make reduces the friction for people to accept it. And I really do not want to write Makefiles lol.

Ingy döt Net03:08:34

This works more or less:

$ cat Makefile 
$(shell exec bb </dev/tty 2>&1 >/dev/tty)
$ make
user=> (println "Hello!")
Hello!
nil
user=> 

babashka 2
Ingy döt Net03:08:55

This is even better if you assume bash and rlwrap:

$ cat Makefile 
SHELL := bash
$(shell exec rlwrap bb </dev/tty &>/dev/tty)
$ make
Babashka v1.3.182 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (println "hi")
(println "hi")
hi
nil
user=> 

Ingy döt Net03:08:18

That's not what you asked but I'm ok with make. I'll give it a go.

Matthew Downey03:08:24

nice! any idea for a cross-platform way to install bb from the makefile? so that make install or whatever does it for you

Ingy döt Net03:08:34

ok this seems to be a start to what you want:

$ cat Makefile 
SHELL := bash
%:
	@[[ -n $$(command -v bb) ]] || command-to-install-bb
	@bb $(MAKECMDGOALS)
$ make version
babashka v1.3.182
$ 

Ingy döt Net03:08:26

You'll want to check if make is GNU make, and you can inline all the code you want to install bb. You do without bash if you want but I just think in bash so...

Ingy döt Net03:08:59

Let me know if you need help and if you get something working I'd be happy to review it for you.

Ingy döt Net03:08:20

Here's on without Bash:

$ cat Makefile 
%:
	@command -v bb >/dev/null || { command-to-install-bb; }
	@bb $(MAKECMDGOALS)
$ make version
babashka v1.3.182
$ 
you can put mutliple commands inside { ... } (separated by semis). MAKECMDGOALS might be GNU make specific, but lots of systems depend on GNU make and it's by far the most common.

❤️ 2
Ingy döt Net03:08:25

Here's another more sane Makefile from a project of mine that proxies several of its targets to lein: https://github.com/yaml/yamlscript/blob/clojure/clojure/Makefile

Ingy döt Net03:08:04

FWIW I will always put a Makefile in front of my tooling for any project in any language(s), even in environments where that's not the norm. I think it's a great idea!

Ingy döt Net03:08:34

And a shameless plug for a little something I once wrote that lets you define GNU make target dependencies functionally instead of only file stamp based, called MakePlus: https://makeplus.net/

Matthew Downey14:08:31

Super helpful, thank you!

👍 2
mmer12:08:07

How long does it take until the scoop is updated to get this new version?

borkdude12:08:35

This happens auto-magically, every hour I think

mmer12:08:15

OK I will be a bit more patient 🙂. Great work the way.

🙏 2
littleli13:08:55

LOL. it runs on cron schedule: 15 */3 * * * Or when I trigger manually, like right now! Enjoy new update.

littleli13:08:42

So the answer is: up to 3 hours after release on Github

borkdude13:08:57

I also published 184 since 183 contains some undesired debug output, for most people it doesn't matter

mmer11:08:17

I can confirm it has all filtered through now. Thanks.

🎉 2