blob: 6eee7db85e43a2c041fc9119bb10974f90bebecd [file]
# Copyright 2024 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("//kotlin:core.bzl", "kt_ksp_plugin")
load("//kotlin:jvm.bzl", "kt_jvm_library")
load(":ksp_test.bzl", "ksp_action_test", "ksp_conflicting_options_test", "ksp_options_action_test", "ksp_outputs_test", "ksp_plugin_empty_options_provider_test", "ksp_plugin_options_provider_test", "ksp_single_action_test")
# Simple KSP plugin for testing (uses moshi which generates Kotlin code)
kt_ksp_plugin(
name = "moshi_plugin",
processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)
# KSP plugin with processor options for testing the options attribute
kt_ksp_plugin(
name = "moshi_plugin_with_options",
options = {
"another_key": "another_value",
"test_key": "test_value",
},
processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)
# Target under test - a simple kt_jvm_library with KSP plugin
kt_jvm_library(
name = "ksp_test_lib",
srcs = ["TestModel.kt"],
plugins = [":moshi_plugin"],
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
],
)
# Two KSP plugins that share the same option key — used to test conflict detection
kt_ksp_plugin(
name = "moshi_plugin_with_option_a",
options = {"shared_key": "value_from_a"},
processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)
kt_ksp_plugin(
name = "moshi_plugin_with_option_b",
options = {"shared_key": "value_from_b"},
processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin_codegen",
],
)
# Target under test - kt_jvm_library with KSP plugin that has options
kt_jvm_library(
name = "ksp_test_lib_with_options",
srcs = ["TestModel.kt"],
plugins = [":moshi_plugin_with_options"],
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
],
)
# Target under test - library with two plugins that have the same option key.
# Tagged manual so it is not analyzed by wildcard builds; the analysis test
# below pulls it in via target_under_test.
kt_jvm_library(
name = "ksp_test_lib_with_conflicting_options",
srcs = ["TestModel.kt"],
plugins = [
":moshi_plugin_with_option_a",
":moshi_plugin_with_option_b",
],
tags = ["manual"],
deps = [
"@kotlin_rules_maven//:com_squareup_moshi_moshi",
"@kotlin_rules_maven//:com_squareup_moshi_moshi_kotlin",
],
)
# Test that KSP produces expected outputs
ksp_outputs_test(
name = "ksp_outputs_test",
target_under_test = ":ksp_test_lib",
)
# Test that KSP creates the right action
ksp_action_test(
name = "ksp_action_test",
target_under_test = ":ksp_test_lib",
)
# Test that KSP uses a single action (no tree artifacts)
ksp_single_action_test(
name = "ksp_single_action_test",
target_under_test = ":ksp_test_lib",
)
# Test that KspPluginInfo carries options correctly
ksp_plugin_options_provider_test(
name = "ksp_plugin_options_provider_test",
target_under_test = ":moshi_plugin_with_options",
)
# Test that KspPluginInfo has empty options when none specified
ksp_plugin_empty_options_provider_test(
name = "ksp_plugin_empty_options_provider_test",
target_under_test = ":moshi_plugin",
)
# Test that KSP2 action still works when plugin has options
ksp_options_action_test(
name = "ksp_options_action_test",
target_under_test = ":ksp_test_lib_with_options",
)
# Test that conflicting KSP option keys across plugins fail analysis
ksp_conflicting_options_test(
name = "ksp_conflicting_options_test",
target_under_test = ":ksp_test_lib_with_conflicting_options",
)
test_suite(
name = "ksp_tests",
tests = [
":ksp_action_test",
":ksp_conflicting_options_test",
":ksp_options_action_test",
":ksp_outputs_test",
":ksp_plugin_empty_options_provider_test",
":ksp_plugin_options_provider_test",
":ksp_single_action_test",
],
)