1# Copyright 2022 Google LLC. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the License); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15load("//kotlin/common/testing:testing_rules.bzl", "kt_testing_rules") 16load("//kotlin/jvm/testing:for_analysis.bzl", ktfa = "kt_for_analysis") 17load("//kotlin/jvm/testing:jvm_library_analysis_test.bzl", "kt_jvm_library_analysis_test") 18 19package( 20 default_applicable_licenses = ["//:license"], 21 default_testonly = True, 22) 23 24licenses(["notice"]) 25 26DEFAULT_KOTLINC_PLUGINS = [ 27 "jvm-abi-gen.jar", 28] 29 30kt_jvm_library_analysis_test( 31 name = "has_plugin_and_only_kt_srcs_test", 32 expect_processor_classpath = True, 33 expected_exported_processor_classes = [], 34 expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS + ["kt_compiler_plugin.jar"], 35 expected_processor_classes = ["java.plugin.class"], 36 target_under_test = ktfa.kt_jvm_library( 37 name = "has_plugin_and_only_kt_srcs", 38 srcs = ["Input.kt"], 39 plugins = [ 40 ":java_plugin", 41 ":kt_compiler_plugin", 42 ], 43 ), 44) 45 46kt_jvm_library_analysis_test( 47 name = "has_plugin_and_only_java_srcs_test", 48 expect_processor_classpath = True, 49 expected_exported_processor_classes = [], 50 expected_kotlinc_plugin_jar_names = [], # No kotlinc action 51 expected_processor_classes = ["java.plugin.class"], 52 target_under_test = ktfa.kt_jvm_library( 53 name = "has_plugin_and_only_java_srcs", 54 srcs = ["Input.java"], 55 plugins = [ 56 ":java_plugin", 57 ":kt_compiler_plugin", 58 ], 59 ), 60) 61 62kt_jvm_library_analysis_test( 63 name = "has_plugin_without_processor_class_test", 64 expect_processor_classpath = True, 65 expected_exported_processor_classes = [], 66 target_under_test = ktfa.kt_jvm_library( 67 name = "has_plugin_without_processor_class", 68 srcs = ["Input.java"], 69 plugins = [ 70 ktfa.java_plugin( 71 name = "java_plugin_without_processor_class", 72 srcs = ["Input.java"], 73 ), 74 ], 75 ), 76) 77 78[ 79 kt_jvm_library_analysis_test( 80 name = "dep_on_" + exporter + "_test", 81 expect_processor_classpath = True, 82 expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS + ["kt_compiler_plugin.jar"], 83 expected_processor_classes = ["java.plugin.class"], 84 target_under_test = ktfa.kt_jvm_library( 85 name = "dep_on_" + exporter, 86 srcs = ["Input.kt"], 87 deps = [exporter], 88 ), 89 ) 90 for exporter in [ 91 "java_library_with_exported_plugin", 92 "kt_jvm_library_with_exported_plugin", 93 ] + [ 94 "kt_jvm_library_exporting_java_library_with_exported_plugin", 95 "kt_jvm_library_exporting_kt_jvm_library_with_exported_plugin", 96 ] 97] 98 99[ 100 kt_jvm_library_analysis_test( 101 name = "kt_jvm_library_exporting_" + export + "_test", 102 expect_processor_classpath = False, 103 expected_exported_processor_classes = ["java.plugin.class"], 104 expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS, 105 expected_processor_classes = [], 106 target_under_test = ktfa.kt_jvm_library( 107 name = "kt_jvm_library_exporting_" + export, 108 srcs = ["Input.kt"], 109 exports = [export], 110 ), 111 ) 112 for export in [ 113 "java_library_with_exported_plugin", 114 "kt_jvm_library_with_exported_plugin", 115 ] 116] 117 118ktfa.java_library( 119 name = "java_library_with_exported_plugin", 120 srcs = ["Input.java"], 121 exported_plugins = [ 122 ":java_plugin", 123 ":kt_compiler_plugin", 124 ], 125) 126 127kt_jvm_library_analysis_test( 128 name = "kt_jvm_library_with_exported_plugin_test", 129 expect_processor_classpath = False, 130 expected_exported_processor_classes = ["java.plugin.class"], 131 expected_kotlinc_plugin_jar_names = DEFAULT_KOTLINC_PLUGINS, 132 expected_processor_classes = [], # exported plugin should *not* run on exporter itself 133 target_under_test = ktfa.kt_jvm_library( 134 name = "kt_jvm_library_with_exported_plugin", 135 srcs = ["Input.kt"], 136 exported_plugins = [ 137 ":java_plugin", 138 ":kt_compiler_plugin", 139 ], 140 ), 141) 142 143ktfa.java_plugin( 144 name = "java_plugin", 145 srcs = ["Input.java"], 146 processor_class = "java.plugin.class", 147) 148 149ktfa.kt_compiler_plugin( 150 name = "kt_compiler_plugin", 151 jar = kt_testing_rules.create_file(name = "kt_compiler_plugin.jar"), 152 plugin_id = "kt.plugin", 153) 154