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_library.""" 15 16load(":adapters/base.bzl", "make_adapter") 17load( 18 ":providers.bzl", 19 "MIAndroidDexInfo", 20 "MIJavaResourcesInfo", 21 "providers", 22) 23load(":transform.bzl", "dex", "extract_jar_resources") 24 25def _aspect_attrs(): 26 """Attrs of the rule requiring traversal by the aspect.""" 27 return ["deps", "exports", "runtime_deps"] 28 29def _adapt(target, ctx): 30 """Adapts the rule and target data. 31 32 Args: 33 target: The target. 34 ctx: The context. 35 36 Returns: 37 A list of providers. 38 """ 39 if ctx.rule.attr.neverlink: 40 return [] 41 42 return [ 43 providers.make_mi_android_dex_info( 44 dex_shards = dex( 45 ctx, 46 target[JavaInfo].runtime_output_jars, 47 target[JavaInfo].transitive_compile_time_jars, 48 ), 49 deps = providers.collect( 50 MIAndroidDexInfo, 51 ctx.rule.attr.deps, 52 ctx.rule.attr.runtime_deps, 53 ctx.rule.attr.exports, 54 ), 55 ), 56 providers.make_mi_java_resources_info( 57 java_resources = extract_jar_resources( 58 ctx, 59 target[JavaInfo].runtime_output_jars, 60 ), 61 deps = providers.collect( 62 MIJavaResourcesInfo, 63 ctx.rule.attr.deps, 64 ctx.rule.attr.runtime_deps, 65 ctx.rule.attr.exports, 66 ), 67 ), 68 ] 69 70java_library = make_adapter(_aspect_attrs, _adapt) 71