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

Move default toolchain dependencies logic to .bzl file #1561

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

aszady
Copy link
Contributor

@aszady aszady commented Mar 26, 2024

Description

Purely refactoring change.
Encapsulates the logic of selecting dependencies into a function. Should come in handy in future changes.

Motivation

Originally #1290.
Partitioned from / inspired by #1552.

@aszady aszady requested review from liucijus and simuons as code owners March 26, 2024 19:31
Purely refactoring change.
Encapsulates the logic of selecting dependencies into a function.
Should come in handy in future changes.
Copy link
Collaborator

@simuons simuons left a comment

Choose a reason for hiding this comment

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

Please take a look at comments.


_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.

scala/BUILD Outdated
_SEMANTICDB_DEPS = ["@org_scalameta_semanticdb_scalac"] if SCALA_MAJOR_VERSION.startswith("2") else []

setup_scala_toolchain(
setup_scala_toolchain_with_default_classpaths(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this new macro really needed? I mean scala_version attribute eventually should be passed to setup_scala_toolchain because it will be needed in target_setting. So maybe default classpaths should be added there if None was passed.

I think it is nice to have deps_id mappings extracted into separate bzl file with lookup exposed function. But for now I would avoid adding new macro and change setup_scala_toolchain to

setup_scala_toolchain(
    name = "default_toolchain",
    scala_compile_classpath = default_deps("scala_compile_classpath", SCALA_VERSION),
    scala_library_classpath = default_deps("scala_library_classpath", SCALA_VERSION),
    scala_macro_classpath = default_deps("scala_macro_classpath", SCALA_VERSION),
    use_argument_file_in_runner = True,
)

Similarly to what you did for declare_deps_provider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This macro is not necessary.

So since we have #1566 already merged (scala_version is now passed to setup_scala_toolchain), we can already proceed with default classpaths if None is provided.

I pushed the relevant revision.

Copy link
Collaborator

@liucijus liucijus left a comment

Choose a reason for hiding this comment

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

Thanks, @aszady!

@liucijus liucijus merged commit a6b26df into bazelbuild:master Apr 12, 2024
2 checks passed
@aszady aszady deleted the setup.bzl branch May 13, 2024 12:57
aszady added a commit to aszady/rules_scala that referenced this pull request May 14, 2024
These should also point to Scala version-specific artifacts.
See previous PR: bazelbuild#1561
aszady added a commit to aszady/rules_scala that referenced this pull request May 14, 2024
These should also point to Scala version-specific artifacts.
See previous PR: bazelbuild#1561
aszady added a commit to aszady/rules_scala that referenced this pull request May 14, 2024
These should also point to Scala version-specific artifacts.
See previous PR: bazelbuild#1561
liucijus pushed a commit that referenced this pull request May 15, 2024
These should also point to Scala version-specific artifacts.
See previous PR: #1561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants