1# Copyright 2021 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 15""" 16Definition of java_library rule. 17""" 18 19load("//java/common:java_semantics.bzl", "semantics") 20load("//java/common/rules:android_lint.bzl", "android_lint_subrule") 21load("//java/common/rules:java_library.bzl", "JAVA_LIBRARY_ATTRS") 22load("//java/common/rules/impl:bazel_java_library_impl.bzl", "bazel_java_library_rule") 23load("//java/private:java_info.bzl", "JavaInfo") 24 25def _proxy(ctx): 26 return bazel_java_library_rule( 27 ctx, 28 ctx.files.srcs, 29 ctx.attr.deps, 30 ctx.attr.runtime_deps, 31 ctx.attr.plugins, 32 ctx.attr.exports, 33 ctx.attr.exported_plugins, 34 ctx.files.resources, 35 ctx.attr.javacopts, 36 ctx.attr.neverlink, 37 ctx.files.proguard_specs, 38 ctx.attr.add_exports, 39 ctx.attr.add_opens, 40 ctx.attr.bootclasspath, 41 ctx.attr.javabuilder_jvm_flags, 42 ).values() 43 44java_library = rule( 45 _proxy, 46 doc = """ 47<p>This rule compiles and links sources into a <code>.jar</code> file.</p> 48 49<h4>Implicit outputs</h4> 50<ul> 51 <li><code>lib<var>name</var>.jar</code>: A Java archive containing the class files.</li> 52 <li><code>lib<var>name</var>-src.jar</code>: An archive containing the sources ("source 53 jar").</li> 54</ul> 55 """, 56 attrs = JAVA_LIBRARY_ATTRS, 57 provides = [JavaInfo], 58 outputs = { 59 "classjar": "lib%{name}.jar", 60 "sourcejar": "lib%{name}-src.jar", 61 }, 62 fragments = ["java", "cpp"], 63 toolchains = [semantics.JAVA_TOOLCHAIN], 64 subrules = [android_lint_subrule], 65) 66