Skip to content

Commit ca27760

Browse files
authored
Create the @scala_compiler_sources repo (bazel-contrib#1635)
* Create the `@scala_compiler_sources` repo Contains aliases to versioned Scala compiler source repository targets. Part of bazel-contrib#1482. Updates the version specific repo references in the srcs attribute of `//third_party/dependency_analyzer/src/main/io/bazel/rulesscala/dependencyanalyzer/compiler:dep_reporting_compiler`. Now these are references to versioned targets in `@scala_compiler_sources//`, which are aliases to those versioned compiler source repos. In a Bzlmod world, this enables `rules_scala` to import only the `scala_compiler_sources` repo in `MODULE.bazel`, instead of importing each individual versioned compiler source repo. This then allows `rules_scala` clients to set multiple `SCALA_VERSIONS` without requiring them to import this repo or any versioned compiler source repo. The Bzlmodifcation of the test repos under `dt_patches` (coming in a future change) revealed the need for this flexibility. * Push select() into @scala_compiler_sources//:src Requested by @simuons in bazel-contrib#1635.
1 parent 487c2fa commit ca27760

File tree

2 files changed

+37
-6
lines changed
  • scala/private/macros
  • third_party/dependency_analyzer/src/main/io/bazel/rulesscala/dependencyanalyzer/compiler

2 files changed

+37
-6
lines changed

scala/private/macros/scala_repositories.bzl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,37 @@ dt_patched_compiler = repository_rule(
2525
implementation = _dt_patched_compiler_impl,
2626
)
2727

28+
_COMPILER_SOURCE_ALIAS_TEMPLATE = """alias(
29+
name = "src",
30+
visibility = ["//visibility:public"],
31+
actual = select({{{compiler_sources}
32+
}}),
33+
)
34+
"""
35+
36+
_COMPILER_SOURCES_ENTRY_TEMPLATE = """
37+
"@io_bazel_rules_scala_config//:scala_version{scala_version_suffix}":
38+
"@scala_compiler_source{scala_version_suffix}//:src","""
39+
40+
def _compiler_sources_repo_impl(rctx):
41+
sources = [
42+
_COMPILER_SOURCES_ENTRY_TEMPLATE.format(
43+
scala_version_suffix = version_suffix(scala_version),
44+
)
45+
for scala_version in SCALA_VERSIONS
46+
]
47+
build_content = _COMPILER_SOURCE_ALIAS_TEMPLATE.format(
48+
compiler_sources = "".join(sources),
49+
)
50+
rctx.file("BUILD", content = build_content, executable = False)
51+
52+
compiler_sources_repo = repository_rule(
53+
implementation = _compiler_sources_repo_impl,
54+
attrs = {
55+
"scala_versions": attr.string_list(mandatory = True),
56+
},
57+
)
58+
2859
def _validate_scalac_srcjar(srcjar):
2960
if type(srcjar) != "dict":
3061
return False
@@ -137,6 +168,11 @@ def rules_scala_setup(scala_compiler_srcjar = None):
137168
for scala_version in SCALA_VERSIONS:
138169
dt_patched_compiler_setup(scala_version, scala_compiler_srcjar)
139170

171+
compiler_sources_repo(
172+
name = "scala_compiler_sources",
173+
scala_versions = SCALA_VERSIONS,
174+
)
175+
140176
def _artifact_ids(scala_version):
141177
return [
142178
"io_bazel_rules_scala_scala_library",

third_party/dependency_analyzer/src/main/io/bazel/rulesscala/dependencyanalyzer/compiler/BUILD

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
load("//scala:scala.bzl", "scala_library_for_plugin_bootstrapping")
2-
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSIONS")
3-
load("@io_bazel_rules_scala//scala:scala_cross_version.bzl", "version_suffix")
42

53
scala_library_for_plugin_bootstrapping(
64
name = "dep_reporting_compiler",
7-
srcs = select({
8-
"@io_bazel_rules_scala_config//:scala_version" + version_suffix(v): ["@scala_compiler_source%s//:src" % version_suffix(v)]
9-
for v in SCALA_VERSIONS
10-
}),
5+
srcs = ["@scala_compiler_sources//:src"],
116
scalac_jvm_flags = ["-Xmx128M"], # fixme - workaround for a failing test
127
visibility = ["//visibility:public"],
138
deps = ["//scala/private/toolchain_deps:scala_compile_classpath"],

0 commit comments

Comments
 (0)