Toolchainize all testing toolchains #1653
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Moves the Scalatest, JUnit, and Specs2 toolchains into
@io_bazel_rules_scala_toolchains//testing
. Part of #1482.Introduces more macros to return a framework's Maven artifact dependencies, rather than inlining them in a
repositories
call. These inlined lists are replaced by macro invocations, and now thescala_toolchains
macro can invoke these macros to collect artifact IDs to pass torepositories
. This also allows for future changes to introduce ascala_version
parameter if necessary, similar to howscalafmt_artifact_ids
already works.Updates all
WORKSPACE
files to set the appropriatescala_toolchains
parameters and to remove the unnecessary repository import and toolchain registration macros.Adds a
fetch_sources_by_id
parameter torepositories
fromthird_party/repositories/repositories.bzl
.Updates
scala/scala_maven_import_external.bzl
to generate aload
line for//scala:scala_import.bzl
based on the repo's canonical name, not@io_bazel_rules_scala
.As usual, includes several other opportunistic removals of the
@io_bazel_rules_scala
repo name prefix to avoid an internal dependency on that name.Motivation
The macros returning artifact ID lists help avoid collisions when creating repositories dependencies upon which multiple frameworks depend under Bzlmod.
WORKSPACE
doesn't seem affected by these collisions, but Bzlmod will produce errors like the following, where bothscala_proto
andtwitter_scrooge
depend uponio_bazel_rules_scala_guava
:Recent updates to
scripts/create_repository.py
(#1639, #1642) make it easy to emit full direct dependency lists for artifacts included inthird_party/repositories/scala_*.bzl
. This increases the likelihood of collisions, since this expanded metadata forces the macros that instantiate artifact repos to instantiate even more repos.By fetching lists of artifact IDs from these macros,
scala_toolchains
can now consolidate them into dictionary keys. Then it passes these unique keys torepositories
directly, avoiding the problem of instantiating the same repo multiple times in the same module extension.This, in turn, also avoids the need to add parameters to the original
WORKSPACE
macros that instantiate dependencies to avoid collisions under Bzlmod. Thescala_toolchains
macro never needs to call these original macros, under eitherWORKSPACE
or Bzlmod.Finally, it also reduces duplication between these artifact ID lists and the
_*_DEPS
symbols originally fromtesting/BUILD
(and now intesting/deps.bzl
). The dependency labels are now generated programatically.(Aside: As I mentioned, we may eventually need to pass a Scala version argument to these macros. It will be possible to cross that bridge without too much trouble if and when that day comes. Or I can try to future proof it in a follow up pull request.)
Adding the
fetch_sources_by_id
parameter torepositories()
enablesscala_toolchains
to build theartifact_ids_to_fetch_sources
mapping from artifact ID lists returned by these new macros. The values assigned to each id match the originalfetch_sources
settings in the corresponding originalWORKSPACE
macros.Removing
@io_bazel_rules_scala
target prefixes means Bzlmod users won't necessarily have to set therepo_name
parameter ofbazel_dep
when usingrules_scala
.