Skip to content
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
53 changes: 8 additions & 45 deletions scala/BUILD
Original file line number Diff line number Diff line change
@@ -1,65 +1,28 @@
load("@rules_java//java:defs.bzl", "java_import", "java_library")
load("//scala:providers.bzl", "declare_deps_provider")
load("//scala:scala.bzl", "setup_scala_toolchain")
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_MAJOR_VERSION")
load("//scala/private:macros/setup_scala_toolchain.bzl", "default_deps", "setup_scala_toolchain")
load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")

toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
)

_SCALA_COMPILE_CLASSPATH_DEPS = [
"@io_bazel_rules_scala_scala_compiler",
"@io_bazel_rules_scala_scala_library",
] + (["@io_bazel_rules_scala_scala_reflect"] if SCALA_MAJOR_VERSION.startswith("2") else [
"@io_bazel_rules_scala_scala_interfaces",
"@io_bazel_rules_scala_scala_tasty_core",
"@io_bazel_rules_scala_scala_asm",
"@io_bazel_rules_scala_scala_library_2",
])

_SCALA_LIBRARY_CLASSPATH_DEPS = [
"@io_bazel_rules_scala_scala_library",
] + (["@io_bazel_rules_scala_scala_reflect"] if SCALA_MAJOR_VERSION.startswith("2") else [
"@io_bazel_rules_scala_scala_library_2",
])

_SCALA_MACRO_CLASSPATH_DEPS = [
"@io_bazel_rules_scala_scala_library",
] + (["@io_bazel_rules_scala_scala_reflect"] if SCALA_MAJOR_VERSION.startswith("2") else [
"@io_bazel_rules_scala_scala_library_2",
])

_PARSER_COMBINATORS_DEPS = ["@io_bazel_rules_scala_scala_parser_combinators"]

_SCALA_XML_DEPS = ["@io_bazel_rules_scala_scala_xml"]

_SEMANTICDB_DEPS = ["@org_scalameta_semanticdb_scalac"] if SCALA_MAJOR_VERSION.startswith("2") else []

setup_scala_toolchain(
name = "default_toolchain",
scala_compile_classpath = _SCALA_COMPILE_CLASSPATH_DEPS,
scala_library_classpath = _SCALA_LIBRARY_CLASSPATH_DEPS,
scala_macro_classpath = _SCALA_MACRO_CLASSPATH_DEPS,
use_argument_file_in_runner = True,
)

setup_scala_toolchain(
name = "unused_dependency_checker_error_toolchain",
dependency_tracking_method = "ast-plus",
scala_compile_classpath = _SCALA_COMPILE_CLASSPATH_DEPS,
scala_library_classpath = _SCALA_LIBRARY_CLASSPATH_DEPS,
scala_macro_classpath = _SCALA_MACRO_CLASSPATH_DEPS,
unused_dependency_checker_mode = "error",
)

setup_scala_toolchain(
name = "minimal_direct_source_deps",
dependency_mode = "plus-one",
dependency_tracking_method = "ast",
scala_compile_classpath = _SCALA_COMPILE_CLASSPATH_DEPS,
scala_library_classpath = _SCALA_LIBRARY_CLASSPATH_DEPS,
scala_macro_classpath = _SCALA_MACRO_CLASSPATH_DEPS,
strict_deps_mode = "error",
unused_dependency_checker_mode = "error",
)
Expand All @@ -80,40 +43,40 @@ declare_deps_provider(
name = "scala_compile_classpath_provider",
deps_id = "scala_compile_classpath",
visibility = ["//visibility:public"],
deps = _SCALA_COMPILE_CLASSPATH_DEPS,
deps = default_deps("scala_compile_classpath", SCALA_VERSION),
)

declare_deps_provider(
name = "scala_library_classpath_provider",
deps_id = "scala_library_classpath",
visibility = ["//visibility:public"],
deps = _SCALA_LIBRARY_CLASSPATH_DEPS,
deps = default_deps("scala_library_classpath", SCALA_VERSION),
)

declare_deps_provider(
name = "scala_macro_classpath_provider",
deps_id = "scala_macro_classpath",
visibility = ["//visibility:public"],
deps = _SCALA_MACRO_CLASSPATH_DEPS,
deps = default_deps("scala_macro_classpath", SCALA_VERSION),
)

declare_deps_provider(
name = "scala_xml_provider",
deps_id = "scala_xml",
visibility = ["//visibility:public"],
deps = _SCALA_XML_DEPS,
deps = default_deps("scala_xml", SCALA_VERSION),
)

declare_deps_provider(
name = "parser_combinators_provider",
deps_id = "parser_combinators",
visibility = ["//visibility:public"],
deps = _PARSER_COMBINATORS_DEPS,
deps = default_deps("parser_combinators", SCALA_VERSION),
)

