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 java_lite_proto_library. 15 16The java_lite_proto_library rule applies an aspect onto its proto dependencies. 17Creates a "lite.jar" at every proto traversed. This adapter is used to just 18propagate the deps, the proto_library rules. 19""" 20 21load(":adapters/base.bzl", "make_adapter") 22load(":providers.bzl", "MIAndroidDexInfo", "MIJavaResourcesInfo", "providers") 23 24def _aspect_attrs(): 25 """Attrs of the rule requiring traversal by the aspect.""" 26 return ["deps", "_aspect_proto_toolchain_for_javalite"] 27 28def _adapt(target, ctx): 29 """Adapts the rule and target data. 30 31 Args: 32 target: The target. 33 ctx: The context. 34 35 Returns: 36 A list of providers. 37 """ 38 if not ctx.rule.attr.deps: 39 return [] 40 return [ 41 providers.make_mi_android_dex_info( 42 deps = providers.collect( 43 MIAndroidDexInfo, 44 ctx.rule.attr.deps, 45 [ctx.rule.attr._aspect_proto_toolchain_for_javalite], 46 ), 47 ), 48 providers.make_mi_java_resources_info( 49 deps = providers.collect( 50 MIJavaResourcesInfo, 51 ctx.rule.attr.deps, 52 [ctx.rule.attr._aspect_proto_toolchain_for_javalite], 53 ), 54 ), 55 ] 56 57java_lite_proto_library = make_adapter(_aspect_attrs, _adapt) 58