4
4
#
5
5
# The default `JacocoCoverage_jarjar_deploy.jar` has some issues:
6
6
#
7
- # 1. Bazel uses Jacoco 0.8.3 that has poor Scala support, including a bug that filters out Scala lambdas on Scala >=2.12
8
- #
9
- # Bug report:
10
- # https://github.com/bazelbuild/rules_scala/issues/1056
11
- # https://github.com/bazelbuild/bazel/issues/11674
12
- #
13
- # Backported fix from Jacoco 0.8.5 to Jacoco 0.8.3 (current Bazel is not compatible with Jacoco 0.8.5):
14
- # https://github.com/gergelyfabian/jacoco/tree/0.8.3-scala-lambda-fix
15
- #
16
- # 2. Bazel ignores Jacoco's filtering for branch coverage metrics:
17
- #
18
- # Bug report:
19
- # https://github.com/bazelbuild/bazel/issues/12696
20
- #
21
- # Proposed fix:
22
- # https://github.com/gergelyfabian/bazel/tree/branch_coverage_respect_jacoco_filtering
23
- #
24
- # 3. Scala support on newer Jacoco versions (including 0.8.5) is still lacking some functionality
7
+ # 1. Scala support on newer Jacoco versions (including 0.8.7) is still lacking some functionality
25
8
#
26
9
# E.g. a lot of generated methods for case classes, lazy vals or other Scala features are causing falsely missed branches in branch coverage.
27
10
#
28
11
# Proposed changes in:
29
12
# https://github.com/gergelyfabian/jacoco/tree/scala
30
13
#
31
- # Backported to 0.8.3 (to be usable with current Bazel):
32
- # https://github.com/gergelyfabian/jacoco/tree/0.8.3-scala
14
+ # Backported to 0.8.7 (to be usable with current Bazel):
15
+ # https://github.com/gergelyfabian/jacoco/tree/0.8.7-scala
16
+ #
17
+ # 2. Bazel's code for generating `JacocoCoverage_jarjar_deploy.jar` needs changes after our Jacoco changes
33
18
#
34
- # These branches also include the Scala 2.12 lambda coverage fix.
19
+ # It implements an interface that we have extended, so that implementation also needs to be extended.
20
+ #
21
+ # This has been added on https://github.com/gergelyfabian/bazel/tree/jacoco_0.8.7_scala.
35
22
#
36
23
# You can use this script to build a custom version of `JacocoCoverage_jarjar_deploy.jar`, including any fixes from the above list you wish
37
24
# and then provide the built jar as a parameter of `java_toolchain` and/or `scala_toolchain` to use the changed behavior for coverage.
38
25
#
39
- # Choose the fixes from the above list by configuring the used branches for Bazel and Jacoco repos below.
26
+ # Choose the fixes from the above list by configuring the used branch for Jacoco/Bazel repos below.
40
27
#
41
28
# Patches:
42
29
#
55
42
56
43
set -e
57
44
58
-
59
-
60
- if [[ " $OSTYPE " == " linux-gnu" * ]]; then
61
- readlink_cmd=" readlink"
62
- elif [[ " $OSTYPE " == " darwin" * ]]; then
63
- readlink_cmd=" greadlink"
64
- else
65
- echo " OS not supported: $OSTYPE "
66
- exit 1
67
- fi
45
+ # 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
50
+ # export PATH=$JAVA_HOME/bin:$PATH
68
51
69
52
JAVA_VERSION=$( java -version 2>&1 | head -1 \
70
53
| cut -d' "' -f2 \
@@ -77,41 +60,60 @@ if [ "$JAVA_VERSION" != "8" ]; then
77
60
exit 1
78
61
fi
79
62
63
+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then
64
+ readlink_cmd=" readlink"
65
+ elif [[ " $OSTYPE " == " darwin" * ]]; then
66
+ readlink_cmd=" greadlink"
67
+ else
68
+ echo " OS not supported: $OSTYPE "
69
+ exit 1
70
+ fi
71
+
80
72
source_path=$( $readlink_cmd -f $( dirname ${BASH_SOURCE[0]} ) )
81
73
82
74
build_dir=/tmp/bazel_jacocorunner_build
83
75
84
76
mkdir -p $build_dir
85
77
78
+ # Read the Bazel major version.
79
+ bazel_major_version=$1
80
+ if [ -z " $bazel_major_version " ]; then
81
+ echo " Please provide Bazel major version"
82
+ exit 1
83
+ elif [ " $bazel_major_version " != " 5" ] && [ " $bazel_major_version " != " 6" ]; then
84
+ echo " Unsupported Bazel major version: $bazel_major_version "
85
+ exit 1
86
+ fi
87
+ echo " Selected Bazel major version: $bazel_major_version "
88
+
86
89
jacoco_repo=$build_dir /jacoco
87
90
# Take a fork for Jacoco that contains Scala fixes.
88
91
jacoco_remote=https://github.com/gergelyfabian/jacoco
89
- # Choose a branch you'd like to use.
90
- # Default option, take only fixes for Scala 2.12 lambdas backported to Jacoco 0.8.3:
91
- jacoco_branch=0.8.3-scala-lambda-fix
92
- # Advanced option, take further fixes for Scala (2.11, 2.12 and 2.13) - branch in development:
93
- # jacoco_branch=0.8.3-scala
92
+ # Take further fixes for Scala (2.11, 2.12 and 2.13) - branch in development:
93
+ jacoco_branch=0.8.7-scala
94
94
95
95
# Choose the patches that you'd like to use:
96
96
jacoco_patches=" "
97
- # Bazel needs to have a certain Jacoco package version:
98
- jacoco_patches=" $jacoco_patches 0001-Build-Jacoco-for-Bazel.patch"
97
+ # Bazel needs to have a certain Jacoco package version (dependent on Bazel major version) :
98
+ jacoco_patches=" $jacoco_patches 0001-Build-Jacoco-for-Bazel- $bazel_major_version .0 .patch"
99
99
# Uncomment this if you are behind a proxy:
100
100
# jacoco_patches="$jacoco_patches 0002-Build-Jacoco-behind-proxy.patch"
101
101
102
102
103
- # Jacoco version should be 0.8.3 in any case as Bazel is only compatible with that at this moment.
104
- jacoco_version=0.8.3
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
105
106
106
bazel_repo=$build_dir /bazel
107
- bazel_remote=https://github.com/bazelbuild/bazel
108
- bazel_branch=master
109
- bazel_tag=4.1.0
110
-
111
- # Advanced option: take a fork that has fixes for Jacoco LCOV formatter, to respect Jacoco filtering
112
- # (fixes for Scala in Jacoco respected in Bazel branch coverage):
113
- # bazel_remote=https://github.com/gergelyfabian/bazel
114
- # bazel_branch=branch_coverage_respect_jacoco_filtering
107
+ bazel_remote=https://github.com/gergelyfabian/bazel
108
+ if [ " $bazel_major_version " = " 5" ]; then
109
+ bazel_version=6.0.0-pre.20220520.1
110
+ # Version of Bazel with extending Bazel's Jacoco interface implementation for our 0.8.7-scala jacoco branch.
111
+ bazel_branch=jacoco_0.8.7_scala
112
+ else
113
+ bazel_version=6.3.2
114
+ # Version of Bazel with extending Bazel's Jacoco interface implementation for our 0.8.7-scala jacoco branch.
115
+ bazel_branch=6.3.2_jacoco_0.8.7_scala
116
+ fi
115
117
116
118
bazel_build_target=JacocoCoverage_jarjar_deploy.jar
117
119
@@ -147,10 +149,10 @@ mvn clean install
147
149
(
148
150
cd $bazel_repo
149
151
git remote update
150
- git checkout tags/$bazel_tag
152
+ git reset --hard HEAD
153
+ git checkout $bazel_branch
151
154
152
- # Advanced option - check out a branch instead of the release tag
153
- # git checkout origin/$bazel_branch
155
+ echo " $bazel_version " > .bazelversion
154
156
155
157
# Prepare Jacoco version.
156
158
cd third_party/java/jacoco
0 commit comments