Extracting the target label from JavaInfo

37 views
Skip to first unread message

ig...@wix.com

unread,
Jun 14, 2018, 2:00:18 AM6/14/18
to Bazel/JVM Special Interest Group
Hello,

I am experimenting with extracting the actual target label for each of the dependencies exposed in JavaInfo.
I'm trying to implement a rule that is similar to the maven assembly plugin, and I want to exclude certain targets from being packaged in the resulting jar.
For this, I define a list of targets in the rule to exclude, and I want to filter them out from the depset provided by JavaInfo.
So I wonder if there's a way to lookup those labels, or is there a better way you can think of.

Thanks!
Igal.

ig...@wix.com

unread,
Jun 18, 2018, 7:20:05 AM6/18/18
to Bazel/JVM Special Interest Group
A few updates on my experiments:

My plan with comparing JavaInfos didn't work out, because on the `transitive_runtime_deps` and friends I get a set of File entries, which don't have JavaInfo associated with them.
I went with plan B, comparing labels instead. I am now able to produce a fat jar (using the deployable.jar implementation), with certain jars excluded out of it (by providing targets labels to an 'exclude' list)

my custom rule (currently named 'scala_assembly') looks like this:

scala_assembly(
    name = "my-output-jar"
    for-target="//foo/bar/mybinary"
    exclude=["//com/quux/dependency"]
)

I now want to implement exclusion based on package semantics (i.e. excluding "//com/quux/..."). My current implementation can read paths and check them against the paths extracted from the 'exclude' and 'transitive_runtime_deps' targets, but this requires me to work with strings, and I rather have something better.

Do you have any ideas on how to implement this filtering better than just comparing path strings?

Let me know if something wasn't clear!

Thanks! 

ig...@wix.com

unread,
Jun 18, 2018, 8:54:44 AM6/18/18
to Bazel/JVM Special Interest Group
I wanted to make it clear that by "comparing files" I meant comparing their labels, which seems reasonable data type to use in comparison.
Again, any better suggestions are highly welcomed!

P. Oscar Boykin

unread,
Jun 18, 2018, 2:33:39 PM6/18/18
to ig...@wix.com, bazel-...@googlegroups.com
You may already know this, but we have used this in production with success:


you do have to write the jarjar commands yourself. Yours looks fancier since you can think in terms of targets.

That said, it seems like it is possible what we also want is neverlink support in rules_scala (which we don't currently have) and that might cover many cases (although linking seems to me like it should be controlled at the binary site not the library side, but there are some exceptions to that, e.g. Hadoop).

--
You received this message because you are subscribed to the Google Groups "Bazel/JVM Special Interest Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-sig-jv...@googlegroups.com.
To post to this group, send email to bazel-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-sig-jvm/b4de2818-216b-4cb2-93de-c1897eb90697%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

ittai zeidman

unread,
Jul 16, 2018, 6:52:50 AM7/16/18
to P. Oscar Boykin, ig...@wix.com, bazel-...@googlegroups.com, Elena-Irina Iancu, Dmitry Lomov
Irina/Dmitry,
Any thoughts if we can indeed base on the below approach for connecting the target label to jars?

Lukács T. Berki

unread,
Nov 5, 2018, 9:06:46 AM11/5/18
to ittai zeidman, P. Oscar Boykin, ig...@wix.com, bazel-...@googlegroups.com, Elena-Irina Iancu, Dmitry Lomov
@igalt: Sorry for the extremely late answer.
@Ittai: Depends on what you want to do. I can imagine two ways at the moment:

You can use the "owner" field of files to tell the which label produced a given file, i.e.:

for f in ctx.files.srcs:
  print("%s is produced by %s" % (f.path, f.owner))

Bazel also puts the label of the rule that produces a .jar into the "Target-Label" entry in the manifest of the jar. Of course, that does not help if you want to filter .jar files from the inputs of a given action.

On Mon, Jul 16, 2018 at 12:52 PM, ittai zeidman <itt...@gmail.com> wrote:
Irina/Dmitry,
Any thoughts if we can indeed base on the below approach for connecting the target label to jars?
On Mon, Jun 18, 2018 at 9:33 PM P. Oscar Boykin <oscar....@gmail.com> wrote:
You may already know this, but we have used this in production with success:


you do have to write the jarjar commands yourself. Yours looks fancier since you can think in terms of targets.

That said, it seems like it is possible what we also want is neverlink support in rules_scala (which we don't currently have) and that might cover many cases (although linking seems to me like it should be controlled at the binary site not the library side, but there are some exceptions to that, e.g. Hadoop).

On Mon, Jun 18, 2018 at 1:20 AM igalt via Bazel/JVM Special Interest Group <bazel-sig-jvm@googlegroups.com> wrote:
A few updates on my experiments:

My plan with comparing JavaInfos didn't work out, because on the `transitive_runtime_deps` and friends I get a set of File entries, which don't have JavaInfo associated with them.
I went with plan B, comparing labels instead. I am now able to produce a fat jar (using the deployable.jar implementation), with certain jars excluded out of it (by providing targets labels to an 'exclude' list)

my custom rule (currently named 'scala_assembly') looks like this:

scala_assembly(
    name = "my-output-jar"
    for-target="//foo/bar/mybinary"
    exclude=["//com/quux/dependency"]
)

I now want to implement exclusion based on package semantics (i.e. excluding "//com/quux/..."). My current implementation can read paths and check them against the paths extracted from the 'exclude' and 'transitive_runtime_deps' targets, but this requires me to work with strings, and I rather have something better.

Do you have any ideas on how to implement this filtering better than just comparing path strings?

Let me know if something wasn't clear!

Thanks! 

On Thursday, June 14, 2018 at 9:00:18 AM UTC+3, ig...@wix.com wrote:
Hello,

I am experimenting with extracting the actual target label for each of the dependencies exposed in JavaInfo.
I'm trying to implement a rule that is similar to the maven assembly plugin, and I want to exclude certain targets from being packaged in the resulting jar.
For this, I define a list of targets in the rule to exclude, and I want to filter them out from the depset provided by JavaInfo.
So I wonder if there's a way to lookup those labels, or is there a better way you can think of.

Thanks!
Igal.

--
You received this message because you are subscribed to the Google Groups "Bazel/JVM Special Interest Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-sig-jvm+unsubscribe@googlegroups.com.

To post to this group, send email to bazel-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-sig-jvm/b4de2818-216b-4cb2-93de-c1897eb90697%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

--
You received this message because you are subscribed to the Google Groups "Bazel/JVM Special Interest Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-sig-jvm+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Bazel/JVM Special Interest Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-sig-jvm+unsubscribe@googlegroups.com.

To post to this group, send email to bazel-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Lukács T. Berki | Software Engineer | lbe...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891
Reply all
Reply to author
Forward
0 new messages