Skip to content

Commit

Permalink
Move scala_toolchains to scala/toolchains.bzl
Browse files Browse the repository at this point in the history
Removes this symbol from `scala/scala.bzl` as well as
`setup_scala_testing_toolchain`, and deletes
`scala/private/macros/toolchains.bzl`. Part of bazelbuild#1482 and bazelbuild#1652.

This is required for Bazel 8 and `rules_java` 8 compatibility, but is
also compatible with Bazel 6 and 7. In bazelbuild#1652, @hvadehra suggested
partitioning the `.bzl` files such that `WORKSPACE` doesn't `load` a
file that tries to `load` symbols from `rules_java`. I successfully did
so in a separate branch, and along with other minor changes, got
`rules_scala` to build with `rules_java` 8.5.1.

The other changes will come in separate pull requests, but it makes
sense to land this change now before adding any other toolchains to
`scala_toolchains`.

---

Arguably, we should remove all macros exported from `scala/scala.bzl`
that only instantiate toolchain dependencies and define toolchains. That
may be a breaking change for some users, but will ultimately be
necessary for these macros to remain compatible with Bazel 8.
  • Loading branch information
mbland committed Dec 1, 2024
1 parent 1ec795e commit 3d2c94d
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 158 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(enable_compiler_dependency_tracking = True)

load("//scala:scala.bzl", "scala_toolchains")
load("//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(
fetch_sources = True,
Expand Down
22 changes: 17 additions & 5 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ Test framework dependencies are configured via testing toolchain. For convenienc
`setup_scala_testing_toolchain` can be used to define such toolchains.

```starlark
load("@io_bazel_rules_scala//scala:scala.bzl", "setup_scala_testing_toolchain")
load(
"@io_bazel_rules_scala//testing:testing.bzl",
"setup_scala_testing_toolchain",
)
```

Attributes
Expand All @@ -53,7 +56,10 @@ Examples (assumes maven deps are managed with rules_jvm_external):

```starlark
# BUILD
load("@io_bazel_rules_scala//scala:scala.bzl", "setup_scala_testing_toolchain")
load(
"@io_bazel_rules_scala//testing:testing.bzl",
"setup_scala_testing_toolchain",
)

setup_scala_testing_toolchain(
name = "scalatest_toolchain",
Expand All @@ -77,7 +83,10 @@ register_toolchains('//:scalatest_toolchain')
#### JUnit 4
```starlark
# BUILD
load("@io_bazel_rules_scala//scala:scala.bzl", "setup_scala_testing_toolchain")
load(
"@io_bazel_rules_scala//testing:testing.bzl",
"setup_scala_testing_toolchain",
)

setup_scala_testing_toolchain(
name = "junit_toolchain",
Expand All @@ -98,7 +107,10 @@ For Specs2 rules to work, `junit_classpath`, `specs2_junit_classpath` and `specs
be configured.
```starlark
# BUILD
load("@io_bazel_rules_scala//scala:scala.bzl", "setup_scala_testing_toolchain")
load(
"@io_bazel_rules_scala//testing:testing.bzl",
"setup_scala_testing_toolchain",
)

setup_scala_testing_toolchain(
name = "specs2_toolchain",
Expand All @@ -122,4 +134,4 @@ Register the toolchain
```starlark
# WORKSPACE
register_toolchains('//:specs2_toolchain')
```
```
2 changes: 1 addition & 1 deletion dt_patches/test_dt_patches/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(enable_compiler_dependency_tracking = True)

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
Expand Down
2 changes: 1 addition & 1 deletion dt_patches/test_dt_patches_user_srcjar/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(enable_compiler_dependency_tracking = True)

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
Expand Down
2 changes: 1 addition & 1 deletion examples/crossbuild/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ scala_config(
],
)

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(scalatest = True)

Expand Down
2 changes: 1 addition & 1 deletion examples/scala3/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(scala_version = "3.5.2")

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(fetch_sources = True)

Expand Down
2 changes: 1 addition & 1 deletion examples/semanticdb/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(scala_version = "2.13.15")

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(fetch_sources = True)

Expand Down
5 changes: 4 additions & 1 deletion examples/testing/multi_frameworks_toolchain/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "setup_scala_testing_toolchain")
load(
"@io_bazel_rules_scala//testing:testing.bzl",
"setup_scala_testing_toolchain",
)

setup_scala_testing_toolchain(
name = "testing_toolchain",
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/multi_frameworks_toolchain/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(
fetch_sources = True,
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/scalatest_repositories/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(
fetch_sources = True,
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/specs2_junit_repositories/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_toolchains")

scala_toolchains(
fetch_sources = True,
Expand Down
128 changes: 0 additions & 128 deletions scala/private/macros/toolchains.bzl

This file was deleted.

5 changes: 4 additions & 1 deletion scala/private/macros/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ load(
"""

_TESTING_TOOLCHAIN_BUILD = """
load("@@{rules_scala_repo}//scala:scala.bzl", "setup_scala_testing_toolchain")
load("@@{rules_scala_repo}//scala:scala_cross_version.bzl", "version_suffix")
load(
"@@{rules_scala_repo}//testing:deps.bzl",
"{deps_symbols}",
)
load(
"@@{rules_scala_repo}//testing:testing.bzl",
"setup_scala_testing_toolchain",
)
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSIONS")
[
Expand Down
10 changes: 0 additions & 10 deletions scala/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ load(
"//specs2:specs2_junit.bzl",
_specs2_junit_dependencies = "specs2_junit_dependencies",
)
load(
"//scala/private:macros/toolchains.bzl",
_scala_toolchains = "scala_toolchains",
)
load(
"//scala/private:macros/toolchains_repo.bzl",
_scala_toolchains_repo = "scala_toolchains_repo",
Expand Down Expand Up @@ -50,10 +46,6 @@ load(
_scala_test = "scala_test",
_scala_test_suite = "scala_test_suite",
)
load(
"//testing:testing.bzl",
_setup_scala_testing_toolchain = "setup_scala_testing_toolchain",
)

def scala_specs2_junit_test(name, **kwargs):
_scala_junit_test(
Expand Down Expand Up @@ -87,7 +79,5 @@ rules_scala_setup = _rules_scala_setup
rules_scala_toolchain_deps_repositories = _rules_scala_toolchain_deps_repositories
scala_test = _scala_test
scala_test_suite = _scala_test_suite
setup_scala_testing_toolchain = _setup_scala_testing_toolchain
setup_scala_toolchain = _setup_scala_toolchain
scala_toolchains = _scala_toolchains
scala_toolchains_repo = _scala_toolchains_repo
Loading

0 comments on commit 3d2c94d

Please sign in to comment.