From 3074e1a0198db8f0dc02eb65b4eb933b9fc628ea Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 23 Apr 2024 05:25:34 -0700 Subject: [PATCH] Support Bazel rules_kotlin's toolchain without legacy providers This is a prerequisite to finally turn down legacy struct providers. The last such instance is used in rules_kotlin. And it's used to serve as integration with IntelliJ. After this change, PR https://github.com/bazelbuild/rules_kotlin/pull/1157 may be merged, keeping rules_kotlin working with IntelliJ. Legacy struct providers have been deprecated by Bazel. Replacing them with modern providers, will make it possible to simplify and remove legacy handling from Bazel. More info on: https://bazel.build/extending/rules#migrating_from_legacy_providers Issue: bazelbuild/bazel#19467 (cherry picked from commit 702227e6b827cea102bcce6722302c426ad17188) --- aspect/intellij_info_impl.bzl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index 65f93d4cb41..5732ca3807e 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -44,6 +44,7 @@ DEPS = [ "tests", # From test_suite "compilers", # From go_proto_library "associates", # From kotlin rules + "_kt_toolchain", # From rules_kotlin ] # Run-time dependency attributes, grouped by type. @@ -1020,13 +1021,15 @@ def collect_java_toolchain_info(target, ide_info, ide_info_file, output_groups): def artifact_to_path(artifact): return artifact.root_execution_path_fragment + "/" + artifact.relative_path -def collect_kotlin_toolchain_info(target, ide_info, ide_info_file, output_groups): +def collect_kotlin_toolchain_info(target, ctx, ide_info, ide_info_file, output_groups): """Updates kotlin_toolchain-relevant output groups, returns false if not a kotlin_toolchain target.""" - if not hasattr(target, "kt"): - return False - kt = target.kt - if not hasattr(kt, "language_version"): + if ctx.rule.kind == "_kt_toolchain" and platform_common.ToolchainInfo in target: + kt = target[platform_common.ToolchainInfo] + elif hasattr(target, "kt") and hasattr(target.kt, "language_version"): + kt = target.kt # Legacy struct provider mechanism + else: return False + ide_info["kt_toolchain_ide_info"] = struct( language_version = kt.language_version, ) @@ -1186,7 +1189,7 @@ def intellij_info_aspect_impl(target, ctx, semantics): handled = collect_java_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled handled = collect_java_toolchain_info(target, ide_info, ide_info_file, output_groups) or handled handled = collect_android_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled - handled = collect_kotlin_toolchain_info(target, ide_info, ide_info_file, output_groups) or handled + handled = collect_kotlin_toolchain_info(target, ctx, ide_info, ide_info_file, output_groups) or handled # Any extra ide info if hasattr(semantics, "extra_ide_info"):