declare_deps_provider(
name = "semanticdb_provider",
deps_id = "semanticdb",
visibility = ["//visibility:public"],
deps = _SEMANTICDB_DEPS,
deps = default_deps("semanticdb", SCALA_VERSION),
)
65 changes: 62 additions & 3 deletions scala/private/macros/setup_scala_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ load("@io_bazel_rules_scala_config//:config.bzl", "SCALA_VERSION")

def setup_scala_toolchain(
name,
scala_compile_classpath,
scala_library_classpath,
scala_macro_classpath,
scala_compile_classpath = None,
scala_library_classpath = None,
scala_macro_classpath = None,
scala_version = SCALA_VERSION,
scala_xml_deps = None,
parser_combinators_deps = None,
Expand All @@ -22,20 +22,26 @@ def setup_scala_toolchain(
scala_macro_classpath_provider = "%s_scala_macro_classpath_provider" % name
semanticdb_deps_provider = "%s_semanticdb_deps_provider" % name

if scala_compile_classpath == None:
scala_compile_classpath = default_deps("scala_compile_classpath", scala_version)
declare_deps_provider(
name = scala_compile_classpath_provider,
deps_id = "scala_compile_classpath",
visibility = visibility,
deps = scala_compile_classpath,
)

if scala_library_classpath == None:
scala_library_classpath = default_deps("scala_library_classpath", scala_version)
declare_deps_provider(
name = scala_library_classpath_provider,
deps_id = "scala_library_classpath",
visibility = visibility,
deps = scala_library_classpath,
)

if scala_macro_classpath == None:
scala_macro_classpath = default_deps("scala_macro_classpath", scala_version)
declare_deps_provider(
name = scala_macro_classpath_provider,
deps_id = "scala_macro_classpath",
Expand Down Expand Up @@ -99,3 +105,56 @@ def setup_scala_toolchain(
target_settings = ["@io_bazel_rules_scala_config//:scala_version" + version_suffix(scala_version)],
visibility = visibility,
)

_DEFAULT_DEPS = {
"scala_compile_classpath": {
"any": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this "any" introduced to reduce duplication? I'm afraid this assumption that labels match between scala version might not always hold, leaving "any" obsolete.

I think some duplication here is fine. I would just list all major scala versions and deps lables for each dep_id.

imho that would look simpler. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, any is here just to avoid duplication.

My goal was to keep the change minimal (here: not changing the logic of producing the relevant labels). This deduplication is not a new concept, as it expresses the same intention as the old version in the BUILD file, e.g.:

_SCALA_COMPILE_CLASSPATH_DEPS = [
    "@io_bazel_rules_scala_scala_compiler",
    "@io_bazel_rules_scala_scala_library",
] + (["@io_bazel_rules_scala_scala_reflect"] if SCALA_MAJOR_VERSION.startswith("2") else [
    "@io_bazel_rules_scala_scala_interfaces",
    "@io_bazel_rules_scala_scala_tasty_core",
    "@io_bazel_rules_scala_scala_asm",
    "@io_bazel_rules_scala_scala_library_2",
])

translated into:

    "scala_compile_classpath": {
        "any": [
            "@io_bazel_rules_scala_scala_compiler",
            "@io_bazel_rules_scala_scala_library",
        ],
        "2": [
            "@io_bazel_rules_scala_scala_reflect",
        ],
        "3": [
            "@io_bazel_rules_scala_scala_interfaces",
            "@io_bazel_rules_scala_scala_tasty_core",
            "@io_bazel_rules_scala_scala_asm",
            "@io_bazel_rules_scala_scala_library_2",
        ],
    },

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand your intent. Probably it's just a matter of personal taste. Since it's private and encapsulated in a function I'm totally fine with that.

"@io_bazel_rules_scala_scala_compiler",
"@io_bazel_rules_scala_scala_library",
],
"2": [
"@io_bazel_rules_scala_scala_reflect",
],
"3": [
"@io_bazel_rules_scala_scala_interfaces",
"@io_bazel_rules_scala_scala_tasty_core",
"@io_bazel_rules_scala_scala_asm",
"@io_bazel_rules_scala_scala_library_2",
],
},
"scala_library_classpath": {
"any": [
"@io_bazel_rules_scala_scala_library",
],
"2": [
"@io_bazel_rules_scala_scala_reflect",
],
"3": [
"@io_bazel_rules_scala_scala_library_2",
],
},
"scala_macro_classpath": {
"any": [
"@io_bazel_rules_scala_scala_library",
],
"2": [
"@io_bazel_rules_scala_scala_reflect",
],
"3": [
"@io_bazel_rules_scala_scala_library_2",
],
},
"scala_xml": {
"any": ["@io_bazel_rules_scala_scala_xml"],
},
"parser_combinators": {
"any": ["@io_bazel_rules_scala_scala_parser_combinators"],
},
"semanticdb": {
"2": ["@org_scalameta_semanticdb_scalac"],
},
}

def default_deps(deps_id, scala_version):
versions = _DEFAULT_DEPS[deps_id]
return versions.get("any", []) + versions.get(scala_version[0], [])