From 5117a50894419dc1ba93bb109c7ff0f7c5985ce5 Mon Sep 17 00:00:00 2001 From: Mai Hussien Date: Thu, 24 Oct 2024 14:37:59 -0700 Subject: [PATCH] Use aspect to toolchain propagation to collect information of Cc and 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 --- aspect/intellij_info.bzl | 2 ++ aspect/intellij_info_impl.bzl | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aspect/intellij_info.bzl b/aspect/intellij_info.bzl index 54a2be601b9..652b83c95a4 100644 --- a/aspect/intellij_info.bzl +++ b/aspect/intellij_info.bzl @@ -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): diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index c09e1833a1c..d4da3601775 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -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", @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 )