Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use version-aware naming for scala_compiler_source repository #1560

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions scala/private/macros/scala_repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load(
"@io_bazel_rules_scala//scala:scala_cross_version.bzl",
"extract_major_version",
"extract_minor_version",
"version_suffix",
_default_maven_server_urls = "default_maven_server_urls",
)
load("//third_party/repositories:repositories.bzl", "repositories")
load(
"@io_bazel_rules_scala_config//:config.bzl",
"SCALA_MAJOR_VERSION",
"SCALA_MINOR_VERSION",
"SCALA_VERSION",
"SCALA_VERSIONS",
)

def _dt_patched_compiler_impl(rctx):
Expand Down Expand Up @@ -37,16 +39,18 @@ def _validate_scalac_srcjar(srcjar):
count += 1
return count == 1

def dt_patched_compiler_setup(scala_compiler_srcjar = None):
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.patch" % SCALA_MAJOR_VERSION
def dt_patched_compiler_setup(scala_version, scala_compiler_srcjar = None):
scala_major_version = extract_major_version(scala_version)
scala_minor_version = extract_minor_version(scala_version)
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.patch" % scala_major_version

minor_version = int(SCALA_MINOR_VERSION)
minor_version = int(scala_minor_version)

if SCALA_MAJOR_VERSION == "2.12":
if scala_major_version == "2.12":
if minor_version >= 1 and minor_version <= 7:
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.1.patch" % SCALA_MAJOR_VERSION
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.1.patch" % scala_major_version
elif minor_version <= 11:
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.8.patch" % SCALA_MAJOR_VERSION
patch = "@io_bazel_rules_scala//dt_patches:dt_compiler_%s.8.patch" % scala_major_version

build_file_content = "\n".join([
"package(default_visibility = [\"//visibility:public\"])",
Expand All @@ -56,7 +60,7 @@ def dt_patched_compiler_setup(scala_compiler_srcjar = None):
")",
])
default_scalac_srcjar = {
"url": "https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/%s/scala-compiler-%s-sources.jar" % (SCALA_VERSION, SCALA_VERSION),
"url": "https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/%s/scala-compiler-%s-sources.jar" % (scala_version, scala_version),
}
srcjar = scala_compiler_srcjar if scala_compiler_srcjar != None else default_scalac_srcjar
_validate_scalac_srcjar(srcjar) or fail(
Expand All @@ -65,14 +69,14 @@ def dt_patched_compiler_setup(scala_compiler_srcjar = None):
)
if "label" in srcjar:
dt_patched_compiler(
name = "scala_compiler_source",
name = "scala_compiler_source" + version_suffix(scala_version),
build_file_content = build_file_content,
patch = patch,
srcjar = srcjar["label"],
)
else:
http_archive(
name = "scala_compiler_source",
name = "scala_compiler_source" + version_suffix(scala_version),
build_file_content = build_file_content,
patches = [patch],
url = srcjar.get("url"),
Expand Down Expand Up @@ -120,7 +124,8 @@ def rules_scala_setup(scala_compiler_srcjar = None):
],
)

dt_patched_compiler_setup(scala_compiler_srcjar)
for scala_version in SCALA_VERSIONS:
dt_patched_compiler_setup(scala_version, scala_compiler_srcjar)

ARTIFACT_IDS = [
"io_bazel_rules_scala_scala_library",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
load("//scala:scala.bzl", "scala_library_for_plugin_bootstrapping")
load("//scala:scala_cross_version.bzl", "version_suffix")
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")

scala_library_for_plugin_bootstrapping(
name = "dep_reporting_compiler",
srcs = ["@scala_compiler_source//:src"],
srcs = ["@scala_compiler_source%s//:src" % version_suffix(SCALA_VERSION)],
scalac_jvm_flags = ["-Xmx128M"], # fixme - workaround for a failing test
visibility = ["//visibility:public"],
deps = ["//scala/private/toolchain_deps:scala_compile_classpath"],
Expand Down