From 6d4ea432508a938af32a21e4938f8554023ce08a Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 5 Apr 2024 11:02:27 +0200 Subject: [PATCH 1/3] Remove legacy struct providers in main repo --- kotlin/internal/jvm/impl.bzl | 74 +++++++++---------- .../internal/utils/generate_jvm_service.bzl | 30 ++++---- src/main/starlark/core/options/opts.javac.bzl | 6 +- .../starlark/core/options/opts.kotlinc.bzl | 6 +- 4 files changed, 50 insertions(+), 66 deletions(-) diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl index 9d48e020d..3e38a000c 100644 --- a/kotlin/internal/jvm/impl.bzl +++ b/kotlin/internal/jvm/impl.bzl @@ -41,25 +41,22 @@ def _make_providers(ctx, providers, transitive_files = depset(order = "default") files = [ctx.outputs.jar] if providers.java.outputs.jdeps: files.append(providers.java.outputs.jdeps) - return struct( - kt = providers.kt, - providers = [ - providers.java, - providers.kt, - providers.instrumented_files, - DefaultInfo( - files = depset(files), - runfiles = ctx.runfiles( - # explicitly include data files, otherwise they appear to be missing - files = ctx.files.data, - transitive_files = transitive_files, - # continue to use collect_default until proper transitive data collecting is - # implmented. - collect_default = True, - ), + return [ + providers.java, + providers.kt, + providers.instrumented_files, + DefaultInfo( + files = depset(files), + runfiles = ctx.runfiles( + # explicitly include data files, otherwise they appear to be missing + files = ctx.files.data, + transitive_files = transitive_files, + # continue to use collect_default until proper transitive data collecting is + # implmented. + collect_default = True, ), - ] + list(additional_providers), - ) + ), + ] + list(additional_providers) def _write_launcher_action(ctx, rjars, main_class, jvm_flags): """Macro that writes out a launcher script shell script. @@ -193,28 +190,25 @@ def kt_jvm_import_impl(ctx): ), ) - return struct( - kt = kt_info, - providers = [ - DefaultInfo( - files = depset(direct = [artifact.class_jar]), - runfiles = ctx.runfiles( - # Append class jar with the optional sources jar - files = [artifact.class_jar] + [artifact.source_jar] if artifact.source_jar else [], - ).merge_all([d[DefaultInfo].default_runfiles for d in ctx.attr.deps]), - ), - JavaInfo( - output_jar = artifact.class_jar, - compile_jar = artifact.class_jar, - source_jar = artifact.source_jar, - runtime_deps = [dep[JavaInfo] for dep in ctx.attr.runtime_deps if JavaInfo in dep], - deps = [dep[JavaInfo] for dep in ctx.attr.deps if JavaInfo in dep], - exports = [d[JavaInfo] for d in getattr(ctx.attr, "exports", [])], - neverlink = getattr(ctx.attr, "neverlink", False), - ), - kt_info, - ], - ) + return [ + DefaultInfo( + files = depset(direct = [artifact.class_jar]), + runfiles = ctx.runfiles( + # Append class jar with the optional sources jar + files = [artifact.class_jar] + [artifact.source_jar] if artifact.source_jar else [], + ).merge_all([d[DefaultInfo].default_runfiles for d in ctx.attr.deps]), + ), + JavaInfo( + output_jar = artifact.class_jar, + compile_jar = artifact.class_jar, + source_jar = artifact.source_jar, + runtime_deps = [dep[JavaInfo] for dep in ctx.attr.runtime_deps if JavaInfo in dep], + deps = [dep[JavaInfo] for dep in ctx.attr.deps if JavaInfo in dep], + exports = [d[JavaInfo] for d in getattr(ctx.attr, "exports", [])], + neverlink = getattr(ctx.attr, "neverlink", False), + ), + kt_info, + ] def kt_jvm_library_impl(ctx): if ctx.attr.neverlink and ctx.attr.runtime_deps: diff --git a/kotlin/internal/utils/generate_jvm_service.bzl b/kotlin/internal/utils/generate_jvm_service.bzl index 8af8c12a0..8bad49fae 100644 --- a/kotlin/internal/utils/generate_jvm_service.bzl +++ b/kotlin/internal/utils/generate_jvm_service.bzl @@ -46,22 +46,20 @@ def _generate_jvm_service_impl(ctx): arguments = [zipper_args], progress_message = "JVM service info jar for %%{label}", ) - return struct( - providers = [ - JavaInfo( - output_jar = jar, - compile_jar = jar, - source_jar = jar, - runtime_deps = [], - exports = [], - neverlink = False, - ), - DefaultInfo( - files = depset([jar]), - runfiles = ctx.runfiles(files = [jar]), - ), - ], - ) + return [ + JavaInfo( + output_jar = jar, + compile_jar = jar, + source_jar = jar, + runtime_deps = [], + exports = [], + neverlink = False, + ), + DefaultInfo( + files = depset([jar]), + runfiles = ctx.runfiles(files = [jar]), + ), + ] def _write_service_file(ctx, srv, impls): f = ctx.actions.declare_file(ctx.label.name + "/" + srv) diff --git a/src/main/starlark/core/options/opts.javac.bzl b/src/main/starlark/core/options/opts.javac.bzl index a6c852b91..78974868a 100644 --- a/src/main/starlark/core/options/opts.javac.bzl +++ b/src/main/starlark/core/options/opts.javac.bzl @@ -100,11 +100,7 @@ _JOPTS = { } def _javac_options_impl(ctx): - return struct( - providers = [ - JavacOptions(**{n: getattr(ctx.attr, n, None) for n in _JOPTS}), - ], - ) + return [JavacOptions(**{n: getattr(ctx.attr, n, None) for n in _JOPTS})] JavacOptions = provider( fields = { diff --git a/src/main/starlark/core/options/opts.kotlinc.bzl b/src/main/starlark/core/options/opts.kotlinc.bzl index 9b15fb8ea..013f78ef6 100644 --- a/src/main/starlark/core/options/opts.kotlinc.bzl +++ b/src/main/starlark/core/options/opts.kotlinc.bzl @@ -362,11 +362,7 @@ KotlincOptions = provider( ) def _kotlinc_options_impl(ctx): - return struct( - providers = [ - KotlincOptions(**{n: getattr(ctx.attr, n, None) for n in _KOPTS}), - ], - ) + return [KotlincOptions(**{n: getattr(ctx.attr, n, None) for n in _KOPTS})] kt_kotlinc_options = rule( implementation = _kotlinc_options_impl, From 2852ecfc6c181977fea17dfee8d3194059a9db33 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 19 Apr 2024 15:01:36 +0200 Subject: [PATCH 2/3] Change _toolchain to provide Kotlin toolchain info --- kotlin/internal/jvm/jvm.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index 2f20de6d7..baa2bda41 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -140,9 +140,9 @@ _implicit_deps = { allow_single_file = True, ), "_toolchain": attr.label( - doc = """The Kotlin JVM Runtime. it's only purpose is to enable the Android native rules to discover the Kotlin - runtime for dexing""", - default = Label("//kotlin/compiler:kotlin-stdlib"), + doc = """The Kotlin toolchain. it's only purpose is to enable the Intellij + to discover Kotlin language version""", + default = Label("//kotlin/internal:default_toolchain_impl"), cfg = "target", ), "_java_toolchain": attr.label( From 93bbd243817f7bbc3f539a309d23da3e02ca8cd9 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 19 Apr 2024 15:44:49 +0200 Subject: [PATCH 3/3] Add back original _toolchain and use _kt_toolchain for Kotlin --- kotlin/internal/jvm/jvm.bzl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kotlin/internal/jvm/jvm.bzl b/kotlin/internal/jvm/jvm.bzl index baa2bda41..76cf17448 100644 --- a/kotlin/internal/jvm/jvm.bzl +++ b/kotlin/internal/jvm/jvm.bzl @@ -140,6 +140,12 @@ _implicit_deps = { allow_single_file = True, ), "_toolchain": attr.label( + doc = """The Kotlin JVM Runtime. it's only purpose is to enable the Android native rules to discover the Kotlin + runtime for dexing""", + default = Label("//kotlin/compiler:kotlin-stdlib"), + cfg = "target", + ), + "_kt_toolchain": attr.label( doc = """The Kotlin toolchain. it's only purpose is to enable the Intellij to discover Kotlin language version""", default = Label("//kotlin/internal:default_toolchain_impl"),