From 373c09edb2e0dc8c697766370be6fb08ecdf0aec Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 29 Sep 2023 21:59:48 +0200 Subject: [PATCH 1/4] Load Java providers and java_common from rules_java --- kotlin/internal/defs.bzl | 3 --- kotlin/internal/jvm/associates.bzl | 1 + kotlin/internal/jvm/compile.bzl | 1 + kotlin/internal/jvm/impl.bzl | 6 ++---- kotlin/internal/jvm/jvm.bzl | 1 + kotlin/internal/jvm/plugins.bzl | 12 ++++++------ kotlin/internal/lint/ktlint_test.bzl | 1 + kotlin/internal/toolchains.bzl | 1 + kotlin/internal/utils/generate_jvm_service.bzl | 1 + src/main/kotlin/bootstrap.bzl | 1 + third_party/jarjar.bzl | 1 + 11 files changed, 16 insertions(+), 13 deletions(-) diff --git a/kotlin/internal/defs.bzl b/kotlin/internal/defs.bzl index c01558fd9..eb91aaa9e 100644 --- a/kotlin/internal/defs.bzl +++ b/kotlin/internal/defs.bzl @@ -19,9 +19,6 @@ 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/associates.bzl b/kotlin/internal/jvm/associates.bzl index 121671c3c..1b2668a52 100644 --- a/kotlin/internal/jvm/associates.bzl +++ b/kotlin/internal/jvm/associates.bzl @@ -11,6 +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. +load("@rules_java//java:defs.bzl", "JavaInfo") load( "//kotlin/internal:defs.bzl", _KtJvmInfo = "KtJvmInfo", diff --git a/kotlin/internal/jvm/compile.bzl b/kotlin/internal/jvm/compile.bzl index 4ad2af49a..117c8a41a 100644 --- a/kotlin/internal/jvm/compile.bzl +++ b/kotlin/internal/jvm/compile.bzl @@ -17,6 +17,7 @@ load( # 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("@rules_java//java:defs.bzl", "JavaInfo", "java_common") load( "//kotlin/internal:defs.bzl", _KtCompilerPluginInfo = "KtCompilerPluginInfo", diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl index 78116f477..6b42dfd7c 100644 --- a/kotlin/internal/jvm/impl.bzl +++ b/kotlin/internal/jvm/impl.bzl @@ -1,6 +1,5 @@ load( "//kotlin/internal:defs.bzl", - _JavaPluginInfo = "JavaPluginInfo", _KspPluginInfo = "KspPluginInfo", _KtCompilerPluginInfo = "KtCompilerPluginInfo", _KtJvmInfo = "KtJvmInfo", @@ -20,6 +19,7 @@ load( # 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("@rules_java//java:defs.bzl", "JavaInfo", "java_common", "JavaPluginInfo") load( "//kotlin/internal/jvm:compile.bzl", "export_only_providers", @@ -422,15 +422,13 @@ def kt_compiler_plugin_impl(ctx): ] def kt_ksp_plugin_impl(ctx): - _JavaPluginInfo = getattr(java_common, "JavaPluginInfo") - info = java_common.merge([dep[JavaInfo] for dep in ctx.attr.deps]) classpath = depset(info.runtime_output_jars, transitive = [info.transitive_runtime_jars]) return [ DefaultInfo(files = classpath), _KspPluginInfo(plugins = [ - _JavaPluginInfo( + JavaPluginInfo( runtime_deps = [ info, ], diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index ed3029c35..ea2374740 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -92,6 +92,7 @@ kt_jvm_binary( ``` """ +load("@rules_java//java:defs.bzl", "JavaInfo") load( "//kotlin/internal:defs.bzl", _JAVA_RUNTIME_TOOLCHAIN_TYPE = "JAVA_RUNTIME_TOOLCHAIN_TYPE", diff --git a/kotlin/internal/jvm/plugins.bzl b/kotlin/internal/jvm/plugins.bzl index 2fca70acc..71c44026e 100644 --- a/kotlin/internal/jvm/plugins.bzl +++ b/kotlin/internal/jvm/plugins.bzl @@ -11,9 +11,9 @@ # 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("@rules_java//java:defs.bzl", "JavaInfo", "JavaPluginInfo") load( "//kotlin/internal:defs.bzl", - _JavaPluginInfo = "JavaPluginInfo", _KspPluginInfo = "KspPluginInfo", ) @@ -31,8 +31,8 @@ def _targets_to_annotation_processors(targets): if _KspPluginInfo in targets: # KSP plugins are handled by the KSP Kotlinc compiler plugin pass - elif _JavaPluginInfo in t: - p = t[_JavaPluginInfo].plugins + elif JavaPluginInfo in t: + p = t[JavaPluginInfo].plugins if p.processor_jars: plugins.append(p) elif JavaInfo in t: @@ -50,13 +50,13 @@ def _targets_to_ksp_annotation_processors(targets): return depset(plugins) def _targets_to_annotation_processors_java_plugin_info(targets): - return [t[_JavaPluginInfo] for t in targets if _JavaPluginInfo in t] + return [t[JavaPluginInfo] for t in targets if JavaPluginInfo in t] def _targets_to_transitive_runtime_jars(targets): transitive = [] for t in targets: - if _JavaPluginInfo in t: - transitive.append(t[_JavaPluginInfo].plugins.processor_jars) + if JavaPluginInfo in t: + transitive.append(t[JavaPluginInfo].plugins.processor_jars) elif JavaInfo in t: transitive.append(t[JavaInfo].plugins.processor_jars) elif _KspPluginInfo in t: diff --git a/kotlin/internal/lint/ktlint_test.bzl b/kotlin/internal/lint/ktlint_test.bzl index 7a8c5dd91..f46a71a16 100644 --- a/kotlin/internal/lint/ktlint_test.bzl +++ b/kotlin/internal/lint/ktlint_test.bzl @@ -1,3 +1,4 @@ +load("@rules_java//java:defs.bzl", "java_common") load("//kotlin/internal/utils:windows.bzl", "create_windows_native_launcher_script") load(":editorconfig.bzl", "get_editorconfig", "is_android_rules_enabled", "is_experimental_rules_enabled") load(":ktlint_config.bzl", "KtlintConfigInfo") diff --git a/kotlin/internal/toolchains.bzl b/kotlin/internal/toolchains.bzl index 40fd21de2..406c66ae3 100644 --- a/kotlin/internal/toolchains.bzl +++ b/kotlin/internal/toolchains.bzl @@ -19,6 +19,7 @@ load( # 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("@rules_java//java:defs.bzl", "JavaInfo", "java_common") load( "//kotlin/internal:opts.bzl", "JavacOptions", diff --git a/kotlin/internal/utils/generate_jvm_service.bzl b/kotlin/internal/utils/generate_jvm_service.bzl index 3d757972c..8af8c12a0 100644 --- a/kotlin/internal/utils/generate_jvm_service.bzl +++ b/kotlin/internal/utils/generate_jvm_service.bzl @@ -11,6 +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. +load("@rules_java//java:defs.bzl", "JavaInfo") def _generate_jvm_service_impl(ctx): """ diff --git a/src/main/kotlin/bootstrap.bzl b/src/main/kotlin/bootstrap.bzl index cdca22d45..d85f3d734 100644 --- a/src/main/kotlin/bootstrap.bzl +++ b/src/main/kotlin/bootstrap.bzl @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_java//java:defs.bzl", "java_binary", "java_import") +load("//third_party:jarjar.bzl", "jar_jar") load("//kotlin:jvm.bzl", _for_ide = "kt_jvm_library") load("//kotlin:lint.bzl", _ktlint_fix = "ktlint_fix", _ktlint_test = "ktlint_test") load("//third_party:jarjar.bzl", "jar_jar") diff --git a/third_party/jarjar.bzl b/third_party/jarjar.bzl index 8f03fdbb5..0eedc25a8 100644 --- a/third_party/jarjar.bzl +++ b/third_party/jarjar.bzl @@ -11,6 +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. +load("@rules_java//java:defs.bzl", "JavaInfo") def jarjar_action(actions, rules, input, output, jarjar): actions.run( From 493acf79ee2e3d0b460eb44aa155693ccdd99c81 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 29 Sep 2023 22:56:10 +0200 Subject: [PATCH 2/4] fixup --- kotlin/internal/jvm/impl.bzl | 2 +- kotlin/internal/toolchains.bzl | 2 +- src/main/kotlin/bootstrap.bzl | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl index 6b42dfd7c..b97bc3656 100644 --- a/kotlin/internal/jvm/impl.bzl +++ b/kotlin/internal/jvm/impl.bzl @@ -1,3 +1,4 @@ +load("@rules_java//java:defs.bzl", "JavaInfo", "java_common", "JavaPluginInfo") load( "//kotlin/internal:defs.bzl", _KspPluginInfo = "KspPluginInfo", @@ -19,7 +20,6 @@ load( # 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("@rules_java//java:defs.bzl", "JavaInfo", "java_common", "JavaPluginInfo") load( "//kotlin/internal/jvm:compile.bzl", "export_only_providers", diff --git a/kotlin/internal/toolchains.bzl b/kotlin/internal/toolchains.bzl index 406c66ae3..72fc0ba72 100644 --- a/kotlin/internal/toolchains.bzl +++ b/kotlin/internal/toolchains.bzl @@ -1,3 +1,4 @@ +load("@rules_java//java:defs.bzl", "JavaInfo", "java_common") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load( "//kotlin/internal:defs.bzl", @@ -19,7 +20,6 @@ load( # 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("@rules_java//java:defs.bzl", "JavaInfo", "java_common") load( "//kotlin/internal:opts.bzl", "JavacOptions", diff --git a/src/main/kotlin/bootstrap.bzl b/src/main/kotlin/bootstrap.bzl index d85f3d734..cdca22d45 100644 --- a/src/main/kotlin/bootstrap.bzl +++ b/src/main/kotlin/bootstrap.bzl @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. load("@rules_java//java:defs.bzl", "java_binary", "java_import") -load("//third_party:jarjar.bzl", "jar_jar") load("//kotlin:jvm.bzl", _for_ide = "kt_jvm_library") load("//kotlin:lint.bzl", _ktlint_fix = "ktlint_fix", _ktlint_test = "ktlint_test") load("//third_party:jarjar.bzl", "jar_jar") From f08cf23ce6127ef1ac50573fd7e04b4ec9c126d0 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 29 Sep 2023 23:06:44 +0200 Subject: [PATCH 3/4] fixup --- kotlin/internal/BUILD | 1 + kotlin/internal/toolchains.bzl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/kotlin/internal/BUILD b/kotlin/internal/BUILD index 2605db892..223323d20 100644 --- a/kotlin/internal/BUILD +++ b/kotlin/internal/BUILD @@ -45,5 +45,6 @@ bzl_library( "//kotlin/internal/lint", "//kotlin/internal/utils", "//src/main/starlark", + "@rules_java//java:rules", ], ) diff --git a/kotlin/internal/toolchains.bzl b/kotlin/internal/toolchains.bzl index 72fc0ba72..849957128 100644 --- a/kotlin/internal/toolchains.bzl +++ b/kotlin/internal/toolchains.bzl @@ -1,5 +1,5 @@ -load("@rules_java//java:defs.bzl", "JavaInfo", "java_common") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") +load("@rules_java//java:defs.bzl", "JavaInfo", "java_common") load( "//kotlin/internal:defs.bzl", _KT_COMPILER_REPO = "KT_COMPILER_REPO", From 36dcec4e1ba31a973e83e05b52239143286283ea Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 29 Sep 2023 23:16:03 +0200 Subject: [PATCH 4/4] fixup --- kotlin/internal/jvm/impl.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl index b97bc3656..4c6569829 100644 --- a/kotlin/internal/jvm/impl.bzl +++ b/kotlin/internal/jvm/impl.bzl @@ -1,4 +1,4 @@ -load("@rules_java//java:defs.bzl", "JavaInfo", "java_common", "JavaPluginInfo") +load("@rules_java//java:defs.bzl", "JavaInfo", "JavaPluginInfo", "java_common") load( "//kotlin/internal:defs.bzl", _KspPluginInfo = "KspPluginInfo",