Skip to content

Commit 124421e

Browse files
authored
Add data attr to kt_plugin_cfg and kt_compiler_plugin (#1364)
* Add data attr to kt_plugin_cfg and kt_compiler_plugin * Regenerate docs * Update JC example with stability conf
1 parent f9157bb commit 124421e

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

docs/kotlin.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ Lint Kotlin files, and fail if the linter raises errors.
297297
<pre>
298298
load("@rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin")
299299

300-
kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_compiler_plugin-deps">deps</a>, <a href="#kt_compiler_plugin-compile_phase">compile_phase</a>, <a href="#kt_compiler_plugin-id">id</a>, <a href="#kt_compiler_plugin-options">options</a>, <a href="#kt_compiler_plugin-stubs_phase">stubs_phase</a>, <a href="#kt_compiler_plugin-target_embedded_compiler">target_embedded_compiler</a>)
300+
kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_compiler_plugin-deps">deps</a>, <a href="#kt_compiler_plugin-data">data</a>, <a href="#kt_compiler_plugin-compile_phase">compile_phase</a>, <a href="#kt_compiler_plugin-id">id</a>, <a href="#kt_compiler_plugin-options">options</a>, <a href="#kt_compiler_plugin-stubs_phase">stubs_phase</a>,
301+
<a href="#kt_compiler_plugin-target_embedded_compiler">target_embedded_compiler</a>)
301302
</pre>
302303

