Skip to content

Commit e75d7f1

Browse files
authored
Update docs for version 7.0.0, remove old APIs (#1703)
* Update docs for version 7.0.0, remove old APIs Describes the new `scala_toolchains()` API, breaking changes, Bazel compatibility matrix, and breaking of the `io_bazel_rules_scala` repo name dependency. Part of #1482, #1647, #1652, and #1699, it also removes obsolete `WORKSPACE` APIs in favor of `scala_toolchains()`, et. al. Much of the README text regarding `WORKSPACE` configuration, Bazel compatibility, and breaking changes comes from: - #1482 (comment) The "Breaking changes in `rules_scala` 7.x" section of `README.md` describes the removed `WORKSPACE` macros, and provides guidance for adopting the `scala_toolchains()` API. Also includes information about the upcoming Bzlmod implementation (#1482) and the Bazel 8 compatibility changes for `rules_scala` 8.x (#1652). Contains a light editing pass over almost every Markdown file to resolve `markdownlint` warnings when editing in VSCode. Also added `.markdownlint.json` to silence rule `MD033/no-inline-html`, since several docs contain `<br/>` and/or `<table>` elements. - https://github.com/DavidAnson/vscode-markdownlint?tab=readme-ov-file#markdownlintconfig Performed other opportunistic grammar edits and added new information, including: - `docs/coverage.md`: Describes how to determine the default JaCoCo version used by `rules_java` - `scripts/README.md`: Updates `create_repository.py` docs extensively, and adds a section for `sync_bazelversion.sh` - Replaces `starlark` code fences with `py`, since the syntax is identical and editors seem to support it better. --- Since the next major release is imminent, ensuring the documentation accurately reflects all the changes since v6.6.0 has become an urgent priority. Rather than leave the old `WORKSPACE` APIs in place, which could lead to surprising failures, this change removes all of them. This also changes some code that still depended on some of these obsolete macros, including `scala_toolchains()`. Since all the toolchainization changes led to the entire project already using `scala_toolchains()` and `scala_register_toolchains()` exclusively, this proved a low risk refactoring. With some Bzlmod and Bazel 8 information already in place, very little will need to change when these implementations land. The commits that contain those implementations will also include their relevant documentation updates. * Update GitHub refs, minor grammar error in README It seems the README won't expand refs like #1482. This updates such refs to use the repo prefix, e.g., #1482. * More small README.md improvements * s/stanza/snippet/g Thanks to @bartoszkosiorek for pointing out in #1703 that "stanza" isn't a common word. That was my former English Lit major innie leaking out, applying a poetry term (a group of lines, like a paragraph) out of context. * Add Bzlmod repo scope change, `scala_toolchain` Explicitly notes that some `rules_scala` APIs may break, specifically `setup_scala_toolchain`. Part of #1482. Brought to my attention by @michalbogacz in a `#scala` thread in the Bazel Slack workspace, which was in the context of michalbogacz/scala-bazel-monorepo#26. - https://bazelbuild.slack.com/archives/CDCKJ2KFZ/p1740144886159909 * Update README.md per @grepwood's feedback in #1703 - Updates links not to use code tags, since it gives the appearance of multiple adjacent links. - Updates issue reference missing the `bazelbuild/rules_scala` prefix. - Moves paragraphs above "Getting started" `WORKSPACE` snippet to a new "Important changes in `rules_scala` v7.0.0 configuration" section following the snippet. * Update `scala_toolchains()` docstring Removes the reference to `@rules_scala_toolchains`, since that's not really a public interface detail. Prompted by a ping from @gergelyfabian in a Bazel Slack workspace direct message, asking about the docstring currently reflected on `master`. * Fix `WORKSPACE` snippet for `rules_java` 7.x The `WORKSPACE` snippet in the `README.md` now matches what's currently in all the other `WORKSPACE` files. I'd previously included the `rules_java` 8.x statements from my Bazel 8 compatibility branch in the `README.md` changes for `rules_scala` 7.x. @gergelyfabian tried the previous snippet from #1703, and it broke his build: - #1703 (comment) * Clean up cross-compilation.md, rm deprecated attr Includes a full editing pass over `docs/cross-compilation.md` and removes the `incompatible_use_toolchain_transition` attribute, which has been deprecated since before Bazel 6.5.0. - https://bazel.build/versions/6.4.0/rules/lib/globals?hl=en#rule The "Cross-build support tiers" could use extra review by someone more knowledgable about that aspect of `rules_scala`. Prompted by a suggestion by @gergelyfabian in #1703 to update a single line, but turned into a complete overhaul. * Fix `io_bazel_rules_scala`, version in README Removes a remaining, incorrect `@io_bazel_rules_scala` reference in `README.md`, as well as in the `.github/workflows/workspace_snippet.sh` script. Updates the `README.md` to use `<VERSION>` in place of `7.0.0` in the `WORKSPACE` snippet under "Getting started". Prompted by a couple comments by @gergelyfabian in #1703. I used the following command to confirm no more unintentional `io_bazel_rules_scala` references remain. (I'm leaving the `test_intellij_aspect.sh` script alone for now.) ```txt $ git ls-files | xargs grep 'io_bazel_rules_scala[^_]' .github/workflows/workspace_snippet.sh: name = "rules_scala", # Can be "io_bazel_rules_scala" if you still need it. README.md: name = "rules_scala", # Can be "io_bazel_rules_scala" if you still need it. README.md:- __`rules_scala` no longer requires the `io_bazel_rules_scala` repository test_intellij_aspect.sh: bazel test --test_output=errors --override_repository io_bazel_rules_scala="${rules_scala_dir}" --extra_toolchains=@io_bazel_rules_scala//scala:default_toolchain //aspect/testing/tests/src/com/google/idea/blaze/aspect/scala/... ``` There are still many `io_bazel_rules_scala_.*` references, most of them for internal toolchain dependency repos. The `@io_bazel_rules_scala_config` repository is the exception, which is a publicly documented interface. (We _could_ change it, as another potential known breakage for `rules_scala` v7.0.0.) * Remove `testing` parameter from `scala_toolchains` Removed in favor of using the existing `scalatest`, `junit`, and `specs2` parameters at @simuons's suggestion in: - #1482 (comment) Also updated the `scala_toolchains()` docstring slightly and added `doc` parameters to the `attrs` for `_scala_toolchains_repo()`.
1 parent cd1bf15 commit e75d7f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1584
-1066
lines changed

.github/workflows/workspace_snippet.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Paste this snippet into your \`WORKSPACE\` file:
1919
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2020
2121
http_archive(
22-
name = "io_bazel_rules_scala",
22+
name = "rules_scala", # Can be "io_bazel_rules_scala" if you still need it.
2323
sha256 = "${SHA}",
2424
strip_prefix = "${PREFIX}",
2525
url = "https://github.com/bazelbuild/rules_scala/releases/download/${TAG}/${ARCHIVE}",

.markdownlint.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"default": true,
3+
"MD013": false,
4+
"MD033": false
5+
}

README.md

+587-143
Large diffs are not rendered by default.

WORKSPACE

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ load("//scala:deps.bzl", "rules_scala_dependencies")
55

66
rules_scala_dependencies()
77

8-
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
8+
load(
9+
"@rules_java//java:repositories.bzl",
10+
"rules_java_dependencies",
11+
"rules_java_toolchains",
12+
)
913

1014
rules_java_dependencies()
1115

@@ -51,9 +55,11 @@ load("//scala:toolchains.bzl", "scala_register_toolchains", "scala_toolchains")
5155
scala_toolchains(
5256
fetch_sources = True,
5357
jmh = True,
58+
junit = True,
5459
scala_proto = True,
5560
scalafmt = True,
56-
testing = True,
61+
scalatest = True,
62+
specs2 = True,
5763
twitter_scrooge = True,
5864
)
5965

docs/coverage.md

+73-21
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
## Coverage support
1+
# Coverage support
22

3-
### Running tests with coverage
3+
## Running tests with coverage
44

55
rules_scala supports coverage:
66

7-
```
7+
```txt
88
bazel coverage //...
99
```
1010

1111
It will produce several .dat files with results for your targets.
1212

1313
You can also add more options to receive a combined coverage report:
1414

15-
```
15+
```txt
1616
bazel coverage \
1717
--combined_report=lcov \
1818
--coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main" \
@@ -21,18 +21,18 @@ bazel coverage \
2121

2222
This should produce a single `bazel-out/_coverage/_coverage_report.dat` from all coverage files that are generated.
2323

24-
### Processing coverage reports
24+
## Processing coverage reports
2525

26-
You can install `lcov` package (that supports the format Bazel uses for coverage reports) to have access to additional tools:
26+
You can install the [`lcov`](https://github.com/linux-test-project/lcov) package (that supports the format Bazel uses for coverage reports) to have access to additional tools:
2727

28-
```
28+
```txt
2929
# Use your system package manager. E.g. on Ubuntu:
3030
sudo apt install lcov
3131
```
3232

3333
Having `lcov` package installed you can extract information from your coverage reports:
3434

35-
```
35+
```txt
3636
# For a summary:
3737
lcov --summary your-coverage-report.dat
3838
# For details:
@@ -55,26 +55,78 @@ echo "coverage report at file://${destdir}/index.html"
5555

5656
```
5757

58-
### Support for testing frameworks
58+
## Support for testing frameworks
5959

6060
Coverage support has been only tested with [ScalaTest](http://www.scalatest.org/).
6161

62-
### Working around missing lambda coverage with Scala 2.12+
62+
## JaCoCo
6363

64-
The current Jacoco version in Bazel (0.8.3) has missing coverage for lambdas
65-
(including for comprehensions; see issue https://github.com/bazelbuild/rules_scala/issues/1056). Also, the support for
66-
filtering out code generated by the Scala compiler is quite reduced in Jacoco.
64+
`rules_scala` uses the [JaCoCo](https://www.jacoco.org/jacoco/) library imported
65+
by the underlying [`rules_java`](https://github.com/bazelbuild/rules_java)
66+
module to generate code coverage. `rules_java`, in turn, imports JaCoCo via the
67+
[`java_tools`](https://github.com/bazelbuild/java_tools) repository, built from
68+
the [tools/jdk/BUILD.java_tools](
69+
https://github.com/bazelbuild/bazel/blob/master/tools/jdk/BUILD.java_tools) file
70+
and [third_party/java/jacoco](
71+
https://github.com/bazelbuild/bazel/blob/master/third_party/java/jacoco/BUILD)
72+
package in the Bazel source. `java_tools` and `rules_java` are released more
73+
frequently than Bazel itself, decoupling them from the Bazel release cycle.
6774

68-
This can be worked around by building a fixed version of Jacoco yourselves (including backported fixes from 0.8.5) and reconfiguring your
69-
build to use that one instead of the default `jacocorunner`.
75+
To check the version of JaCoCo used by a specific version of `rules_java`:
7076

71-
You can build jacocorunner with a script in `scripts/build_jacocorunner/build_jacocorunner.sh` (see comments there for more explanation and options).
77+
- Open [`java/repositories.bzl` in the `rules_java` source](
78+
https://github.com/bazelbuild/rules_java/blob/master/java/repositories.bzl).
79+
80+
- Select a specific version of `rules_java` using the **Switch branches/tabs**
81+
dropdown menu.
82+
83+
- Alternatively, replace `master` with the `rules_java` version in the
84+
`java/repositories.bzl` URL.
85+
86+
- Make note of the version of `java_tools` specified in the `JAVA_TOOLS_CONFIG`
87+
dictionary. For example, [`rules_java` 8.9.0 uses `java_tools` v.13.16](
88+
https://github.com/bazelbuild/rules_java/blob/8.9.0/java/repositories.bzl#L49).
89+
90+
- Download the `java_tools` archive using the archive URL:
91+
92+
```txt
93+
curl -LO https://mirror.bazel.build/bazel_java_tools/releases/java/v13.16/java_tools-v13.16.zip
94+
```
95+
96+
- Unzip the archive, then inspect the top level `BUILD` file:
7297
73-
An older version of this script (for Bazel 4) can be found in `scripts/build_jacocorunner/build_jacocorunner_bazel_4.0.sh`.
98+
```sh
99+
$ grep 'jacoco\.core-' BUILD
100+
101+
jars = ["java_tools/third_party/java/jacoco/org.jacoco.core-0.8.11.jar"],
102+
srcjar = "java_tools/third_party/java/jacoco/org.jacoco.core-0.8.11-sources.jar",
103+
srcs = ["java_tools/third_party/java/jacoco/org.jacoco.core-0.8.11.jar"],
104+
```
105+
106+
| `rules_java` version | `java_tools` version | JaCoCo version |
107+
| :-: | :-: | :-: |
108+
| [8.9.0](https://github.com/bazelbuild/rules_java/blob/8.9.0/java/repositories.bzl#L49) | v13.16 | [0.8.11][JaCoCo version] |
109+
| [7.12.4](https://github.com/bazelbuild/rules_java/blob/7.12.4/java/repositories.bzl#L49) | v13.9 | [0.8.11][JaCoCo version] |
110+
111+
For information on updating the [JaCoCo version][] used by `rules_java`,
112+
`java_tools`, and Bazel, see [Bazel's &quot;Upgrading Jacoco version&quot;
113+
README](
114+
https://github.com/bazelbuild/bazel/blob/master/third_party/java/jacoco/README.md).
115+
116+
[JaCoCo version]: https://www.jacoco.org/jacoco/trunk/doc/changes.html
117+
118+
## Working around missing JaCoCo features
119+
120+
The version of JaCoCo that ships with `rules_java` may lack support for newer
121+
Scala features. To work around this, build an updated version of JaCoCo and
122+
configure the project to use this new artifact instead of the default
123+
`jacocorunner`.
124+
125+
You can build jacocorunner with a script in `scripts/build_jacocorunner/build_jacocorunner.sh` (see comments there for more explanation and options).
74126
75127
Then, you can use the `jacocorunner` property of `scala_toolchain` to provide the jacocorunner you have built:
76128
77-
```
129+
```py
78130
# Example contents of coverage_local_jacocorunner/BUILD
79131
scala_toolchain(
80132
name = "local_jacocorunner_toolchain_impl",
@@ -85,7 +137,7 @@ scala_toolchain(
85137
toolchain(
86138
name = "local_jacocorunner_scala_toolchain",
87139
toolchain = "local_jacocorunner_toolchain_impl",
88-
toolchain_type = "@io_bazel_rules_scala//scala:toolchain_type",
140+
toolchain_type = "@rules_scala//scala:toolchain_type",
89141
visibility = ["//visibility:public"],
90142
)
91143
@@ -100,15 +152,15 @@ keeping binaries in your repository).
100152

101153
Finally, provide the `scala_toolchain` in your `.bazelrc` or as an option to `bazel coverage`:
102154

103-
```
155+
```txt
104156
coverage --extra_toolchains="//coverage_local_jacocorunner:local_jacocorunner_scala_toolchain"
105157
```
106158

107159
You could also register the toolchain in your `WORKSPACE`.
108160

109161
You can verify that the locally built `jacocorunner` works with `manual_test/coverage_local_jacocorunner/test.sh`.
110162

111-
#### Notes
163+
## Notes
112164

113165
Please ensure these scripts use Java 8.
114166

0 commit comments

Comments
 (0)