Skip to content

Commit

Permalink
Make kt_compiler_plugin work with android_binary
Browse files Browse the repository at this point in the history
  • Loading branch information
jongerrish committed Nov 12, 2020
1 parent 54c5ec8 commit 53a9577
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/android/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ maven_install(
"junit:junit:4.12",
"androidx.test.espresso:espresso-core:3.1.1",
"org.hamcrest:hamcrest-library:1.3",
"org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc",
],
repositories = [
"https://jcenter.bintray.com/",
Expand Down
13 changes: 12 additions & 1 deletion examples/android/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_android_library")

kt_compiler_plugin(
name = "serialization_plugin",
deps = [
"@com_github_jetbrains_kotlin//:kotlinx-serialization-compiler-plugin",
],
)

kt_android_library(
name = "lib",
Expand All @@ -7,6 +14,10 @@ kt_android_library(
manifest = "src/main/AndroidManifest.xml",
visibility = ["//visibility:public"],
deps = [
"@maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
"@maven//:androidx_appcompat_appcompat",
],
plugins = [
":serialization_plugin",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ class MainActivity : Activity() {
.setTitle("Blah")
.setMessage("Blah blah blah?")
.show()
// Ensure Serialization plugin has run and generated code correctly.
Data.serializer()
}
}
7 changes: 4 additions & 3 deletions kotlin/internal/jvm/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def kt_jvm_compile_action(ctx, rule_kind, output_jar, compile_jar):
dirs = _compiler_directories(ctx)
srcs = _partitioned_srcs(ctx.files.srcs)
friend = _compiler_friends(ctx, friends = getattr(ctx.attr, "friends", []))
compile_deps = _compiler_deps(toolchains, friend, deps = ctx.attr.deps + ctx.attr.plugins)
compile_deps = _compiler_deps(toolchains, friend, deps = ctx.attr.deps)
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
Expand Down Expand Up @@ -388,9 +388,10 @@ def _run_kt_builder_action(ctx, rule_kind, toolchains, dirs, srcs, friend, compi
omit_if_empty = True,
)

plugin_jars = _plugins_to_classpaths(plugins)
args.add_all(
"--pluginpath",
_plugins_to_classpaths(plugins),
plugin_jars,
omit_if_empty = True,
)
args.add_all(
Expand Down Expand Up @@ -419,7 +420,7 @@ def _run_kt_builder_action(ctx, rule_kind, toolchains, dirs, srcs, friend, compi
mnemonic = "KotlinCompile",
inputs = depset(
ctx.files.srcs,
transitive = [compile_deps.compile_jars, transitive_runtime_jars],
transitive = [compile_deps.compile_jars, transitive_runtime_jars, depset(plugin_jars)],
),
tools = tools,
input_manifests = input_manifests,
Expand Down

0 comments on commit 53a9577

Please sign in to comment.