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 15"""Rule for asserting plugin propagation.""" 16 17load("@bazel_skylib//lib:sets.bzl", "sets") 18load("@bazel_skylib//rules:build_test.bzl", "build_test") 19load("//kotlin:traverse_exports.bzl", "kt_traverse_exports") 20load("//:visibility.bzl", "RULES_KOTLIN") 21 22def _assert_propagation_impl(ctx): 23 expected_ids = sets.make(ctx.attr.expected_plugin_ids) 24 actual_ids = sets.make([ 25 p.plugin_id 26 for p in kt_traverse_exports.expand_compiler_plugins(ctx.attr.deps).to_list() 27 ]) 28 29 if not sets.is_equal(expected_ids, actual_ids): 30 fail("Expected IDs %s, actual IDs %s" % (sets.to_list(expected_ids), sets.to_list(actual_ids))) 31 32 return [ 33 # Needed for kt_traverse_exports.aspect 34 JavaInfo( 35 compile_jar = ctx.file._empty_jar, 36 output_jar = ctx.file._empty_jar, 37 ), 38 ] 39 40_assert_propagation = rule( 41 implementation = _assert_propagation_impl, 42 attrs = dict( 43 exports = attr.label_list(), 44 exported_plugins = attr.label_list(), 45 expected_plugin_ids = attr.string_list(), 46 deps = attr.label_list(aspects = [kt_traverse_exports.aspect]), 47 _empty_jar = attr.label( 48 allow_single_file = True, 49 default = "//tests/analysis/compiler_plugin:empty_jar", 50 ), 51 ), 52) 53 54def assert_propagation_test(name, **kwargs): 55 _assert_propagation(name = name, **kwargs) 56 57 build_test(name = name + "_build", targets = [name]) 58