Fork me on GitHub
#babashka
<
2023-11-23
>
mmer09:11:43

With the bb uberjar and other packaging methods are bb tasks still exposed?

mmer13:12:46

When you use this option does the :init task get called in the same way that the bb task-name does?

borkdude13:12:39

at least, I would expect so

mmer13:12:05

I also have a supplementary question - you say put the bb.edn on your classpath, as I am not a java dev, what does that actually mean in practical terms?

borkdude13:12:06

the wiki already explains: Put the file in resources/META-INF/bb.edn and add resources to your classpath

borkdude13:12:20

so:

{:paths ["resources"]}

mmer13:12:49

Thanks I was looking at the bb book, and was struggling to understand this - my bad - not yours.

mmer13:12:21

Does that mean you could not then use bb task after putting it in the resource folder?

borkdude13:12:55

no problem! all the files that are on the classpath end up in the jar, but without the paths prepended. so file resources/foo.txt becomes /foo.txt in the jar file (a jar file is just a zip file)

borkdude13:12:35

you have to provide a copy of your bb.edn there, else it won't be part of the jar and bb doesn't have this information

mmer13:12:02

OK, slight shame to have to duplicate the file 🙂

borkdude13:12:24

you can just make this part of your build script, copy the file and ignore it in gitignore, be creative ;)

mmer13:12:12

Interestingly, when you do this the bb tasks option is not available - i.e. ./uber-foo tasks does not return the tasks list with docs?

borkdude13:12:29

please read the docs better

borkdude13:12:03

You basically have to write your own wrapper that invokes a task

borkdude13:12:29

The normal bb arguments do not apply since it's now your own self-contained binary, babashka arguments are not read anymore

mmer13:12:54

I have followed that and have the tasks working from an exec. I was just pointing out that there is a bb option to view the liast of tasks and that is not available when you create the self-contained executable. It would just be good to have a way to tell the user the list of tasks as in bb tasks. Everything else is working as your docs says.

borkdude13:12:55

I can imagine that this is confusing though, sorry for my RTFM-ish remark

borkdude13:12:56

unfortunately I don't think there is currently a way to call bb tasks programmatically

mmer13:12:35

I was just stating that as the tasks option is my main entry point for my users, being able to show the list of tasks as in bb tasks from the self-contained executable would be good. I was wondering about having a task that read the resources/META-INF/bb.edn file and printed out the list.

borkdude13:12:35

Understood. Since this isn't exposed today (but we could in a future version, issue welcome), perhaps you can copy-paste the logic from here:

borkdude13:12:54

You can get to the bb.edn by doing

(slurp (io/resource "bb.edn"))

borkdude14:12:31

I don't think you really need the sci-ctx etc. It's basically just reading an EDN file and determining the original order of tasks, and then print the stuff

mmer14:12:55

That is what I was going to do.

borkdude14:12:46

it's slightly more complicated in the original, but you can probably simplify it for your purposes. it prints docstrings from functions and therefore it needs to load stuff on demand

mmer14:12:57

I was just goign to fetch the task keys and any doc items if they exist.

mmer14:12:46

The io/resource does not seem to return the file. fs/cwd returns the location where the self-contained exe (SCE) is running. I am not sure how you can get inside the exe to access the uberjar files?

borkdude14:12:24

oh (io/resource "META-INF/bb.edn")

mmer14:12:21

Yes thanks.

👍 1
borkdude14:12:21

META-INF is actually a directory inside of the jar

mmer17:12:02

The resultant binary - does that just run on linux?

borkdude17:12:24

@U4C3ZU6KX binaries are OS-specific so you need to build for each OS specifically, but given that you can already download binaries for bb for each OS, you can build all of them on a single machine

borkdude17:12:46

I would go with the -static binary wherever possible for linux and ignore the non-static one

mmer17:12:05

Ok thanks

DeepReef1113:11:03

How to manage verbose argument in babashka? Anyone has a guide about it? Perhaps just a general guide about logging message would be what I need. I am always wondering how it should be managed