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 15"""Attributes.""" 16 17load( 18 "//rules:attrs.bzl", 19 _attrs = "attrs", 20) 21load("//rules:providers.bzl", "StarlarkApkInfo") 22 23ATTRS = _attrs.add( 24 dict( 25 baseline_profiles = attr.label_list( 26 allow_files = [".txt"], 27 doc = ( 28 "The list of baseline profiles. They provide a way for developers " + 29 "to provide profile rules and could be used at installation time to " + 30 "speed up app startup and reduce jank. See " + 31 "https://developer.android.com/topic/performance/baselineprofiles/overview for " + 32 "more details." 33 ), 34 ), 35 deps = attr.label_list( 36 providers = [ 37 [CcInfo], 38 [JavaInfo], 39 ], 40 doc = ( 41 "The list of other libraries to link against. Permitted library types " + 42 "are: `android_library`, `java_library` with `android` constraint and " + 43 "`cc_library` wrapping or producing `.so` native libraries for the " + 44 "Android target platform." 45 ), 46 ), 47 enable_data_binding = attr.bool( 48 default = False, 49 doc = ( 50 "If true, this rule processes [data binding]" + 51 "(https://developer.android.com/topic/libraries/data-binding) " + 52 "expressions in layout resources included through the [resource_files]" + 53 "(https://docs.bazel.build/versions/main/be/android.html#android_binary.resource_files) " + 54 "attribute. Without this setting, data binding expressions produce build " + 55 "failures. To build an Android app with data binding, you must also do the following:" + 56 "\n\n1. Set this attribute for all Android rules that transitively depend on " + 57 "this one. This is because dependers inherit the rule's data binding " + 58 "expressions through resource merging. So they also need to build with " + 59 "data binding to parse those expressions." + 60 "\n\n2. Add a `deps =` entry for the data binding runtime library to all targets " + 61 "that set this attribute. The location of this library depends on your depot setup." 62 ), 63 ), 64 exported_plugins = attr.label_list( 65 providers = [ 66 [JavaPluginInfo], 67 ], 68 cfg = "exec", 69 doc = ( 70 "The list of [java_plugin](https://docs.bazel.build/versions/main/be/java.html#java_plugin)s " + 71 "(e.g. annotation processors) to export to libraries that directly depend on this library. " + 72 "The specified list of `java_plugin`s will be applied to any library which directly depends on " + 73 "this library, just as if that library had explicitly declared these labels in " + 74 "[plugins](#android_library-plugins)." 75 ), 76 ), 77 exports = attr.label_list( 78 providers = [ 79 [CcInfo], 80 [JavaInfo], 81 ], 82 doc = ( 83 "The closure of all rules reached via `exports` attributes are considered " + 84 "direct dependencies of any rule that directly depends on the target with " + 85 "`exports`. The `exports` are not direct deps of the rule they belong to." 86 ), 87 ), 88 exports_manifest = _attrs.tristate.create( 89 default = _attrs.tristate.no, 90 doc = ( 91 "Whether to export manifest entries to `android_binary` targets that " + 92 "depend on this target. `uses-permissions` attributes are never exported." 93 ), 94 ), 95 idl_import_root = attr.string( 96 doc = ( 97 "Package-relative path to the root of the java package tree containing idl " + 98 "sources included in this library. This path will be used as the import root " + 99 "when processing idl sources that depend on this library." + 100 "\n\n" + 101 "When `idl_import_root` is specified, both `idl_parcelables` and `idl_srcs` must " + 102 "be at the path specified by the java package of the object they represent " + 103 "under `idl_import_root`. When `idl_import_root` is not specified, both " + 104 "`idl_parcelables` and `idl_srcs` must be at the path specified by their " + 105 "package under a Java root. " + 106 "See [examples](#examples)" 107 ), 108 ), 109 idl_parcelables = attr.label_list( 110 allow_files = [".aidl"], 111 doc = ( 112 "List of Android IDL definitions to supply as imports. These files will " + 113 "be made available as imports for any `android_library` target that depends " + 114 "on this library, directly or via its transitive closure, but will not be " + 115 "translated to Java or compiled. Only `.aidl` files that correspond directly " + 116 "to `.java` sources in this library should be included (e.g., custom " + 117 "implementations of Parcelable), otherwise `idl_srcs` should be used." + 118 "\n\n" + 119 "These files must be placed appropriately for the aidl compiler to find " + 120 "them. See the description of [idl_import_root](#android_library-idl_import_root) " + 121 "for information about what this means." 122 ), 123 ), 124 idl_preprocessed = attr.label_list( 125 allow_files = [".aidl"], 126 doc = ( 127 "List of preprocessed Android IDL definitions to supply as imports. These " + 128 "files will be made available as imports for any `android_library` target " + 129 "that depends on this library, directly or via its transitive closure, but " + 130 "will not be translated to Java or compiled. Only preprocessed `.aidl` " + 131 "files that correspond directly to `.java` sources in this library should " + 132 "be included (e.g., custom implementations of Parcelable), otherwise use " + 133 "`idl_srcs` for Android IDL definitions that need to be translated to Java " + 134 "interfaces and use `idl_parcelable` for non-preprocessed AIDL files." 135 ), 136 ), 137 idl_srcs = attr.label_list( 138 allow_files = [".aidl"], 139 doc = ( 140 "List of Android IDL definitions to translate to Java interfaces. After " + 141 "the Java interfaces are generated, they will be compiled together with " + 142 "the contents of `srcs`. These files will be made available as imports " + 143 "for any `android_library` target that depends on this library, directly " + 144 "or via its transitive closure." + 145 "\n\n" + 146 "These files must be placed appropriately for the aidl compiler to find " + 147 "them. See the description of [idl_import_root](#android_library-idl_import_root) " + 148 "for information about what this means." 149 ), 150 ), 151 idl_uses_aosp_compiler = attr.bool( 152 default = False, 153 doc = ( 154 "Use the upstream AOSP compiler to generate Java files out of `idl_srcs`." + 155 "The upstream AOSP compiler provides several new language features that the " + 156 "Google3-only compiler doesn't provide. For example: structured parcelables, " + 157 "unions, enums, nested type declarations, constant expressions, annotations, " + 158 "and more. " + 159 "See [AIDL Doc](https://source.android.com/docs/core/architecture/aidl/overview) " + 160 "for more details. " + 161 "Note: the use of the AOSP compiler in google3 is restricted due to performance " + 162 "considerations. This should not be broadly used unless these features are " + 163 "strictly required." 164 ), 165 ), 166 idlopts = attr.string_list( 167 mandatory = False, 168 allow_empty = True, 169 default = [], 170 doc = ( 171 "Add these flags to the AIDL compiler command." 172 ), 173 ), 174 neverlink = attr.bool( 175 default = False, 176 doc = ( 177 "Only use this library for compilation and not at runtime. The outputs " + 178 "of a rule marked as neverlink will not be used in `.apk` creation. " + 179 "Useful if the library will be provided by the runtime environment during execution." 180 ), 181 ), 182 proguard_specs = attr.label_list( 183 allow_files = True, 184 doc = ( 185 "Files to be used as Proguard specification. These will describe the set " + 186 "of specifications to be used by Proguard. If specified, they will be " + 187 "added to any `android_binary` target depending on this library. The " + 188 "files included here must only have idempotent rules, namely -dontnote, " + 189 "-dontwarn, assumenosideeffects, and rules that start with -keep. Other " + 190 "options can only appear in `android_binary`'s proguard_specs, to " + 191 "ensure non-tautological merges." 192 ), 193 ), 194 resource_apks = attr.label_list( 195 allow_rules = ["apk_import"], 196 providers = [ 197 [StarlarkApkInfo], 198 ], 199 doc = ( 200 "List of resource only apks to link against." 201 ), 202 ), 203 srcs = attr.label_list( 204 allow_files = [".java", ".srcjar"], 205 doc = ( 206 "The list of `.java` or `.srcjar` files that are processed to create the " + 207 "target. `srcs` files of type `.java` are compiled. For *readability's " + 208 "sake*, it is not good to put the name of a generated `.java` source " + 209 "file into the `srcs`. Instead, put the depended-on rule name in the `srcs`, " + 210 "as described below." + 211 "\n\n" + 212 "`srcs` files of type `.srcjar` are unpacked and compiled. (This is useful " + 213 "if you need to generate a set of `.java` files with a genrule or build extension.)" 214 ), 215 ), 216 # TODO(b/127517031): Remove these entries once fixed. 217 _defined_assets = attr.bool(default = False), 218 _defined_assets_dir = attr.bool(default = False), 219 _defined_idl_import_root = attr.bool(default = False), 220 _defined_idl_parcelables = attr.bool(default = False), 221 _defined_idl_srcs = attr.bool(default = False), 222 _defined_local_resources = attr.bool(default = False), 223 _java_toolchain = attr.label( 224 default = Label("//tools/jdk:toolchain_android_only"), 225 ), 226 # TODO(str): Remove when fully migrated to android_instrumentation_test 227 _android_test_migration = attr.bool(default = False), 228 _flags = attr.label( 229 default = "//rules/flags", 230 ), 231 _package_name = attr.string(), # for sending the package name to the outputs callback 232 ), 233 _attrs.COMPILATION, 234 _attrs.DATA_CONTEXT, 235 _attrs.ANDROID_TOOLCHAIN_ATTRS, 236 _attrs.AUTOMATIC_EXEC_GROUPS_ENABLED, 237) 238