From 0e6bb377daa5756eea3654d6fb8bd47a4a5aef75 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 10:09:19 -0700 Subject: [PATCH 1/7] Remove kt_jvm_plugin_aspect now that all versions of Bazel support JavaPluginInfo --- kotlin/internal/jvm/jvm.bzl | 6 ------ kotlin/internal/jvm/plugins.bzl | 30 ------------------------------ 2 files changed, 36 deletions(-) diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index 90495998c..96fb9beb9 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -101,10 +101,6 @@ load( _KtJvmInfo = "KtJvmInfo", _TOOLCHAIN_TYPE = "TOOLCHAIN_TYPE", ) -load( - "//kotlin/internal/jvm:plugins.bzl", - _kt_jvm_plugin_aspect = "kt_jvm_plugin_aspect", -) load( "//kotlin/internal:opts.bzl", _JavacOptions = "JavacOptions", @@ -168,7 +164,6 @@ _common_attr = utils.add_dicts( "deps": attr.label_list( doc = """A list of dependencies of this rule.See general comments about `deps` at [Attributes common to all build rules](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).""", - aspects = [] if hasattr(java_common, "JavaPluginInfo") else [_kt_jvm_plugin_aspect], providers = [ [JavaInfo], ], @@ -209,7 +204,6 @@ _common_attr = utils.add_dicts( ), "plugins": attr.label_list( default = [], - aspects = [] if hasattr(java_common, "JavaPluginInfo") else [_kt_jvm_plugin_aspect], cfg = "exec", ), "module_name": attr.string( diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 427d70cba..0a6eb3e42 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -89,33 +89,3 @@ def merge_plugin_infos(attrs): annotation_processors = _targets_to_annotation_processors(attrs), transitive_runtime_jars = _targets_to_transitive_runtime_jars(attrs), ) - -def _kt_jvm_plugin_aspect_impl(_, ctx): - if ctx.rule.kind == "java_plugin": - processor = ctx.rule.attr - merged_deps = java_common.merge([j[JavaInfo] for j in processor.deps]) - return [KtJvmPluginInfo( - annotation_processors = depset([ - struct( - label = _utils.restore_label(ctx.label), - processor_class = processor.processor_class, - classpath = merged_deps.transitive_runtime_jars, - generates_api = processor.generates_api, - ), - ]), - transitive_runtime_jars = depset(transitive = [merged_deps.transitive_runtime_jars]), - )] - elif ctx.rule.kind == "java_library": - return [merge_plugin_infos(ctx.rule.attr.exported_plugins)] - else: - return _EMPTY_PLUGIN_INFO - -kt_jvm_plugin_aspect = aspect( - doc = """This aspect collects Java Plugins info and other Kotlin compiler plugin configurations from the graph.""", - attr_aspects = [ - "plugins", - "exported_plugins", - ], - provides = [KtJvmPluginInfo], - implementation = _kt_jvm_plugin_aspect_impl, -) From 9e8f6493f47490bbb9068d4c14e4f17dadfa05df Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 10:12:21 -0700 Subject: [PATCH 2/7] Fix --- kotlin/internal/jvm/plugins.bzl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 0a6eb3e42..670dbfa99 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -11,11 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -load( - "//kotlin/internal/utils:utils.bzl", - _utils = "utils", -) - KtJvmPluginInfo = provider( doc = "This provider contains the plugin info for the JVM aspect", fields = { From a170fcc2fd01299fef3f77b27e9f6d1c1e4aa6cf Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 10:15:06 -0700 Subject: [PATCH 3/7] More remove --- kotlin/internal/jvm/plugins.bzl | 2 -- 1 file changed, 2 deletions(-) diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 670dbfa99..c20a85d0a 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -19,8 +19,6 @@ KtJvmPluginInfo = provider( }, ) -_EMPTY_PLUGIN_INFO = [KtJvmPluginInfo(annotation_processors = depset(), transitive_runtime_jars = depset())] - # Mapping functions for args.add_all. # These preserve the transitive depsets until needed. def _kt_plugin_to_processor(processor): From fade1ee0c587ca12f6733d85dcc634daad3d43a3 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 10:23:12 -0700 Subject: [PATCH 4/7] Default plugins.bzl to using JavaPluginInfo --- kotlin/internal/jvm/plugins.bzl | 58 +++++++++++++-------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index c20a85d0a..7c3229ef2 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -11,6 +11,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +_JavaPluginInfo = getattr(java_common, "JavaPluginInfo") + KtJvmPluginInfo = provider( doc = "This provider contains the plugin info for the JVM aspect", fields = { @@ -22,49 +24,35 @@ KtJvmPluginInfo = provider( # Mapping functions for args.add_all. # These preserve the transitive depsets until needed. def _kt_plugin_to_processor(processor): - if hasattr(java_common, "JavaPluginInfo"): - return processor.processor_classes.to_list() - return processor.processor_class + return processor.processor_classes.to_list() def _kt_plugin_to_processorpath(processor): - if hasattr(java_common, "JavaPluginInfo"): - return [j.path for j in processor.processor_jars.to_list()] - return [j.path for j in processor.classpath.to_list()] + return [j.path for j in processor.processor_jars.to_list()] def _targets_to_annotation_processors(targets): - if hasattr(java_common, "JavaPluginInfo"): - _JavaPluginInfo = getattr(java_common, "JavaPluginInfo") - plugins = [] - for t in targets: - if _JavaPluginInfo in t: - p = t[_JavaPluginInfo].plugins - if p.processor_jars: - plugins.append(p) - elif JavaInfo in t: - p = t[JavaInfo].plugins - if p.processor_jars: - plugins.append(p) - return depset(plugins) - - return depset(transitive = [t[KtJvmPluginInfo].annotation_processors for t in targets if KtJvmPluginInfo in t]) + plugins = [] + for t in targets: + if _JavaPluginInfo in t: + p = t[_JavaPluginInfo].plugins + if p.processor_jars: + plugins.append(p) + elif JavaInfo in t: + p = t[JavaInfo].plugins + if p.processor_jars: + plugins.append(p) + return depset(plugins) def _targets_to_annotation_processors_java_plugin_info(targets): - if hasattr(java_common, "JavaPluginInfo"): - _JavaPluginInfo = getattr(java_common, "JavaPluginInfo") - return [t[_JavaPluginInfo] for t in targets if _JavaPluginInfo in t] - return [t[JavaInfo] for t in targets if JavaInfo in t] + return [t[_JavaPluginInfo] for t in targets if _JavaPluginInfo in t] def _targets_to_transitive_runtime_jars(targets): - if hasattr(java_common, "JavaPluginInfo"): - _JavaPluginInfo = getattr(java_common, "JavaPluginInfo") - return depset( - transitive = [ - (t[_JavaPluginInfo] if _JavaPluginInfo in t else t[JavaInfo]).plugins.processor_jars - for t in targets - if _JavaPluginInfo in t or JavaInfo in t - ], - ) - return depset(transitive = [t[KtJvmPluginInfo].transitive_runtime_jars for t in targets if KtJvmPluginInfo in t]) + return depset( + transitive = [ + (t[_JavaPluginInfo] if _JavaPluginInfo in t else t[JavaInfo]).plugins.processor_jars + for t in targets + if _JavaPluginInfo in t or JavaInfo in t + ], + ) mappers = struct( targets_to_annotation_processors = _targets_to_annotation_processors, From f1072fb1dc8b15e888051d344be8ab8f119660cc Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 10:34:03 -0700 Subject: [PATCH 5/7] More cleanup --- kotlin/internal/jvm/plugins.bzl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 7c3229ef2..8fdd0d6d5 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -61,12 +61,3 @@ mappers = struct( kt_plugin_to_processor = _kt_plugin_to_processor, kt_plugin_to_processorpath = _kt_plugin_to_processorpath, ) - -def merge_plugin_infos(attrs): - """Merge all of the plugin infos found in the provided sequence of attributes. - Returns: - A KtJvmPluginInfo provider, Each of the entries is serializable.""" - return KtJvmPluginInfo( - annotation_processors = _targets_to_annotation_processors(attrs), - transitive_runtime_jars = _targets_to_transitive_runtime_jars(attrs), - ) From 7e7a9d9581f19a17d63f2bc5d6ece646fa692bdb Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 19:01:05 -0700 Subject: [PATCH 6/7] Remove KtJvmPluginInfo --- kotlin/internal/jvm/plugins.bzl | 8 -------- 1 file changed, 8 deletions(-) diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 8fdd0d6d5..4540e8e97 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -13,14 +13,6 @@ # limitations under the License. _JavaPluginInfo = getattr(java_common, "JavaPluginInfo") -KtJvmPluginInfo = provider( - doc = "This provider contains the plugin info for the JVM aspect", - fields = { - "annotation_processors": "depset of structs containing annotation processor definitions", - "transitive_runtime_jars": "depset of transitive_runtime_jars for this plugin and deps", - }, -) - # Mapping functions for args.add_all. # These preserve the transitive depsets until needed. def _kt_plugin_to_processor(processor): From 567a33cb7097799de924cd0cef91c757fea2ea3d Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Tue, 11 Apr 2023 19:02:53 -0700 Subject: [PATCH 7/7] More --- kotlin/internal/defs.bzl | 3 +++ kotlin/internal/jvm/plugins.bzl | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kotlin/internal/defs.bzl b/kotlin/internal/defs.bzl index 8f5702bad..da9e515aa 100644 --- a/kotlin/internal/defs.bzl +++ b/kotlin/internal/defs.bzl @@ -19,6 +19,9 @@ TOOLCHAIN_TYPE = "%s" % Label("//kotlin/internal:kt_toolchain_type") JAVA_TOOLCHAIN_TYPE = "@bazel_tools//tools/jdk:toolchain_type" JAVA_RUNTIME_TOOLCHAIN_TYPE = "@bazel_tools//tools/jdk:runtime_toolchain_type" +# Upstream provider for Java plugins +JavaPluginInfo = getattr(java_common, "JavaPluginInfo") + # The name of the Kotlin compiler workspace. KT_COMPILER_REPO = "com_github_jetbrains_kotlin" diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 4540e8e97..996c66eae 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -_JavaPluginInfo = getattr(java_common, "JavaPluginInfo") +load("//kotlin/internal:defs.bzl", _JavaPluginInfo = "JavaPluginInfo") # Mapping functions for args.add_all. # These preserve the transitive depsets until needed.