What's a sh_library?

460 views
Skip to first unread message

Dan Fabulich

unread,
May 23, 2016, 5:12:47 PM5/23/16
to bazel-discuss
sh_binary and sh_library confuse me.

Here's what I think I understand:

1) sh_binary targets are executable; they can have deps and data dependencies
2) sh_library targets aren't "executable" from Bazel's perspective
3) You can't list a sh_binary as a dep of a sh_binary; you have to convert it to a sh_library to do that
4) If you list a sh_binary X in as a "data" dependency of another sh_binary Y, X won't have access to its data/runfiles
5) Therefore, if you have a script that you both want to run and allow other sh_binary scripts to run it, you have to double-declare it as a sh_binary and as a sh_library. When invoking it directly, use the sh_binary; when depending on the script, use the sh_library.

Is that all true? If so, WHY is it true? It seems like an pointless distinction. sh_binary targets should be able to just declare other sh_binary targets as dependencies. What's the harm?

I suppose the same argument could be made re: py_binary targets, but at least py_binary targets have a wrapper environment script, so there it makes somewhat more sense.

-Dan

Damien Martin-guillerez

unread,
May 24, 2016, 3:59:08 AM5/24/16
to Dan Fabulich, bazel-discuss
Hi Dan,

I think the main reason behind that distinction is that inside Google, we have do a packaging of sh_binary into a unique artifact that you can execute. sh_library are here for inclusion.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/34216e27-ad18-4c68-833b-031db4d3d6e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages