Skip to content

Commit 89196c0

Browse files
JacocoRunner script: update for Jacoco 0.8.11 and Bazel 7.0.2 (#1567)
* JacocoRunner script: update for Jacoco 0.8.11 and Bazel 7.0.2 rules_scala has issues with coverage on JDK 21. Bazel has solved this in bazelbuild/bazel#20845 by upgrading Jacoco and ASM. Added option to build JacocoRunner for Bazel 7, the version with fix will be used with Jacoco interface changes. Jacoco upgraded to 0.8.11 (including the Jacoco/Bazel branches used for that). * Require using Java 17 for building Jacoco 0.8.11
1 parent 914e4ee commit 89196c0

File tree

2 files changed

+75
-28
lines changed

2 files changed

+75
-28
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
From 712d62a8238f3a7fe51e1cf4cc2520b5f249e1d3 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Gergely=20F=C3=A1bi=C3=A1n?= <gergo.fb@gmail.com>
3+
Date: Tue, 09 Apr 2024 12:28:00 +0200
4+
Subject: [PATCH] Build Jacoco for Bazel
5+
6+
---
7+
org.jacoco.build/pom.xml | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/org.jacoco.build/pom.xml b/org.jacoco.build/pom.xml
11+
index 8aae1543..067cc6a7 100644
12+
--- a/org.jacoco.build/pom.xml
13+
+++ b/org.jacoco.build/pom.xml
14+
@@ -691,11 +691,11 @@
15+
16+
buildDate = qualifier.substring(0, 4) + "/" + qualifier.substring(4, 6) + "/" + qualifier.substring(6, 8);
17+
project.getProperties().setProperty("build.date", buildDate);
18+
19+
commitId = project.getProperties().get("build.commitId");
20+
- pkgName = commitId.substring(commitId.length() - 7, commitId.length());
21+
+ pkgName = "4742761";
22+
project.getProperties().setProperty("jacoco.runtime.package.name", "org.jacoco.agent.rt.internal_" + pkgName);
23+
24+
void loadLicense(String libraryId) {
25+
version = project.getProperties().get(libraryId + ".version");
26+
path = project.getBasedir().toPath().resolve("../org.jacoco.build/licenses/" + libraryId + "-" + version + ".html");
27+
--
28+
2.25.1
29+

scripts/build_jacocorunner/build_jacocorunner.sh

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
#
33
# Script to build custom version of `JacocoCoverage_jarjar_deploy.jar` from Jacoco and Bazel repositories.
44
#
5+
# The script has three flavours: Bazel 5, 6 and 7. Documenting the details for Bazel 7 here.
6+
#
57
# The default `JacocoCoverage_jarjar_deploy.jar` has some issues:
68
#
7-
# 1. Scala support on newer Jacoco versions (including 0.8.7) is still lacking some functionality
9+
# 1. Scala support on newer Jacoco versions (including 0.8.11) is still lacking some functionality
810
#
911
# E.g. a lot of generated methods for case classes, lazy vals or other Scala features are causing falsely missed branches in branch coverage.
1012
#
1113
# Proposed changes in:
1214
# https://github.com/gergelyfabian/jacoco/tree/scala
1315
#
14-
# Backported to 0.8.7 (to be usable with current Bazel):
15-
# https://github.com/gergelyfabian/jacoco/tree/0.8.7-scala
16+
# Backported to 0.8.11 (to be usable with current Bazel):
17+
# https://github.com/gergelyfabian/jacoco/tree/0.8.11-scala
1618
#
1719
# 2. Bazel's code for generating `JacocoCoverage_jarjar_deploy.jar` needs changes after our Jacoco changes
1820
#
1921
# It implements an interface that we have extended, so that implementation also needs to be extended.
2022
#
21-
# This has been added on https://github.com/gergelyfabian/bazel/tree/jacoco_0.8.7_scala.
23+
# This has been added on https://github.com/gergelyfabian/bazel/tree/7.0.2_jacoco_0.8.11_scala.
2224
#
2325
# You can use this script to build a custom version of `JacocoCoverage_jarjar_deploy.jar`, including any fixes from the above list you wish
2426
# and then provide the built jar as a parameter of `java_toolchain` and/or `scala_toolchain` to use the changed behavior for coverage.
@@ -30,7 +32,7 @@
3032
# There are also some patches that may need to be applied for Jacoco, according to your preferences:
3133
#
3234
# 1. Bazel is compatible only with Jacoco in a specific package name. This is not Jacoco-specific, so not committed to the Jacoco fork.
33-
# See 0001-Build-Jacoco-for-Bazel.patch.
35+
# See 0001-Build-Jacoco-for-Bazel-*.patch (for each Bazel version).
3436
# 2. Building Jacoco behind a proxy needs a workaround.
3537
# See 0002-Build-Jacoco-behind-proxy.patch.
3638
#
@@ -43,23 +45,13 @@
4345
set -e
4446

4547
# Note!!
46-
# Ensure Java 8 is used for building Jacoco (experienced issue when using e.g. Java 17).
47-
# You may need to change this on your system.
48-
# If this matches your system, you could uncomment these lines:
49-
#export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
48+
# Ensure Java 8 is used for building Jacoco <0.8.11 (experienced issue when using e.g. Java 17).
49+
# Java 17+ is needed for Jacoco 0.8.11+.
50+
#
51+
# If it's necessary and this matches your system, you could uncomment these lines:
52+
#export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
5053
#export PATH=$JAVA_HOME/bin:$PATH
5154

52-
JAVA_VERSION=$(java -version 2>&1 | head -1 \
53-
| cut -d'"' -f2 \
54-
| sed 's/^1\.//' \
55-
| cut -d'.' -f1)
56-
57-
if [ "$JAVA_VERSION" != "8" ]; then
58-
echo "Unexpected java version: $JAVA_VERSION"
59-
echo "Please ensure this script is run with Java 8"
60-
exit 1
61-
fi
62-
6355
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
6456
readlink_cmd="readlink"
6557
elif [[ "$OSTYPE" == "darwin"* ]]; then
@@ -80,7 +72,7 @@ bazel_major_version=$1
8072
if [ -z "$bazel_major_version" ]; then
8173
echo "Please provide Bazel major version"
8274
exit 1
83-
elif [ "$bazel_major_version" != "5" ] && [ "$bazel_major_version" != "6" ]; then
75+
elif [ "$bazel_major_version" != "5" ] && [ "$bazel_major_version" != "6" ] && [ "$bazel_major_version" != "7" ]; then
8476
echo "Unsupported Bazel major version: $bazel_major_version"
8577
exit 1
8678
fi
@@ -89,8 +81,6 @@ echo "Selected Bazel major version: $bazel_major_version"
8981
jacoco_repo=$build_dir/jacoco
9082
# Take a fork for Jacoco that contains Scala fixes.
9183
jacoco_remote=https://github.com/gergelyfabian/jacoco
92-
# Take further fixes for Scala (2.11, 2.12 and 2.13) - branch in development:
93-
jacoco_branch=0.8.7-scala
9484

9585
# Choose the patches that you'd like to use:
9686
jacoco_patches=""
@@ -99,20 +89,48 @@ jacoco_patches="$jacoco_patches 0001-Build-Jacoco-for-Bazel-$bazel_major_version
9989
# Uncomment this if you are behind a proxy:
10090
#jacoco_patches="$jacoco_patches 0002-Build-Jacoco-behind-proxy.patch"
10191

102-
103-
# Jacoco version should be 0.8.7 in any case as Bazel is only compatible with that at this moment.
104-
jacoco_version=0.8.7
105-
10692
bazel_repo=$build_dir/bazel
10793
bazel_remote=https://github.com/gergelyfabian/bazel
10894
if [ "$bazel_major_version" = "5" ]; then
95+
# Take further fixes for Scala (2.11, 2.12 and 2.13) - branch in development:
96+
jacoco_branch=0.8.7-scala
97+
jacoco_version=0.8.7
10998
bazel_version=6.0.0-pre.20220520.1
11099
# Version of Bazel with extending Bazel's Jacoco interface implementation for our 0.8.7-scala jacoco branch.
111100
bazel_branch=jacoco_0.8.7_scala
112-
else
101+
elif [ "$bazel_major_version" = "6" ]; then
102+
# Take further fixes for Scala (2.11, 2.12 and 2.13) - branch in development:
103+
jacoco_branch=0.8.7-scala
104+
jacoco_version=0.8.7
113105
bazel_version=6.3.2
114106
# Version of Bazel with extending Bazel's Jacoco interface implementation for our 0.8.7-scala jacoco branch.
115107
bazel_branch=6.3.2_jacoco_0.8.7_scala
108+
else
109+
# Take further fixes for Scala (2.11, 2.12 and 2.13) - branch in development:
110+
jacoco_branch=0.8.11-scala
111+
jacoco_version=0.8.11
112+
bazel_version=7.0.2
113+
# Version of Bazel with extending Bazel's Jacoco interface implementation for our 0.8.11-scala jacoco branch.
114+
bazel_branch=7.0.2_jacoco_0.8.11_scala
115+
fi
116+
117+
JAVA_VERSION=$(java -version 2>&1 | head -1 \
118+
| cut -d'"' -f2 \
119+
| sed 's/^1\.//' \
120+
| cut -d'.' -f1)
121+
122+
if [ "$bazel_major_version" == "7" ]; then
123+
if [ "$JAVA_VERSION" != "17" ]; then
124+
echo "Unexpected java version: $JAVA_VERSION"
125+
echo "Please ensure this script is run with Java 17"
126+
exit 1
127+
fi
128+
else
129+
if [ "$JAVA_VERSION" != "8" ]; then
130+
echo "Unexpected java version: $JAVA_VERSION"
131+
echo "Please ensure this script is run with Java 8"
132+
exit 1
133+
fi
116134
fi
117135

118136
bazel_build_target=JacocoCoverage_jarjar_deploy.jar

0 commit comments

Comments
 (0)