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("//rules:android_neverlink_aspect.bzl", "android_neverlink_aspect") 18load( 19 "//rules:attrs.bzl", 20 _attrs = "attrs", 21) 22load("//rules:dex_desugar_aspect.bzl", "dex_desugar_aspect") 23load( 24 "//rules:native_deps.bzl", 25 "split_config_aspect", 26) 27load("//rules:providers.bzl", "StarlarkApkInfo") 28 29def make_deps(allow_rules, providers, aspects): 30 return attr.label_list( 31 allow_files = True, 32 allow_rules = allow_rules, 33 providers = providers, 34 aspects = aspects, 35 cfg = android_common.multi_cpu_configuration, 36 ) 37 38DEPS_ALLOW_RULES = [ 39 "aar_import", 40 "android_library", 41 "cc_library", 42 "java_import", 43 "java_library", 44 "java_lite_proto_library", 45] 46 47DEPS_PROVIDERS = [ 48 [CcInfo], 49 [JavaInfo], 50 ["AndroidResourcesInfo", "AndroidAssetsInfo"], 51] 52 53DEPS_ASPECTS = [ 54 dex_desugar_aspect, 55 android_neverlink_aspect, 56] 57 58ATTRS = _attrs.replace( 59 _attrs.add( 60 dict( 61 srcs = attr.label_list( 62 # TODO(timpeut): Set PropertyFlag direct_compile_time_input 63 allow_files = [".java", ".srcjar"], 64 ), 65 deps = make_deps(DEPS_ALLOW_RULES, DEPS_PROVIDERS, DEPS_ASPECTS), 66 enable_data_binding = attr.bool(), 67 instruments = attr.label(), 68 manifest_values = attr.string_dict(), 69 manifest_merger = attr.string( 70 default = "auto", 71 values = ["auto", "legacy", "android", "force_android"], 72 ), 73 native_target = attr.label( 74 allow_files = False, 75 allow_rules = ["android_binary", "android_test"], 76 ), 77 generate_art_profile = attr.bool( 78 default = True, 79 doc = """ 80 Whether to generate ART profile. If true, the ART profile will be generated 81 and bundled into your APK’s asset directory. During APK installation, Android 82 Runtime(ART) will perform Ahead-of-time (AOT) compilation of methods in the 83 profile, speeding up app startup time or reducing jank in some circumstances. 84 """, 85 ), 86 startup_profiles = attr.label_list( 87 allow_empty = True, 88 allow_files = [".txt"], 89 doc = """ 90 List of baseline profiles that were collected at runtime (often from start-up) for 91 this binary. When this is specified, all baseline profiles (including these) are 92 used to inform code optimizations in the build toolchain. This may improve runtime 93 performance at the cost of dex size. If the dex size cost is too large and the 94 performance wins too small, the same profiles can be provided as a dep from an 95 android_library with `baseline_profiles` to avoid the runtime-focused code 96 optimizations that are enabled by `startup_profiles`. 97 """, 98 ), 99 proguard_specs = attr.label_list(allow_empty = True, allow_files = True), 100 resource_apks = attr.label_list( 101 allow_rules = ["apk_import"], 102 providers = [ 103 [StarlarkApkInfo], 104 ], 105 doc = ( 106 "List of resource only apks to link against." 107 ), 108 ), 109 resource_configuration_filters = attr.string_list(), 110 densities = attr.string_list(), 111 nocompress_extensions = attr.string_list(), 112 shrink_resources = _attrs.tristate.create( 113 default = _attrs.tristate.auto, 114 ), 115 dexopts = attr.string_list(), 116 main_dex_list = attr.label(allow_single_file = True), 117 main_dex_list_opts = attr.string_list(), 118 main_dex_proguard_specs = attr.label_list(allow_empty = True, allow_files = True), 119 min_sdk_version = attr.int(), 120 incremental_dexing = _attrs.tristate.create( 121 default = _attrs.tristate.auto, 122 ), 123 proguard_generate_mapping = attr.bool(default = False), 124 proguard_optimization_passes = attr.int(), 125 proguard_apply_mapping = attr.label(allow_single_file = True), 126 multidex = attr.string( 127 default = "native", 128 values = ["native", "legacy", "manual_main_dex"], 129 ), 130 _java_toolchain = attr.label( 131 default = Label("//tools/jdk:toolchain_android_only"), 132 ), 133 _defined_resource_files = attr.bool(default = False), 134 _enable_manifest_merging = attr.bool(default = True), 135 _cc_toolchain_split = attr.label( 136 cfg = android_common.multi_cpu_configuration, 137 default = "@bazel_tools//tools/cpp:current_cc_toolchain", 138 aspects = [split_config_aspect], 139 ), 140 _optimizing_dexer = attr.label( 141 cfg = "exec", 142 allow_single_file = True, 143 default = configuration_field( 144 fragment = "android", 145 name = "optimizing_dexer", 146 ), 147 ), 148 _desugared_java8_legacy_apis = attr.label( 149 default = Label("//tools/android:desugared_java8_legacy_apis"), 150 allow_single_file = True, 151 ), 152 _bytecode_optimizer = attr.label( 153 default = configuration_field( 154 fragment = "java", 155 name = "bytecode_optimizer", 156 ), 157 cfg = "exec", 158 executable = True, 159 ), 160 _legacy_main_dex_list_generator = attr.label( 161 default = configuration_field( 162 fragment = "android", 163 name = "legacy_main_dex_list_generator", 164 ), 165 cfg = "exec", 166 executable = True, 167 ), 168 ), 169 _attrs.COMPILATION, 170 _attrs.DATA_CONTEXT, 171 _attrs.ANDROID_TOOLCHAIN_ATTRS, 172 _attrs.AUTOMATIC_EXEC_GROUPS_ENABLED, 173 ), 174 # TODO(b/167599192): don't override manifest attr to remove .xml file restriction. 175 manifest = attr.label( 176 allow_single_file = True, 177 ), 178) 179