303304
Define a plugin for the Kotlin compiler to run. The plugin can then be referenced in the `plugins` attribute
@@ -339,6 +340,7 @@ kt_jvm_library(
339340
| :------------- | :------------- | :------------- | :------------- | :------------- |
340341
| <a id="kt_compiler_plugin-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
341342
| <a id="kt_compiler_plugin-deps"></a>deps | The list of libraries to be added to the compiler's plugin classpath | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
343+
| <a id="kt_compiler_plugin-data"></a>data | The list of data files to be used by compiler's plugin | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
342344
| <a id="kt_compiler_plugin-compile_phase"></a>compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: `allopen`, `sam_with_reciever` | Boolean | optional | `True` |
343345
| <a id="kt_compiler_plugin-id"></a>id | The ID of the plugin | String | required | |
344346
| <a id="kt_compiler_plugin-options"></a>options | Dictionary of options to be passed to the plugin. Supports the following template values:<br><br>- `{generatedClasses}`: directory for generated class output - `{temp}`: temporary directory, discarded between invocations - `{generatedSources}`: directory for generated source output - `{classpath}` : replaced with a list of jars separated by the filesystem appropriate separator. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | `{}` |
@@ -488,7 +490,7 @@ kt_jvm_library(
488490
<pre>
489491
load("@rules_kotlin//kotlin:core.bzl", "kt_plugin_cfg")
490492

491-
kt_plugin_cfg(<a href="#kt_plugin_cfg-name">name</a>, <a href="#kt_plugin_cfg-deps">deps</a>, <a href="#kt_plugin_cfg-options">options</a>, <a href="#kt_plugin_cfg-plugin">plugin</a>)
493+
kt_plugin_cfg(<a href="#kt_plugin_cfg-name">name</a>, <a href="#kt_plugin_cfg-deps">deps</a>, <a href="#kt_plugin_cfg-data">data</a>, <a href="#kt_plugin_cfg-options">options</a>, <a href="#kt_plugin_cfg-plugin">plugin</a>)
492494
</pre>
493495

494496
Configurations for kt_compiler_plugin, ksp_plugin, and java_plugin.
@@ -502,6 +504,7 @@ This allows setting options and dependencies independently from the initial plug
502504
| :------------- | :------------- | :------------- | :------------- | :------------- |
503505
| <a id="kt_plugin_cfg-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
504506
| <a id="kt_plugin_cfg-deps"></a>deps | Dependencies for this configuration. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
507+
| <a id="kt_plugin_cfg-data"></a>data | The list of data files to be used by compiler's plugin | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
505508
| <a id="kt_plugin_cfg-options"></a>options | A dictionary of flag to values to be used as plugin configuration options. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> List of strings</a> | optional | `{}` |
506509
| <a id="kt_plugin_cfg-plugin"></a>plugin | The plugin to associate with this configuration | <a href="https://bazel.build/concepts/labels">Label</a> | required | |
507510

examples/jetpack_compose/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ define_kt_toolchain(
1818

1919
kt_compiler_plugin(
2020
name = "jetpack_compose_compiler_plugin",
21+
data = [":stability_config"],
2122
id = "androidx.compose.compiler.plugins.kotlin",
2223
options = {
2324
"sourceInformation": "true", # Required for AS Layout Inspector, disable for release builds
25+
"stabilityConfigurationPath": "$(locations :stability_config)",
2426
},
2527
target_embedded_compiler = True,
2628
visibility = ["//visibility:public"],
@@ -29,6 +31,11 @@ kt_compiler_plugin(
2931
],
3032
)
3133

34+
filegroup(
35+
name = "stability_config",
36+
srcs = ["stability.conf"],
37+
)
38+
3239
platform(
3340
name = "arm64-v8a",
3441
constraint_values = [

examples/jetpack_compose/WORKSPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22

3+
# TODO (rbeazleyspot) Update release url when #1364 is released
34
http_archive(
45
name = "rules_kotlin",
56
sha256 = "34e8c0351764b71d78f76c8746e98063979ce08dcf1a91666f3f3bc2949a533d",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
android.net.Uri

kotlin/internal/jvm/impl.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ def _reshade_embedded_kotlinc_jars(target, ctx, jars, deps):
392392
],
393393
)
394394

395+
def _expand_location_with_data_deps(ctx):
396+
return lambda targets: ctx.expand_location(targets, ctx.attr.data)
397+
395398
def kt_compiler_plugin_impl(ctx):
396399
plugin_id = ctx.attr.id
397400

@@ -413,7 +416,7 @@ def kt_compiler_plugin_impl(ctx):
413416
classpath = depset(info.runtime_output_jars, transitive = [info.transitive_runtime_jars])
414417

415418
# TODO(1035): Migrate kt_compiler_plugin.options to string_list_dict
416-
options = plugin_common.resolve_plugin_options(plugin_id, {k: [v] for (k, v) in ctx.attr.options.items()}, ctx.expand_location)
419+
options = plugin_common.resolve_plugin_options(plugin_id, {k: [v] for (k, v) in ctx.attr.options.items()}, _expand_location_with_data_deps(ctx))
417420

418421
return [
419422
DefaultInfo(files = classpath),
@@ -432,7 +435,7 @@ def kt_plugin_cfg_impl(ctx):
432435
plugin = ctx.attr.plugin[_KtCompilerPluginInfo]
433436
return [
434437
plugin,
435-
] + plugin.resolve_cfg(plugin, ctx.attr.options, ctx.attr.deps, ctx.expand_location)
438+
] + plugin.resolve_cfg(plugin, ctx.attr.options, ctx.attr.deps, _expand_location_with_data_deps(ctx))
436439

437440
def kt_ksp_plugin_impl(ctx):
438441
deps = ctx.attr.deps

kotlin/internal/jvm/jvm.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ kt_jvm_library(
535535
```
536536
""",
537537
attrs = {
538+
"data": attr.label_list(
539+
doc = "The list of data files to be used by compiler's plugin",
540+
providers = [DefaultInfo],
541+
cfg = "exec",
542+
),
538543
"deps": attr.label_list(
539544
doc = "The list of libraries to be added to the compiler's plugin classpath",
540545
providers = [JavaInfo],
@@ -663,6 +668,11 @@ kt_plugin_cfg = rule(
663668
],
664669
cfg = "exec",
665670
),
671+
"data": attr.label_list(
672+
doc = "The list of data files to be used by compiler's plugin",
673+
providers = [DefaultInfo],
674+
cfg = "exec",
675+
),
666676
},
667677
)
668678

0 commit comments

Comments
 (0)