Skip to content

Commit cd1bf15

Browse files
authored
Fix setup_scala_testing_toolchain() classpaths (#1707)
* Fix `setup_scala_testing_toolchain()` classpaths Fixes #1706. Removes the addition of the Scala version suffix to `*_classpath` argument labels in `setup_scala_testing_toolchain()`. To facilitate the fix: - Moves everything from `testing/deps.bzl` into `testing/testing.bzl` and removes the original `testing/deps.bzl` file. - Updates `repositories()` from `scala/scala_cross_version.bzl` to accept and return `None` as an argument. - Updates `examples/testing/multi_frameworks_toolchain/BUILD` to provide a reproduction and validation of the fix. After updating `multi_frameworks_toolchain/BUILD`, but before applying the fix, the `multi_framework_toolchain_example` test case broke in a similar fashion to #1706: ```txt $ RULES_SCALA_TEST_ONLY=multi_framework_toolchain_example \ ./test_examples.sh running test multi_framework_toolchain_example ERROR: .../examples/testing/multi_frameworks_toolchain/BUILD:19:30: no such package '@io_bazel_rules_scala_org_specs2_specs2_fp_2_12_20_2_12_20//': The repository '@io_bazel_rules_scala_org_specs2_specs2_fp_2_12_20_2_12_20' could not be resolved: Repository '@io_bazel_rules_scala_org_specs2_specs2_fp_2_12_20_2_12_20' is not defined and referenced by '//:testing_toolchain_specs2_classpath_provider' ERROR: Analysis of target '//:testing_toolchain_specs2_classpath_provider' failed; build aborted: Analysis failed INFO: Elapsed time: 0.159s INFO: 0 processes. ERROR: Couldn't start the build. Unable to run tests ``` * Fix `repositories()` docstring grammatical error
1 parent 78e860f commit cd1bf15

File tree

5 files changed

+96
-55
lines changed

5 files changed

+96
-55
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,60 @@
1+
load("@rules_scala//scala:scala_cross_version.bzl", "repositories")
12
load(
23
"@rules_scala//testing:testing.bzl",
34
"setup_scala_testing_toolchain",
45
)
6+
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")
57

8+
# This example uses the same toolchain deps you'd get from using
9+
# `scala_toolchains(junit = True, scalatest = True, specs2 = True)`. It's a
10+
# working example that we test via `test_examples.sh` that avoids introducing a
11+
# dependency on `rules_jvm_external` (for now).
12+
#
13+
# Normally, you'd use `rules_jvm_external` and references to artifacts like
14+
# `@maven//:org_scalatest_scalatest_shouldmatchers_2_13` to define custom
15+
# classpaths.
16+
#
17+
# You would _not_ need to load `repositories` or `SCALA_VERSION`. This example
18+
# needs them to test against a regression of #1706.
619
setup_scala_testing_toolchain(
720
name = "testing_toolchain",
8-
junit_classpath = [
9-
"@io_bazel_rules_scala_junit_junit",
10-
"@io_bazel_rules_scala_org_hamcrest_hamcrest_core",
11-
],
12-
scalatest_classpath = [
13-
"@io_bazel_rules_scala_scalactic",
14-
"@io_bazel_rules_scala_scalatest",
15-
"@io_bazel_rules_scala_scalatest_compatible",
16-
"@io_bazel_rules_scala_scalatest_core",
17-
"@io_bazel_rules_scala_scalatest_featurespec",
18-
"@io_bazel_rules_scala_scalatest_flatspec",
19-
"@io_bazel_rules_scala_scalatest_freespec",
20-
"@io_bazel_rules_scala_scalatest_funspec",
21-
"@io_bazel_rules_scala_scalatest_funsuite",
22-
"@io_bazel_rules_scala_scalatest_matchers_core",
23-
"@io_bazel_rules_scala_scalatest_mustmatchers",
24-
"@io_bazel_rules_scala_scalatest_shouldmatchers",
25-
],
26-
specs2_classpath = [
27-
"@io_bazel_rules_scala_org_specs2_specs2_common",
28-
"@io_bazel_rules_scala_org_specs2_specs2_core",
29-
"@io_bazel_rules_scala_org_specs2_specs2_fp",
30-
"@io_bazel_rules_scala_org_specs2_specs2_matcher",
31-
],
32-
specs2_junit_classpath = [
33-
"@io_bazel_rules_scala_org_specs2_specs2_junit",
34-
],
21+
junit_classpath = repositories(
22+
SCALA_VERSION,
23+
[
24+
"@io_bazel_rules_scala_junit_junit",
25+
"@io_bazel_rules_scala_org_hamcrest_hamcrest_core",
26+
],
27+
),
28+
scalatest_classpath = repositories(
29+
SCALA_VERSION,
30+
[
31+
"@io_bazel_rules_scala_scalactic",
32+
"@io_bazel_rules_scala_scalatest",
33+
"@io_bazel_rules_scala_scalatest_compatible",
34+
"@io_bazel_rules_scala_scalatest_core",
35+
"@io_bazel_rules_scala_scalatest_featurespec",
36+
"@io_bazel_rules_scala_scalatest_flatspec",
37+
"@io_bazel_rules_scala_scalatest_freespec",
38+
"@io_bazel_rules_scala_scalatest_funspec",
39+
"@io_bazel_rules_scala_scalatest_funsuite",
40+
"@io_bazel_rules_scala_scalatest_matchers_core",
41+
"@io_bazel_rules_scala_scalatest_mustmatchers",
42+
"@io_bazel_rules_scala_scalatest_shouldmatchers",
43+
],
44+
),
45+
specs2_classpath = repositories(
46+
SCALA_VERSION,
47+
[
48+
"@io_bazel_rules_scala_org_specs2_specs2_common",
49+
"@io_bazel_rules_scala_org_specs2_specs2_core",
50+
"@io_bazel_rules_scala_org_specs2_specs2_fp",
51+
"@io_bazel_rules_scala_org_specs2_specs2_matcher",
52+
],
53+
),
54+
specs2_junit_classpath = repositories(
55+
SCALA_VERSION,
56+
[
57+
"@io_bazel_rules_scala_org_specs2_specs2_junit",
58+
],
59+
),
3560
)

scala/scala_cross_version.bzl

+16-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,22 @@ def version_suffix(scala_version):
5353
return "_" + sanitize_version(scala_version)
5454

5555
def repositories(scala_version, repos):
56-
"""Adds the Scala version suffix to a list of repository IDs."""
56+
"""Adds the Scala version suffix to a list of repository IDs.
57+
58+
If `repos` is `None`, this will return `None`. This enables the massaging of
59+
optional function arguments.
60+
61+
Args:
62+
scala_version: the Scala version to append to each repo name
63+
repos: list of repository names
64+
65+
Returns:
66+
a list of repository names with the Scala version suffix appended, or
67+
`None` if `repos` is `None`
68+
"""
69+
if repos == None:
70+
return None
71+
5772
suffix = version_suffix(scala_version)
5873
return [repo + suffix for repo in repos]
5974

scala/toolchains_repo.bzl

+8-7
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ load(
155155
"""
156156

157157
_TESTING_TOOLCHAIN_BUILD = """
158-
load("@@{rules_scala_repo}//scala:scala_cross_version.bzl", "version_suffix")
159158
load(
160-
"@@{rules_scala_repo}//testing:deps.bzl",
161-
"{deps_symbols}",
159+
"@@{rules_scala_repo}//scala:scala_cross_version.bzl",
160+
"repositories",
161+
"version_suffix",
162162
)
163163
load(
164164
"@@{rules_scala_repo}//testing:testing.bzl",
165+
"{deps_symbols}",
165166
"setup_scala_testing_toolchain",
166167
)
167168
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSIONS")
@@ -170,10 +171,10 @@ load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSIONS")
170171
setup_scala_testing_toolchain(
171172
name = "testing_toolchain" + version_suffix(scala_version),
172173
scala_version = scala_version,
173-
scalatest_classpath = {scalatest},
174-
junit_classpath = {junit},
175-
specs2_classpath = {specs2},
176-
specs2_junit_classpath = {specs2_junit},
174+
scalatest_classpath = repositories(scala_version, {scalatest}),
175+
junit_classpath = repositories(scala_version, {junit}),
176+
specs2_classpath = repositories(scala_version, {specs2}),
177+
specs2_junit_classpath = repositories(scala_version, {specs2_junit}),
177178
)
178179
for scala_version in SCALA_VERSIONS
179180
]

testing/deps.bzl

-15
This file was deleted.

testing/testing.bzl

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1+
load("//junit:junit.bzl", "junit_artifact_ids")
12
load("//scala:providers.bzl", "declare_deps_provider")
2-
load("//scala:scala_cross_version.bzl", "repositories", "version_suffix")
3+
load("//scala:scala_cross_version.bzl", "version_suffix")
4+
load("//scalatest:scalatest.bzl", "scalatest_artifact_ids")
5+
load("//specs2:specs2.bzl", "specs2_artifact_ids")
6+
load("//specs2:specs2_junit.bzl", "specs2_junit_artifact_ids")
37
load("//testing/toolchain:toolchain.bzl", "scala_testing_toolchain")
48
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")
59

10+
def _repoize(ids):
11+
return ["@" + id for id in ids]
12+
13+
JUNIT_DEPS = _repoize(junit_artifact_ids())
14+
15+
SCALATEST_DEPS = _repoize(scalatest_artifact_ids())
16+
17+
SPECS2_DEPS = _repoize(specs2_artifact_ids())
18+
19+
SPECS2_JUNIT_DEPS = _repoize(specs2_junit_artifact_ids())
20+
621
DEP_PROVIDERS = [
722
"junit_classpath",
823
"scalatest_classpath",
@@ -35,7 +50,7 @@ def setup_scala_testing_toolchain(
3550
_declare_deps_provider(
3651
name,
3752
"junit_classpath",
38-
repositories(scala_version, junit_classpath),
53+
junit_classpath,
3954
visibility,
4055
),
4156
)
@@ -45,7 +60,7 @@ def setup_scala_testing_toolchain(
4560
_declare_deps_provider(
4661
name,
4762
"specs2_junit_classpath",
48-
repositories(scala_version, specs2_junit_classpath),
63+
specs2_junit_classpath,
4964
visibility,
5065
),
5166
)
@@ -55,7 +70,7 @@ def setup_scala_testing_toolchain(
5570
_declare_deps_provider(
5671
name,
5772
"specs2_classpath",
58-
repositories(scala_version, specs2_classpath),
73+
specs2_classpath,
5974
visibility,
6075
),
6176
)
@@ -65,7 +80,7 @@ def setup_scala_testing_toolchain(
6580
_declare_deps_provider(
6681
name,
6782
"scalatest_classpath",
68-
repositories(scala_version, scalatest_classpath),
83+
scalatest_classpath,
6984
visibility,
7085
),
7186
)

0 commit comments

Comments
 (0)