1# Copyright 2018 The Bazel Authors. 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"""Rule adapter for proto_lang_toolchain.""" 15 16load(":adapters/base.bzl", "make_adapter") 17load(":providers.bzl", "MIAndroidDexInfo", "MIJavaResourcesInfo", "providers") 18 19def _aspect_attrs(): 20 """Attrs of the rule requiring traversal by the aspect.""" 21 return ["runtime"] 22 23def _adapt(unused_target, ctx): 24 """Adapts the rule and target data. 25 26 Args: 27 unused_target: The target. 28 ctx: The context. 29 30 Returns: 31 A list of providers. 32 """ 33 if not ctx.rule.attr.runtime: 34 return [] 35 return [ 36 providers.make_mi_android_dex_info( 37 deps = providers.collect( 38 MIAndroidDexInfo, 39 [ctx.rule.attr.runtime], 40 ), 41 ), 42 providers.make_mi_java_resources_info( 43 deps = providers.collect( 44 MIJavaResourcesInfo, 45 [ctx.rule.attr.runtime], 46 ), 47 ), 48 ] 49 50proto_lang_toolchain = make_adapter(_aspect_attrs, _adapt) 51