Skip to content

Commit 269e736

Browse files
committed
Use version-aware naming for scala_compiler_source repository
A small preparation for multiple `SCALA_VERSIONS`.
1 parent a779ad0 commit 269e736

File tree

2 files changed

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

2 files changed

+20
-13
lines changed

scala/private/macros/scala_repositories.bzl

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22
load(
33
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
4+
"extract_major_version",
5+
"extract_minor_version",
6+
"version_suffix",
47
_default_maven_server_urls = "default_maven_server_urls",
58
)
69
load("//third_party/repositories:repositories.bzl", "repositories")
710
load(
811
"@io_bazel_rules_scala_config//:config.bzl",
912
"SCALA_MAJOR_VERSION",
10-
"SCALA_MINOR_VERSION",
11-
"SCALA_VERSION",
13+
"SCALA_VERSIONS",
1214
)
1315

1416
def _dt_patched_compiler_impl(rctx):
@@ -37,16 +39,18 @@ def _validate_scalac_srcjar(srcjar):
3739
count += 1
3840
return count == 1
3941

40-
def dt_patched_compiler_setup(scala_compiler_srcjar = None):
41-
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.patch" % SCALA_MAJOR_VERSION
42+
def dt_patched_compiler_setup(scala_version, scala_compiler_srcjar = None):
43+
scala_major_version = extract_major_version(scala_version)
44+
scala_minor_version = extract_minor_version(scala_version)
45+
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.patch" % scala_major_version
4246

43-
minor_version = int(SCALA_MINOR_VERSION)
47+
minor_version = int(scala_minor_version)
4448

45-
if SCALA_MAJOR_VERSION == "2.12":
49+
if scala_major_version == "2.12":
4650
if minor_version >= 1 and minor_version <= 7:
47-
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.1.patch" % SCALA_MAJOR_VERSION
51+
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.1.patch" % scala_major_version
4852
elif minor_version <= 11:
49-
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.8.patch" % SCALA_MAJOR_VERSION
53+
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.8.patch" % scala_major_version
5054

5155
build_file_content = "\n".join([
5256
"package(default_visibility = [\"//visibility:public\"])",
@@ -56,7 +60,7 @@ def dt_patched_compiler_setup(scala_compiler_srcjar = None):
5660
")",
5761
])
5862
default_scalac_srcjar = {
59-
"url": "https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/%s/scala-compiler-%s-sources.jar" % (SCALA_VERSION, SCALA_VERSION),
63+
"url": "https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/%s/scala-compiler-%s-sources.jar" % (scala_version, scala_version),
6064
}
6165
srcjar = scala_compiler_srcjar if scala_compiler_srcjar != None else default_scalac_srcjar
6266
_validate_scalac_srcjar(srcjar) or fail(
@@ -65,14 +69,14 @@ def dt_patched_compiler_setup(scala_compiler_srcjar = None):
6569
)
6670
if "label" in srcjar:
6771
dt_patched_compiler(
68-
name = "scala_compiler_source",
72+
name = "scala_compiler_source" + version_suffix(scala_version),
6973
build_file_content = build_file_content,
7074
patch = patch,
7175
srcjar = srcjar["label"],
7276
)
7377
else:
7478
http_archive(
75-
name = "scala_compiler_source",
79+
name = "scala_compiler_source" + version_suffix(scala_version),
7680
build_file_content = build_file_content,
7781
patches = [patch],
7882
url = srcjar.get("url"),
@@ -120,7 +124,8 @@ def rules_scala_setup(scala_compiler_srcjar = None):
120124
],
121125
)
122126

123-
dt_patched_compiler_setup(scala_compiler_srcjar)
127+
for scala_version in SCALA_VERSIONS:
128+
dt_patched_compiler_setup(scala_version, scala_compiler_srcjar)
124129

125130
ARTIFACT_IDS = [
126131
"io_bazel_rules_scala_scala_library",

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
load("//scala:scala.bzl", "scala_library_for_plugin_bootstrapping")
2+
load("//scala:scala_cross_version.bzl", "version_suffix")
3+
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")
24

35
scala_library_for_plugin_bootstrapping(
46
name = "dep_reporting_compiler",
5-
srcs = ["@scala_compiler_source//:src"],
7+
srcs = ["@scala_compiler_source%s//:src" % version_suffix(SCALA_VERSION)],
68
scalac_jvm_flags = ["-Xmx128M"], # fixme - workaround for a failing test
79
visibility = ["//visibility:public"],
810
deps = ["//scala/private/toolchain_deps:scala_compile_classpath"],

0 commit comments

Comments
 (0)