Skip to content

Commit

Permalink
Remove legacy struct providers (#1157)
Browse files Browse the repository at this point in the history
* Remove legacy struct providers in main repo

* Change _toolchain to provide Kotlin toolchain info

* Add back original _toolchain and use _kt_toolchain for Kotlin
  • Loading branch information
comius authored and restingbull committed May 31, 2024
1 parent cf3de5d commit aee350c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 66 deletions.
74 changes: 34 additions & 40 deletions kotlin/internal/jvm/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions kotlin/internal/jvm/jvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ _implicit_deps = {
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"),
cfg = "target",
),
"_java_toolchain": attr.label(
default = Label("@bazel_tools//tools/jdk:current_java_toolchain"),
),
Expand Down
30 changes: 14 additions & 16 deletions kotlin/internal/utils/generate_jvm_service.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions src/main/starlark/core/options/opts.javac.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 1 addition & 5 deletions src/main/starlark/core/options/opts.kotlinc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit aee350c

Please sign in to comment.