Skip to content

Commit

Permalink
Replace WORKSPACE calls with scala_toolchains()
Browse files Browse the repository at this point in the history
Also added `@io_bazel_rules_scala_toolchains//...:all` to
`register_toolchains()` calls everywhere, even when not specifically
necessary. This proves the mechanism is safe and works with `WORKSPACE`
now, and will make future updates to consolidate other toolchains less
noisy.
  • Loading branch information
mbland committed Oct 25, 2024
1 parent 75a7d9f commit bd2364a
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 151 deletions.
26 changes: 8 additions & 18 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config(enable_compiler_dependency_tracking = True)

load(
"//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)
load("//scala:scala.bzl", "scala_toolchains")

rules_scala_setup()
scala_toolchains(fetch_sources = True)

rules_scala_toolchain_deps_repositories(fetch_sources = True)

scala_toolchains_repo()
register_toolchains(
"//testing:testing_toolchain",
"//scala:unused_dependency_checker_error_toolchain",
"//test/proto:scalapb_toolchain",
"@io_bazel_rules_scala_toolchains//...:all",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down Expand Up @@ -89,8 +87,6 @@ load("//specs2:specs2_junit.bzl", "specs2_junit_repositories")

specs2_junit_repositories()

register_toolchains("//testing:testing_toolchain")

load("//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories")

scalafmt_default_config()
Expand Down Expand Up @@ -122,12 +118,6 @@ local_repository(
path = "third_party/test/example_external_workspace",
)

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

scala_register_unused_deps_toolchains()

register_toolchains("@io_bazel_rules_scala//test/proto:scalapb_toolchain")

load("//scala:scala_maven_import_external.bzl", "java_import_external")

# bazel's java_import_external has been altered in rules_scala to be a macro based on jvm_import_external
Expand Down
18 changes: 6 additions & 12 deletions dt_patches/test_dt_patches/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +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",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
Expand Down Expand Up @@ -68,16 +63,15 @@ scala_maven_import_external(
server_urls = default_maven_server_urls(),
)

rules_scala_setup()

rules_scala_toolchain_deps_repositories(
scala_toolchains(
fetch_sources = True,
validate_scala_version = False,
)

scala_toolchains_repo()

register_toolchains(":dt_scala_toolchain")
register_toolchains(
":dt_scala_toolchain",
"@io_bazel_rules_scala_toolchains//...:all",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down
23 changes: 7 additions & 16 deletions dt_patches/test_dt_patches_user_srcjar/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +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",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_toolchains")
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"default_maven_server_urls",
Expand Down Expand Up @@ -123,16 +118,16 @@ srcjars_by_version = {
},
}

rules_scala_setup(scala_compiler_srcjar = srcjars_by_version[SCALA_VERSION])

rules_scala_toolchain_deps_repositories(
scala_toolchains(
fetch_sources = True,
scala_compiler_srcjars = srcjars_by_version,
validate_scala_version = False,
)

scala_toolchains_repo()

register_toolchains(":dt_scala_toolchain")
register_toolchains(
":dt_scala_toolchain",
"@io_bazel_rules_scala_toolchains//...:all",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand All @@ -149,7 +144,3 @@ rules_proto_toolchains()
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

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

scala_register_toolchains()
13 changes: 3 additions & 10 deletions examples/crossbuild/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,11 @@ scala_config(
],
)

load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories()
scala_toolchains()

scala_toolchains_repo()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down
13 changes: 3 additions & 10 deletions examples/scala3/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ 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",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories(fetch_sources = True)
scala_toolchains(fetch_sources = True)

scala_toolchains_repo()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down
22 changes: 7 additions & 15 deletions examples/semanticdb/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ 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",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories(fetch_sources = True)
scala_toolchains(fetch_sources = True)

scala_toolchains_repo()
register_toolchains(
#Register and use the custom toolchain that has semanticdb enabled
"//:semanticdb_toolchain",
"@io_bazel_rules_scala_toolchains//...:all",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand All @@ -62,8 +59,3 @@ rules_proto_toolchains()
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

#Register and use the custom toolchain that has semanticdb enabled
register_toolchains(
"//:semanticdb_toolchain",
)
18 changes: 6 additions & 12 deletions examples/testing/multi_frameworks_toolchain/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,14 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories(fetch_sources = True)
scala_toolchains(fetch_sources = True)

scala_toolchains_repo()
register_toolchains(
":testing_toolchain",
"@io_bazel_rules_scala_toolchains//...:all",
)

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down Expand Up @@ -73,5 +69,3 @@ scalatest_repositories()
junit_repositories()

specs2_junit_repositories()

register_toolchains(":testing_toolchain")
13 changes: 3 additions & 10 deletions examples/testing/scalatest_repositories/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories(fetch_sources = True)
scala_toolchains(fetch_sources = True)

scala_toolchains_repo()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down
13 changes: 3 additions & 10 deletions examples/testing/specs2_junit_repositories/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories(fetch_sources = True)
scala_toolchains(fetch_sources = True)

scala_toolchains_repo()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down
14 changes: 3 additions & 11 deletions test_cross_build/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,11 @@ scala_config(
)

# loads other rules Rules Scala depends on
load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

rules_scala_toolchain_deps_repositories()

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

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

scala_register_toolchains()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")

Expand Down
22 changes: 12 additions & 10 deletions test_version/WORKSPACE.template
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,24 @@ scala_config(enable_compiler_dependency_tracking = True)

load("@io_bazel_rules_scala//scala:scala_cross_version.bzl", "extract_major_version")

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

scala_toolchains(fetch_sources = True)

register_toolchains()
register_toolchains(
"@io_bazel_rules_scala//scala:unused_dependency_checker_error_toolchain",
"@io_bazel_rules_scala//testing:testing_toolchain",
"@io_bazel_rules_scala_toolchains//...:all",
)


load(
"@io_bazel_rules_scala//scala:scala.bzl",
"scala_repositories",
"scala_toolchains_repo",
)

scala_repositories(fetch_sources = True)

scala_toolchains_repo()

load(":scrooge_repositories.bzl", "scrooge_repositories")
${twitter_scrooge_repositories}
load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "twitter_scrooge")
Expand All @@ -89,9 +97,3 @@ specs2_junit_repositories()
load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "scalatest_toolchain")

scalatest_repositories()

register_toolchains("@io_bazel_rules_scala//testing:testing_toolchain")

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

scala_register_unused_deps_toolchains()
13 changes: 3 additions & 10 deletions third_party/test/example_external_workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

load(
"@io_bazel_rules_scala//scala:scala.bzl",
"rules_scala_setup",
"rules_scala_toolchain_deps_repositories",
"scala_toolchains_repo",
)

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

rules_scala_toolchain_deps_repositories(fetch_sources = True)
scala_toolchains(fetch_sources = True)

scala_toolchains_repo()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down
10 changes: 3 additions & 7 deletions third_party/test/proto/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@ load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")

scala_config()

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

scala_repositories()
scala_toolchains()

scala_toolchains_repo()
register_toolchains("@io_bazel_rules_scala_toolchains//...:all")

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

Expand Down

0 comments on commit bd2364a

Please sign in to comment.