Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the name of the classpath manifest jar to JacocoCoverageRunner #21365

Closed
wants to merge 9 commits into from

Conversation

c-mita
Copy link
Member

@c-mita c-mita commented Feb 15, 2024

When the java classpath exceeds the limit, we create a manifest JAR
and pass that on the classpath. JacocoCoverageRunner knows how to
extract information from this JAR. But if another JAR ends up on that
classpath, it confuses the coverage runner which is expecting only a
single jar in this case.

This changes the java_stub_template file to export the name of the
created manifest jar so the coverage runner can extract it.

We also change the template file so the relevant exports don't occur
in the middle of a larger function.

It's possible this is somewhat overengineered and that we could
always rely on the manifest jar always being the first one discovered
by the coverage runner, but it is not totally obvious to me that that
will always be true.

Fixes #21268

@c-mita c-mita requested a review from hvadehra February 15, 2024 11:37
@github-actions github-actions bot added team-Rules-Java Issues for Java rules awaiting-review PR is awaiting review from an assigned reviewer labels Feb 15, 2024
@c-mita
Copy link
Member Author

c-mita commented Feb 15, 2024

Do we need to handle version-skew between Bazel and java_tools? If so, we may need to add a bit more logic to JacocoCoverageRunner?

@hvadehra
Copy link
Member

Do we need to handle version-skew between Bazel and java_tools? If so, we may need to add a bit more logic to JacocoCoverageRunner?

Yes, I think we need to. java_tools / rules_java upgrades happen more frequently than bazel upgrades.

@c-mita
Copy link
Member Author

c-mita commented Feb 15, 2024

Do we need to handle version-skew between Bazel and java_tools? If so, we may need to add a bit more logic to JacocoCoverageRunner?

Yes, I think we need to. java_tools / rules_java upgrades happen more frequently than bazel upgrades.

Done.

It's not a tested path since the Bazel shell tests always use a fresh build, but I have verified that it should work.

@hvadehra
Copy link
Member

Just a quick clarification before I properly review, my understanding is this change is currently doing two things:

  1. Export the manifest jar path from the stub template and start using that in JacocoCoverageRunner if set.
  2. If the above does not apply (i.e. for Bazel versions not including this change), stop assuming there is only one URL and try to identify the jar from the first URL.

Why are we doing (2)? If we think that fixes things, then we don't need (1). My concern is we're subtly altering behavior for currently released Bazel on a java_tools upgrade. Can we not just do (1) and cherry pick that into 7.1?

@c-mita
Copy link
Member Author

c-mita commented Feb 16, 2024

Just a quick clarification before I properly review, my understanding is this change is currently doing two things:

  1. Export the manifest jar path from the stub template and start using that in JacocoCoverageRunner if set.
  2. If the above does not apply (i.e. for Bazel versions not including this change), stop assuming there is only one URL and try to identify the jar from the first URL.

Why are we doing (2)? If we think that fixes things, then we don't need (1). My concern is we're subtly altering behavior for currently released Bazel on a java_tools upgrade. Can we not just do (1) and cherry pick that into 7.1?

Whilst I may suspect that 2. fixes things in all cases, I cannot prove it. Hence 1.

Just doing 1. breaks things if java_tools is ahead of Blaze, since we're looking for an environment variable that isn't being set and ignoring the one that is. If that's not a problem then 2. is not needed, which is what I originally asked.

@hvadehra
Copy link
Member

Sorry, I guess I misunderstood your question about version skew. I meant that in JacocoCoverageRunner we can't assume the new variable will be available/exported.

Assuming we can get this into 7.1, I think it's safer to leave the old behavior as is if the variable isn't set. This should be acceptable as after all, this is long standing (buggy) behavior and not a regression as such. WDYT?

@c-mita
Copy link
Member Author

c-mita commented Feb 16, 2024

I don't really get the rationale for that and it doesn't simplify the logic at all. The diff is simply:

@@ -380,7 +380,7 @@ public class JacocoCoverageRunner {
         System.err.println("Classpath JAR " + wrappedJar + " not provided");
         return null;
       }
-    } else if (jarIsWrapped && urls[0].getPath().endsWith("-classpath.jar")) {
+    } else if (jarIsWrapped && urls.length == 1) {
       classPathUrl = urls[0];
     }
     if (classPathUrl != null) {

Regardless, I've done it.

Copy link
Member

@hvadehra hvadehra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not disable the tests. For the new test case that currently only works for java_tools built at HEAD, maybe exit early if JAVA_TOOLS == 'released"?

Also maybe add a TODO to clean up the legacy logic in java_stub_template.txt when we update to a new java_tools version that includes this change?

@c-mita
Copy link
Member Author

c-mita commented Feb 19, 2024

Lets not disable the tests. For the new test case that currently only works for java_tools built at HEAD, maybe exit early if JAVA_TOOLS == 'released"?

Also maybe add a TODO to clean up the legacy logic in java_stub_template.txt when we update to a new java_tools version that includes this change?

Good point on the test; done.

@hvadehra hvadehra added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Feb 19, 2024
@hvadehra
Copy link
Member

@bazel-io fork 7.1.0

@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Feb 19, 2024
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Feb 19, 2024
When the java classpath exceeds the limit, we create a manifest JAR
and pass that on the classpath. JacocoCoverageRunner knows how to
extract information from this JAR. But if another JAR ends up on that
classpath, it confuses the coverage runner which is expecting only a
single jar in this case.

This changes the java_stub_template file to export the name of the
created manifest jar so the coverage runner can extract it.

We also change the template file so the relevant exports don't occur
in the middle of a larger function.

It's possible this is somewhat overengineered and that we could
always rely on the manifest jar always being the first one discovered
by the coverage runner, but it is not totally obvious to me that that
will always be true.

Fixes bazelbuild#21268

Closes bazelbuild#21365.

PiperOrigin-RevId: 608333782
Change-Id: I9895689fd9d771c9198e36bef222a9f86ada573e
github-merge-queue bot pushed a commit that referenced this pull request Feb 20, 2024
…Runner (#21413)

When the java classpath exceeds the limit, we create a manifest JAR
and pass that on the classpath. JacocoCoverageRunner knows how to
extract information from this JAR. But if another JAR ends up on that
classpath, it confuses the coverage runner which is expecting only a
single jar in this case.

This changes the java_stub_template file to export the name of the
created manifest jar so the coverage runner can extract it.

We also change the template file so the relevant exports don't occur
in the middle of a larger function.

It's possible this is somewhat overengineered and that we could
always rely on the manifest jar always being the first one discovered
by the coverage runner, but it is not totally obvious to me that that
will always be true.

Fixes #21268

Closes #21365.

Commit
a2ebdf7

PiperOrigin-RevId: 608333782
Change-Id: I9895689fd9d771c9198e36bef222a9f86ada573e

Co-authored-by: Charles Mita <cmita@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Java] Coverage not collected for some manifest jars
2 participants