Skip to content

Commit d26f05b

Browse files
Bencodeserikkerber
authored andcommitted
Support for ksp_options
1 parent c6a2ffd commit d26f05b

File tree

8 files changed

+265
-248
lines changed

8 files changed

+265
-248
lines changed

examples/ksp/BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ kt_jvm_library(
9393
":tea_lib_src",
9494
":chai_lib_src",
9595
],
96+
ksp_opts = {
97+
"arg1": "value1",
98+
"arg2": "value2",
99+
},
96100
plugins = [
97101
"//third_party:dagger_ksp_plugin",
98102
"//third_party:moshi-kotlin-codegen",

kotlin/internal/jvm/compile.bzl

+9-3
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def _run_kt_builder_action(
525525
"""Creates a KotlinBuilder action invocation."""
526526
kotlinc_options = ctx.attr.kotlinc_opts[KotlincOptions] if ctx.attr.kotlinc_opts else toolchains.kt.kotlinc_options
527527
javac_options = ctx.attr.javac_opts[JavacOptions] if ctx.attr.javac_opts else toolchains.kt.javac_options
528-
528+
ksp_opts = ctx.attr.ksp_opts if ctx.attr.ksp_opts else None
529529
args = _utils.init_args(ctx, rule_kind, associates.module_name, kotlinc_options)
530530

531531
for f, path in outputs.items():
@@ -587,6 +587,12 @@ def _run_kt_builder_action(
587587
omit_if_empty = True,
588588
)
589589

590+
if ksp_opts:
591+
args.add_all(
592+
"--ksp_opts",
593+
_utils.dic_to_option_list(ksp_opts),
594+
)
595+
590596
args.add("--build_kotlin", build_kotlin)
591597

592598
progress_message = "%s %%{label} { kt: %d, java: %d, srcjars: %d } for %s" % (
@@ -984,10 +990,10 @@ def _run_kt_java_builder_actions(
984990
)
985991

986992
annotation_processing = None
987-
if annotation_processors:
993+
if annotation_processors or ksp_annotation_processors:
988994
outputs_list = [java_info.outputs for java_info in java_infos]
989995
annotation_processing = _create_annotation_processing(
990-
annotation_processors = annotation_processors,
996+
annotation_processors = annotation_processors or ksp_annotation_processors,
991997
ap_class_jar = [jars.class_jar for outputs in outputs_list for jars in outputs.jars][0],
992998
ap_source_jar = ap_generated_src_jar,
993999
)

kotlin/internal/jvm/jvm.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ _common_attr = utils.add_dicts(
253253
Transitive deps required for compilation must be explicitly added""",
254254
default = Label("//kotlin/settings:experimental_prune_transitive_deps"),
255255
),
256+
"ksp_opts": attr.string_dict(
257+
doc = """KSP processor options to be used when compiling this target.""",
258+
default = {},
259+
mandatory = False,
260+
),
256261
"_use_auto_exec_groups": attr.bool(default = False),
257262
},
258263
)

kotlin/internal/utils/utils.bzl

+8
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,18 @@ def _builder_workspace_name(ctx):
7575
lbl = ctx.workspace_name
7676
return lbl.replace("external/", "")
7777

78+
def _dic_to_option_list(dic):
79+
"""Converts a dictionary to a list of options in the form of `key=value`"""
80+
options = []
81+
for key, value in dic.items():
82+
options.append(key + "=" + value)
83+
return options
84+
7885
utils = struct(
7986
add_dicts = _add_dicts,
8087
init_args = _init_builder_args,
8188
restore_label = _restore_label,
8289
derive_module_name = _derive_module_name,
8390
builder_workspace_name = _builder_workspace_name,
91+
dic_to_option_list = _dic_to_option_list,
8492
)

kotlin/settings/BUILD.bazel

-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
2-
3-
# Copyright 2020 The Bazel Authors. All rights reserved.
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the "License");
6-
# you may not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
162
load("//src/main/starlark/release:packager.bzl", "release_archive")
173

184
release_archive(

0 commit comments

Comments
 (0)