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

Create the @scala_compiler_sources repo #1635

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 37 additions & 1 deletion scala/private/macros/scala_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@ dt_patched_compiler = repository_rule(
implementation = _dt_patched_compiler_impl,
)

_PACKAGE_VISIBILITY_PUBLIC = """package(
default_visibility = [\"//visibility:public\"],
)
"""

_COMPILER_SOURCE_ALIAS_FORMAT = """alias(
name = "src{scala_version_suffix}",
actual = "@scala_compiler_source{scala_version_suffix}//:src",
visibility = ["//visibility:public"],
)
"""

def _compiler_sources_repo_impl(rctx):
build_content = [_PACKAGE_VISIBILITY_PUBLIC]
build_content.extend([
_COMPILER_SOURCE_ALIAS_FORMAT.format(
scala_version_suffix = version_suffix(scala_version),
)
for scala_version in SCALA_VERSIONS
])

rctx.file("BUILD", content = "\n".join(build_content), executable = False)

compiler_sources_repo = repository_rule(
implementation = _compiler_sources_repo_impl,
attrs = {
"scala_versions": attr.string_list(mandatory = True),
},
)

def _validate_scalac_srcjar(srcjar):
if type(srcjar) != "dict":
return False
Expand All @@ -49,7 +79,8 @@ def dt_patched_compiler_setup(scala_version, scala_compiler_srcjar = None):
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\"])",
_PACKAGE_VISIBILITY_PUBLIC,
"",
"filegroup(",
" name = \"src\",",
" srcs=[\"scala/tools/nsc/symtab/SymbolLoaders.scala\"],",
Expand Down Expand Up @@ -137,6 +168,11 @@ def rules_scala_setup(scala_compiler_srcjar = None):
for scala_version in SCALA_VERSIONS:
dt_patched_compiler_setup(scala_version, scala_compiler_srcjar)

compiler_sources_repo(
name = "scala_compiler_sources",
scala_versions = SCALA_VERSIONS,
)

def _artifact_ids(scala_version):
return [
"io_bazel_rules_scala_scala_library",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ load("@io_bazel_rules_scala//scala:scala_cross_version.bzl", "version_suffix")
scala_library_for_plugin_bootstrapping(
name = "dep_reporting_compiler",
srcs = select({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are hiding/unifying version specific repositories under @scala_compiler_sources maybe this select should be moved into that repository. I mean @scala_compiler_sources would have a single alias target with select to version specific sources. For example:

alias(
  name = "src",
  visibility = ["//visibility:public"],
  actual = select({"@io_bazel_rules_scala_config//:scala_version_2_12_19": "@scala_compiler_source_2_12_19//:src"}),
)

And here in compilation target you would specify srcs = ["@scala_compiler_sources//:src"],

What do you think?

Also I think that compilation target could go into that new repository, but let's not go down that rabbit hole now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. Done.

"@io_bazel_rules_scala_config//:scala_version" + version_suffix(v): ["@scala_compiler_source%s//:src" % version_suffix(v)]
"@io_bazel_rules_scala_config//:scala_version" + version_suffix(v): [
"@scala_compiler_sources//:src%s" % version_suffix(v),
]
for v in SCALA_VERSIONS
}),
scalac_jvm_flags = ["-Xmx128M"], # fixme - workaround for a failing test
Expand Down