Skip to content

Commit

Permalink
Use aspect to toolchain propagation to collect information of Cc and …
Browse files Browse the repository at this point in the history
…Kotlin toolchains

the `_toolchain` attribute is removed by `rules_kotlin` and `_cc_toolchain` attribute is planned to be removed by `rules_cc`. This change uses the new approach of aspect to toolchains propagation based on toolchain types instead. This feature is available in Blaze but not in all Bazel versions. Therefore, we keep using the old attribute-based approach for Bazel as the toolchain attributes will still be there for Bazel.

PiperOrigin-RevId: 689520709
  • Loading branch information
mai93 authored and copybara-github committed Oct 25, 2024
1 parent 4ff0f69 commit 5117a50
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions aspect/intellij_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ load(

EXTRA_DEPS = [
"embed", # From go rules (bazel only)
"_cc_toolchain", # From rules_cc (bazel only)
"_kt_toolchain", # From rules_kotlin (bazel only)
]

def tool_label(tool_name):
Expand Down
17 changes: 13 additions & 4 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load(
)

IntelliJInfo = provider(
doc = "Collected infromation about the targets visited by the aspect.",
doc = "Collected information about the targets visited by the aspect.",
fields = [
"export_deps",
"kind",
Expand All @@ -38,7 +38,6 @@ UNSUPPORTED_FEATURES = [

# Compile-time dependency attributes, grouped by type.
DEPS = [
"_cc_toolchain", # From cc rules
"_stl", # From cc rules
"malloc", # From cc_binary rules
"_java_toolchain", # From java rules
Expand All @@ -52,7 +51,6 @@ DEPS = [
"test_app", # android_instrumentation_test
"instruments", # android_instrumentation_test
"tests", # From test_suite
"_kt_toolchain", # From rules_kotlin
]

# Run-time dependency attributes, grouped by type.
Expand Down Expand Up @@ -1071,6 +1069,16 @@ def intellij_info_aspect_impl(target, ctx, semantics):
rule_attrs,
semantics_extra_deps(DEPS, semantics, "extra_deps"),
)

# Collect direct toolchain type-based dependencies
if hasattr(semantics, "toolchains_propagation"):
direct_dep_targets.extend(
semantics.toolchains_propagation.collect_toolchain_deps(
ctx,
semantics.toolchains_propagation.toolchain_types,
),
)

direct_deps = make_deps(direct_dep_targets, COMPILE_TIME)

# Add exports from direct dependencies
Expand Down Expand Up @@ -1209,7 +1217,7 @@ def semantics_extra_deps(base, semantics, name):
extra_deps = getattr(semantics, name)
return base + extra_deps

def make_intellij_info_aspect(aspect_impl, semantics):
def make_intellij_info_aspect(aspect_impl, semantics, **kwargs):
"""Creates the aspect given the semantics."""
tool_label = semantics.tool_label
flag_hack_label = semantics.flag_hack_label
Expand Down Expand Up @@ -1253,4 +1261,5 @@ def make_intellij_info_aspect(aspect_impl, semantics):
fragments = ["cpp"],
required_aspect_providers = [[JavaInfo], [CcInfo]] + semantics.extra_required_aspect_providers,
implementation = aspect_impl,
**kwargs
)

0 comments on commit 5117a50

Please sign in to comment.