Skip to content

Commit

Permalink
Fix missing plugin inputs (bazelbuild#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
justhecuke-zz authored Apr 28, 2020
1 parent 4a1213e commit dbf68b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar):
friend = _compiler_friends(ctx, friends = getattr(ctx.attr, "friends", []))
compile_deps = _compiler_deps(toolchains, friend, deps = ctx.attr.deps + ctx.attr.plugins)
annotation_processors = _plugin_mappers.targets_to_annotation_processors(ctx.attr.plugins + ctx.attr.deps)
transitive_runtime_jars = _plugin_mappers.targets_to_transitive_runtime_jars(ctx.attr.plugins + ctx.attr.deps)
plugins = ctx.attr.plugins

_run_kt_builder_action(
Expand All @@ -236,6 +237,7 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar):
friend = friend,
compile_deps = compile_deps,
annotation_processors = annotation_processors,
transitive_runtime_jars = transitive_runtime_jars,
plugins = plugins,
outputs = {
"output": output_jar,
Expand Down Expand Up @@ -271,7 +273,7 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar):
),
)

def _run_kt_builder_action(ctx, rule_kind, toolchains, dirs, srcs, friend, compile_deps, annotation_processors, plugins, outputs):
def _run_kt_builder_action(ctx, rule_kind, toolchains, dirs, srcs, friend, compile_deps, annotation_processors, transitive_runtime_jars, plugins, outputs):
"""Creates a KotlinBuilder action invocation."""
args = _utils.init_args(ctx, rule_kind, friend.module_name)

Expand Down Expand Up @@ -325,7 +327,9 @@ def _run_kt_builder_action(ctx, rule_kind, toolchains, dirs, srcs, friend, compi

ctx.actions.run(
mnemonic = "KotlinCompile",
inputs = depset(ctx.files.srcs, transitive = [compile_deps.compile_jars]),
inputs = depset(
ctx.files.srcs,
transitive = [compile_deps.compile_jars, transitive_runtime_jars]),
tools = tools,
input_manifests = input_manifests,
outputs = [f for f in outputs.values()],
Expand Down
1 change: 1 addition & 0 deletions kotlin/internal/jvm/jvm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ _common_attr = utils.add_dicts(
default = [],
aspects = [_kt_jvm_plugin_aspect],
providers = [JavaInfo],
cfg = "host",
),
"module_name": attr.string(
doc = """The name of the module, if not provided the module name is derived from the label. --e.g.,
Expand Down
9 changes: 8 additions & 1 deletion kotlin/internal/jvm/plugins.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ 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",
},
)

_EMPTY_PLUGIN_INFO = [KtJvmPluginInfo(annotation_processors = depset())]
_EMPTY_PLUGIN_INFO = [KtJvmPluginInfo(annotation_processors = depset(), transitive_runtime_jars = depset())]

# Mapping functions for args.add_all.
# These preserve the transitive depsets until needed.
Expand All @@ -36,11 +37,15 @@ def _kt_plugin_to_processorpath(processor):
def _targets_to_annotation_processors(targets):
return depset(transitive = [t[KtJvmPluginInfo].annotation_processors for t in targets if t[KtJvmPluginInfo]])

def _targets_to_transitive_runtime_jars(targets):
return depset(transitive = [t[KtJvmPluginInfo].transitive_runtime_jars for t in targets if t[KtJvmPluginInfo]])

def _targets_to_plugins(targets):
return depset(transitive = [t[KtJvmPluginInfo].plugins for t in targets if t[KtJvmPluginInfo]])

mappers = struct(
targets_to_annotation_processors = _targets_to_annotation_processors,
targets_to_transitive_runtime_jars = _targets_to_transitive_runtime_jars,
kt_plugin_to_processor = _kt_plugin_to_processor,
kt_plugin_to_processorpath = _kt_plugin_to_processorpath,
)
Expand All @@ -51,6 +56,7 @@ def merge_plugin_infos(attrs):
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),
)

def _kt_jvm_plugin_aspect_impl(target, ctx):
Expand All @@ -66,6 +72,7 @@ def _kt_jvm_plugin_aspect_impl(target, ctx):
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)]
Expand Down

0 comments on commit dbf68b5

Please sign in to comment.