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.
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#
4345set -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-
6355if [[ " $OSTYPE " == " linux-gnu" * ]]; then
6456 readlink_cmd=" readlink"
6557elif [[ " $OSTYPE " == " darwin" * ]]; then
@@ -80,7 +72,7 @@ bazel_major_version=$1
8072if [ -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
8678fi
@@ -89,8 +81,6 @@ echo "Selected Bazel major version: $bazel_major_version"
8981jacoco_repo=$build_dir /jacoco
9082# Take a fork for Jacoco that contains Scala fixes.
9183jacoco_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:
9686jacoco_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-
10692bazel_repo=$build_dir /bazel
10793bazel_remote=https://github.com/gergelyfabian/bazel
10894if [ " $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
116134fi
117135
118136bazel_build_target=JacocoCoverage_jarjar_deploy.jar
0 commit comments