1*8975f5c5SAndroid Build Coastguard Worker# Copyright 2014 The Chromium Authors 2*8975f5c5SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*8975f5c5SAndroid Build Coastguard Worker# found in the LICENSE file. 4*8975f5c5SAndroid Build Coastguard Worker 5*8975f5c5SAndroid Build Coastguard Worker# Do not add any imports to non-//build directories here. 6*8975f5c5SAndroid Build Coastguard Worker# Some projects (e.g. V8) do not have non-build directories DEPS'ed in. 7*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/android/channel.gni") 8*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/android/config.gni") 9*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/compiler/compiler.gni") 10*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/compute_inputs_for_analyze.gni") 11*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/coverage/coverage.gni") 12*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/python.gni") 13*8975f5c5SAndroid Build Coastguard Workerimport("//build/config/sanitizers/sanitizers.gni") 14*8975f5c5SAndroid Build Coastguard Workerimport("//build/toolchain/kythe.gni") 15*8975f5c5SAndroid Build Coastguard Workerimport("//build/util/generate_wrapper.gni") 16*8975f5c5SAndroid Build Coastguard Workerimport("//build_overrides/build.gni") 17*8975f5c5SAndroid Build Coastguard Workerif (current_toolchain == default_toolchain) { 18*8975f5c5SAndroid Build Coastguard Worker import("//build/toolchain/concurrent_links.gni") 19*8975f5c5SAndroid Build Coastguard Worker} 20*8975f5c5SAndroid Build Coastguard Workerassert(is_android) 21*8975f5c5SAndroid Build Coastguard Worker 22*8975f5c5SAndroid Build Coastguard Workerdefault_android_sdk_dep = "//third_party/android_sdk:android_sdk_java" 23*8975f5c5SAndroid Build Coastguard Worker_kotlin_stdlib_dep = "//third_party/kotlin_stdlib:kotlin_stdlib_java" 24*8975f5c5SAndroid Build Coastguard Worker_jacoco_dep = "//third_party/jacoco:jacocoagent_java" 25*8975f5c5SAndroid Build Coastguard Worker_jacoco_host_jar = 26*8975f5c5SAndroid Build Coastguard Worker "$root_build_dir/lib.java/third_party/jacoco/jacocoagent_java.jar" 27*8975f5c5SAndroid Build Coastguard Worker_robolectric_libs_dir = 28*8975f5c5SAndroid Build Coastguard Worker rebase_path( 29*8975f5c5SAndroid Build Coastguard Worker get_label_info("//:foo($robolectric_toolchain)", "root_out_dir"), 30*8975f5c5SAndroid Build Coastguard Worker root_build_dir) 31*8975f5c5SAndroid Build Coastguard Worker_nullaway_jar = "//third_party/android_build_tools/nullaway/cipd/nullaway.jar" 32*8975f5c5SAndroid Build Coastguard Worker_rebased_nullaway_jar = rebase_path(_nullaway_jar, root_build_dir) 33*8975f5c5SAndroid Build Coastguard Worker 34*8975f5c5SAndroid Build Coastguard Worker# The following _java_*_types variables capture all the existing target types. 35*8975f5c5SAndroid Build Coastguard Worker# If a new type is introduced, please add it to one of these categories, 36*8975f5c5SAndroid Build Coastguard Worker# preferring the more specific resource/library types. 37*8975f5c5SAndroid Build Coastguard Worker_java_resource_types = [ 38*8975f5c5SAndroid Build Coastguard Worker "android_assets", 39*8975f5c5SAndroid Build Coastguard Worker "android_resources", 40*8975f5c5SAndroid Build Coastguard Worker] 41*8975f5c5SAndroid Build Coastguard Worker 42*8975f5c5SAndroid Build Coastguard Worker_java_library_types = [ 43*8975f5c5SAndroid Build Coastguard Worker "java_library", 44*8975f5c5SAndroid Build Coastguard Worker "system_java_library", 45*8975f5c5SAndroid Build Coastguard Worker "android_app_bundle_module", 46*8975f5c5SAndroid Build Coastguard Worker] 47*8975f5c5SAndroid Build Coastguard Worker 48*8975f5c5SAndroid Build Coastguard Worker# These are leaf java target types. They cannot be passed as deps to other 49*8975f5c5SAndroid Build Coastguard Worker# targets. Thus their naming schemes are not enforced. 50*8975f5c5SAndroid Build Coastguard Worker_java_leaf_types = [ 51*8975f5c5SAndroid Build Coastguard Worker "android_apk", 52*8975f5c5SAndroid Build Coastguard Worker "android_app_bundle", 53*8975f5c5SAndroid Build Coastguard Worker "dist_aar", 54*8975f5c5SAndroid Build Coastguard Worker "dist_jar", 55*8975f5c5SAndroid Build Coastguard Worker "java_annotation_processor", 56*8975f5c5SAndroid Build Coastguard Worker "java_binary", 57*8975f5c5SAndroid Build Coastguard Worker "robolectric_binary", 58*8975f5c5SAndroid Build Coastguard Worker] 59*8975f5c5SAndroid Build Coastguard Worker 60*8975f5c5SAndroid Build Coastguard Worker# All _java_resource_types targets must conform to these patterns. 61*8975f5c5SAndroid Build Coastguard Workerjava_resource_patterns = [ 62*8975f5c5SAndroid Build Coastguard Worker "*_assets", 63*8975f5c5SAndroid Build Coastguard Worker "*_grd", 64*8975f5c5SAndroid Build Coastguard Worker "*_java_strings", 65*8975f5c5SAndroid Build Coastguard Worker "*locale_paks", 66*8975f5c5SAndroid Build Coastguard Worker "*_resources", 67*8975f5c5SAndroid Build Coastguard Worker "*strings_java", 68*8975f5c5SAndroid Build Coastguard Worker "*android*:assets", 69*8975f5c5SAndroid Build Coastguard Worker "*:*_apk_*resources", 70*8975f5c5SAndroid Build Coastguard Worker "*android*:resources", 71*8975f5c5SAndroid Build Coastguard Worker] 72*8975f5c5SAndroid Build Coastguard Worker 73*8975f5c5SAndroid Build Coastguard Worker# All _java_library_types targets must conform to these patterns. This includes 74*8975f5c5SAndroid Build Coastguard Worker# all non-leaf targets that use java_library_impl. 75*8975f5c5SAndroid Build Coastguard Workerjava_library_patterns = [ 76*8975f5c5SAndroid Build Coastguard Worker "*_java", 77*8975f5c5SAndroid Build Coastguard Worker "*_javalib", 78*8975f5c5SAndroid Build Coastguard Worker "*javatests", 79*8975f5c5SAndroid Build Coastguard Worker "*_bundle_module", 80*8975f5c5SAndroid Build Coastguard Worker "*:*_java_*", # E.g. chrome_java_test_support 81*8975f5c5SAndroid Build Coastguard Worker "*:java", 82*8975f5c5SAndroid Build Coastguard Worker "*/java", # to allow filtering without expanding labels //a/java -> 83*8975f5c5SAndroid Build Coastguard Worker # //a/java:java 84*8975f5c5SAndroid Build Coastguard Worker "*:junit", 85*8975f5c5SAndroid Build Coastguard Worker "*/junit", 86*8975f5c5SAndroid Build Coastguard Worker "*:junit_*", 87*8975f5c5SAndroid Build Coastguard Worker "*:*_junit_*", 88*8975f5c5SAndroid Build Coastguard Worker 89*8975f5c5SAndroid Build Coastguard Worker # TODO(agrieve): Rename to glue_java 90*8975f5c5SAndroid Build Coastguard Worker "//android_webview/glue", 91*8975f5c5SAndroid Build Coastguard Worker "//android_webview/glue:glue", 92*8975f5c5SAndroid Build Coastguard Worker] 93*8975f5c5SAndroid Build Coastguard Worker 94*8975f5c5SAndroid Build Coastguard Worker# These identify all non-leaf targets that have .build_config.json files. This is the 95*8975f5c5SAndroid Build Coastguard Worker# set of patterns that other targets can use to filter out java targets. 96*8975f5c5SAndroid Build Coastguard Workerjava_target_patterns = java_library_patterns + java_resource_patterns 97*8975f5c5SAndroid Build Coastguard Worker 98*8975f5c5SAndroid Build Coastguard Worker_r8_path = "//third_party/r8/cipd/lib/r8.jar" 99*8975f5c5SAndroid Build Coastguard Worker_custom_r8_path = "//third_party/r8/custom_r8.jar" 100*8975f5c5SAndroid Build Coastguard Worker 101*8975f5c5SAndroid Build Coastguard Worker# This duplication is intentional, so we avoid updating the r8.jar used by 102*8975f5c5SAndroid Build Coastguard Worker# dexing unless necessary, since each update invalidates all incremental dexing 103*8975f5c5SAndroid Build Coastguard Worker# and unnecessarily slows down all bots. 104*8975f5c5SAndroid Build Coastguard Worker_d8_path = "//third_party/r8/d8/cipd/lib/r8.jar" 105*8975f5c5SAndroid Build Coastguard Worker_custom_d8_path = "//third_party/r8/custom_d8.jar" 106*8975f5c5SAndroid Build Coastguard Worker_default_lint_jar_path = "//third_party/android_build_tools/lint/cipd/lint.jar" 107*8975f5c5SAndroid Build Coastguard Worker_custom_lint_jar_path = "//third_party/android_build_tools/lint/custom_lint.jar" 108*8975f5c5SAndroid Build Coastguard Worker_manifest_merger_jar_path = 109*8975f5c5SAndroid Build Coastguard Worker "//third_party/android_build_tools/manifest_merger/cipd/manifest-merger.jar" 110*8975f5c5SAndroid Build Coastguard Worker 111*8975f5c5SAndroid Build Coastguard Worker# Put the bug number in the target name so that false-positives have a hint in 112*8975f5c5SAndroid Build Coastguard Worker# the error message about why non-existent dependencies are there. 113*8975f5c5SAndroid Build Coastguard Workerbuild_config_target_suffix = "__build_config_crbug_908819" 114*8975f5c5SAndroid Build Coastguard Worker 115*8975f5c5SAndroid Build Coastguard Worker# Write the target's .build_config.json file. This is a json file that contains a 116*8975f5c5SAndroid Build Coastguard Worker# dictionary of information about how to build this target (things that 117*8975f5c5SAndroid Build Coastguard Worker# require knowledge about this target's dependencies and cannot be calculated 118*8975f5c5SAndroid Build Coastguard Worker# at gn-time). There is a special syntax to add a value in that dictionary to 119*8975f5c5SAndroid Build Coastguard Worker# an action/action_foreachs args: 120*8975f5c5SAndroid Build Coastguard Worker# --python-arg=@FileArg($rebased_build_config_path:key0:key1) 121*8975f5c5SAndroid Build Coastguard Worker# At runtime, such an arg will be replaced by the value in the build_config. 122*8975f5c5SAndroid Build Coastguard Worker# See build/android/gyp/write_build_config.py and 123*8975f5c5SAndroid Build Coastguard Worker# build/android/gyp/util/build_utils.py:ExpandFileArgs 124*8975f5c5SAndroid Build Coastguard Workertemplate("write_build_config") { 125*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 126*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, [ "testonly" ]) 127*8975f5c5SAndroid Build Coastguard Worker _type = invoker.type 128*8975f5c5SAndroid Build Coastguard Worker _parent_invoker = invoker.invoker 129*8975f5c5SAndroid Build Coastguard Worker _target_label = 130*8975f5c5SAndroid Build Coastguard Worker get_label_info(":${_parent_invoker.target_name}", "label_no_toolchain") 131*8975f5c5SAndroid Build Coastguard Worker 132*8975f5c5SAndroid Build Coastguard Worker # Ensure targets match naming patterns so that __assetres, __header, __host, 133*8975f5c5SAndroid Build Coastguard Worker # and __validate targets work properly. 134*8975f5c5SAndroid Build Coastguard Worker if (filter_exclude([ _type ], _java_resource_types) == []) { 135*8975f5c5SAndroid Build Coastguard Worker if (filter_exclude([ _target_label ], java_resource_patterns) != []) { 136*8975f5c5SAndroid Build Coastguard Worker assert(false, "Invalid java resource target name: $_target_label") 137*8975f5c5SAndroid Build Coastguard Worker } 138*8975f5c5SAndroid Build Coastguard Worker } else if (filter_exclude([ _type ], _java_library_types) == []) { 139*8975f5c5SAndroid Build Coastguard Worker if (filter_exclude([ _target_label ], java_library_patterns) != [] || 140*8975f5c5SAndroid Build Coastguard Worker filter_exclude([ _target_label ], java_resource_patterns) == []) { 141*8975f5c5SAndroid Build Coastguard Worker assert(false, "Invalid java library target name: $_target_label") 142*8975f5c5SAndroid Build Coastguard Worker } 143*8975f5c5SAndroid Build Coastguard Worker } else if (_type == "group") { 144*8975f5c5SAndroid Build Coastguard Worker if (filter_exclude([ _target_label ], java_target_patterns) != []) { 145*8975f5c5SAndroid Build Coastguard Worker assert(false, "Invalid java target name: $_target_label") 146*8975f5c5SAndroid Build Coastguard Worker } 147*8975f5c5SAndroid Build Coastguard Worker } else if (filter_exclude([ _type ], _java_leaf_types) != []) { 148*8975f5c5SAndroid Build Coastguard Worker assert(false, "This java type needs a category: $_type") 149*8975f5c5SAndroid Build Coastguard Worker } 150*8975f5c5SAndroid Build Coastguard Worker 151*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.public_target_label)) { 152*8975f5c5SAndroid Build Coastguard Worker _target_label = invoker.public_target_label 153*8975f5c5SAndroid Build Coastguard Worker } 154*8975f5c5SAndroid Build Coastguard Worker 155*8975f5c5SAndroid Build Coastguard Worker deps = [] 156*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 157*8975f5c5SAndroid Build Coastguard Worker deps = invoker.deps 158*8975f5c5SAndroid Build Coastguard Worker } 159*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.android_manifest_dep)) { 160*8975f5c5SAndroid Build Coastguard Worker deps += [ invoker.android_manifest_dep ] 161*8975f5c5SAndroid Build Coastguard Worker } 162*8975f5c5SAndroid Build Coastguard Worker 163*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/write_build_config.py" 164*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 165*8975f5c5SAndroid Build Coastguard Worker inputs = [] 166*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.build_config ] 167*8975f5c5SAndroid Build Coastguard Worker 168*8975f5c5SAndroid Build Coastguard Worker _deps_configs = [] 169*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.possible_config_deps)) { 170*8975f5c5SAndroid Build Coastguard Worker foreach(_possible_dep, invoker.possible_config_deps) { 171*8975f5c5SAndroid Build Coastguard Worker _dep_label = get_label_info(_possible_dep, "label_no_toolchain") 172*8975f5c5SAndroid Build Coastguard Worker if (filter_exclude([ _dep_label ], java_target_patterns) == []) { 173*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 174*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_possible_dep, "target_gen_dir") 175*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_possible_dep, "name") 176*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 177*8975f5c5SAndroid Build Coastguard Worker 178*8975f5c5SAndroid Build Coastguard Worker _deps_configs += [ _dep_config ] 179*8975f5c5SAndroid Build Coastguard Worker } 180*8975f5c5SAndroid Build Coastguard Worker } 181*8975f5c5SAndroid Build Coastguard Worker } 182*8975f5c5SAndroid Build Coastguard Worker _public_deps_configs = [] 183*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.possible_config_public_deps)) { 184*8975f5c5SAndroid Build Coastguard Worker foreach(_possible_dep, invoker.possible_config_public_deps) { 185*8975f5c5SAndroid Build Coastguard Worker _dep_label = get_label_info(_possible_dep, "label_no_toolchain") 186*8975f5c5SAndroid Build Coastguard Worker 187*8975f5c5SAndroid Build Coastguard Worker # E.g. Adding an action that generates a .java file that is then 188*8975f5c5SAndroid Build Coastguard Worker # consumed by a subsequent java_library() target would not work 189*8975f5c5SAndroid Build Coastguard Worker # because the libraries depend only on the nested targets of one 190*8975f5c5SAndroid Build Coastguard Worker # another. It is simplest to just ban non-java public_deps. 191*8975f5c5SAndroid Build Coastguard Worker assert(filter_exclude([ _dep_label ], java_target_patterns) == [], 192*8975f5c5SAndroid Build Coastguard Worker "Only java_library targets can be used as public_deps. " + 193*8975f5c5SAndroid Build Coastguard Worker "Found:\n${_dep_label}\non Target:\n" + 194*8975f5c5SAndroid Build Coastguard Worker get_label_info(":$target_name", "label_no_toolchain")) 195*8975f5c5SAndroid Build Coastguard Worker 196*8975f5c5SAndroid Build Coastguard Worker # Put the bug number in the target name so that false-positives 197*8975f5c5SAndroid Build Coastguard Worker # have a hint in the error message about non-existent dependencies. 198*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 199*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_possible_dep, "target_gen_dir") 200*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_possible_dep, "name") 201*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 202*8975f5c5SAndroid Build Coastguard Worker 203*8975f5c5SAndroid Build Coastguard Worker _public_deps_configs += [ _dep_config ] 204*8975f5c5SAndroid Build Coastguard Worker } 205*8975f5c5SAndroid Build Coastguard Worker } 206*8975f5c5SAndroid Build Coastguard Worker inputs += _deps_configs 207*8975f5c5SAndroid Build Coastguard Worker inputs += _public_deps_configs 208*8975f5c5SAndroid Build Coastguard Worker _rebased_deps_configs = rebase_path(_deps_configs, root_build_dir) 209*8975f5c5SAndroid Build Coastguard Worker _rebased_public_deps_configs = 210*8975f5c5SAndroid Build Coastguard Worker rebase_path(_public_deps_configs, root_build_dir) 211*8975f5c5SAndroid Build Coastguard Worker 212*8975f5c5SAndroid Build Coastguard Worker args = [ 213*8975f5c5SAndroid Build Coastguard Worker "--type=$_type", 214*8975f5c5SAndroid Build Coastguard Worker "--depfile", 215*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 216*8975f5c5SAndroid Build Coastguard Worker "--deps-configs=$_rebased_deps_configs", 217*8975f5c5SAndroid Build Coastguard Worker "--public-deps-configs=$_rebased_public_deps_configs", 218*8975f5c5SAndroid Build Coastguard Worker "--build-config", 219*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.build_config, root_build_dir), 220*8975f5c5SAndroid Build Coastguard Worker "--gn-target", 221*8975f5c5SAndroid Build Coastguard Worker _target_label, 222*8975f5c5SAndroid Build Coastguard Worker ] 223*8975f5c5SAndroid Build Coastguard Worker 224*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.preferred_dep) && invoker.preferred_dep) { 225*8975f5c5SAndroid Build Coastguard Worker args += [ "--preferred-dep" ] 226*8975f5c5SAndroid Build Coastguard Worker } 227*8975f5c5SAndroid Build Coastguard Worker 228*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.aar_path)) { 229*8975f5c5SAndroid Build Coastguard Worker args += [ 230*8975f5c5SAndroid Build Coastguard Worker "--aar-path", 231*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.aar_path, root_build_dir), 232*8975f5c5SAndroid Build Coastguard Worker ] 233*8975f5c5SAndroid Build Coastguard Worker } 234*8975f5c5SAndroid Build Coastguard Worker 235*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.chromium_code) && !invoker.chromium_code) { 236*8975f5c5SAndroid Build Coastguard Worker # Default to chromium code if invoker did not pass anything. 237*8975f5c5SAndroid Build Coastguard Worker args += [ "--non-chromium-code" ] 238*8975f5c5SAndroid Build Coastguard Worker } 239*8975f5c5SAndroid Build Coastguard Worker 240*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.device_jar_path)) { 241*8975f5c5SAndroid Build Coastguard Worker args += [ 242*8975f5c5SAndroid Build Coastguard Worker "--device-jar-path", 243*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.device_jar_path, root_build_dir), 244*8975f5c5SAndroid Build Coastguard Worker ] 245*8975f5c5SAndroid Build Coastguard Worker } 246*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.host_jar_path)) { 247*8975f5c5SAndroid Build Coastguard Worker args += [ 248*8975f5c5SAndroid Build Coastguard Worker "--host-jar-path", 249*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.host_jar_path, root_build_dir), 250*8975f5c5SAndroid Build Coastguard Worker ] 251*8975f5c5SAndroid Build Coastguard Worker } 252*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.unprocessed_jar_path)) { 253*8975f5c5SAndroid Build Coastguard Worker args += [ 254*8975f5c5SAndroid Build Coastguard Worker "--unprocessed-jar-path", 255*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.unprocessed_jar_path, root_build_dir), 256*8975f5c5SAndroid Build Coastguard Worker ] 257*8975f5c5SAndroid Build Coastguard Worker } 258*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.ijar_path)) { 259*8975f5c5SAndroid Build Coastguard Worker args += [ 260*8975f5c5SAndroid Build Coastguard Worker "--interface-jar-path", 261*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.ijar_path, root_build_dir), 262*8975f5c5SAndroid Build Coastguard Worker ] 263*8975f5c5SAndroid Build Coastguard Worker } 264*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.kotlinc_jar_path)) { 265*8975f5c5SAndroid Build Coastguard Worker args += [ 266*8975f5c5SAndroid Build Coastguard Worker "--kotlinc-jar-path", 267*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.kotlinc_jar_path, root_build_dir), 268*8975f5c5SAndroid Build Coastguard Worker ] 269*8975f5c5SAndroid Build Coastguard Worker } 270*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.java_resources_jar)) { 271*8975f5c5SAndroid Build Coastguard Worker args += [ 272*8975f5c5SAndroid Build Coastguard Worker "--java-resources-jar-path", 273*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.java_resources_jar, root_build_dir), 274*8975f5c5SAndroid Build Coastguard Worker ] 275*8975f5c5SAndroid Build Coastguard Worker } 276*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.annotation_processor_deps) && 277*8975f5c5SAndroid Build Coastguard Worker invoker.annotation_processor_deps != []) { 278*8975f5c5SAndroid Build Coastguard Worker _processor_configs = [] 279*8975f5c5SAndroid Build Coastguard Worker foreach(_dep_label, invoker.annotation_processor_deps) { 280*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 281*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_dep_label, "target_gen_dir") 282*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_dep_label, "name") 283*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 284*8975f5c5SAndroid Build Coastguard Worker _processor_configs += [ _dep_config ] 285*8975f5c5SAndroid Build Coastguard Worker } 286*8975f5c5SAndroid Build Coastguard Worker _rebased_processor_configs = 287*8975f5c5SAndroid Build Coastguard Worker rebase_path(_processor_configs, root_build_dir) 288*8975f5c5SAndroid Build Coastguard Worker inputs += _processor_configs 289*8975f5c5SAndroid Build Coastguard Worker args += [ "--annotation-processor-configs=$_rebased_processor_configs" ] 290*8975f5c5SAndroid Build Coastguard Worker } 291*8975f5c5SAndroid Build Coastguard Worker 292*8975f5c5SAndroid Build Coastguard Worker # Dex path for library targets, or the the intermediate library for apks. 293*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.dex_path)) { 294*8975f5c5SAndroid Build Coastguard Worker args += [ 295*8975f5c5SAndroid Build Coastguard Worker "--dex-path", 296*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.dex_path, root_build_dir), 297*8975f5c5SAndroid Build Coastguard Worker ] 298*8975f5c5SAndroid Build Coastguard Worker } 299*8975f5c5SAndroid Build Coastguard Worker 300*8975f5c5SAndroid Build Coastguard Worker # Dex path for the final apk. 301*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.final_dex_path)) { 302*8975f5c5SAndroid Build Coastguard Worker args += [ 303*8975f5c5SAndroid Build Coastguard Worker "--final-dex-path", 304*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.final_dex_path, root_build_dir), 305*8975f5c5SAndroid Build Coastguard Worker ] 306*8975f5c5SAndroid Build Coastguard Worker } 307*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.supports_android) && invoker.supports_android) { 308*8975f5c5SAndroid Build Coastguard Worker args += [ "--supports-android" ] 309*8975f5c5SAndroid Build Coastguard Worker } 310*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.requires_android) && invoker.requires_android) { 311*8975f5c5SAndroid Build Coastguard Worker args += [ "--requires-android" ] 312*8975f5c5SAndroid Build Coastguard Worker } 313*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.is_prebuilt) && invoker.is_prebuilt) { 314*8975f5c5SAndroid Build Coastguard Worker args += [ "--is-prebuilt" ] 315*8975f5c5SAndroid Build Coastguard Worker } 316*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.bypass_platform_checks) && 317*8975f5c5SAndroid Build Coastguard Worker invoker.bypass_platform_checks) { 318*8975f5c5SAndroid Build Coastguard Worker args += [ "--bypass-platform-checks" ] 319*8975f5c5SAndroid Build Coastguard Worker } 320*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.is_robolectric) && invoker.is_robolectric) { 321*8975f5c5SAndroid Build Coastguard Worker args += [ "--is-robolectric" ] 322*8975f5c5SAndroid Build Coastguard Worker } 323*8975f5c5SAndroid Build Coastguard Worker 324*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_under_test)) { 325*8975f5c5SAndroid Build Coastguard Worker _dep_label = invoker.apk_under_test 326*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_dep_label, "target_gen_dir") 327*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_dep_label, "name") 328*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 329*8975f5c5SAndroid Build Coastguard Worker inputs += [ _dep_config ] 330*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 331*8975f5c5SAndroid Build Coastguard Worker args += [ 332*8975f5c5SAndroid Build Coastguard Worker "--tested-apk-config", 333*8975f5c5SAndroid Build Coastguard Worker rebase_path(_dep_config, root_build_dir), 334*8975f5c5SAndroid Build Coastguard Worker ] 335*8975f5c5SAndroid Build Coastguard Worker } 336*8975f5c5SAndroid Build Coastguard Worker 337*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.asset_sources)) { 338*8975f5c5SAndroid Build Coastguard Worker _rebased_asset_sources = 339*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.asset_sources, root_build_dir) 340*8975f5c5SAndroid Build Coastguard Worker args += [ "--asset-sources=$_rebased_asset_sources" ] 341*8975f5c5SAndroid Build Coastguard Worker } 342*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.asset_renaming_sources)) { 343*8975f5c5SAndroid Build Coastguard Worker _rebased_asset_renaming_sources = 344*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.asset_renaming_sources, root_build_dir) 345*8975f5c5SAndroid Build Coastguard Worker args += [ "--asset-renaming-sources=$_rebased_asset_renaming_sources" ] 346*8975f5c5SAndroid Build Coastguard Worker 347*8975f5c5SAndroid Build Coastguard Worker # These are zip paths, so no need to rebase. 348*8975f5c5SAndroid Build Coastguard Worker args += [ 349*8975f5c5SAndroid Build Coastguard Worker "--asset-renaming-destinations=${invoker.asset_renaming_destinations}", 350*8975f5c5SAndroid Build Coastguard Worker ] 351*8975f5c5SAndroid Build Coastguard Worker } 352*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.disable_compression) && invoker.disable_compression) { 353*8975f5c5SAndroid Build Coastguard Worker args += [ "--disable-asset-compression" ] 354*8975f5c5SAndroid Build Coastguard Worker } 355*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.treat_as_locale_paks) && invoker.treat_as_locale_paks) { 356*8975f5c5SAndroid Build Coastguard Worker args += [ "--treat-as-locale-paks" ] 357*8975f5c5SAndroid Build Coastguard Worker } 358*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.suffix_apk_assets_used_by)) { 359*8975f5c5SAndroid Build Coastguard Worker _dep_label = invoker.suffix_apk_assets_used_by 360*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_dep_label, "target_gen_dir") 361*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_dep_label, "name") 362*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 363*8975f5c5SAndroid Build Coastguard Worker if (_dep_config != invoker.build_config) { 364*8975f5c5SAndroid Build Coastguard Worker inputs += [ _dep_config ] 365*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 366*8975f5c5SAndroid Build Coastguard Worker } 367*8975f5c5SAndroid Build Coastguard Worker args += [ 368*8975f5c5SAndroid Build Coastguard Worker "--suffix-apk-assets-used-by", 369*8975f5c5SAndroid Build Coastguard Worker rebase_path(_dep_config, root_build_dir), 370*8975f5c5SAndroid Build Coastguard Worker ] 371*8975f5c5SAndroid Build Coastguard Worker } 372*8975f5c5SAndroid Build Coastguard Worker 373*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.merged_android_manifest)) { 374*8975f5c5SAndroid Build Coastguard Worker args += [ 375*8975f5c5SAndroid Build Coastguard Worker "--merged-android-manifest", 376*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.merged_android_manifest, root_build_dir), 377*8975f5c5SAndroid Build Coastguard Worker ] 378*8975f5c5SAndroid Build Coastguard Worker } 379*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.android_manifest)) { 380*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.android_manifest ] 381*8975f5c5SAndroid Build Coastguard Worker args += [ 382*8975f5c5SAndroid Build Coastguard Worker "--android-manifest", 383*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.android_manifest, root_build_dir), 384*8975f5c5SAndroid Build Coastguard Worker ] 385*8975f5c5SAndroid Build Coastguard Worker } 386*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resources_zip)) { 387*8975f5c5SAndroid Build Coastguard Worker args += [ 388*8975f5c5SAndroid Build Coastguard Worker "--resources-zip", 389*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.resources_zip, root_build_dir), 390*8975f5c5SAndroid Build Coastguard Worker ] 391*8975f5c5SAndroid Build Coastguard Worker } 392*8975f5c5SAndroid Build Coastguard Worker 393*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resource_overlay) && invoker.resource_overlay) { 394*8975f5c5SAndroid Build Coastguard Worker args += [ "--resource-overlay" ] 395*8975f5c5SAndroid Build Coastguard Worker } 396*8975f5c5SAndroid Build Coastguard Worker 397*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.custom_package)) { 398*8975f5c5SAndroid Build Coastguard Worker args += [ 399*8975f5c5SAndroid Build Coastguard Worker "--package-name", 400*8975f5c5SAndroid Build Coastguard Worker invoker.custom_package, 401*8975f5c5SAndroid Build Coastguard Worker ] 402*8975f5c5SAndroid Build Coastguard Worker } 403*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.r_text)) { 404*8975f5c5SAndroid Build Coastguard Worker args += [ 405*8975f5c5SAndroid Build Coastguard Worker "--r-text-path", 406*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.r_text, root_build_dir), 407*8975f5c5SAndroid Build Coastguard Worker ] 408*8975f5c5SAndroid Build Coastguard Worker } 409*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.res_size_info_path)) { 410*8975f5c5SAndroid Build Coastguard Worker args += [ 411*8975f5c5SAndroid Build Coastguard Worker "--res-size-info", 412*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.res_size_info_path, root_build_dir), 413*8975f5c5SAndroid Build Coastguard Worker ] 414*8975f5c5SAndroid Build Coastguard Worker } 415*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.res_sources_path)) { 416*8975f5c5SAndroid Build Coastguard Worker _res_sources_path = rebase_path(invoker.res_sources_path, root_build_dir) 417*8975f5c5SAndroid Build Coastguard Worker args += [ "--res-sources-path=$_res_sources_path" ] 418*8975f5c5SAndroid Build Coastguard Worker } 419*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proto_resources_path)) { 420*8975f5c5SAndroid Build Coastguard Worker _rebased_proto_resources = 421*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proto_resources_path, root_build_dir) 422*8975f5c5SAndroid Build Coastguard Worker args += [ "--apk-proto-resources=$_rebased_proto_resources" ] 423*8975f5c5SAndroid Build Coastguard Worker } 424*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.r_text_path)) { 425*8975f5c5SAndroid Build Coastguard Worker _rebased_rtxt_path = rebase_path(invoker.r_text_path, root_build_dir) 426*8975f5c5SAndroid Build Coastguard Worker args += [ "--r-text-path=$_rebased_rtxt_path" ] 427*8975f5c5SAndroid Build Coastguard Worker } 428*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.module_pathmap_path)) { 429*8975f5c5SAndroid Build Coastguard Worker _rebased_pathmap_path = 430*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.module_pathmap_path, root_build_dir) 431*8975f5c5SAndroid Build Coastguard Worker args += [ "--module-pathmap-path=$_rebased_pathmap_path" ] 432*8975f5c5SAndroid Build Coastguard Worker } 433*8975f5c5SAndroid Build Coastguard Worker 434*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.shared_libraries_runtime_deps_file)) { 435*8975f5c5SAndroid Build Coastguard Worker # Don't list shared_libraries_runtime_deps_file as an input in order to 436*8975f5c5SAndroid Build Coastguard Worker # avoid having to depend on the runtime_deps target. See comment in 437*8975f5c5SAndroid Build Coastguard Worker # rules.gni for why we do this. 438*8975f5c5SAndroid Build Coastguard Worker args += [ 439*8975f5c5SAndroid Build Coastguard Worker "--shared-libraries-runtime-deps", 440*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.shared_libraries_runtime_deps_file, root_build_dir), 441*8975f5c5SAndroid Build Coastguard Worker ] 442*8975f5c5SAndroid Build Coastguard Worker } 443*8975f5c5SAndroid Build Coastguard Worker 444*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.base_allowlist_rtxt_path)) { 445*8975f5c5SAndroid Build Coastguard Worker args += [ 446*8975f5c5SAndroid Build Coastguard Worker "--base-allowlist-rtxt-path", 447*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.base_allowlist_rtxt_path, root_build_dir), 448*8975f5c5SAndroid Build Coastguard Worker ] 449*8975f5c5SAndroid Build Coastguard Worker } 450*8975f5c5SAndroid Build Coastguard Worker 451*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.loadable_modules)) { 452*8975f5c5SAndroid Build Coastguard Worker _rebased_loadable_modules = 453*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.loadable_modules, root_build_dir) 454*8975f5c5SAndroid Build Coastguard Worker args += [ "--loadable-modules=$_rebased_loadable_modules" ] 455*8975f5c5SAndroid Build Coastguard Worker } 456*8975f5c5SAndroid Build Coastguard Worker 457*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.secondary_abi_shared_libraries_runtime_deps_file)) { 458*8975f5c5SAndroid Build Coastguard Worker # Don't list secondary_abi_shared_libraries_runtime_deps_file as an 459*8975f5c5SAndroid Build Coastguard Worker # input in order to avoid having to depend on the runtime_deps target. 460*8975f5c5SAndroid Build Coastguard Worker # See comment in rules.gni for why we do this. 461*8975f5c5SAndroid Build Coastguard Worker args += [ 462*8975f5c5SAndroid Build Coastguard Worker "--secondary-abi-shared-libraries-runtime-deps", 463*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.secondary_abi_shared_libraries_runtime_deps_file, 464*8975f5c5SAndroid Build Coastguard Worker root_build_dir), 465*8975f5c5SAndroid Build Coastguard Worker ] 466*8975f5c5SAndroid Build Coastguard Worker } 467*8975f5c5SAndroid Build Coastguard Worker 468*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.secondary_abi_loadable_modules) && 469*8975f5c5SAndroid Build Coastguard Worker invoker.secondary_abi_loadable_modules != []) { 470*8975f5c5SAndroid Build Coastguard Worker _rebased_secondary_abi_loadable_modules = 471*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.secondary_abi_loadable_modules, root_build_dir) 472*8975f5c5SAndroid Build Coastguard Worker args += [ "--secondary-abi-loadable-modules=$_rebased_secondary_abi_loadable_modules" ] 473*8975f5c5SAndroid Build Coastguard Worker } 474*8975f5c5SAndroid Build Coastguard Worker 475*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.native_lib_placeholders) && 476*8975f5c5SAndroid Build Coastguard Worker invoker.native_lib_placeholders != []) { 477*8975f5c5SAndroid Build Coastguard Worker args += [ "--native-lib-placeholders=${invoker.native_lib_placeholders}" ] 478*8975f5c5SAndroid Build Coastguard Worker } 479*8975f5c5SAndroid Build Coastguard Worker 480*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.secondary_native_lib_placeholders) && 481*8975f5c5SAndroid Build Coastguard Worker invoker.secondary_native_lib_placeholders != []) { 482*8975f5c5SAndroid Build Coastguard Worker args += [ "--secondary-native-lib-placeholders=${invoker.secondary_native_lib_placeholders}" ] 483*8975f5c5SAndroid Build Coastguard Worker } 484*8975f5c5SAndroid Build Coastguard Worker 485*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.library_always_compress)) { 486*8975f5c5SAndroid Build Coastguard Worker args += [ "--library-always-compress=${invoker.library_always_compress}" ] 487*8975f5c5SAndroid Build Coastguard Worker } 488*8975f5c5SAndroid Build Coastguard Worker 489*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_path)) { 490*8975f5c5SAndroid Build Coastguard Worker # TODO(tiborg): Remove APK path from build config and use 491*8975f5c5SAndroid Build Coastguard Worker # install_artifacts from metadata instead. 492*8975f5c5SAndroid Build Coastguard Worker _rebased_apk_path = rebase_path(invoker.apk_path, root_build_dir) 493*8975f5c5SAndroid Build Coastguard Worker args += [ "--apk-path=$_rebased_apk_path" ] 494*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.incremental_apk_path)) { 495*8975f5c5SAndroid Build Coastguard Worker _rebased_incremental_apk_path = 496*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.incremental_apk_path, root_build_dir) 497*8975f5c5SAndroid Build Coastguard Worker _rebased_incremental_install_json_path = 498*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.incremental_install_json_path, root_build_dir) 499*8975f5c5SAndroid Build Coastguard Worker args += [ 500*8975f5c5SAndroid Build Coastguard Worker "--incremental-install-json-path=$_rebased_incremental_install_json_path", 501*8975f5c5SAndroid Build Coastguard Worker "--incremental-apk-path=$_rebased_incremental_apk_path", 502*8975f5c5SAndroid Build Coastguard Worker ] 503*8975f5c5SAndroid Build Coastguard Worker } 504*8975f5c5SAndroid Build Coastguard Worker } 505*8975f5c5SAndroid Build Coastguard Worker 506*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.target_sources_file)) { 507*8975f5c5SAndroid Build Coastguard Worker args += [ 508*8975f5c5SAndroid Build Coastguard Worker "--target-sources-file", 509*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.target_sources_file, root_build_dir), 510*8975f5c5SAndroid Build Coastguard Worker ] 511*8975f5c5SAndroid Build Coastguard Worker } 512*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjar)) { 513*8975f5c5SAndroid Build Coastguard Worker args += [ 514*8975f5c5SAndroid Build Coastguard Worker "--srcjar", 515*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.srcjar, root_build_dir), 516*8975f5c5SAndroid Build Coastguard Worker ] 517*8975f5c5SAndroid Build Coastguard Worker } 518*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.bundled_srcjars)) { 519*8975f5c5SAndroid Build Coastguard Worker _rebased_bundled_srcjars = 520*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.bundled_srcjars, root_build_dir) 521*8975f5c5SAndroid Build Coastguard Worker args += [ "--bundled-srcjars=$_rebased_bundled_srcjars" ] 522*8975f5c5SAndroid Build Coastguard Worker } 523*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) { 524*8975f5c5SAndroid Build Coastguard Worker args += [ "--proguard-enabled" ] 525*8975f5c5SAndroid Build Coastguard Worker } 526*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_mapping_path)) { 527*8975f5c5SAndroid Build Coastguard Worker _rebased_proguard_mapping_path = 528*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_mapping_path, root_build_dir) 529*8975f5c5SAndroid Build Coastguard Worker args += [ "--proguard-mapping-path=$_rebased_proguard_mapping_path" ] 530*8975f5c5SAndroid Build Coastguard Worker } 531*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.input_jars_paths)) { 532*8975f5c5SAndroid Build Coastguard Worker _rebased_input_jars_paths = 533*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_jars_paths, root_build_dir) 534*8975f5c5SAndroid Build Coastguard Worker args += [ "--extra-classpath-jars=$_rebased_input_jars_paths" ] 535*8975f5c5SAndroid Build Coastguard Worker } 536*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.low_classpath_priority) && 537*8975f5c5SAndroid Build Coastguard Worker invoker.low_classpath_priority) { 538*8975f5c5SAndroid Build Coastguard Worker args += [ "--low-classpath-priority" ] 539*8975f5c5SAndroid Build Coastguard Worker } 540*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.mergeable_android_manifests)) { 541*8975f5c5SAndroid Build Coastguard Worker _rebased_mergeable_android_manifests = 542*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.mergeable_android_manifests, root_build_dir) 543*8975f5c5SAndroid Build Coastguard Worker args += [ 544*8975f5c5SAndroid Build Coastguard Worker "--mergeable-android-manifests=$_rebased_mergeable_android_manifests", 545*8975f5c5SAndroid Build Coastguard Worker ] 546*8975f5c5SAndroid Build Coastguard Worker } 547*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_configs)) { 548*8975f5c5SAndroid Build Coastguard Worker _rebased_proguard_configs = 549*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_configs, root_build_dir) 550*8975f5c5SAndroid Build Coastguard Worker args += [ "--proguard-configs=$_rebased_proguard_configs" ] 551*8975f5c5SAndroid Build Coastguard Worker } 552*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.gradle_treat_as_prebuilt) && 553*8975f5c5SAndroid Build Coastguard Worker invoker.gradle_treat_as_prebuilt) { 554*8975f5c5SAndroid Build Coastguard Worker args += [ "--gradle-treat-as-prebuilt" ] 555*8975f5c5SAndroid Build Coastguard Worker } 556*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.main_class)) { 557*8975f5c5SAndroid Build Coastguard Worker args += [ 558*8975f5c5SAndroid Build Coastguard Worker "--main-class", 559*8975f5c5SAndroid Build Coastguard Worker invoker.main_class, 560*8975f5c5SAndroid Build Coastguard Worker ] 561*8975f5c5SAndroid Build Coastguard Worker } 562*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.base_module_target)) { 563*8975f5c5SAndroid Build Coastguard Worker _dep_label = invoker.base_module_target 564*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_dep_label, "target_gen_dir") 565*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_dep_label, "name") 566*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 567*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 568*8975f5c5SAndroid Build Coastguard Worker inputs += [ _dep_config ] 569*8975f5c5SAndroid Build Coastguard Worker args += [ 570*8975f5c5SAndroid Build Coastguard Worker "--base-module-build-config", 571*8975f5c5SAndroid Build Coastguard Worker rebase_path(_dep_config, root_build_dir), 572*8975f5c5SAndroid Build Coastguard Worker ] 573*8975f5c5SAndroid Build Coastguard Worker } 574*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.parent_module_target)) { 575*8975f5c5SAndroid Build Coastguard Worker _dep_label = invoker.parent_module_target 576*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_dep_label, "target_gen_dir") 577*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_dep_label, "name") 578*8975f5c5SAndroid Build Coastguard Worker _dep_config = "$_dep_gen_dir/$_dep_name.build_config.json" 579*8975f5c5SAndroid Build Coastguard Worker deps += [ "$_dep_label$build_config_target_suffix" ] 580*8975f5c5SAndroid Build Coastguard Worker inputs += [ _dep_config ] 581*8975f5c5SAndroid Build Coastguard Worker args += [ 582*8975f5c5SAndroid Build Coastguard Worker "--parent-module-build-config", 583*8975f5c5SAndroid Build Coastguard Worker rebase_path(_dep_config, root_build_dir), 584*8975f5c5SAndroid Build Coastguard Worker ] 585*8975f5c5SAndroid Build Coastguard Worker } 586*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.module_name)) { 587*8975f5c5SAndroid Build Coastguard Worker args += [ 588*8975f5c5SAndroid Build Coastguard Worker "--module-name", 589*8975f5c5SAndroid Build Coastguard Worker invoker.module_name, 590*8975f5c5SAndroid Build Coastguard Worker ] 591*8975f5c5SAndroid Build Coastguard Worker } 592*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.modules)) { 593*8975f5c5SAndroid Build Coastguard Worker foreach(_module, invoker.modules) { 594*8975f5c5SAndroid Build Coastguard Worker if (defined(_module.uses_split)) { 595*8975f5c5SAndroid Build Coastguard Worker args += [ "--uses-split=${_module.name}:${_module.uses_split}" ] 596*8975f5c5SAndroid Build Coastguard Worker } 597*8975f5c5SAndroid Build Coastguard Worker } 598*8975f5c5SAndroid Build Coastguard Worker } 599*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.module_build_configs)) { 600*8975f5c5SAndroid Build Coastguard Worker inputs += invoker.module_build_configs 601*8975f5c5SAndroid Build Coastguard Worker _rebased_configs = 602*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.module_build_configs, root_build_dir) 603*8975f5c5SAndroid Build Coastguard Worker args += [ "--module-build-configs=$_rebased_configs" ] 604*8975f5c5SAndroid Build Coastguard Worker } 605*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.add_view_trace_events) && 606*8975f5c5SAndroid Build Coastguard Worker invoker.add_view_trace_events) { 607*8975f5c5SAndroid Build Coastguard Worker # Adding trace events involves rewriting bytecode and generating a new set 608*8975f5c5SAndroid Build Coastguard Worker # of jar files. In order to avoid conflicts between bundles we save the 609*8975f5c5SAndroid Build Coastguard Worker # new jars in a bundle specific gen/ directory. The build config for the 610*8975f5c5SAndroid Build Coastguard Worker # bundle, and each one of its modules need a path to a bundle specific 611*8975f5c5SAndroid Build Coastguard Worker # gen/ directory in order to generate a list of rewritten jar paths. 612*8975f5c5SAndroid Build Coastguard Worker # We use the base module's target_gen_dir because non-base modules and the 613*8975f5c5SAndroid Build Coastguard Worker # app bundle targets have a reference to it (base_module_target). 614*8975f5c5SAndroid Build Coastguard Worker if (_type == "android_app_bundle") { 615*8975f5c5SAndroid Build Coastguard Worker _trace_events_target_name = 616*8975f5c5SAndroid Build Coastguard Worker get_label_info(_parent_invoker.base_module_target, "name") 617*8975f5c5SAndroid Build Coastguard Worker } else if (defined(invoker.base_module_target)) { 618*8975f5c5SAndroid Build Coastguard Worker _trace_events_target_name = 619*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.base_module_target, "name") 620*8975f5c5SAndroid Build Coastguard Worker } else { 621*8975f5c5SAndroid Build Coastguard Worker _grandparent_invoker = _parent_invoker.invoker 622*8975f5c5SAndroid Build Coastguard Worker _trace_events_target_name = _grandparent_invoker.target_name 623*8975f5c5SAndroid Build Coastguard Worker } 624*8975f5c5SAndroid Build Coastguard Worker 625*8975f5c5SAndroid Build Coastguard Worker # FIXME: This should likely be using the base module's target_out_dir 626*8975f5c5SAndroid Build Coastguard Worker # rather than the current target's. 627*8975f5c5SAndroid Build Coastguard Worker args += [ 628*8975f5c5SAndroid Build Coastguard Worker "--trace-events-jar-dir", 629*8975f5c5SAndroid Build Coastguard Worker rebase_path("$target_out_dir/$_trace_events_target_name", 630*8975f5c5SAndroid Build Coastguard Worker root_build_dir), 631*8975f5c5SAndroid Build Coastguard Worker ] 632*8975f5c5SAndroid Build Coastguard Worker } 633*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.version_name)) { 634*8975f5c5SAndroid Build Coastguard Worker args += [ 635*8975f5c5SAndroid Build Coastguard Worker "--version-name", 636*8975f5c5SAndroid Build Coastguard Worker invoker.version_name, 637*8975f5c5SAndroid Build Coastguard Worker ] 638*8975f5c5SAndroid Build Coastguard Worker } 639*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.version_code)) { 640*8975f5c5SAndroid Build Coastguard Worker args += [ 641*8975f5c5SAndroid Build Coastguard Worker "--version-code", 642*8975f5c5SAndroid Build Coastguard Worker invoker.version_code, 643*8975f5c5SAndroid Build Coastguard Worker ] 644*8975f5c5SAndroid Build Coastguard Worker } 645*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.recursive_resource_deps) && 646*8975f5c5SAndroid Build Coastguard Worker invoker.recursive_resource_deps) { 647*8975f5c5SAndroid Build Coastguard Worker args += [ "--recursive-resource-deps" ] 648*8975f5c5SAndroid Build Coastguard Worker } 649*8975f5c5SAndroid Build Coastguard Worker if (current_toolchain != default_toolchain) { 650*8975f5c5SAndroid Build Coastguard Worker # This has to be a built-time error rather than a GN assert because many 651*8975f5c5SAndroid Build Coastguard Worker # packages have a mix of java and non-java targets. For example, the 652*8975f5c5SAndroid Build Coastguard Worker # following would fail even though nothing depends on :bar(//baz): 653*8975f5c5SAndroid Build Coastguard Worker # 654*8975f5c5SAndroid Build Coastguard Worker # shared_library("foo") { 655*8975f5c5SAndroid Build Coastguard Worker # } 656*8975f5c5SAndroid Build Coastguard Worker # 657*8975f5c5SAndroid Build Coastguard Worker # android_library("bar") { 658*8975f5c5SAndroid Build Coastguard Worker # deps = [ ":foo(//baz)" ] 659*8975f5c5SAndroid Build Coastguard Worker # assert(current_toolchain == default_toolchain) 660*8975f5c5SAndroid Build Coastguard Worker # } 661*8975f5c5SAndroid Build Coastguard Worker _msg = [ 662*8975f5c5SAndroid Build Coastguard Worker "Tried to build an Android target in a non-default toolchain.", 663*8975f5c5SAndroid Build Coastguard Worker "target: $_target_label", 664*8975f5c5SAndroid Build Coastguard Worker "current_toolchain: $current_toolchain", 665*8975f5c5SAndroid Build Coastguard Worker "default_toolchain: $default_toolchain", 666*8975f5c5SAndroid Build Coastguard Worker ] 667*8975f5c5SAndroid Build Coastguard Worker args += [ "--fail=$_msg" ] 668*8975f5c5SAndroid Build Coastguard Worker } 669*8975f5c5SAndroid Build Coastguard Worker } 670*8975f5c5SAndroid Build Coastguard Worker} 671*8975f5c5SAndroid Build Coastguard Worker 672*8975f5c5SAndroid Build Coastguard Workertemplate("generate_android_wrapper") { 673*8975f5c5SAndroid Build Coastguard Worker generate_wrapper(target_name) { 674*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 675*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 676*8975f5c5SAndroid Build Coastguard Worker generator_script = "//build/android/gyp/generate_android_wrapper.py" 677*8975f5c5SAndroid Build Coastguard Worker sources = [ 678*8975f5c5SAndroid Build Coastguard Worker "//build/android/gyp/util/build_utils.py", 679*8975f5c5SAndroid Build Coastguard Worker "//build/gn_helpers.py", 680*8975f5c5SAndroid Build Coastguard Worker "//build/util/generate_wrapper.py", 681*8975f5c5SAndroid Build Coastguard Worker ] 682*8975f5c5SAndroid Build Coastguard Worker } 683*8975f5c5SAndroid Build Coastguard Worker} 684*8975f5c5SAndroid Build Coastguard Worker 685*8975f5c5SAndroid Build Coastguard Workertemplate("generate_r_java") { 686*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 687*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 688*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/${invoker.target_name}.d" 689*8975f5c5SAndroid Build Coastguard Worker inputs = [ invoker.build_config ] 690*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.srcjar_path ] 691*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 692*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/create_r_java.py" 693*8975f5c5SAndroid Build Coastguard Worker args = [ 694*8975f5c5SAndroid Build Coastguard Worker "--depfile", 695*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 696*8975f5c5SAndroid Build Coastguard Worker "--srcjar-out", 697*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.srcjar_path, root_build_dir), 698*8975f5c5SAndroid Build Coastguard Worker "--deps-rtxts=@FileArg($_rebased_build_config:deps_info:dependency_r_txt_files)", 699*8975f5c5SAndroid Build Coastguard Worker "--r-package=${invoker.package}", 700*8975f5c5SAndroid Build Coastguard Worker ] 701*8975f5c5SAndroid Build Coastguard Worker } 702*8975f5c5SAndroid Build Coastguard Worker} 703*8975f5c5SAndroid Build Coastguard Worker 704*8975f5c5SAndroid Build Coastguard Worker# Generates a script in the build bin directory which runs the test 705*8975f5c5SAndroid Build Coastguard Worker# target using the test runner script in build/android/test_runner.py. 706*8975f5c5SAndroid Build Coastguard Workertemplate("test_runner_script") { 707*8975f5c5SAndroid Build Coastguard Worker testonly = true 708*8975f5c5SAndroid Build Coastguard Worker _test_name = invoker.test_name 709*8975f5c5SAndroid Build Coastguard Worker _test_type = invoker.test_type 710*8975f5c5SAndroid Build Coastguard Worker _is_unit_test = defined(invoker.is_unit_test) && invoker.is_unit_test 711*8975f5c5SAndroid Build Coastguard Worker _incremental_apk = defined(invoker.incremental_apk) && invoker.incremental_apk 712*8975f5c5SAndroid Build Coastguard Worker 713*8975f5c5SAndroid Build Coastguard Worker _runtime_deps = 714*8975f5c5SAndroid Build Coastguard Worker !defined(invoker.ignore_all_data_deps) || !invoker.ignore_all_data_deps 715*8975f5c5SAndroid Build Coastguard Worker 716*8975f5c5SAndroid Build Coastguard Worker if (_runtime_deps) { 717*8975f5c5SAndroid Build Coastguard Worker # This runtime_deps file is used at runtime and thus cannot go in 718*8975f5c5SAndroid Build Coastguard Worker # target_gen_dir. 719*8975f5c5SAndroid Build Coastguard Worker _target_dir_name = get_label_info(":$target_name", "dir") 720*8975f5c5SAndroid Build Coastguard Worker _runtime_deps_file = 721*8975f5c5SAndroid Build Coastguard Worker "$root_out_dir/gen.runtime/$_target_dir_name/$target_name.runtime_deps" 722*8975f5c5SAndroid Build Coastguard Worker _runtime_deps_target = "${target_name}__write_deps" 723*8975f5c5SAndroid Build Coastguard Worker group(_runtime_deps_target) { 724*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 725*8975f5c5SAndroid Build Coastguard Worker [ 726*8975f5c5SAndroid Build Coastguard Worker "data", 727*8975f5c5SAndroid Build Coastguard Worker "deps", 728*8975f5c5SAndroid Build Coastguard Worker "public_deps", 729*8975f5c5SAndroid Build Coastguard Worker ]) 730*8975f5c5SAndroid Build Coastguard Worker data_deps = [] 731*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.data_deps)) { 732*8975f5c5SAndroid Build Coastguard Worker data_deps += invoker.data_deps 733*8975f5c5SAndroid Build Coastguard Worker } 734*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.additional_apks)) { 735*8975f5c5SAndroid Build Coastguard Worker data_deps += invoker.additional_apks 736*8975f5c5SAndroid Build Coastguard Worker } 737*8975f5c5SAndroid Build Coastguard Worker write_runtime_deps = _runtime_deps_file 738*8975f5c5SAndroid Build Coastguard Worker } 739*8975f5c5SAndroid Build Coastguard Worker } 740*8975f5c5SAndroid Build Coastguard Worker 741*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_under_test)) { 742*8975f5c5SAndroid Build Coastguard Worker _install_artifacts_json = 743*8975f5c5SAndroid Build Coastguard Worker "${target_gen_dir}/${target_name}.install_artifacts" 744*8975f5c5SAndroid Build Coastguard Worker _install_artifacts_target_name = "${target_name}__install_artifacts" 745*8975f5c5SAndroid Build Coastguard Worker generated_file(_install_artifacts_target_name) { 746*8975f5c5SAndroid Build Coastguard Worker deps = [ invoker.apk_under_test ] 747*8975f5c5SAndroid Build Coastguard Worker output_conversion = "json" 748*8975f5c5SAndroid Build Coastguard Worker outputs = [ _install_artifacts_json ] 749*8975f5c5SAndroid Build Coastguard Worker data_keys = [ "install_artifacts" ] 750*8975f5c5SAndroid Build Coastguard Worker walk_keys = [ "install_artifacts_barrier" ] 751*8975f5c5SAndroid Build Coastguard Worker rebase = root_build_dir 752*8975f5c5SAndroid Build Coastguard Worker } 753*8975f5c5SAndroid Build Coastguard Worker } 754*8975f5c5SAndroid Build Coastguard Worker 755*8975f5c5SAndroid Build Coastguard Worker generate_android_wrapper(target_name) { 756*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 757*8975f5c5SAndroid Build Coastguard Worker [ 758*8975f5c5SAndroid Build Coastguard Worker "assert_no_deps", 759*8975f5c5SAndroid Build Coastguard Worker "metadata", 760*8975f5c5SAndroid Build Coastguard Worker "public_deps", 761*8975f5c5SAndroid Build Coastguard Worker "visibility", 762*8975f5c5SAndroid Build Coastguard Worker ]) 763*8975f5c5SAndroid Build Coastguard Worker wrapper_script = "$root_build_dir/bin/run_${_test_name}" 764*8975f5c5SAndroid Build Coastguard Worker 765*8975f5c5SAndroid Build Coastguard Worker executable = "//testing/test_env.py" 766*8975f5c5SAndroid Build Coastguard Worker 767*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.android_test_runner_script)) { 768*8975f5c5SAndroid Build Coastguard Worker _runner_script = invoker.android_test_runner_script 769*8975f5c5SAndroid Build Coastguard Worker } else { 770*8975f5c5SAndroid Build Coastguard Worker _runner_script = "//build/android/test_runner.py" 771*8975f5c5SAndroid Build Coastguard Worker } 772*8975f5c5SAndroid Build Coastguard Worker 773*8975f5c5SAndroid Build Coastguard Worker deps = [] 774*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 775*8975f5c5SAndroid Build Coastguard Worker deps = invoker.deps 776*8975f5c5SAndroid Build Coastguard Worker } 777*8975f5c5SAndroid Build Coastguard Worker data_deps = [ 778*8975f5c5SAndroid Build Coastguard Worker "//build/android:test_runner_core_py", 779*8975f5c5SAndroid Build Coastguard Worker "//testing:test_scripts_shared", 780*8975f5c5SAndroid Build Coastguard Worker ] 781*8975f5c5SAndroid Build Coastguard Worker if (_test_type != "junit") { 782*8975f5c5SAndroid Build Coastguard Worker data_deps += [ "//build/android:test_runner_device_support" ] 783*8975f5c5SAndroid Build Coastguard Worker } 784*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.data_deps)) { 785*8975f5c5SAndroid Build Coastguard Worker data_deps += invoker.data_deps 786*8975f5c5SAndroid Build Coastguard Worker } 787*8975f5c5SAndroid Build Coastguard Worker data = [] 788*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.data)) { 789*8975f5c5SAndroid Build Coastguard Worker data += invoker.data 790*8975f5c5SAndroid Build Coastguard Worker } 791*8975f5c5SAndroid Build Coastguard Worker 792*8975f5c5SAndroid Build Coastguard Worker executable_args = [ 793*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(" + rebase_path(_runner_script, root_build_dir) + ")", 794*8975f5c5SAndroid Build Coastguard Worker _test_type, 795*8975f5c5SAndroid Build Coastguard Worker "--output-directory", 796*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(.)", 797*8975f5c5SAndroid Build Coastguard Worker "--wrapper-script-args", 798*8975f5c5SAndroid Build Coastguard Worker ] 799*8975f5c5SAndroid Build Coastguard Worker 800*8975f5c5SAndroid Build Coastguard Worker if (_is_unit_test) { 801*8975f5c5SAndroid Build Coastguard Worker executable_args += [ "--is-unit-test" ] 802*8975f5c5SAndroid Build Coastguard Worker } 803*8975f5c5SAndroid Build Coastguard Worker 804*8975f5c5SAndroid Build Coastguard Worker if (_runtime_deps) { 805*8975f5c5SAndroid Build Coastguard Worker deps += [ ":$_runtime_deps_target" ] 806*8975f5c5SAndroid Build Coastguard Worker data += [ _runtime_deps_file ] 807*8975f5c5SAndroid Build Coastguard Worker _rebased_runtime_deps_file = 808*8975f5c5SAndroid Build Coastguard Worker rebase_path(_runtime_deps_file, root_build_dir) 809*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 810*8975f5c5SAndroid Build Coastguard Worker "--runtime-deps-path", 811*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_runtime_deps_file})", 812*8975f5c5SAndroid Build Coastguard Worker ] 813*8975f5c5SAndroid Build Coastguard Worker } 814*8975f5c5SAndroid Build Coastguard Worker 815*8975f5c5SAndroid Build Coastguard Worker # apk_target is not used for native executable tests 816*8975f5c5SAndroid Build Coastguard Worker # (e.g. breakpad_unittests). 817*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_target)) { 818*8975f5c5SAndroid Build Coastguard Worker assert(!defined(invoker.executable_dist_dir)) 819*8975f5c5SAndroid Build Coastguard Worker deps += [ "${invoker.apk_target}$build_config_target_suffix" ] 820*8975f5c5SAndroid Build Coastguard Worker _apk_build_config = 821*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.apk_target, "target_gen_dir") + "/" + 822*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.apk_target, "name") + ".build_config.json" 823*8975f5c5SAndroid Build Coastguard Worker _rebased_apk_build_config = rebase_path(_apk_build_config, root_build_dir) 824*8975f5c5SAndroid Build Coastguard Worker not_needed([ "_rebased_apk_build_config" ]) 825*8975f5c5SAndroid Build Coastguard Worker } else if (_test_type == "gtest") { 826*8975f5c5SAndroid Build Coastguard Worker assert( 827*8975f5c5SAndroid Build Coastguard Worker defined(invoker.executable_dist_dir), 828*8975f5c5SAndroid Build Coastguard Worker "Must define either apk_target or executable_dist_dir for test_runner_script()") 829*8975f5c5SAndroid Build Coastguard Worker _rebased_executable_dist_dir = 830*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.executable_dist_dir, root_build_dir) 831*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 832*8975f5c5SAndroid Build Coastguard Worker "--executable-dist-dir", 833*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_executable_dist_dir})", 834*8975f5c5SAndroid Build Coastguard Worker ] 835*8975f5c5SAndroid Build Coastguard Worker } 836*8975f5c5SAndroid Build Coastguard Worker 837*8975f5c5SAndroid Build Coastguard Worker if (use_jacoco_coverage) { 838*8975f5c5SAndroid Build Coastguard Worker # Keep in sync with recipe constant for recipe to find coverage data 839*8975f5c5SAndroid Build Coastguard Worker # files from local java tests: https://bit.ly/3Zul6do 840*8975f5c5SAndroid Build Coastguard Worker _jacoco_coverage_dir_name = "java_coverage" 841*8975f5c5SAndroid Build Coastguard Worker } 842*8975f5c5SAndroid Build Coastguard Worker 843*8975f5c5SAndroid Build Coastguard Worker _device_test = true 844*8975f5c5SAndroid Build Coastguard Worker if (_test_type == "gtest") { 845*8975f5c5SAndroid Build Coastguard Worker assert(defined(invoker.test_suite)) 846*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 847*8975f5c5SAndroid Build Coastguard Worker "--suite", 848*8975f5c5SAndroid Build Coastguard Worker invoker.test_suite, 849*8975f5c5SAndroid Build Coastguard Worker ] 850*8975f5c5SAndroid Build Coastguard Worker if (use_clang_coverage) { 851*8975f5c5SAndroid Build Coastguard Worker # Set a default coverage output directory (can be overridden by user 852*8975f5c5SAndroid Build Coastguard Worker # passing the same flag). 853*8975f5c5SAndroid Build Coastguard Worker _rebased_coverage_dir = 854*8975f5c5SAndroid Build Coastguard Worker rebase_path("$root_out_dir/coverage", root_build_dir) 855*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 856*8975f5c5SAndroid Build Coastguard Worker "--coverage-dir", 857*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_coverage_dir})", 858*8975f5c5SAndroid Build Coastguard Worker ] 859*8975f5c5SAndroid Build Coastguard Worker } 860*8975f5c5SAndroid Build Coastguard Worker } else if (_test_type == "instrumentation") { 861*8975f5c5SAndroid Build Coastguard Worker _test_apk = "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:apk_path))" 862*8975f5c5SAndroid Build Coastguard Worker if (_incremental_apk) { 863*8975f5c5SAndroid Build Coastguard Worker _test_apk = "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:incremental_apk_path))" 864*8975f5c5SAndroid Build Coastguard Worker } 865*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 866*8975f5c5SAndroid Build Coastguard Worker "--test-apk", 867*8975f5c5SAndroid Build Coastguard Worker _test_apk, 868*8975f5c5SAndroid Build Coastguard Worker ] 869*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_under_test)) { 870*8975f5c5SAndroid Build Coastguard Worker if (_incremental_apk) { 871*8975f5c5SAndroid Build Coastguard Worker deps += [ "${invoker.apk_under_test}$build_config_target_suffix" ] 872*8975f5c5SAndroid Build Coastguard Worker _apk_under_test_build_config = 873*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.apk_under_test, "target_gen_dir") + "/" + 874*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.apk_under_test, "name") + 875*8975f5c5SAndroid Build Coastguard Worker ".build_config.json" 876*8975f5c5SAndroid Build Coastguard Worker _rebased_apk_under_test_build_config = 877*8975f5c5SAndroid Build Coastguard Worker rebase_path(_apk_under_test_build_config, root_build_dir) 878*8975f5c5SAndroid Build Coastguard Worker _apk_under_test = "@WrappedPath(@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_apk_path))" 879*8975f5c5SAndroid Build Coastguard Worker } else { 880*8975f5c5SAndroid Build Coastguard Worker deps += [ ":${_install_artifacts_target_name}" ] 881*8975f5c5SAndroid Build Coastguard Worker _rebased_install_artifacts_json = 882*8975f5c5SAndroid Build Coastguard Worker rebase_path(_install_artifacts_json, root_build_dir) 883*8975f5c5SAndroid Build Coastguard Worker _apk_under_test = 884*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(@FileArg($_rebased_install_artifacts_json[]))" 885*8975f5c5SAndroid Build Coastguard Worker } 886*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 887*8975f5c5SAndroid Build Coastguard Worker "--apk-under-test", 888*8975f5c5SAndroid Build Coastguard Worker _apk_under_test, 889*8975f5c5SAndroid Build Coastguard Worker ] 890*8975f5c5SAndroid Build Coastguard Worker } 891*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.use_webview_provider)) { 892*8975f5c5SAndroid Build Coastguard Worker deps += [ "${invoker.use_webview_provider}$build_config_target_suffix" ] 893*8975f5c5SAndroid Build Coastguard Worker _build_config = 894*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.use_webview_provider, "target_gen_dir") + 895*8975f5c5SAndroid Build Coastguard Worker "/" + get_label_info(invoker.use_webview_provider, "name") + 896*8975f5c5SAndroid Build Coastguard Worker ".build_config.json" 897*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 898*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 899*8975f5c5SAndroid Build Coastguard Worker "--use-webview-provider", 900*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(@FileArg($_rebased_build_config:deps_info:apk_path))", 901*8975f5c5SAndroid Build Coastguard Worker ] 902*8975f5c5SAndroid Build Coastguard Worker } 903*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_mapping_path)) { 904*8975f5c5SAndroid Build Coastguard Worker if (_incremental_apk) { 905*8975f5c5SAndroid Build Coastguard Worker not_needed(invoker, [ "proguard_mapping_path" ]) 906*8975f5c5SAndroid Build Coastguard Worker } else { 907*8975f5c5SAndroid Build Coastguard Worker data += [ invoker.proguard_mapping_path ] 908*8975f5c5SAndroid Build Coastguard Worker _rebased_mapping_path = 909*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_mapping_path, root_build_dir) 910*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 911*8975f5c5SAndroid Build Coastguard Worker "--proguard-mapping-path", 912*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath($_rebased_mapping_path)", 913*8975f5c5SAndroid Build Coastguard Worker ] 914*8975f5c5SAndroid Build Coastguard Worker } 915*8975f5c5SAndroid Build Coastguard Worker } 916*8975f5c5SAndroid Build Coastguard Worker if (use_jacoco_coverage) { 917*8975f5c5SAndroid Build Coastguard Worker # Set a default coverage output directory (can be overridden by user 918*8975f5c5SAndroid Build Coastguard Worker # passing the same flag). 919*8975f5c5SAndroid Build Coastguard Worker _rebased_coverage_dir = 920*8975f5c5SAndroid Build Coastguard Worker rebase_path("$root_out_dir/$_jacoco_coverage_dir_name", 921*8975f5c5SAndroid Build Coastguard Worker root_build_dir) 922*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 923*8975f5c5SAndroid Build Coastguard Worker "--coverage-dir", 924*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_coverage_dir})", 925*8975f5c5SAndroid Build Coastguard Worker ] 926*8975f5c5SAndroid Build Coastguard Worker } 927*8975f5c5SAndroid Build Coastguard Worker } else if (_test_type == "junit") { 928*8975f5c5SAndroid Build Coastguard Worker assert(defined(invoker.test_suite)) 929*8975f5c5SAndroid Build Coastguard Worker _device_test = false 930*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 931*8975f5c5SAndroid Build Coastguard Worker "--test-suite", 932*8975f5c5SAndroid Build Coastguard Worker invoker.test_suite, 933*8975f5c5SAndroid Build Coastguard Worker "--native-libs-dir", 934*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath($_robolectric_libs_dir)", 935*8975f5c5SAndroid Build Coastguard Worker ] 936*8975f5c5SAndroid Build Coastguard Worker 937*8975f5c5SAndroid Build Coastguard Worker # Test runner uses this generated wrapper script. 938*8975f5c5SAndroid Build Coastguard Worker data += [ "$root_build_dir/bin/helper/${invoker.test_suite}" ] 939*8975f5c5SAndroid Build Coastguard Worker 940*8975f5c5SAndroid Build Coastguard Worker deps += [ ":${invoker.test_suite}$build_config_target_suffix" ] 941*8975f5c5SAndroid Build Coastguard Worker 942*8975f5c5SAndroid Build Coastguard Worker _rebased_robolectric_runtime_deps_dir = 943*8975f5c5SAndroid Build Coastguard Worker rebase_path("//third_party/robolectric/cipd/lib", root_build_dir) 944*8975f5c5SAndroid Build Coastguard Worker _rebased_resource_apk = rebase_path(invoker.resource_apk, root_build_dir) 945*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 946*8975f5c5SAndroid Build Coastguard Worker "--resource-apk", 947*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_resource_apk})", 948*8975f5c5SAndroid Build Coastguard Worker "--robolectric-runtime-deps-dir", 949*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_robolectric_runtime_deps_dir})", 950*8975f5c5SAndroid Build Coastguard Worker ] 951*8975f5c5SAndroid Build Coastguard Worker if (build_with_chromium) { 952*8975f5c5SAndroid Build Coastguard Worker _allowlist = "//testing/android/junit/shadows-allowlist.txt" 953*8975f5c5SAndroid Build Coastguard Worker data += [ _allowlist ] 954*8975f5c5SAndroid Build Coastguard Worker _rebased_allowlist = rebase_path(_allowlist, root_build_dir) 955*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 956*8975f5c5SAndroid Build Coastguard Worker "--shadows-allowlist", 957*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath($_rebased_allowlist)", 958*8975f5c5SAndroid Build Coastguard Worker ] 959*8975f5c5SAndroid Build Coastguard Worker } 960*8975f5c5SAndroid Build Coastguard Worker if (use_jacoco_coverage) { 961*8975f5c5SAndroid Build Coastguard Worker # Set a default coverage output directory (can be overridden by user 962*8975f5c5SAndroid Build Coastguard Worker # passing the same flag). 963*8975f5c5SAndroid Build Coastguard Worker _rebased_coverage_dir = 964*8975f5c5SAndroid Build Coastguard Worker rebase_path("$root_out_dir/$_jacoco_coverage_dir_name", 965*8975f5c5SAndroid Build Coastguard Worker root_build_dir) 966*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 967*8975f5c5SAndroid Build Coastguard Worker "--coverage-dir", 968*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(${_rebased_coverage_dir})", 969*8975f5c5SAndroid Build Coastguard Worker ] 970*8975f5c5SAndroid Build Coastguard Worker } 971*8975f5c5SAndroid Build Coastguard Worker } else if (_test_type == "linker") { 972*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 973*8975f5c5SAndroid Build Coastguard Worker "--test-apk", 974*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:apk_path))", 975*8975f5c5SAndroid Build Coastguard Worker ] 976*8975f5c5SAndroid Build Coastguard Worker } else { 977*8975f5c5SAndroid Build Coastguard Worker assert(false, "Invalid test type: $_test_type.") 978*8975f5c5SAndroid Build Coastguard Worker } 979*8975f5c5SAndroid Build Coastguard Worker 980*8975f5c5SAndroid Build Coastguard Worker # Devil does not reliably work with component builds of its tools. 981*8975f5c5SAndroid Build Coastguard Worker # There's no benefit to them, so fall back to prebuilts for component builds. 982*8975f5c5SAndroid Build Coastguard Worker # https://crbug.com/1404180 983*8975f5c5SAndroid Build Coastguard Worker if (_test_type != "junit" && !is_component_build) { 984*8975f5c5SAndroid Build Coastguard Worker executable_args += [ "--use-local-devil-tools" ] 985*8975f5c5SAndroid Build Coastguard Worker } 986*8975f5c5SAndroid Build Coastguard Worker 987*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.additional_apks)) { 988*8975f5c5SAndroid Build Coastguard Worker foreach(additional_apk, invoker.additional_apks) { 989*8975f5c5SAndroid Build Coastguard Worker deps += [ "$additional_apk$build_config_target_suffix" ] 990*8975f5c5SAndroid Build Coastguard Worker _build_config = 991*8975f5c5SAndroid Build Coastguard Worker get_label_info(additional_apk, "target_gen_dir") + "/" + 992*8975f5c5SAndroid Build Coastguard Worker get_label_info(additional_apk, "name") + ".build_config.json" 993*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 994*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 995*8975f5c5SAndroid Build Coastguard Worker "--additional-apk", 996*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(@FileArg($_rebased_build_config:deps_info:apk_path))", 997*8975f5c5SAndroid Build Coastguard Worker ] 998*8975f5c5SAndroid Build Coastguard Worker } 999*8975f5c5SAndroid Build Coastguard Worker } 1000*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.shard_timeout)) { 1001*8975f5c5SAndroid Build Coastguard Worker executable_args += [ "--shard-timeout=${invoker.shard_timeout}" ] 1002*8975f5c5SAndroid Build Coastguard Worker } 1003*8975f5c5SAndroid Build Coastguard Worker if (_incremental_apk) { 1004*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 1005*8975f5c5SAndroid Build Coastguard Worker "--test-apk-incremental-install-json", 1006*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(@FileArg($_rebased_apk_build_config:deps_info:incremental_install_json_path))", 1007*8975f5c5SAndroid Build Coastguard Worker ] 1008*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_under_test)) { 1009*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 1010*8975f5c5SAndroid Build Coastguard Worker "--apk-under-test-incremental-install-json", 1011*8975f5c5SAndroid Build Coastguard Worker "@WrappedPath(@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_install_json_path))", 1012*8975f5c5SAndroid Build Coastguard Worker ] 1013*8975f5c5SAndroid Build Coastguard Worker } 1014*8975f5c5SAndroid Build Coastguard Worker executable_args += [ "--fast-local-dev" ] 1015*8975f5c5SAndroid Build Coastguard Worker } 1016*8975f5c5SAndroid Build Coastguard Worker if (_device_test && is_asan) { 1017*8975f5c5SAndroid Build Coastguard Worker executable_args += [ "--timeout-scale=4" ] 1018*8975f5c5SAndroid Build Coastguard Worker } 1019*8975f5c5SAndroid Build Coastguard Worker 1020*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.modules)) { 1021*8975f5c5SAndroid Build Coastguard Worker foreach(module, invoker.modules) { 1022*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 1023*8975f5c5SAndroid Build Coastguard Worker "--module", 1024*8975f5c5SAndroid Build Coastguard Worker module, 1025*8975f5c5SAndroid Build Coastguard Worker ] 1026*8975f5c5SAndroid Build Coastguard Worker } 1027*8975f5c5SAndroid Build Coastguard Worker } 1028*8975f5c5SAndroid Build Coastguard Worker 1029*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.fake_modules)) { 1030*8975f5c5SAndroid Build Coastguard Worker foreach(fake_module, invoker.fake_modules) { 1031*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 1032*8975f5c5SAndroid Build Coastguard Worker "--fake-module", 1033*8975f5c5SAndroid Build Coastguard Worker fake_module, 1034*8975f5c5SAndroid Build Coastguard Worker ] 1035*8975f5c5SAndroid Build Coastguard Worker } 1036*8975f5c5SAndroid Build Coastguard Worker } 1037*8975f5c5SAndroid Build Coastguard Worker 1038*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.additional_locales)) { 1039*8975f5c5SAndroid Build Coastguard Worker foreach(locale, invoker.additional_locales) { 1040*8975f5c5SAndroid Build Coastguard Worker executable_args += [ 1041*8975f5c5SAndroid Build Coastguard Worker "--additional-locale", 1042*8975f5c5SAndroid Build Coastguard Worker locale, 1043*8975f5c5SAndroid Build Coastguard Worker ] 1044*8975f5c5SAndroid Build Coastguard Worker } 1045*8975f5c5SAndroid Build Coastguard Worker } 1046*8975f5c5SAndroid Build Coastguard Worker 1047*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.extra_args)) { 1048*8975f5c5SAndroid Build Coastguard Worker executable_args += invoker.extra_args 1049*8975f5c5SAndroid Build Coastguard Worker } 1050*8975f5c5SAndroid Build Coastguard Worker } 1051*8975f5c5SAndroid Build Coastguard Worker} 1052*8975f5c5SAndroid Build Coastguard Worker 1053*8975f5c5SAndroid Build Coastguard Workerif (enable_java_templates) { 1054*8975f5c5SAndroid Build Coastguard Worker template("android_lint") { 1055*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1056*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1057*8975f5c5SAndroid Build Coastguard Worker 1058*8975f5c5SAndroid Build Coastguard Worker # https://crbug.com/1098752 Fix for bot OOM (https://crbug.com/1098333). 1059*8975f5c5SAndroid Build Coastguard Worker if (defined(java_cmd_pool_size)) { 1060*8975f5c5SAndroid Build Coastguard Worker pool = "//build/config/android:java_cmd_pool($default_toolchain)" 1061*8975f5c5SAndroid Build Coastguard Worker } else { 1062*8975f5c5SAndroid Build Coastguard Worker pool = "//build/toolchain:link_pool($default_toolchain)" 1063*8975f5c5SAndroid Build Coastguard Worker } 1064*8975f5c5SAndroid Build Coastguard Worker 1065*8975f5c5SAndroid Build Coastguard Worker # Lint requires generated sources and generated resources from the build. 1066*8975f5c5SAndroid Build Coastguard Worker # Turbine __header targets depend on all generated sources, and the 1067*8975f5c5SAndroid Build Coastguard Worker # __assetres targets depend on all generated resources. 1068*8975f5c5SAndroid Build Coastguard Worker deps = [] 1069*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 1070*8975f5c5SAndroid Build Coastguard Worker _lib_deps = 1071*8975f5c5SAndroid Build Coastguard Worker filter_exclude(filter_include(invoker.deps, java_library_patterns), 1072*8975f5c5SAndroid Build Coastguard Worker java_resource_patterns) 1073*8975f5c5SAndroid Build Coastguard Worker foreach(_lib_dep, _lib_deps) { 1074*8975f5c5SAndroid Build Coastguard Worker # Expand //foo/java -> //foo/java:java 1075*8975f5c5SAndroid Build Coastguard Worker _lib_dep = get_label_info(_lib_dep, "label_no_toolchain") 1076*8975f5c5SAndroid Build Coastguard Worker deps += [ 1077*8975f5c5SAndroid Build Coastguard Worker "${_lib_dep}__assetres", 1078*8975f5c5SAndroid Build Coastguard Worker "${_lib_dep}__header", 1079*8975f5c5SAndroid Build Coastguard Worker ] 1080*8975f5c5SAndroid Build Coastguard Worker } 1081*8975f5c5SAndroid Build Coastguard Worker 1082*8975f5c5SAndroid Build Coastguard Worker # Keep non-java deps as they may generate files used only by lint. 1083*8975f5c5SAndroid Build Coastguard Worker # e.g. generated suppressions.xml files. 1084*8975f5c5SAndroid Build Coastguard Worker deps += filter_exclude(invoker.deps, _lib_deps) 1085*8975f5c5SAndroid Build Coastguard Worker } 1086*8975f5c5SAndroid Build Coastguard Worker 1087*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.min_sdk_version)) { 1088*8975f5c5SAndroid Build Coastguard Worker _min_sdk_version = invoker.min_sdk_version 1089*8975f5c5SAndroid Build Coastguard Worker } else { 1090*8975f5c5SAndroid Build Coastguard Worker _min_sdk_version = default_min_sdk_version 1091*8975f5c5SAndroid Build Coastguard Worker } 1092*8975f5c5SAndroid Build Coastguard Worker 1093*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.lint_jar_path)) { 1094*8975f5c5SAndroid Build Coastguard Worker _lint_jar_path = invoker.lint_jar_path 1095*8975f5c5SAndroid Build Coastguard Worker } else { 1096*8975f5c5SAndroid Build Coastguard Worker _lint_jar_path = _default_lint_jar_path 1097*8975f5c5SAndroid Build Coastguard Worker } 1098*8975f5c5SAndroid Build Coastguard Worker 1099*8975f5c5SAndroid Build Coastguard Worker # It is not safe to run two lint versions concurrently since they will 1100*8975f5c5SAndroid Build Coastguard Worker # wipe the cache on version mismatch. When using a non-default lint 1101*8975f5c5SAndroid Build Coastguard Worker # version, make each target use their own cache directory. 1102*8975f5c5SAndroid Build Coastguard Worker _use_custom_cache_dir = _lint_jar_path != _default_lint_jar_path 1103*8975f5c5SAndroid Build Coastguard Worker 1104*8975f5c5SAndroid Build Coastguard Worker # Save generated xml files in a consistent location for debugging. 1105*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.lint_gen_dir)) { 1106*8975f5c5SAndroid Build Coastguard Worker _lint_gen_dir = invoker.lint_gen_dir 1107*8975f5c5SAndroid Build Coastguard Worker } else { 1108*8975f5c5SAndroid Build Coastguard Worker _lint_gen_dir = "$target_gen_dir/$target_name" 1109*8975f5c5SAndroid Build Coastguard Worker } 1110*8975f5c5SAndroid Build Coastguard Worker _backported_methods = "//third_party/r8/backported_methods.txt" 1111*8975f5c5SAndroid Build Coastguard Worker 1112*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/lint.py" 1113*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 1114*8975f5c5SAndroid Build Coastguard Worker inputs = java_paths_for_inputs + [ 1115*8975f5c5SAndroid Build Coastguard Worker _lint_jar_path, 1116*8975f5c5SAndroid Build Coastguard Worker _custom_lint_jar_path, 1117*8975f5c5SAndroid Build Coastguard Worker _backported_methods, 1118*8975f5c5SAndroid Build Coastguard Worker ] 1119*8975f5c5SAndroid Build Coastguard Worker 1120*8975f5c5SAndroid Build Coastguard Worker args = [ 1121*8975f5c5SAndroid Build Coastguard Worker "--target-name", 1122*8975f5c5SAndroid Build Coastguard Worker get_label_info(":${target_name}", "label_no_toolchain"), 1123*8975f5c5SAndroid Build Coastguard Worker "--depfile", 1124*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 1125*8975f5c5SAndroid Build Coastguard Worker "--lint-jar-path", 1126*8975f5c5SAndroid Build Coastguard Worker rebase_path(_lint_jar_path, root_build_dir), 1127*8975f5c5SAndroid Build Coastguard Worker "--custom-lint-jar-path", 1128*8975f5c5SAndroid Build Coastguard Worker rebase_path(_custom_lint_jar_path, root_build_dir), 1129*8975f5c5SAndroid Build Coastguard Worker "--lint-gen-dir", 1130*8975f5c5SAndroid Build Coastguard Worker rebase_path(_lint_gen_dir, root_build_dir), 1131*8975f5c5SAndroid Build Coastguard Worker "--android-sdk-version=${lint_android_sdk_version}", 1132*8975f5c5SAndroid Build Coastguard Worker "--min-sdk-version=$_min_sdk_version", 1133*8975f5c5SAndroid Build Coastguard Worker "--android-sdk-root", 1134*8975f5c5SAndroid Build Coastguard Worker rebase_path(lint_android_sdk_root, root_build_dir), 1135*8975f5c5SAndroid Build Coastguard Worker "--backported-methods", 1136*8975f5c5SAndroid Build Coastguard Worker rebase_path(_backported_methods, root_build_dir), 1137*8975f5c5SAndroid Build Coastguard Worker ] 1138*8975f5c5SAndroid Build Coastguard Worker 1139*8975f5c5SAndroid Build Coastguard Worker if (!_use_custom_cache_dir) { 1140*8975f5c5SAndroid Build Coastguard Worker _cache_dir = "$root_build_dir/android_lint_cache" 1141*8975f5c5SAndroid Build Coastguard Worker _create_cache_stamp_path = "$_cache_dir/build.lint.stamp" 1142*8975f5c5SAndroid Build Coastguard Worker 1143*8975f5c5SAndroid Build Coastguard Worker # By default, lint.py will use "$_lint_gen_dir/cache". 1144*8975f5c5SAndroid Build Coastguard Worker args += [ 1145*8975f5c5SAndroid Build Coastguard Worker "--cache-dir", 1146*8975f5c5SAndroid Build Coastguard Worker rebase_path(_cache_dir, root_build_dir), 1147*8975f5c5SAndroid Build Coastguard Worker ] 1148*8975f5c5SAndroid Build Coastguard Worker } 1149*8975f5c5SAndroid Build Coastguard Worker 1150*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.skip_build_server) && invoker.skip_build_server) { 1151*8975f5c5SAndroid Build Coastguard Worker # Nocompile tests need lint to fail through ninja. 1152*8975f5c5SAndroid Build Coastguard Worker args += [ "--skip-build-server" ] 1153*8975f5c5SAndroid Build Coastguard Worker } else if (android_static_analysis == "build_server") { 1154*8975f5c5SAndroid Build Coastguard Worker args += [ "--use-build-server" ] 1155*8975f5c5SAndroid Build Coastguard Worker if (experimental_build_server) { 1156*8975f5c5SAndroid Build Coastguard Worker args += [ "--experimental-build-server" ] 1157*8975f5c5SAndroid Build Coastguard Worker } 1158*8975f5c5SAndroid Build Coastguard Worker } 1159*8975f5c5SAndroid Build Coastguard Worker 1160*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.lint_suppressions_file)) { 1161*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.lint_suppressions_file ] 1162*8975f5c5SAndroid Build Coastguard Worker 1163*8975f5c5SAndroid Build Coastguard Worker args += [ 1164*8975f5c5SAndroid Build Coastguard Worker "--config-path", 1165*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.lint_suppressions_file, root_build_dir), 1166*8975f5c5SAndroid Build Coastguard Worker ] 1167*8975f5c5SAndroid Build Coastguard Worker } 1168*8975f5c5SAndroid Build Coastguard Worker 1169*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.manifest_package)) { 1170*8975f5c5SAndroid Build Coastguard Worker args += [ "--manifest-package=${invoker.manifest_package}" ] 1171*8975f5c5SAndroid Build Coastguard Worker } 1172*8975f5c5SAndroid Build Coastguard Worker 1173*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 1174*8975f5c5SAndroid Build Coastguard Worker args += [ "--warnings-as-errors" ] 1175*8975f5c5SAndroid Build Coastguard Worker } 1176*8975f5c5SAndroid Build Coastguard Worker 1177*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.lint_baseline_file)) { 1178*8975f5c5SAndroid Build Coastguard Worker if (compute_inputs_for_analyze) { 1179*8975f5c5SAndroid Build Coastguard Worker # The baseline file is included in lint.py as a depfile dep. Since 1180*8975f5c5SAndroid Build Coastguard Worker # removing it regenerates the file, it is useful to not have this as 1181*8975f5c5SAndroid Build Coastguard Worker # a gn input during local development. Add it only for bots' analyze. 1182*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.lint_baseline_file ] 1183*8975f5c5SAndroid Build Coastguard Worker } 1184*8975f5c5SAndroid Build Coastguard Worker args += [ 1185*8975f5c5SAndroid Build Coastguard Worker # Baseline allows us to turn on lint warnings without fixing all the 1186*8975f5c5SAndroid Build Coastguard Worker # pre-existing issues. This stops the flood of new issues while the 1187*8975f5c5SAndroid Build Coastguard Worker # existing ones are being fixed. 1188*8975f5c5SAndroid Build Coastguard Worker "--baseline", 1189*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.lint_baseline_file, root_build_dir), 1190*8975f5c5SAndroid Build Coastguard Worker ] 1191*8975f5c5SAndroid Build Coastguard Worker } 1192*8975f5c5SAndroid Build Coastguard Worker 1193*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.create_cache) && invoker.create_cache) { 1194*8975f5c5SAndroid Build Coastguard Worker # Putting the stamp file in the cache dir allows us to depend on ninja 1195*8975f5c5SAndroid Build Coastguard Worker # to create the cache dir for us. 1196*8975f5c5SAndroid Build Coastguard Worker args += [ "--create-cache" ] 1197*8975f5c5SAndroid Build Coastguard Worker _stamp_path = _create_cache_stamp_path 1198*8975f5c5SAndroid Build Coastguard Worker } else { 1199*8975f5c5SAndroid Build Coastguard Worker _stamp_path = "$target_out_dir/$target_name/build.lint.stamp" 1200*8975f5c5SAndroid Build Coastguard Worker deps += [ invoker.build_config_dep ] 1201*8975f5c5SAndroid Build Coastguard Worker if (!_use_custom_cache_dir) { 1202*8975f5c5SAndroid Build Coastguard Worker deps += [ "//build/android:prepare_android_lint_cache" ] 1203*8975f5c5SAndroid Build Coastguard Worker inputs += [ _create_cache_stamp_path ] 1204*8975f5c5SAndroid Build Coastguard Worker } 1205*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.build_config ] 1206*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = 1207*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.build_config, root_build_dir) 1208*8975f5c5SAndroid Build Coastguard Worker 1209*8975f5c5SAndroid Build Coastguard Worker args += [ 1210*8975f5c5SAndroid Build Coastguard Worker "--manifest-path=@FileArg($_rebased_build_config:deps_info:lint_android_manifest)", 1211*8975f5c5SAndroid Build Coastguard Worker "--extra-manifest-paths=@FileArg($_rebased_build_config:deps_info:lint_extra_android_manifests)", 1212*8975f5c5SAndroid Build Coastguard Worker 1213*8975f5c5SAndroid Build Coastguard Worker # Lint requires all source and all resource files to be passed in the 1214*8975f5c5SAndroid Build Coastguard Worker # same invocation for checks like UnusedResources. 1215*8975f5c5SAndroid Build Coastguard Worker "--sources=@FileArg($_rebased_build_config:deps_info:lint_sources)", 1216*8975f5c5SAndroid Build Coastguard Worker "--aars=@FileArg($_rebased_build_config:deps_info:lint_aars)", 1217*8975f5c5SAndroid Build Coastguard Worker "--srcjars=@FileArg($_rebased_build_config:deps_info:lint_srcjars)", 1218*8975f5c5SAndroid Build Coastguard Worker "--resource-sources=@FileArg($_rebased_build_config:deps_info:lint_resource_sources)", 1219*8975f5c5SAndroid Build Coastguard Worker "--resource-zips=@FileArg($_rebased_build_config:deps_info:lint_resource_zips)", 1220*8975f5c5SAndroid Build Coastguard Worker 1221*8975f5c5SAndroid Build Coastguard Worker # The full classpath is required for annotation checks like @IntDef. 1222*8975f5c5SAndroid Build Coastguard Worker "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)", 1223*8975f5c5SAndroid Build Coastguard Worker ] 1224*8975f5c5SAndroid Build Coastguard Worker } 1225*8975f5c5SAndroid Build Coastguard Worker 1226*8975f5c5SAndroid Build Coastguard Worker outputs = [ _stamp_path ] 1227*8975f5c5SAndroid Build Coastguard Worker args += [ 1228*8975f5c5SAndroid Build Coastguard Worker "--stamp", 1229*8975f5c5SAndroid Build Coastguard Worker rebase_path(_stamp_path, root_build_dir), 1230*8975f5c5SAndroid Build Coastguard Worker ] 1231*8975f5c5SAndroid Build Coastguard Worker } 1232*8975f5c5SAndroid Build Coastguard Worker } 1233*8975f5c5SAndroid Build Coastguard Worker 1234*8975f5c5SAndroid Build Coastguard Worker template("proguard") { 1235*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1236*8975f5c5SAndroid Build Coastguard Worker _script = "//build/android/gyp/proguard.py" 1237*8975f5c5SAndroid Build Coastguard Worker _deps = invoker.deps 1238*8975f5c5SAndroid Build Coastguard Worker 1239*8975f5c5SAndroid Build Coastguard Worker _inputs = java_paths_for_inputs + [ 1240*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 1241*8975f5c5SAndroid Build Coastguard Worker _r8_path, 1242*8975f5c5SAndroid Build Coastguard Worker _custom_r8_path, 1243*8975f5c5SAndroid Build Coastguard Worker ] 1244*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.inputs)) { 1245*8975f5c5SAndroid Build Coastguard Worker _inputs += invoker.inputs 1246*8975f5c5SAndroid Build Coastguard Worker } 1247*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_mapping_path)) { 1248*8975f5c5SAndroid Build Coastguard Worker _mapping_path = invoker.proguard_mapping_path 1249*8975f5c5SAndroid Build Coastguard Worker } else { 1250*8975f5c5SAndroid Build Coastguard Worker _mapping_path = "${invoker.output_path}.mapping" 1251*8975f5c5SAndroid Build Coastguard Worker } 1252*8975f5c5SAndroid Build Coastguard Worker 1253*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 1254*8975f5c5SAndroid Build Coastguard Worker 1255*8975f5c5SAndroid Build Coastguard Worker # This is generally the apk name, and serves to identify the mapping 1256*8975f5c5SAndroid Build Coastguard Worker # file that would be required to deobfuscate a stacktrace. 1257*8975f5c5SAndroid Build Coastguard Worker _mapping_basename = get_path_info(_mapping_path, "name") 1258*8975f5c5SAndroid Build Coastguard Worker _version_code = "@FileArg($_rebased_build_config:deps_info:version_code)" 1259*8975f5c5SAndroid Build Coastguard Worker _package_name = "@FileArg($_rebased_build_config:deps_info:package_name)" 1260*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.package_name)) { 1261*8975f5c5SAndroid Build Coastguard Worker _package_name = invoker.package_name 1262*8975f5c5SAndroid Build Coastguard Worker } 1263*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.version_code)) { 1264*8975f5c5SAndroid Build Coastguard Worker _version_code = invoker.version_code 1265*8975f5c5SAndroid Build Coastguard Worker } 1266*8975f5c5SAndroid Build Coastguard Worker 1267*8975f5c5SAndroid Build Coastguard Worker # The Mapping ID is parsed to when uploading mapping files. 1268*8975f5c5SAndroid Build Coastguard Worker # See: https://crbug.com/1417308 1269*8975f5c5SAndroid Build Coastguard Worker _source_file_template = 1270*8975f5c5SAndroid Build Coastguard Worker "chromium-$_mapping_basename-$android_channel-$_version_code" 1271*8975f5c5SAndroid Build Coastguard Worker 1272*8975f5c5SAndroid Build Coastguard Worker _args = [ 1273*8975f5c5SAndroid Build Coastguard Worker "--min-api=${invoker.min_sdk_version}", 1274*8975f5c5SAndroid Build Coastguard Worker "--mapping-output", 1275*8975f5c5SAndroid Build Coastguard Worker rebase_path(_mapping_path, root_build_dir), 1276*8975f5c5SAndroid Build Coastguard Worker "--sdk-jars", 1277*8975f5c5SAndroid Build Coastguard Worker "@FileArg($_rebased_build_config:android:sdk_jars)", 1278*8975f5c5SAndroid Build Coastguard Worker "--sdk-extension-jars", 1279*8975f5c5SAndroid Build Coastguard Worker "@FileArg($_rebased_build_config:deps_info:proguard_classpath_jars)", 1280*8975f5c5SAndroid Build Coastguard Worker "--r8-path", 1281*8975f5c5SAndroid Build Coastguard Worker rebase_path(_r8_path, root_build_dir), 1282*8975f5c5SAndroid Build Coastguard Worker "--custom-r8-path", 1283*8975f5c5SAndroid Build Coastguard Worker rebase_path(_custom_r8_path, root_build_dir), 1284*8975f5c5SAndroid Build Coastguard Worker "--package-name=$_package_name", 1285*8975f5c5SAndroid Build Coastguard Worker "--source-file", 1286*8975f5c5SAndroid Build Coastguard Worker _source_file_template, 1287*8975f5c5SAndroid Build Coastguard Worker "--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)", 1288*8975f5c5SAndroid Build Coastguard Worker ] 1289*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 1290*8975f5c5SAndroid Build Coastguard Worker _args += [ "--warnings-as-errors" ] 1291*8975f5c5SAndroid Build Coastguard Worker } 1292*8975f5c5SAndroid Build Coastguard Worker 1293*8975f5c5SAndroid Build Coastguard Worker if ((!defined(invoker.proguard_enable_obfuscation) || 1294*8975f5c5SAndroid Build Coastguard Worker invoker.proguard_enable_obfuscation) && enable_proguard_obfuscation) { 1295*8975f5c5SAndroid Build Coastguard Worker _args += [ "--enable-obfuscation" ] 1296*8975f5c5SAndroid Build Coastguard Worker } 1297*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.repackage_classes)) { 1298*8975f5c5SAndroid Build Coastguard Worker _args += [ "--repackage-classes=" + invoker.repackage_classes ] 1299*8975f5c5SAndroid Build Coastguard Worker } 1300*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apply_mapping)) { 1301*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.apply_mapping ] 1302*8975f5c5SAndroid Build Coastguard Worker _rebased_apply_mapping_path = 1303*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.apply_mapping, root_build_dir) 1304*8975f5c5SAndroid Build Coastguard Worker args += [ "--apply-mapping=$_rebased_apply_mapping_path" ] 1305*8975f5c5SAndroid Build Coastguard Worker } 1306*8975f5c5SAndroid Build Coastguard Worker 1307*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_configs)) { 1308*8975f5c5SAndroid Build Coastguard Worker _inputs += invoker.proguard_configs 1309*8975f5c5SAndroid Build Coastguard Worker _rebased_proguard_configs = 1310*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_configs, root_build_dir) 1311*8975f5c5SAndroid Build Coastguard Worker _args += [ "--proguard-configs=$_rebased_proguard_configs" ] 1312*8975f5c5SAndroid Build Coastguard Worker } 1313*8975f5c5SAndroid Build Coastguard Worker 1314*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.modules)) { 1315*8975f5c5SAndroid Build Coastguard Worker foreach(_feature_module, invoker.modules) { 1316*8975f5c5SAndroid Build Coastguard Worker _rebased_module_build_config = 1317*8975f5c5SAndroid Build Coastguard Worker rebase_path(_feature_module.build_config, root_build_dir) 1318*8975f5c5SAndroid Build Coastguard Worker _args += [ 1319*8975f5c5SAndroid Build Coastguard Worker "--feature-name=${_feature_module.name}", 1320*8975f5c5SAndroid Build Coastguard Worker "--dex-dest=@FileArg($_rebased_module_build_config:final_dex:path)", 1321*8975f5c5SAndroid Build Coastguard Worker ] 1322*8975f5c5SAndroid Build Coastguard Worker 1323*8975f5c5SAndroid Build Coastguard Worker # The bundle's build config has the correct classpaths - the individual 1324*8975f5c5SAndroid Build Coastguard Worker # modules' build configs may double-use some jars. 1325*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.add_view_trace_events) && 1326*8975f5c5SAndroid Build Coastguard Worker invoker.add_view_trace_events) { 1327*8975f5c5SAndroid Build Coastguard Worker _args += [ "--feature-jars=@FileArg($_rebased_build_config:modules:${_feature_module.name}:trace_event_rewritten_device_classpath)" ] 1328*8975f5c5SAndroid Build Coastguard Worker } else { 1329*8975f5c5SAndroid Build Coastguard Worker _args += [ "--feature-jars=@FileArg($_rebased_build_config:modules:${_feature_module.name}:device_classpath)" ] 1330*8975f5c5SAndroid Build Coastguard Worker } 1331*8975f5c5SAndroid Build Coastguard Worker 1332*8975f5c5SAndroid Build Coastguard Worker if (defined(_feature_module.uses_split)) { 1333*8975f5c5SAndroid Build Coastguard Worker _args += [ "--uses-split=${_feature_module.name}:${_feature_module.uses_split}" ] 1334*8975f5c5SAndroid Build Coastguard Worker } 1335*8975f5c5SAndroid Build Coastguard Worker _deps += [ _feature_module.build_config_target ] 1336*8975f5c5SAndroid Build Coastguard Worker } 1337*8975f5c5SAndroid Build Coastguard Worker _stamp = "${target_gen_dir}/${target_name}.r8.stamp" 1338*8975f5c5SAndroid Build Coastguard Worker _outputs = [ _stamp ] 1339*8975f5c5SAndroid Build Coastguard Worker _output_arg = [ 1340*8975f5c5SAndroid Build Coastguard Worker "--stamp", 1341*8975f5c5SAndroid Build Coastguard Worker rebase_path(_stamp, root_build_dir), 1342*8975f5c5SAndroid Build Coastguard Worker ] 1343*8975f5c5SAndroid Build Coastguard Worker } else { 1344*8975f5c5SAndroid Build Coastguard Worker # We don't directly set the output arg on the _args variable since it is 1345*8975f5c5SAndroid Build Coastguard Worker # shared with the expectation target that uses its own stamp file and 1346*8975f5c5SAndroid Build Coastguard Worker # does not take an --output-path. 1347*8975f5c5SAndroid Build Coastguard Worker _output_arg = [ 1348*8975f5c5SAndroid Build Coastguard Worker "--output-path", 1349*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_path, root_build_dir), 1350*8975f5c5SAndroid Build Coastguard Worker ] 1351*8975f5c5SAndroid Build Coastguard Worker _outputs = [ invoker.output_path ] 1352*8975f5c5SAndroid Build Coastguard Worker } 1353*8975f5c5SAndroid Build Coastguard Worker _outputs += [ _mapping_path ] 1354*8975f5c5SAndroid Build Coastguard Worker 1355*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.input_art_profile)) { 1356*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.input_art_profile ] 1357*8975f5c5SAndroid Build Coastguard Worker _args += [ "--input-art-profile=" + 1358*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_art_profile, root_build_dir) ] 1359*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.output_art_profile)) { 1360*8975f5c5SAndroid Build Coastguard Worker _outputs += [ invoker.output_art_profile ] 1361*8975f5c5SAndroid Build Coastguard Worker _args += [ "--output-art-profile=" + 1362*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_art_profile, root_build_dir) ] 1363*8975f5c5SAndroid Build Coastguard Worker } 1364*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.enable_startup_profile) && 1365*8975f5c5SAndroid Build Coastguard Worker invoker.enable_startup_profile) { 1366*8975f5c5SAndroid Build Coastguard Worker _args += [ "--apply-startup-profile" ] 1367*8975f5c5SAndroid Build Coastguard Worker } 1368*8975f5c5SAndroid Build Coastguard Worker } 1369*8975f5c5SAndroid Build Coastguard Worker 1370*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.enable_proguard_checks) && 1371*8975f5c5SAndroid Build Coastguard Worker !invoker.enable_proguard_checks) { 1372*8975f5c5SAndroid Build Coastguard Worker _args += [ "--disable-checks" ] 1373*8975f5c5SAndroid Build Coastguard Worker } 1374*8975f5c5SAndroid Build Coastguard Worker 1375*8975f5c5SAndroid Build Coastguard Worker _ignore_desugar_missing_deps = 1376*8975f5c5SAndroid Build Coastguard Worker defined(invoker.ignore_desugar_missing_deps) && 1377*8975f5c5SAndroid Build Coastguard Worker invoker.ignore_desugar_missing_deps 1378*8975f5c5SAndroid Build Coastguard Worker if (!_ignore_desugar_missing_deps) { 1379*8975f5c5SAndroid Build Coastguard Worker _args += [ "--show-desugar-default-interface-warnings" ] 1380*8975f5c5SAndroid Build Coastguard Worker } 1381*8975f5c5SAndroid Build Coastguard Worker 1382*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.custom_assertion_handler)) { 1383*8975f5c5SAndroid Build Coastguard Worker _args += [ 1384*8975f5c5SAndroid Build Coastguard Worker "--assertion-handler", 1385*8975f5c5SAndroid Build Coastguard Worker invoker.custom_assertion_handler, 1386*8975f5c5SAndroid Build Coastguard Worker ] 1387*8975f5c5SAndroid Build Coastguard Worker } else if (enable_java_asserts) { 1388*8975f5c5SAndroid Build Coastguard Worker # The default for generating dex file format is 1389*8975f5c5SAndroid Build Coastguard Worker # --force-disable-assertions. 1390*8975f5c5SAndroid Build Coastguard Worker _args += [ "--force-enable-assertions" ] 1391*8975f5c5SAndroid Build Coastguard Worker } 1392*8975f5c5SAndroid Build Coastguard Worker 1393*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.args)) { 1394*8975f5c5SAndroid Build Coastguard Worker _args += invoker.args 1395*8975f5c5SAndroid Build Coastguard Worker } 1396*8975f5c5SAndroid Build Coastguard Worker 1397*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_proguard_config)) { 1398*8975f5c5SAndroid Build Coastguard Worker _expectations_target = 1399*8975f5c5SAndroid Build Coastguard Worker "${invoker.top_target_name}_validate_proguard_config" 1400*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(_expectations_target) { 1401*8975f5c5SAndroid Build Coastguard Worker script = _script 1402*8975f5c5SAndroid Build Coastguard Worker 1403*8975f5c5SAndroid Build Coastguard Worker # Need to depend on all deps so that proguard.txt within .aar files get 1404*8975f5c5SAndroid Build Coastguard Worker # extracted. 1405*8975f5c5SAndroid Build Coastguard Worker deps = _deps 1406*8975f5c5SAndroid Build Coastguard Worker depfile = "${target_gen_dir}/${target_name}.d" 1407*8975f5c5SAndroid Build Coastguard Worker inputs = [ 1408*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 1409*8975f5c5SAndroid Build Coastguard Worker invoker.expected_proguard_config, 1410*8975f5c5SAndroid Build Coastguard Worker ] 1411*8975f5c5SAndroid Build Coastguard Worker _actual_file = "$target_gen_dir/$target_name.proguard_configs" 1412*8975f5c5SAndroid Build Coastguard Worker _failure_file = 1413*8975f5c5SAndroid Build Coastguard Worker "$expectations_failure_dir/" + 1414*8975f5c5SAndroid Build Coastguard Worker string_replace(invoker.expected_proguard_config, "/", "_") 1415*8975f5c5SAndroid Build Coastguard Worker outputs = [ 1416*8975f5c5SAndroid Build Coastguard Worker _actual_file, 1417*8975f5c5SAndroid Build Coastguard Worker _failure_file, 1418*8975f5c5SAndroid Build Coastguard Worker ] 1419*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 1420*8975f5c5SAndroid Build Coastguard Worker "--depfile", 1421*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 1422*8975f5c5SAndroid Build Coastguard Worker "--failure-file", 1423*8975f5c5SAndroid Build Coastguard Worker rebase_path(_failure_file, root_build_dir), 1424*8975f5c5SAndroid Build Coastguard Worker "--expected-file", 1425*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_proguard_config, root_build_dir), 1426*8975f5c5SAndroid Build Coastguard Worker "--actual-file", 1427*8975f5c5SAndroid Build Coastguard Worker rebase_path(_actual_file, root_build_dir), 1428*8975f5c5SAndroid Build Coastguard Worker "--only-verify-expectations", 1429*8975f5c5SAndroid Build Coastguard Worker ] 1430*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_proguard_config_base)) { 1431*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.expected_proguard_config_base ] 1432*8975f5c5SAndroid Build Coastguard Worker args += [ 1433*8975f5c5SAndroid Build Coastguard Worker "--expected-file-base", 1434*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_proguard_config_base, root_build_dir), 1435*8975f5c5SAndroid Build Coastguard Worker ] 1436*8975f5c5SAndroid Build Coastguard Worker } 1437*8975f5c5SAndroid Build Coastguard Worker if (fail_on_android_expectations) { 1438*8975f5c5SAndroid Build Coastguard Worker args += [ "--fail-on-expectations" ] 1439*8975f5c5SAndroid Build Coastguard Worker } 1440*8975f5c5SAndroid Build Coastguard Worker } 1441*8975f5c5SAndroid Build Coastguard Worker _deps += [ ":$_expectations_target" ] 1442*8975f5c5SAndroid Build Coastguard Worker } 1443*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1444*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1445*8975f5c5SAndroid Build Coastguard Worker [ 1446*8975f5c5SAndroid Build Coastguard Worker "data", 1447*8975f5c5SAndroid Build Coastguard Worker "data_deps", 1448*8975f5c5SAndroid Build Coastguard Worker "public_deps", 1449*8975f5c5SAndroid Build Coastguard Worker ]) 1450*8975f5c5SAndroid Build Coastguard Worker script = _script 1451*8975f5c5SAndroid Build Coastguard Worker deps = _deps 1452*8975f5c5SAndroid Build Coastguard Worker inputs = _inputs 1453*8975f5c5SAndroid Build Coastguard Worker outputs = _outputs 1454*8975f5c5SAndroid Build Coastguard Worker depfile = "${target_gen_dir}/${target_name}.d" 1455*8975f5c5SAndroid Build Coastguard Worker args = _args + _output_arg + [ 1456*8975f5c5SAndroid Build Coastguard Worker "--depfile", 1457*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 1458*8975f5c5SAndroid Build Coastguard Worker ] 1459*8975f5c5SAndroid Build Coastguard Worker 1460*8975f5c5SAndroid Build Coastguard Worker # http://crbug.com/725224. Fix for bots running out of memory. 1461*8975f5c5SAndroid Build Coastguard Worker if (defined(java_cmd_pool_size)) { 1462*8975f5c5SAndroid Build Coastguard Worker pool = "//build/config/android:java_cmd_pool($default_toolchain)" 1463*8975f5c5SAndroid Build Coastguard Worker } else { 1464*8975f5c5SAndroid Build Coastguard Worker pool = "//build/toolchain:link_pool($default_toolchain)" 1465*8975f5c5SAndroid Build Coastguard Worker } 1466*8975f5c5SAndroid Build Coastguard Worker } 1467*8975f5c5SAndroid Build Coastguard Worker } 1468*8975f5c5SAndroid Build Coastguard Worker 1469*8975f5c5SAndroid Build Coastguard Worker # Generates a script in the build bin directory to run a java binary. 1470*8975f5c5SAndroid Build Coastguard Worker # 1471*8975f5c5SAndroid Build Coastguard Worker # Variables 1472*8975f5c5SAndroid Build Coastguard Worker # main_class: The class containing the program entry point. 1473*8975f5c5SAndroid Build Coastguard Worker # build_config: Path to .build_config.json for the jar (contains classpath). 1474*8975f5c5SAndroid Build Coastguard Worker # script_name: Name of the script to generate. 1475*8975f5c5SAndroid Build Coastguard Worker # wrapper_script_args: List of extra arguments to pass to the executable. 1476*8975f5c5SAndroid Build Coastguard Worker # tiered_stop_at_level_one: Whether to pass --tiered-stop-at-level-one 1477*8975f5c5SAndroid Build Coastguard Worker # 1478*8975f5c5SAndroid Build Coastguard Worker template("java_binary_script") { 1479*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1480*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1481*8975f5c5SAndroid Build Coastguard Worker 1482*8975f5c5SAndroid Build Coastguard Worker _main_class = invoker.main_class 1483*8975f5c5SAndroid Build Coastguard Worker _build_config = invoker.build_config 1484*8975f5c5SAndroid Build Coastguard Worker _script_name = invoker.script_name 1485*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.max_heap_size)) { 1486*8975f5c5SAndroid Build Coastguard Worker _max_heap_size = invoker.max_heap_size 1487*8975f5c5SAndroid Build Coastguard Worker } else { 1488*8975f5c5SAndroid Build Coastguard Worker _max_heap_size = "1G" 1489*8975f5c5SAndroid Build Coastguard Worker } 1490*8975f5c5SAndroid Build Coastguard Worker 1491*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/create_java_binary_script.py" 1492*8975f5c5SAndroid Build Coastguard Worker inputs = [ _build_config ] 1493*8975f5c5SAndroid Build Coastguard Worker _java_script = "$root_build_dir/bin/$_script_name" 1494*8975f5c5SAndroid Build Coastguard Worker outputs = [ _java_script ] 1495*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 1496*8975f5c5SAndroid Build Coastguard Worker args = [ 1497*8975f5c5SAndroid Build Coastguard Worker "--output", 1498*8975f5c5SAndroid Build Coastguard Worker rebase_path(_java_script, root_build_dir), 1499*8975f5c5SAndroid Build Coastguard Worker "--main-class", 1500*8975f5c5SAndroid Build Coastguard Worker _main_class, 1501*8975f5c5SAndroid Build Coastguard Worker "--classpath=@FileArg($_rebased_build_config:deps_info:host_classpath)", 1502*8975f5c5SAndroid Build Coastguard Worker "--max-heap-size=$_max_heap_size", 1503*8975f5c5SAndroid Build Coastguard Worker ] 1504*8975f5c5SAndroid Build Coastguard Worker data = [] 1505*8975f5c5SAndroid Build Coastguard Worker deps = [ "//third_party/jdk:java_data" ] 1506*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 1507*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 1508*8975f5c5SAndroid Build Coastguard Worker } 1509*8975f5c5SAndroid Build Coastguard Worker 1510*8975f5c5SAndroid Build Coastguard Worker if (enable_java_asserts) { 1511*8975f5c5SAndroid Build Coastguard Worker args += [ "--enable-asserts" ] 1512*8975f5c5SAndroid Build Coastguard Worker } 1513*8975f5c5SAndroid Build Coastguard Worker if (use_jacoco_coverage) { 1514*8975f5c5SAndroid Build Coastguard Worker args += [ 1515*8975f5c5SAndroid Build Coastguard Worker "--classpath", 1516*8975f5c5SAndroid Build Coastguard Worker rebase_path(_jacoco_host_jar, root_build_dir), 1517*8975f5c5SAndroid Build Coastguard Worker ] 1518*8975f5c5SAndroid Build Coastguard Worker data += [ _jacoco_host_jar ] 1519*8975f5c5SAndroid Build Coastguard Worker } 1520*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.tiered_stop_at_level_one) && 1521*8975f5c5SAndroid Build Coastguard Worker invoker.tiered_stop_at_level_one) { 1522*8975f5c5SAndroid Build Coastguard Worker args += [ "--tiered-stop-at-level-one" ] 1523*8975f5c5SAndroid Build Coastguard Worker } 1524*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.extra_classpath_jars)) { 1525*8975f5c5SAndroid Build Coastguard Worker _rebased_extra_classpath_jars = 1526*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.extra_classpath_jars, root_build_dir) 1527*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=${_rebased_extra_classpath_jars}" ] 1528*8975f5c5SAndroid Build Coastguard Worker data += invoker.extra_classpath_jars 1529*8975f5c5SAndroid Build Coastguard Worker } 1530*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.wrapper_script_args)) { 1531*8975f5c5SAndroid Build Coastguard Worker args += [ "--" ] + invoker.wrapper_script_args 1532*8975f5c5SAndroid Build Coastguard Worker } 1533*8975f5c5SAndroid Build Coastguard Worker } 1534*8975f5c5SAndroid Build Coastguard Worker } 1535*8975f5c5SAndroid Build Coastguard Worker 1536*8975f5c5SAndroid Build Coastguard Worker # Variables 1537*8975f5c5SAndroid Build Coastguard Worker # apply_mapping: The path to the ProGuard mapping file to apply. 1538*8975f5c5SAndroid Build Coastguard Worker # disable_incremental: Disable incremental dexing. 1539*8975f5c5SAndroid Build Coastguard Worker template("dex") { 1540*8975f5c5SAndroid Build Coastguard Worker _min_sdk_version = default_min_sdk_version 1541*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.min_sdk_version)) { 1542*8975f5c5SAndroid Build Coastguard Worker _min_sdk_version = invoker.min_sdk_version 1543*8975f5c5SAndroid Build Coastguard Worker } 1544*8975f5c5SAndroid Build Coastguard Worker assert( 1545*8975f5c5SAndroid Build Coastguard Worker _min_sdk_version >= min_supported_sdk_version, 1546*8975f5c5SAndroid Build Coastguard Worker get_label_info(":$target_name", "label_no_toolchain") + " has an unsupported min_sdk_version of $_min_sdk_version (min is $min_supported_sdk_version)") 1547*8975f5c5SAndroid Build Coastguard Worker 1548*8975f5c5SAndroid Build Coastguard Worker _proguard_enabled = 1549*8975f5c5SAndroid Build Coastguard Worker defined(invoker.proguard_enabled) && invoker.proguard_enabled 1550*8975f5c5SAndroid Build Coastguard Worker _is_dex_merging = defined(invoker.input_dex_filearg) 1551*8975f5c5SAndroid Build Coastguard Worker _enable_desugar = !defined(invoker.enable_desugar) || invoker.enable_desugar 1552*8975f5c5SAndroid Build Coastguard Worker _desugar_needs_classpath = _enable_desugar 1553*8975f5c5SAndroid Build Coastguard Worker 1554*8975f5c5SAndroid Build Coastguard Worker # It's not safe to dex merge with libraries dex'ed at higher api versions. 1555*8975f5c5SAndroid Build Coastguard Worker assert(!_is_dex_merging || _min_sdk_version >= default_min_sdk_version) 1556*8975f5c5SAndroid Build Coastguard Worker 1557*8975f5c5SAndroid Build Coastguard Worker # For D8's backported method desugaring to work properly, the dex merge step 1558*8975f5c5SAndroid Build Coastguard Worker # must not be set to a higher minSdkVersion than it was for the libraries. 1559*8975f5c5SAndroid Build Coastguard Worker if (_enable_desugar && _is_dex_merging) { 1560*8975f5c5SAndroid Build Coastguard Worker _min_sdk_version = default_min_sdk_version 1561*8975f5c5SAndroid Build Coastguard Worker } 1562*8975f5c5SAndroid Build Coastguard Worker 1563*8975f5c5SAndroid Build Coastguard Worker assert(defined(invoker.output) || 1564*8975f5c5SAndroid Build Coastguard Worker (_proguard_enabled && defined(invoker.modules))) 1565*8975f5c5SAndroid Build Coastguard Worker assert(!_proguard_enabled || !(defined(invoker.input_dex_filearg) || 1566*8975f5c5SAndroid Build Coastguard Worker defined(invoker.input_classes_filearg) || 1567*8975f5c5SAndroid Build Coastguard Worker defined(invoker.input_class_jars)), 1568*8975f5c5SAndroid Build Coastguard Worker "Cannot explicitly set inputs when proguarding a dex.") 1569*8975f5c5SAndroid Build Coastguard Worker 1570*8975f5c5SAndroid Build Coastguard Worker # Dex merging should not also be dexing. 1571*8975f5c5SAndroid Build Coastguard Worker assert(!(_is_dex_merging && defined(invoker.input_classes_filearg))) 1572*8975f5c5SAndroid Build Coastguard Worker assert(!(_is_dex_merging && defined(invoker.input_class_jars))) 1573*8975f5c5SAndroid Build Coastguard Worker 1574*8975f5c5SAndroid Build Coastguard Worker assert(!(defined(invoker.apply_mapping) && !_proguard_enabled), 1575*8975f5c5SAndroid Build Coastguard Worker "apply_mapping can only be specified if proguard is enabled.") 1576*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.custom_assertion_handler)) { 1577*8975f5c5SAndroid Build Coastguard Worker assert(_proguard_enabled, 1578*8975f5c5SAndroid Build Coastguard Worker "Proguard is required to support the custom assertion handler.") 1579*8975f5c5SAndroid Build Coastguard Worker } 1580*8975f5c5SAndroid Build Coastguard Worker 1581*8975f5c5SAndroid Build Coastguard Worker if (_desugar_needs_classpath || _proguard_enabled) { 1582*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 1583*8975f5c5SAndroid Build Coastguard Worker } 1584*8975f5c5SAndroid Build Coastguard Worker 1585*8975f5c5SAndroid Build Coastguard Worker if (_proguard_enabled) { 1586*8975f5c5SAndroid Build Coastguard Worker _proguard_target_name = target_name 1587*8975f5c5SAndroid Build Coastguard Worker 1588*8975f5c5SAndroid Build Coastguard Worker proguard(_proguard_target_name) { 1589*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1590*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 1591*8975f5c5SAndroid Build Coastguard Worker "add_view_trace_events", 1592*8975f5c5SAndroid Build Coastguard Worker "apply_mapping", 1593*8975f5c5SAndroid Build Coastguard Worker "input_art_profile", 1594*8975f5c5SAndroid Build Coastguard Worker "output_art_profile", 1595*8975f5c5SAndroid Build Coastguard Worker "enable_startup_profile", 1596*8975f5c5SAndroid Build Coastguard Worker "build_config", 1597*8975f5c5SAndroid Build Coastguard Worker "custom_assertion_handler", 1598*8975f5c5SAndroid Build Coastguard Worker "data", 1599*8975f5c5SAndroid Build Coastguard Worker "data_deps", 1600*8975f5c5SAndroid Build Coastguard Worker "deps", 1601*8975f5c5SAndroid Build Coastguard Worker "enable_proguard_checks", 1602*8975f5c5SAndroid Build Coastguard Worker "expected_proguard_config", 1603*8975f5c5SAndroid Build Coastguard Worker "expected_proguard_config_base", 1604*8975f5c5SAndroid Build Coastguard Worker "ignore_desugar_missing_deps", 1605*8975f5c5SAndroid Build Coastguard Worker "inputs", 1606*8975f5c5SAndroid Build Coastguard Worker "modules", 1607*8975f5c5SAndroid Build Coastguard Worker "package_name", 1608*8975f5c5SAndroid Build Coastguard Worker "proguard_configs", 1609*8975f5c5SAndroid Build Coastguard Worker "proguard_enable_obfuscation", 1610*8975f5c5SAndroid Build Coastguard Worker "proguard_mapping_path", 1611*8975f5c5SAndroid Build Coastguard Worker "proguard_sourcefile_suffix", 1612*8975f5c5SAndroid Build Coastguard Worker "repackage_classes", 1613*8975f5c5SAndroid Build Coastguard Worker "top_target_name", 1614*8975f5c5SAndroid Build Coastguard Worker "version_code", 1615*8975f5c5SAndroid Build Coastguard Worker ]) 1616*8975f5c5SAndroid Build Coastguard Worker min_sdk_version = _min_sdk_version 1617*8975f5c5SAndroid Build Coastguard Worker 1618*8975f5c5SAndroid Build Coastguard Worker args = [] 1619*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.has_apk_under_test) && invoker.has_apk_under_test) { 1620*8975f5c5SAndroid Build Coastguard Worker args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:device_classpath_extended)" ] 1621*8975f5c5SAndroid Build Coastguard Worker } else if (defined(invoker.add_view_trace_events) && 1622*8975f5c5SAndroid Build Coastguard Worker invoker.add_view_trace_events && defined(invoker.modules)) { 1623*8975f5c5SAndroid Build Coastguard Worker args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:trace_event_rewritten_device_classpath)" ] 1624*8975f5c5SAndroid Build Coastguard Worker } else { 1625*8975f5c5SAndroid Build Coastguard Worker args += [ "--input-paths=@FileArg($_rebased_build_config:deps_info:device_classpath)" ] 1626*8975f5c5SAndroid Build Coastguard Worker } 1627*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_args)) { 1628*8975f5c5SAndroid Build Coastguard Worker args += invoker.proguard_args 1629*8975f5c5SAndroid Build Coastguard Worker } 1630*8975f5c5SAndroid Build Coastguard Worker 1631*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.output)) { 1632*8975f5c5SAndroid Build Coastguard Worker output_path = invoker.output 1633*8975f5c5SAndroid Build Coastguard Worker } else if (!defined(proguard_mapping_path)) { 1634*8975f5c5SAndroid Build Coastguard Worker proguard_mapping_path = "$target_out_dir/$target_name.mapping" 1635*8975f5c5SAndroid Build Coastguard Worker } 1636*8975f5c5SAndroid Build Coastguard Worker } 1637*8975f5c5SAndroid Build Coastguard Worker } else { # !_proguard_enabled 1638*8975f5c5SAndroid Build Coastguard Worker _is_library = defined(invoker.is_library) && invoker.is_library 1639*8975f5c5SAndroid Build Coastguard Worker assert(!(defined(invoker.input_classes_filearg) && _is_library)) 1640*8975f5c5SAndroid Build Coastguard Worker assert(_is_library == defined(invoker.unprocessed_jar_path)) 1641*8975f5c5SAndroid Build Coastguard Worker _input_class_jars = [] 1642*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.input_class_jars)) { 1643*8975f5c5SAndroid Build Coastguard Worker _input_class_jars = invoker.input_class_jars 1644*8975f5c5SAndroid Build Coastguard Worker } 1645*8975f5c5SAndroid Build Coastguard Worker _deps = invoker.deps 1646*8975f5c5SAndroid Build Coastguard Worker 1647*8975f5c5SAndroid Build Coastguard Worker if (_input_class_jars != []) { 1648*8975f5c5SAndroid Build Coastguard Worker _rebased_input_class_jars = 1649*8975f5c5SAndroid Build Coastguard Worker rebase_path(_input_class_jars, root_build_dir) 1650*8975f5c5SAndroid Build Coastguard Worker } 1651*8975f5c5SAndroid Build Coastguard Worker 1652*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1653*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1654*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 1655*8975f5c5SAndroid Build Coastguard Worker "data", 1656*8975f5c5SAndroid Build Coastguard Worker "data_deps", 1657*8975f5c5SAndroid Build Coastguard Worker ]) 1658*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/dex.py" 1659*8975f5c5SAndroid Build Coastguard Worker deps = _deps 1660*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 1661*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output ] 1662*8975f5c5SAndroid Build Coastguard Worker inputs = [ 1663*8975f5c5SAndroid Build Coastguard Worker "$android_sdk/optional/android.test.base.jar", 1664*8975f5c5SAndroid Build Coastguard Worker "$android_sdk/optional/org.apache.http.legacy.jar", 1665*8975f5c5SAndroid Build Coastguard Worker "//third_party/jdk/current/bin/java", 1666*8975f5c5SAndroid Build Coastguard Worker _custom_d8_path, 1667*8975f5c5SAndroid Build Coastguard Worker _d8_path, 1668*8975f5c5SAndroid Build Coastguard Worker android_sdk_jar, 1669*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 1670*8975f5c5SAndroid Build Coastguard Worker ] + java_paths_for_inputs 1671*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.inputs)) { 1672*8975f5c5SAndroid Build Coastguard Worker inputs += invoker.inputs 1673*8975f5c5SAndroid Build Coastguard Worker } 1674*8975f5c5SAndroid Build Coastguard Worker 1675*8975f5c5SAndroid Build Coastguard Worker if (!_is_library) { 1676*8975f5c5SAndroid Build Coastguard Worker # http://crbug.com/725224. Fix for bots running out of memory. 1677*8975f5c5SAndroid Build Coastguard Worker if (defined(java_cmd_pool_size)) { 1678*8975f5c5SAndroid Build Coastguard Worker pool = "//build/config/android:java_cmd_pool($default_toolchain)" 1679*8975f5c5SAndroid Build Coastguard Worker } else { 1680*8975f5c5SAndroid Build Coastguard Worker pool = "//build/toolchain:link_pool($default_toolchain)" 1681*8975f5c5SAndroid Build Coastguard Worker } 1682*8975f5c5SAndroid Build Coastguard Worker } 1683*8975f5c5SAndroid Build Coastguard Worker 1684*8975f5c5SAndroid Build Coastguard Worker args = [ 1685*8975f5c5SAndroid Build Coastguard Worker "--depfile", 1686*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 1687*8975f5c5SAndroid Build Coastguard Worker "--output", 1688*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output, root_build_dir), 1689*8975f5c5SAndroid Build Coastguard Worker "--min-api=$_min_sdk_version", 1690*8975f5c5SAndroid Build Coastguard Worker "--r8-jar-path", 1691*8975f5c5SAndroid Build Coastguard Worker rebase_path(_d8_path, root_build_dir), 1692*8975f5c5SAndroid Build Coastguard Worker "--custom-d8-jar-path", 1693*8975f5c5SAndroid Build Coastguard Worker rebase_path(_custom_d8_path, root_build_dir), 1694*8975f5c5SAndroid Build Coastguard Worker 1695*8975f5c5SAndroid Build Coastguard Worker # Uncomment when rebuilding custom_d8.jar. 1696*8975f5c5SAndroid Build Coastguard Worker #"--skip-custom-d8", 1697*8975f5c5SAndroid Build Coastguard Worker ] 1698*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 1699*8975f5c5SAndroid Build Coastguard Worker args += [ "--warnings-as-errors" ] 1700*8975f5c5SAndroid Build Coastguard Worker } 1701*8975f5c5SAndroid Build Coastguard Worker 1702*8975f5c5SAndroid Build Coastguard Worker if (enable_incremental_d8 && !(defined(invoker.disable_incremental) && 1703*8975f5c5SAndroid Build Coastguard Worker invoker.disable_incremental)) { 1704*8975f5c5SAndroid Build Coastguard Worker # Don't use incremental dexing for ProGuarded inputs as a precaution. 1705*8975f5c5SAndroid Build Coastguard Worker args += [ 1706*8975f5c5SAndroid Build Coastguard Worker "--incremental-dir", 1707*8975f5c5SAndroid Build Coastguard Worker rebase_path("$target_out_dir/$target_name", root_build_dir), 1708*8975f5c5SAndroid Build Coastguard Worker ] 1709*8975f5c5SAndroid Build Coastguard Worker } 1710*8975f5c5SAndroid Build Coastguard Worker if (_is_library) { 1711*8975f5c5SAndroid Build Coastguard Worker args += [ "--library" ] 1712*8975f5c5SAndroid Build Coastguard Worker } 1713*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.input_dex_filearg)) { 1714*8975f5c5SAndroid Build Coastguard Worker args += [ "--dex-inputs-filearg=${invoker.input_dex_filearg}" ] 1715*8975f5c5SAndroid Build Coastguard Worker } 1716*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.input_classes_filearg)) { 1717*8975f5c5SAndroid Build Coastguard Worker args += [ "--class-inputs-filearg=${invoker.input_classes_filearg}" ] 1718*8975f5c5SAndroid Build Coastguard Worker 1719*8975f5c5SAndroid Build Coastguard Worker # Required for the same reason as unprocessed_jar_path is added to 1720*8975f5c5SAndroid Build Coastguard Worker # classpath (see note below). 1721*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=${invoker.input_classes_filearg}" ] 1722*8975f5c5SAndroid Build Coastguard Worker } 1723*8975f5c5SAndroid Build Coastguard Worker if (_input_class_jars != []) { 1724*8975f5c5SAndroid Build Coastguard Worker inputs += _input_class_jars 1725*8975f5c5SAndroid Build Coastguard Worker args += [ "--class-inputs=${_rebased_input_class_jars}" ] 1726*8975f5c5SAndroid Build Coastguard Worker } 1727*8975f5c5SAndroid Build Coastguard Worker 1728*8975f5c5SAndroid Build Coastguard Worker # Never compile intemediates with --release in order to: 1729*8975f5c5SAndroid Build Coastguard Worker # 1) not require recompiles when toggling is_java_debug, 1730*8975f5c5SAndroid Build Coastguard Worker # 2) allow incremental_install=1 to still have local variable 1731*8975f5c5SAndroid Build Coastguard Worker # information even when is_java_debug=false. 1732*8975f5c5SAndroid Build Coastguard Worker if (!is_java_debug && !_is_library) { 1733*8975f5c5SAndroid Build Coastguard Worker args += [ "--release" ] 1734*8975f5c5SAndroid Build Coastguard Worker } 1735*8975f5c5SAndroid Build Coastguard Worker 1736*8975f5c5SAndroid Build Coastguard Worker if (_enable_desugar) { 1737*8975f5c5SAndroid Build Coastguard Worker args += [ "--desugar" ] 1738*8975f5c5SAndroid Build Coastguard Worker 1739*8975f5c5SAndroid Build Coastguard Worker _ignore_desugar_missing_deps = 1740*8975f5c5SAndroid Build Coastguard Worker defined(invoker.ignore_desugar_missing_deps) && 1741*8975f5c5SAndroid Build Coastguard Worker invoker.ignore_desugar_missing_deps 1742*8975f5c5SAndroid Build Coastguard Worker if (!_ignore_desugar_missing_deps) { 1743*8975f5c5SAndroid Build Coastguard Worker args += [ "--show-desugar-default-interface-warnings" ] 1744*8975f5c5SAndroid Build Coastguard Worker } 1745*8975f5c5SAndroid Build Coastguard Worker } 1746*8975f5c5SAndroid Build Coastguard Worker if (_desugar_needs_classpath) { 1747*8975f5c5SAndroid Build Coastguard Worker # Cannot use header jar for the active jar, because it does not 1748*8975f5c5SAndroid Build Coastguard Worker # contain anonymous classes. https://crbug.com/1342018#c5 1749*8975f5c5SAndroid Build Coastguard Worker # Cannot use processed .jar here because it might have classes 1750*8975f5c5SAndroid Build Coastguard Worker # filtered out via jar_excluded_patterns. 1751*8975f5c5SAndroid Build Coastguard Worker # Must come first in classpath in order to take precedence over 1752*8975f5c5SAndroid Build Coastguard Worker # deps that defined the same classes (via jar_excluded_patterns). 1753*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.unprocessed_jar_path)) { 1754*8975f5c5SAndroid Build Coastguard Worker args += [ 1755*8975f5c5SAndroid Build Coastguard Worker "--classpath", 1756*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.unprocessed_jar_path, root_build_dir), 1757*8975f5c5SAndroid Build Coastguard Worker 1758*8975f5c5SAndroid Build Coastguard Worker # Pass the full classpath to find new dependencies that are not in 1759*8975f5c5SAndroid Build Coastguard Worker # the .desugardeps file. 1760*8975f5c5SAndroid Build Coastguard Worker "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)", 1761*8975f5c5SAndroid Build Coastguard Worker ] 1762*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.unprocessed_jar_path ] 1763*8975f5c5SAndroid Build Coastguard Worker } 1764*8975f5c5SAndroid Build Coastguard Worker _desugar_dependencies_path = 1765*8975f5c5SAndroid Build Coastguard Worker "$target_gen_dir/$target_name.desugardeps" 1766*8975f5c5SAndroid Build Coastguard Worker args += [ 1767*8975f5c5SAndroid Build Coastguard Worker "--desugar-dependencies", 1768*8975f5c5SAndroid Build Coastguard Worker rebase_path(_desugar_dependencies_path, root_build_dir), 1769*8975f5c5SAndroid Build Coastguard Worker "--bootclasspath=@FileArg($_rebased_build_config:android:sdk_jars)", 1770*8975f5c5SAndroid Build Coastguard Worker ] 1771*8975f5c5SAndroid Build Coastguard Worker } 1772*8975f5c5SAndroid Build Coastguard Worker 1773*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.custom_assertion_handler)) { 1774*8975f5c5SAndroid Build Coastguard Worker args += [ 1775*8975f5c5SAndroid Build Coastguard Worker "--assertion-handler", 1776*8975f5c5SAndroid Build Coastguard Worker invoker.custom_assertion_handler, 1777*8975f5c5SAndroid Build Coastguard Worker ] 1778*8975f5c5SAndroid Build Coastguard Worker } else if (enable_java_asserts) { 1779*8975f5c5SAndroid Build Coastguard Worker # The default for generating dex file format is 1780*8975f5c5SAndroid Build Coastguard Worker # --force-disable-assertions. 1781*8975f5c5SAndroid Build Coastguard Worker args += [ "--force-enable-assertions" ] 1782*8975f5c5SAndroid Build Coastguard Worker } 1783*8975f5c5SAndroid Build Coastguard Worker } 1784*8975f5c5SAndroid Build Coastguard Worker } 1785*8975f5c5SAndroid Build Coastguard Worker } 1786*8975f5c5SAndroid Build Coastguard Worker 1787*8975f5c5SAndroid Build Coastguard Worker template("jacoco_instr") { 1788*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1789*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1790*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 1791*8975f5c5SAndroid Build Coastguard Worker "deps", 1792*8975f5c5SAndroid Build Coastguard Worker "public_deps", 1793*8975f5c5SAndroid Build Coastguard Worker ]) 1794*8975f5c5SAndroid Build Coastguard Worker 1795*8975f5c5SAndroid Build Coastguard Worker # The name needs to match the SOURCES_JSON_FILES_SUFFIX in 1796*8975f5c5SAndroid Build Coastguard Worker # generate_coverage_metadata_for_java.py. 1797*8975f5c5SAndroid Build Coastguard Worker _sources_json_file = "$target_out_dir/${target_name}__jacoco_sources.json" 1798*8975f5c5SAndroid Build Coastguard Worker _jacococli_jar = "//third_party/jacoco/cipd/lib/jacococli.jar" 1799*8975f5c5SAndroid Build Coastguard Worker 1800*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/jacoco_instr.py" 1801*8975f5c5SAndroid Build Coastguard Worker inputs = invoker.source_files + java_paths_for_inputs + [ 1802*8975f5c5SAndroid Build Coastguard Worker _jacococli_jar, 1803*8975f5c5SAndroid Build Coastguard Worker invoker.input_jar_path, 1804*8975f5c5SAndroid Build Coastguard Worker ] 1805*8975f5c5SAndroid Build Coastguard Worker outputs = [ 1806*8975f5c5SAndroid Build Coastguard Worker _sources_json_file, 1807*8975f5c5SAndroid Build Coastguard Worker invoker.output_jar_path, 1808*8975f5c5SAndroid Build Coastguard Worker ] 1809*8975f5c5SAndroid Build Coastguard Worker args = [ 1810*8975f5c5SAndroid Build Coastguard Worker "--root-build-dir", 1811*8975f5c5SAndroid Build Coastguard Worker root_build_dir, 1812*8975f5c5SAndroid Build Coastguard Worker "--input-path", 1813*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_jar_path, root_build_dir), 1814*8975f5c5SAndroid Build Coastguard Worker "--output-path", 1815*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_jar_path, root_build_dir), 1816*8975f5c5SAndroid Build Coastguard Worker "--sources-json-file", 1817*8975f5c5SAndroid Build Coastguard Worker rebase_path(_sources_json_file, root_build_dir), 1818*8975f5c5SAndroid Build Coastguard Worker "--target-sources-file", 1819*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.target_sources_file, root_build_dir), 1820*8975f5c5SAndroid Build Coastguard Worker "--jacococli-jar", 1821*8975f5c5SAndroid Build Coastguard Worker rebase_path(_jacococli_jar, root_build_dir), 1822*8975f5c5SAndroid Build Coastguard Worker ] 1823*8975f5c5SAndroid Build Coastguard Worker if (coverage_instrumentation_input_file != "") { 1824*8975f5c5SAndroid Build Coastguard Worker args += [ 1825*8975f5c5SAndroid Build Coastguard Worker "--files-to-instrument", 1826*8975f5c5SAndroid Build Coastguard Worker rebase_path(coverage_instrumentation_input_file, root_build_dir), 1827*8975f5c5SAndroid Build Coastguard Worker ] 1828*8975f5c5SAndroid Build Coastguard Worker } 1829*8975f5c5SAndroid Build Coastguard Worker } 1830*8975f5c5SAndroid Build Coastguard Worker } 1831*8975f5c5SAndroid Build Coastguard Worker 1832*8975f5c5SAndroid Build Coastguard Worker template("filter_jar") { 1833*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1834*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/filter_zip.py" 1835*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1836*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 1837*8975f5c5SAndroid Build Coastguard Worker "deps", 1838*8975f5c5SAndroid Build Coastguard Worker "data", 1839*8975f5c5SAndroid Build Coastguard Worker "data_deps", 1840*8975f5c5SAndroid Build Coastguard Worker ]) 1841*8975f5c5SAndroid Build Coastguard Worker inputs = [ invoker.input_jar ] 1842*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.inputs)) { 1843*8975f5c5SAndroid Build Coastguard Worker inputs += invoker.inputs 1844*8975f5c5SAndroid Build Coastguard Worker } 1845*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output_jar ] 1846*8975f5c5SAndroid Build Coastguard Worker 1847*8975f5c5SAndroid Build Coastguard Worker _jar_excluded_patterns = [] 1848*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.jar_excluded_patterns)) { 1849*8975f5c5SAndroid Build Coastguard Worker _jar_excluded_patterns = invoker.jar_excluded_patterns 1850*8975f5c5SAndroid Build Coastguard Worker } 1851*8975f5c5SAndroid Build Coastguard Worker _jar_included_patterns = [] 1852*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.jar_included_patterns)) { 1853*8975f5c5SAndroid Build Coastguard Worker _jar_included_patterns = invoker.jar_included_patterns 1854*8975f5c5SAndroid Build Coastguard Worker } 1855*8975f5c5SAndroid Build Coastguard Worker args = [ 1856*8975f5c5SAndroid Build Coastguard Worker "--input", 1857*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_jar, root_build_dir), 1858*8975f5c5SAndroid Build Coastguard Worker "--output", 1859*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_jar, root_build_dir), 1860*8975f5c5SAndroid Build Coastguard Worker "--exclude-globs=${_jar_excluded_patterns}", 1861*8975f5c5SAndroid Build Coastguard Worker "--include-globs=${_jar_included_patterns}", 1862*8975f5c5SAndroid Build Coastguard Worker ] 1863*8975f5c5SAndroid Build Coastguard Worker } 1864*8975f5c5SAndroid Build Coastguard Worker } 1865*8975f5c5SAndroid Build Coastguard Worker 1866*8975f5c5SAndroid Build Coastguard Worker template("process_java_library") { 1867*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1868*8975f5c5SAndroid Build Coastguard Worker 1869*8975f5c5SAndroid Build Coastguard Worker _previous_output_jar = invoker.input_jar_path 1870*8975f5c5SAndroid Build Coastguard Worker 1871*8975f5c5SAndroid Build Coastguard Worker if (invoker.jacoco_instrument) { 1872*8975f5c5SAndroid Build Coastguard Worker _filter_jar_target_name = "${target_name}__filter_jar" 1873*8975f5c5SAndroid Build Coastguard Worker _filter_jar_output_jar = "$target_out_dir/$target_name.filter.jar" 1874*8975f5c5SAndroid Build Coastguard Worker } else { 1875*8975f5c5SAndroid Build Coastguard Worker _filter_jar_target_name = target_name 1876*8975f5c5SAndroid Build Coastguard Worker _filter_jar_output_jar = invoker.output_jar_path 1877*8975f5c5SAndroid Build Coastguard Worker } 1878*8975f5c5SAndroid Build Coastguard Worker 1879*8975f5c5SAndroid Build Coastguard Worker filter_jar(_filter_jar_target_name) { 1880*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1881*8975f5c5SAndroid Build Coastguard Worker [ 1882*8975f5c5SAndroid Build Coastguard Worker "data", 1883*8975f5c5SAndroid Build Coastguard Worker "data_deps", 1884*8975f5c5SAndroid Build Coastguard Worker "jar_excluded_patterns", 1885*8975f5c5SAndroid Build Coastguard Worker "jar_included_patterns", 1886*8975f5c5SAndroid Build Coastguard Worker ]) 1887*8975f5c5SAndroid Build Coastguard Worker deps = invoker.deps 1888*8975f5c5SAndroid Build Coastguard Worker input_jar = _previous_output_jar 1889*8975f5c5SAndroid Build Coastguard Worker output_jar = _filter_jar_output_jar 1890*8975f5c5SAndroid Build Coastguard Worker } 1891*8975f5c5SAndroid Build Coastguard Worker 1892*8975f5c5SAndroid Build Coastguard Worker if (invoker.jacoco_instrument) { 1893*8975f5c5SAndroid Build Coastguard Worker # Jacoco must run after desugar (or else desugar sometimes fails). 1894*8975f5c5SAndroid Build Coastguard Worker # It must run after filtering to avoid the same (filtered) class mapping 1895*8975f5c5SAndroid Build Coastguard Worker # to multiple .jar files. 1896*8975f5c5SAndroid Build Coastguard Worker # We run offline code coverage processing here rather than with a 1897*8975f5c5SAndroid Build Coastguard Worker # javaagent as the desired coverage data was not being generated. 1898*8975f5c5SAndroid Build Coastguard Worker # See crbug.com/1097815. 1899*8975f5c5SAndroid Build Coastguard Worker jacoco_instr(target_name) { 1900*8975f5c5SAndroid Build Coastguard Worker deps = [ ":$_filter_jar_target_name" ] + invoker.deps 1901*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1902*8975f5c5SAndroid Build Coastguard Worker [ 1903*8975f5c5SAndroid Build Coastguard Worker "source_files", 1904*8975f5c5SAndroid Build Coastguard Worker "target_sources_file", 1905*8975f5c5SAndroid Build Coastguard Worker ]) 1906*8975f5c5SAndroid Build Coastguard Worker 1907*8975f5c5SAndroid Build Coastguard Worker input_jar_path = _filter_jar_output_jar 1908*8975f5c5SAndroid Build Coastguard Worker output_jar_path = invoker.output_jar_path 1909*8975f5c5SAndroid Build Coastguard Worker } 1910*8975f5c5SAndroid Build Coastguard Worker } 1911*8975f5c5SAndroid Build Coastguard Worker } 1912*8975f5c5SAndroid Build Coastguard Worker 1913*8975f5c5SAndroid Build Coastguard Worker template("bytecode_processor") { 1914*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1915*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 1916*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 1917*8975f5c5SAndroid Build Coastguard Worker "data_deps", 1918*8975f5c5SAndroid Build Coastguard Worker "deps", 1919*8975f5c5SAndroid Build Coastguard Worker ]) 1920*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/bytecode_processor.py" 1921*8975f5c5SAndroid Build Coastguard Worker inputs = java_paths_for_inputs + [ 1922*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 1923*8975f5c5SAndroid Build Coastguard Worker invoker.input_jar, 1924*8975f5c5SAndroid Build Coastguard Worker ] 1925*8975f5c5SAndroid Build Coastguard Worker outputs = [ "$target_out_dir/$target_name.bytecode.stamp" ] 1926*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 1927*8975f5c5SAndroid Build Coastguard Worker args = [ 1928*8975f5c5SAndroid Build Coastguard Worker "--target-name", 1929*8975f5c5SAndroid Build Coastguard Worker get_label_info(":${target_name}", "label_no_toolchain"), 1930*8975f5c5SAndroid Build Coastguard Worker "--gn-target=${invoker.target_label}", 1931*8975f5c5SAndroid Build Coastguard Worker "--input-jar", 1932*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_jar, root_build_dir), 1933*8975f5c5SAndroid Build Coastguard Worker "--stamp", 1934*8975f5c5SAndroid Build Coastguard Worker rebase_path(outputs[0], root_build_dir), 1935*8975f5c5SAndroid Build Coastguard Worker "--chromium-output-dir", 1936*8975f5c5SAndroid Build Coastguard Worker rebase_path(root_build_dir, root_build_dir), 1937*8975f5c5SAndroid Build Coastguard Worker "--direct-classpath-jars=@FileArg($_rebased_build_config:javac:classpath)", 1938*8975f5c5SAndroid Build Coastguard Worker "--full-classpath-jars=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)", 1939*8975f5c5SAndroid Build Coastguard Worker "--full-classpath-gn-targets=@FileArg($_rebased_build_config:deps_info:javac_full_classpath_targets)", 1940*8975f5c5SAndroid Build Coastguard Worker ] 1941*8975f5c5SAndroid Build Coastguard Worker if (auto_add_missing_java_deps) { 1942*8975f5c5SAndroid Build Coastguard Worker args += [ "--auto-add-deps" ] 1943*8975f5c5SAndroid Build Coastguard Worker } 1944*8975f5c5SAndroid Build Coastguard Worker if (android_static_analysis == "build_server") { 1945*8975f5c5SAndroid Build Coastguard Worker args += [ "--use-build-server" ] 1946*8975f5c5SAndroid Build Coastguard Worker if (experimental_build_server) { 1947*8975f5c5SAndroid Build Coastguard Worker args += [ "--experimental-build-server" ] 1948*8975f5c5SAndroid Build Coastguard Worker } 1949*8975f5c5SAndroid Build Coastguard Worker } 1950*8975f5c5SAndroid Build Coastguard Worker if (invoker.include_android_sdk) { 1951*8975f5c5SAndroid Build Coastguard Worker args += [ "--sdk-classpath-jars=@FileArg($_rebased_build_config:android:sdk_jars)" ] 1952*8975f5c5SAndroid Build Coastguard Worker } 1953*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 1954*8975f5c5SAndroid Build Coastguard Worker args += [ "--warnings-as-errors" ] 1955*8975f5c5SAndroid Build Coastguard Worker } 1956*8975f5c5SAndroid Build Coastguard Worker } 1957*8975f5c5SAndroid Build Coastguard Worker } 1958*8975f5c5SAndroid Build Coastguard Worker 1959*8975f5c5SAndroid Build Coastguard Worker template("merge_manifests") { 1960*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 1961*8975f5c5SAndroid Build Coastguard Worker assert( 1962*8975f5c5SAndroid Build Coastguard Worker invoker.min_sdk_version >= min_supported_sdk_version, 1963*8975f5c5SAndroid Build Coastguard Worker get_label_info(":$target_name", "label_no_toolchain") + " has an unsupported min_sdk_version of ${invoker.min_sdk_version} (min is $min_supported_sdk_version)") 1964*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 1965*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/merge_manifest.py" 1966*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 1967*8975f5c5SAndroid Build Coastguard Worker 1968*8975f5c5SAndroid Build Coastguard Worker inputs = java_paths_for_inputs + [ 1969*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 1970*8975f5c5SAndroid Build Coastguard Worker invoker.input_manifest, 1971*8975f5c5SAndroid Build Coastguard Worker _manifest_merger_jar_path, 1972*8975f5c5SAndroid Build Coastguard Worker ] 1973*8975f5c5SAndroid Build Coastguard Worker 1974*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output_manifest ] 1975*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 1976*8975f5c5SAndroid Build Coastguard Worker 1977*8975f5c5SAndroid Build Coastguard Worker args = [ 1978*8975f5c5SAndroid Build Coastguard Worker "--depfile", 1979*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 1980*8975f5c5SAndroid Build Coastguard Worker "--manifest-merger-jar", 1981*8975f5c5SAndroid Build Coastguard Worker rebase_path(_manifest_merger_jar_path, root_build_dir), 1982*8975f5c5SAndroid Build Coastguard Worker "--root-manifest", 1983*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_manifest, root_build_dir), 1984*8975f5c5SAndroid Build Coastguard Worker "--output", 1985*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_manifest, root_build_dir), 1986*8975f5c5SAndroid Build Coastguard Worker "--extras", 1987*8975f5c5SAndroid Build Coastguard Worker "@FileArg($_rebased_build_config:deps_info:extra_android_manifests)", 1988*8975f5c5SAndroid Build Coastguard Worker "--min-sdk-version=${invoker.min_sdk_version}", 1989*8975f5c5SAndroid Build Coastguard Worker "--target-sdk-version=${invoker.target_sdk_version}", 1990*8975f5c5SAndroid Build Coastguard Worker ] 1991*8975f5c5SAndroid Build Coastguard Worker 1992*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.manifest_package)) { 1993*8975f5c5SAndroid Build Coastguard Worker args += [ "--manifest-package=${invoker.manifest_package}" ] 1994*8975f5c5SAndroid Build Coastguard Worker } 1995*8975f5c5SAndroid Build Coastguard Worker 1996*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.max_sdk_version)) { 1997*8975f5c5SAndroid Build Coastguard Worker args += [ "--max-sdk-version=${invoker.max_sdk_version}" ] 1998*8975f5c5SAndroid Build Coastguard Worker } 1999*8975f5c5SAndroid Build Coastguard Worker 2000*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 2001*8975f5c5SAndroid Build Coastguard Worker args += [ "--warnings-as-errors" ] 2002*8975f5c5SAndroid Build Coastguard Worker } 2003*8975f5c5SAndroid Build Coastguard Worker } 2004*8975f5c5SAndroid Build Coastguard Worker } 2005*8975f5c5SAndroid Build Coastguard Worker 2006*8975f5c5SAndroid Build Coastguard Worker # This template is used to parse a set of resource directories and 2007*8975f5c5SAndroid Build Coastguard Worker # create the R.txt, .srcjar and .resources.zip for it. 2008*8975f5c5SAndroid Build Coastguard Worker # 2009*8975f5c5SAndroid Build Coastguard Worker # Input variables: 2010*8975f5c5SAndroid Build Coastguard Worker # deps: Specifies the input dependencies for this target. 2011*8975f5c5SAndroid Build Coastguard Worker # 2012*8975f5c5SAndroid Build Coastguard Worker # build_config: Path to the .build_config.json file corresponding to the target. 2013*8975f5c5SAndroid Build Coastguard Worker # 2014*8975f5c5SAndroid Build Coastguard Worker # sources: 2015*8975f5c5SAndroid Build Coastguard Worker # List of input resource files. 2016*8975f5c5SAndroid Build Coastguard Worker # 2017*8975f5c5SAndroid Build Coastguard Worker # custom_package: (optional) 2018*8975f5c5SAndroid Build Coastguard Worker # Package name for the generated R.java source file. Optional if 2019*8975f5c5SAndroid Build Coastguard Worker # android_manifest is not provided. 2020*8975f5c5SAndroid Build Coastguard Worker # 2021*8975f5c5SAndroid Build Coastguard Worker # android_manifest: (optional) 2022*8975f5c5SAndroid Build Coastguard Worker # If custom_package is not provided, path to an AndroidManifest.xml file 2023*8975f5c5SAndroid Build Coastguard Worker # that is only used to extract a package name out of it. 2024*8975f5c5SAndroid Build Coastguard Worker # 2025*8975f5c5SAndroid Build Coastguard Worker # r_text_in_path: (optional) 2026*8975f5c5SAndroid Build Coastguard Worker # Path to an input R.txt file to use to generate the R.java file. 2027*8975f5c5SAndroid Build Coastguard Worker # The default is to use 'aapt' to generate the file from the content 2028*8975f5c5SAndroid Build Coastguard Worker # of the resource directories. 2029*8975f5c5SAndroid Build Coastguard Worker # 2030*8975f5c5SAndroid Build Coastguard Worker # Output variables: 2031*8975f5c5SAndroid Build Coastguard Worker # resources_zip: 2032*8975f5c5SAndroid Build Coastguard Worker # Path to a .resources.zip that will simply contain all the 2033*8975f5c5SAndroid Build Coastguard Worker # input resources, collected in a single archive. 2034*8975f5c5SAndroid Build Coastguard Worker # 2035*8975f5c5SAndroid Build Coastguard Worker # r_text_out_path: Path for the generated R.txt file. 2036*8975f5c5SAndroid Build Coastguard Worker # 2037*8975f5c5SAndroid Build Coastguard Worker template("prepare_resources") { 2038*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 2039*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 2040*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 2041*8975f5c5SAndroid Build Coastguard Worker "deps", 2042*8975f5c5SAndroid Build Coastguard Worker "public_deps", 2043*8975f5c5SAndroid Build Coastguard Worker "sources", 2044*8975f5c5SAndroid Build Coastguard Worker ]) 2045*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/prepare_resources.py" 2046*8975f5c5SAndroid Build Coastguard Worker 2047*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/${invoker.target_name}.d" 2048*8975f5c5SAndroid Build Coastguard Worker outputs = [ 2049*8975f5c5SAndroid Build Coastguard Worker invoker.resources_zip, 2050*8975f5c5SAndroid Build Coastguard Worker invoker.resources_zip + ".info", 2051*8975f5c5SAndroid Build Coastguard Worker invoker.r_text_out_path, 2052*8975f5c5SAndroid Build Coastguard Worker ] 2053*8975f5c5SAndroid Build Coastguard Worker 2054*8975f5c5SAndroid Build Coastguard Worker inputs = [ invoker.res_sources_path ] 2055*8975f5c5SAndroid Build Coastguard Worker 2056*8975f5c5SAndroid Build Coastguard Worker _rebased_res_sources_path = 2057*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.res_sources_path, root_build_dir) 2058*8975f5c5SAndroid Build Coastguard Worker 2059*8975f5c5SAndroid Build Coastguard Worker args = [ 2060*8975f5c5SAndroid Build Coastguard Worker "--depfile", 2061*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 2062*8975f5c5SAndroid Build Coastguard Worker "--res-sources-path=$_rebased_res_sources_path", 2063*8975f5c5SAndroid Build Coastguard Worker "--resource-zip-out", 2064*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.resources_zip, root_build_dir), 2065*8975f5c5SAndroid Build Coastguard Worker "--r-text-out", 2066*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.r_text_out_path, root_build_dir), 2067*8975f5c5SAndroid Build Coastguard Worker ] 2068*8975f5c5SAndroid Build Coastguard Worker 2069*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.r_text_in_path)) { 2070*8975f5c5SAndroid Build Coastguard Worker _r_text_in_path = invoker.r_text_in_path 2071*8975f5c5SAndroid Build Coastguard Worker inputs += [ _r_text_in_path ] 2072*8975f5c5SAndroid Build Coastguard Worker args += [ 2073*8975f5c5SAndroid Build Coastguard Worker "--r-text-in", 2074*8975f5c5SAndroid Build Coastguard Worker rebase_path(_r_text_in_path, root_build_dir), 2075*8975f5c5SAndroid Build Coastguard Worker ] 2076*8975f5c5SAndroid Build Coastguard Worker } 2077*8975f5c5SAndroid Build Coastguard Worker 2078*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.strip_drawables) && invoker.strip_drawables) { 2079*8975f5c5SAndroid Build Coastguard Worker args += [ "--strip-drawables" ] 2080*8975f5c5SAndroid Build Coastguard Worker } 2081*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.allow_missing_resources) && 2082*8975f5c5SAndroid Build Coastguard Worker invoker.allow_missing_resources) { 2083*8975f5c5SAndroid Build Coastguard Worker args += [ "--allow-missing-resources" ] 2084*8975f5c5SAndroid Build Coastguard Worker } 2085*8975f5c5SAndroid Build Coastguard Worker } 2086*8975f5c5SAndroid Build Coastguard Worker } 2087*8975f5c5SAndroid Build Coastguard Worker 2088*8975f5c5SAndroid Build Coastguard Worker # A template that is used to compile all resources needed by a binary 2089*8975f5c5SAndroid Build Coastguard Worker # (e.g. an android_apk or a robolectric_binary) into an intermediate .ar_ 2090*8975f5c5SAndroid Build Coastguard Worker # archive. It can also generate an associated .srcjar that contains the 2091*8975f5c5SAndroid Build Coastguard Worker # final R.java sources for all resource packages the binary depends on. 2092*8975f5c5SAndroid Build Coastguard Worker # 2093*8975f5c5SAndroid Build Coastguard Worker # Input variables: 2094*8975f5c5SAndroid Build Coastguard Worker # android_sdk_dep: The sdk dep that these resources should compile against. 2095*8975f5c5SAndroid Build Coastguard Worker # 2096*8975f5c5SAndroid Build Coastguard Worker # deps: Specifies the input dependencies for this target. 2097*8975f5c5SAndroid Build Coastguard Worker # 2098*8975f5c5SAndroid Build Coastguard Worker # build_config: Path to the .build_config.json file corresponding to the target. 2099*8975f5c5SAndroid Build Coastguard Worker # 2100*8975f5c5SAndroid Build Coastguard Worker # build_config_dep: Dep target to generate the .build_config.json file. 2101*8975f5c5SAndroid Build Coastguard Worker # 2102*8975f5c5SAndroid Build Coastguard Worker # android_manifest: Path to root manifest for the binary. 2103*8975f5c5SAndroid Build Coastguard Worker # 2104*8975f5c5SAndroid Build Coastguard Worker # version_code: (optional) 2105*8975f5c5SAndroid Build Coastguard Worker # 2106*8975f5c5SAndroid Build Coastguard Worker # version_name: (optional) 2107*8975f5c5SAndroid Build Coastguard Worker # 2108*8975f5c5SAndroid Build Coastguard Worker # shared_resources: (optional) 2109*8975f5c5SAndroid Build Coastguard Worker # If true, make all variables in each generated R.java file non-final, 2110*8975f5c5SAndroid Build Coastguard Worker # and provide an onResourcesLoaded() method that can be used to reset 2111*8975f5c5SAndroid Build Coastguard Worker # their package index at load time. Useful when the APK corresponds to 2112*8975f5c5SAndroid Build Coastguard Worker # a library that is loaded at runtime, like system_webview_apk or 2113*8975f5c5SAndroid Build Coastguard Worker # monochrome_apk. 2114*8975f5c5SAndroid Build Coastguard Worker # 2115*8975f5c5SAndroid Build Coastguard Worker # app_as_shared_lib: (optional) 2116*8975f5c5SAndroid Build Coastguard Worker # If true, same effect as shared_resources, but also ensures that the 2117*8975f5c5SAndroid Build Coastguard Worker # resources can be used by the APK when it is loaded as a regular 2118*8975f5c5SAndroid Build Coastguard Worker # application as well. Useful for the monochrome_public_apk target 2119*8975f5c5SAndroid Build Coastguard Worker # which is both an application and a shared runtime library that 2120*8975f5c5SAndroid Build Coastguard Worker # implements the system webview feature. 2121*8975f5c5SAndroid Build Coastguard Worker # 2122*8975f5c5SAndroid Build Coastguard Worker # shared_resources_allowlist: (optional) 2123*8975f5c5SAndroid Build Coastguard Worker # Path to an R.txt file. If provided, acts similar to shared_resources 2124*8975f5c5SAndroid Build Coastguard Worker # except that it restricts the list of non-final resource variables 2125*8975f5c5SAndroid Build Coastguard Worker # to the list from the input R.txt file. Overrides shared_resources 2126*8975f5c5SAndroid Build Coastguard Worker # when both are specified. 2127*8975f5c5SAndroid Build Coastguard Worker # 2128*8975f5c5SAndroid Build Coastguard Worker # shared_resources_allowlist_locales: (optional) 2129*8975f5c5SAndroid Build Coastguard Worker # If shared_resources_allowlist is used, provide an optional list of 2130*8975f5c5SAndroid Build Coastguard Worker # Chromium locale names to determine which localized shared string 2131*8975f5c5SAndroid Build Coastguard Worker # resources to put in the final output, even if aapt_locale_allowlist 2132*8975f5c5SAndroid Build Coastguard Worker # is defined to a smaller subset. 2133*8975f5c5SAndroid Build Coastguard Worker # 2134*8975f5c5SAndroid Build Coastguard Worker # aapt_locale_allowlist: (optional) 2135*8975f5c5SAndroid Build Coastguard Worker # Restrict compiled locale-dependent resources to a specific allowlist. 2136*8975f5c5SAndroid Build Coastguard Worker # NOTE: This is a list of Chromium locale names, not Android ones. 2137*8975f5c5SAndroid Build Coastguard Worker # 2138*8975f5c5SAndroid Build Coastguard Worker # r_java_root_package_name: (optional) 2139*8975f5c5SAndroid Build Coastguard Worker # Short package name for this target's root R java file (ex. input of 2140*8975f5c5SAndroid Build Coastguard Worker # "base" would become "gen.base_module" for the root R java package name). 2141*8975f5c5SAndroid Build Coastguard Worker # Optional as defaults to "base". 2142*8975f5c5SAndroid Build Coastguard Worker # 2143*8975f5c5SAndroid Build Coastguard Worker # resource_exclusion_regex: (optional) 2144*8975f5c5SAndroid Build Coastguard Worker # 2145*8975f5c5SAndroid Build Coastguard Worker # resource_exclusion_exceptions: (optional) 2146*8975f5c5SAndroid Build Coastguard Worker # 2147*8975f5c5SAndroid Build Coastguard Worker # resource_values_filter_rules: (optional) 2148*8975f5c5SAndroid Build Coastguard Worker # 2149*8975f5c5SAndroid Build Coastguard Worker # png_to_webp: (optional) 2150*8975f5c5SAndroid Build Coastguard Worker # If true, convert all PNG resources (except 9-patch files) to WebP. 2151*8975f5c5SAndroid Build Coastguard Worker # 2152*8975f5c5SAndroid Build Coastguard Worker # post_process_script: (optional) 2153*8975f5c5SAndroid Build Coastguard Worker # 2154*8975f5c5SAndroid Build Coastguard Worker # package_name: (optional) 2155*8975f5c5SAndroid Build Coastguard Worker # Name of the package for the purpose of creating R class. 2156*8975f5c5SAndroid Build Coastguard Worker # 2157*8975f5c5SAndroid Build Coastguard Worker # package_id: (optional) 2158*8975f5c5SAndroid Build Coastguard Worker # Use a custom package ID in resource IDs. 2159*8975f5c5SAndroid Build Coastguard Worker # 2160*8975f5c5SAndroid Build Coastguard Worker # arsc_package_name: (optional) 2161*8975f5c5SAndroid Build Coastguard Worker # Use this package name in the arsc file rather than the package name 2162*8975f5c5SAndroid Build Coastguard Worker # found in the AndroidManifest.xml. Does not affect the package name 2163*8975f5c5SAndroid Build Coastguard Worker # used in AndroidManifest.xml. 2164*8975f5c5SAndroid Build Coastguard Worker # 2165*8975f5c5SAndroid Build Coastguard Worker # resource_ids_provider_dep: (optional) 2166*8975f5c5SAndroid Build Coastguard Worker # Use resource IDs provided by another APK target when compiling resources 2167*8975f5c5SAndroid Build Coastguard Worker # (via. "aapt2 link --stable-ids") 2168*8975f5c5SAndroid Build Coastguard Worker # 2169*8975f5c5SAndroid Build Coastguard Worker # override_target_sdk: (optional) 2170*8975f5c5SAndroid Build Coastguard Worker # Update the manifest to target this SDK 2171*8975f5c5SAndroid Build Coastguard Worker # 2172*8975f5c5SAndroid Build Coastguard Worker # Output variables: 2173*8975f5c5SAndroid Build Coastguard Worker # arsc_output: Path to output .ap_ file (optional). 2174*8975f5c5SAndroid Build Coastguard Worker # 2175*8975f5c5SAndroid Build Coastguard Worker # proto_output: Path to output .proto.ap_ file (optional). 2176*8975f5c5SAndroid Build Coastguard Worker # 2177*8975f5c5SAndroid Build Coastguard Worker # r_text_out_path: (optional): 2178*8975f5c5SAndroid Build Coastguard Worker # Path for the corresponding generated R.txt file. 2179*8975f5c5SAndroid Build Coastguard Worker # 2180*8975f5c5SAndroid Build Coastguard Worker # proguard_file: (optional) 2181*8975f5c5SAndroid Build Coastguard Worker # Path to proguard configuration file for this apk target. 2182*8975f5c5SAndroid Build Coastguard Worker # 2183*8975f5c5SAndroid Build Coastguard Worker template("compile_resources") { 2184*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 2185*8975f5c5SAndroid Build Coastguard Worker 2186*8975f5c5SAndroid Build Coastguard Worker _deps = invoker.deps + [ invoker.build_config_dep ] 2187*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.android_manifest_dep)) { 2188*8975f5c5SAndroid Build Coastguard Worker _deps += [ invoker.android_manifest_dep ] 2189*8975f5c5SAndroid Build Coastguard Worker } 2190*8975f5c5SAndroid Build Coastguard Worker 2191*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.arsc_output)) { 2192*8975f5c5SAndroid Build Coastguard Worker _arsc_output = invoker.arsc_output 2193*8975f5c5SAndroid Build Coastguard Worker } 2194*8975f5c5SAndroid Build Coastguard Worker _final_srcjar_path = "${target_gen_dir}/${target_name}.srcjar" 2195*8975f5c5SAndroid Build Coastguard Worker 2196*8975f5c5SAndroid Build Coastguard Worker _script = "//build/android/gyp/compile_resources.py" 2197*8975f5c5SAndroid Build Coastguard Worker 2198*8975f5c5SAndroid Build Coastguard Worker _target_sdk_version = invoker.target_sdk_version 2199*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.override_target_sdk)) { 2200*8975f5c5SAndroid Build Coastguard Worker _target_sdk_version = invoker.override_target_sdk 2201*8975f5c5SAndroid Build Coastguard Worker } 2202*8975f5c5SAndroid Build Coastguard Worker 2203*8975f5c5SAndroid Build Coastguard Worker _common_inputs = [ 2204*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 2205*8975f5c5SAndroid Build Coastguard Worker android_sdk_tools_bundle_aapt2, 2206*8975f5c5SAndroid Build Coastguard Worker android_sdk_jar, 2207*8975f5c5SAndroid Build Coastguard Worker 2208*8975f5c5SAndroid Build Coastguard Worker # TODO(b/315080809#comment4): remove these files after fixing 2209*8975f5c5SAndroid Build Coastguard Worker # build/print_python_deps.py. 2210*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/__init__.py", 2211*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/__init__.py", 2212*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/compiler/__init__.py", 2213*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/compiler/plugin_pb2.py", 2214*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/descriptor.py", 2215*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/descriptor_database.py", 2216*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/descriptor_pb2.py", 2217*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/descriptor_pool.py", 2218*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/__init__.py", 2219*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/_parameterized.py", 2220*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/api_implementation.py", 2221*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/builder.py", 2222*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/containers.py", 2223*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/decoder.py", 2224*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py", 2225*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test.py", 2226*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/descriptor_test.py", 2227*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/encoder.py", 2228*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/enum_type_wrapper.py", 2229*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/extension_dict.py", 2230*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/generator_test.py", 2231*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/import_test.py", 2232*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/import_test_package/__init__.py", 2233*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/json_format_test.py", 2234*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/keywords_test.py", 2235*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/message_factory_test.py", 2236*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/message_listener.py", 2237*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/message_test.py", 2238*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/proto_builder_test.py", 2239*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/python_message.py", 2240*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/reflection_test.py", 2241*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/service_reflection_test.py", 2242*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/symbol_database_test.py", 2243*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/test_util.py", 2244*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/testing_refleaks.py", 2245*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py", 2246*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/text_format_test.py", 2247*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/type_checkers.py", 2248*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/unknown_fields_test.py", 2249*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/well_known_types.py", 2250*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/well_known_types_test.py", 2251*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/wire_format.py", 2252*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/internal/wire_format_test.py", 2253*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/json_format.py", 2254*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/message.py", 2255*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/message_factory.py", 2256*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/proto_builder.py", 2257*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/pyext/__init__.py", 2258*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/pyext/cpp_message.py", 2259*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/reflection.py", 2260*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/service.py", 2261*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/service_reflection.py", 2262*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/symbol_database.py", 2263*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/text_encoding.py", 2264*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/text_format.py", 2265*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/unknown_fields.py", 2266*8975f5c5SAndroid Build Coastguard Worker "//third_party/protobuf/python/google/protobuf/util/__init__.py", 2267*8975f5c5SAndroid Build Coastguard Worker ] 2268*8975f5c5SAndroid Build Coastguard Worker 2269*8975f5c5SAndroid Build Coastguard Worker _inputs = _common_inputs 2270*8975f5c5SAndroid Build Coastguard Worker 2271*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 2272*8975f5c5SAndroid Build Coastguard Worker 2273*8975f5c5SAndroid Build Coastguard Worker _rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir) 2274*8975f5c5SAndroid Build Coastguard Worker _args = [ 2275*8975f5c5SAndroid Build Coastguard Worker "--include-resources=$_rebased_android_sdk_jar", 2276*8975f5c5SAndroid Build Coastguard Worker "--aapt2-path", 2277*8975f5c5SAndroid Build Coastguard Worker rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir), 2278*8975f5c5SAndroid Build Coastguard Worker "--dependencies-res-zips=@FileArg($_rebased_build_config:deps_info:dependency_zips)", 2279*8975f5c5SAndroid Build Coastguard Worker "--extra-res-packages=@FileArg($_rebased_build_config:deps_info:extra_package_names)", 2280*8975f5c5SAndroid Build Coastguard Worker "--min-sdk-version=${invoker.min_sdk_version}", 2281*8975f5c5SAndroid Build Coastguard Worker "--target-sdk-version=${_target_sdk_version}", 2282*8975f5c5SAndroid Build Coastguard Worker "--webp-cache-dir=obj/android-webp-cache", 2283*8975f5c5SAndroid Build Coastguard Worker ] 2284*8975f5c5SAndroid Build Coastguard Worker 2285*8975f5c5SAndroid Build Coastguard Worker # TODO(b/355432192): Remove this flag once not needed by Compose. 2286*8975f5c5SAndroid Build Coastguard Worker if (defined(enable_hilt_internal) && enable_hilt_internal) { 2287*8975f5c5SAndroid Build Coastguard Worker _args += [ "--xml-namespaces" ] 2288*8975f5c5SAndroid Build Coastguard Worker } 2289*8975f5c5SAndroid Build Coastguard Worker 2290*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.android_manifest ] 2291*8975f5c5SAndroid Build Coastguard Worker _outputs = [ _final_srcjar_path ] 2292*8975f5c5SAndroid Build Coastguard Worker _args += [ 2293*8975f5c5SAndroid Build Coastguard Worker "--android-manifest", 2294*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.android_manifest, root_build_dir), 2295*8975f5c5SAndroid Build Coastguard Worker "--srcjar-out", 2296*8975f5c5SAndroid Build Coastguard Worker rebase_path(_final_srcjar_path, root_build_dir), 2297*8975f5c5SAndroid Build Coastguard Worker ] 2298*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.version_code)) { 2299*8975f5c5SAndroid Build Coastguard Worker _args += [ 2300*8975f5c5SAndroid Build Coastguard Worker "--version-code", 2301*8975f5c5SAndroid Build Coastguard Worker invoker.version_code, 2302*8975f5c5SAndroid Build Coastguard Worker ] 2303*8975f5c5SAndroid Build Coastguard Worker } 2304*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.version_name)) { 2305*8975f5c5SAndroid Build Coastguard Worker _args += [ 2306*8975f5c5SAndroid Build Coastguard Worker "--version-name", 2307*8975f5c5SAndroid Build Coastguard Worker invoker.version_name, 2308*8975f5c5SAndroid Build Coastguard Worker ] 2309*8975f5c5SAndroid Build Coastguard Worker } 2310*8975f5c5SAndroid Build Coastguard Worker if (defined(_arsc_output)) { 2311*8975f5c5SAndroid Build Coastguard Worker _outputs += [ _arsc_output ] 2312*8975f5c5SAndroid Build Coastguard Worker _args += [ 2313*8975f5c5SAndroid Build Coastguard Worker "--arsc-path", 2314*8975f5c5SAndroid Build Coastguard Worker rebase_path(_arsc_output, root_build_dir), 2315*8975f5c5SAndroid Build Coastguard Worker ] 2316*8975f5c5SAndroid Build Coastguard Worker } 2317*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proto_output)) { 2318*8975f5c5SAndroid Build Coastguard Worker _outputs += [ invoker.proto_output ] 2319*8975f5c5SAndroid Build Coastguard Worker _args += [ 2320*8975f5c5SAndroid Build Coastguard Worker "--proto-path", 2321*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proto_output, root_build_dir), 2322*8975f5c5SAndroid Build Coastguard Worker ] 2323*8975f5c5SAndroid Build Coastguard Worker } 2324*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.size_info_path)) { 2325*8975f5c5SAndroid Build Coastguard Worker _outputs += [ invoker.size_info_path ] 2326*8975f5c5SAndroid Build Coastguard Worker _args += [ 2327*8975f5c5SAndroid Build Coastguard Worker "--info-path", 2328*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.size_info_path, root_build_dir), 2329*8975f5c5SAndroid Build Coastguard Worker ] 2330*8975f5c5SAndroid Build Coastguard Worker } 2331*8975f5c5SAndroid Build Coastguard Worker 2332*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.r_java_root_package_name)) { 2333*8975f5c5SAndroid Build Coastguard Worker _args += [ 2334*8975f5c5SAndroid Build Coastguard Worker "--r-java-root-package-name", 2335*8975f5c5SAndroid Build Coastguard Worker invoker.r_java_root_package_name, 2336*8975f5c5SAndroid Build Coastguard Worker ] 2337*8975f5c5SAndroid Build Coastguard Worker } 2338*8975f5c5SAndroid Build Coastguard Worker 2339*8975f5c5SAndroid Build Coastguard Worker # Useful to have android:debuggable in the manifest even for Release 2340*8975f5c5SAndroid Build Coastguard Worker # builds. Just omit it for officai 2341*8975f5c5SAndroid Build Coastguard Worker if (debuggable_apks) { 2342*8975f5c5SAndroid Build Coastguard Worker _args += [ "--debuggable" ] 2343*8975f5c5SAndroid Build Coastguard Worker } 2344*8975f5c5SAndroid Build Coastguard Worker 2345*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.r_text_out_path)) { 2346*8975f5c5SAndroid Build Coastguard Worker _outputs += [ invoker.r_text_out_path ] 2347*8975f5c5SAndroid Build Coastguard Worker _args += [ 2348*8975f5c5SAndroid Build Coastguard Worker "--r-text-out", 2349*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.r_text_out_path, root_build_dir), 2350*8975f5c5SAndroid Build Coastguard Worker ] 2351*8975f5c5SAndroid Build Coastguard Worker } 2352*8975f5c5SAndroid Build Coastguard Worker 2353*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.rename_manifest_package)) { 2354*8975f5c5SAndroid Build Coastguard Worker _args += [ 2355*8975f5c5SAndroid Build Coastguard Worker "--rename-manifest-package", 2356*8975f5c5SAndroid Build Coastguard Worker invoker.rename_manifest_package, 2357*8975f5c5SAndroid Build Coastguard Worker ] 2358*8975f5c5SAndroid Build Coastguard Worker } 2359*8975f5c5SAndroid Build Coastguard Worker 2360*8975f5c5SAndroid Build Coastguard Worker # Define the flags related to shared resources. 2361*8975f5c5SAndroid Build Coastguard Worker # 2362*8975f5c5SAndroid Build Coastguard Worker # Note the small sanity check to ensure that the package ID of the 2363*8975f5c5SAndroid Build Coastguard Worker # generated resources table is correct. It should be 0x02 for runtime 2364*8975f5c5SAndroid Build Coastguard Worker # shared libraries, and 0x7f otherwise. 2365*8975f5c5SAndroid Build Coastguard Worker 2366*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.shared_resources) && invoker.shared_resources) { 2367*8975f5c5SAndroid Build Coastguard Worker _args += [ "--shared-resources" ] 2368*8975f5c5SAndroid Build Coastguard Worker } 2369*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.app_as_shared_lib) && invoker.app_as_shared_lib) { 2370*8975f5c5SAndroid Build Coastguard Worker _args += [ "--app-as-shared-lib" ] 2371*8975f5c5SAndroid Build Coastguard Worker } 2372*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.package_id)) { 2373*8975f5c5SAndroid Build Coastguard Worker _args += [ "--package-id=${invoker.package_id}" ] 2374*8975f5c5SAndroid Build Coastguard Worker } 2375*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.package_name)) { 2376*8975f5c5SAndroid Build Coastguard Worker _args += [ 2377*8975f5c5SAndroid Build Coastguard Worker "--package-name", 2378*8975f5c5SAndroid Build Coastguard Worker invoker.package_name, 2379*8975f5c5SAndroid Build Coastguard Worker ] 2380*8975f5c5SAndroid Build Coastguard Worker } 2381*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.arsc_package_name)) { 2382*8975f5c5SAndroid Build Coastguard Worker _args += [ 2383*8975f5c5SAndroid Build Coastguard Worker "--arsc-package-name", 2384*8975f5c5SAndroid Build Coastguard Worker invoker.arsc_package_name, 2385*8975f5c5SAndroid Build Coastguard Worker ] 2386*8975f5c5SAndroid Build Coastguard Worker } 2387*8975f5c5SAndroid Build Coastguard Worker 2388*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.shared_resources_allowlist)) { 2389*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.shared_resources_allowlist ] 2390*8975f5c5SAndroid Build Coastguard Worker _args += [ 2391*8975f5c5SAndroid Build Coastguard Worker "--shared-resources-allowlist", 2392*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.shared_resources_allowlist, root_build_dir), 2393*8975f5c5SAndroid Build Coastguard Worker ] 2394*8975f5c5SAndroid Build Coastguard Worker } 2395*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.shared_resources_allowlist_locales)) { 2396*8975f5c5SAndroid Build Coastguard Worker _args += [ "--shared-resources-allowlist-locales=" + 2397*8975f5c5SAndroid Build Coastguard Worker "${invoker.shared_resources_allowlist_locales}" ] 2398*8975f5c5SAndroid Build Coastguard Worker } 2399*8975f5c5SAndroid Build Coastguard Worker 2400*8975f5c5SAndroid Build Coastguard Worker if (!defined(testonly) || !testonly || 2401*8975f5c5SAndroid Build Coastguard Worker (defined(invoker.enforce_resource_overlays_in_tests) && 2402*8975f5c5SAndroid Build Coastguard Worker invoker.enforce_resource_overlays_in_tests)) { 2403*8975f5c5SAndroid Build Coastguard Worker _args += [ "--dependencies-res-zip-overlays=@FileArg($_rebased_build_config:deps_info:dependency_zip_overlays)" ] 2404*8975f5c5SAndroid Build Coastguard Worker } else { 2405*8975f5c5SAndroid Build Coastguard Worker _args += [ "--dependencies-res-zip-overlays=@FileArg($_rebased_build_config:deps_info:dependency_zips)" ] 2406*8975f5c5SAndroid Build Coastguard Worker } 2407*8975f5c5SAndroid Build Coastguard Worker 2408*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_file)) { 2409*8975f5c5SAndroid Build Coastguard Worker _outputs += [ invoker.proguard_file ] 2410*8975f5c5SAndroid Build Coastguard Worker _args += [ 2411*8975f5c5SAndroid Build Coastguard Worker "--proguard-file", 2412*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_file, root_build_dir), 2413*8975f5c5SAndroid Build Coastguard Worker ] 2414*8975f5c5SAndroid Build Coastguard Worker } 2415*8975f5c5SAndroid Build Coastguard Worker 2416*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.aapt_locale_allowlist)) { 2417*8975f5c5SAndroid Build Coastguard Worker _args += [ "--locale-allowlist=${invoker.aapt_locale_allowlist}" ] 2418*8975f5c5SAndroid Build Coastguard Worker } 2419*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.png_to_webp) && invoker.png_to_webp) { 2420*8975f5c5SAndroid Build Coastguard Worker _webp_target = "//third_party/libwebp:cwebp($host_toolchain)" 2421*8975f5c5SAndroid Build Coastguard Worker _webp_binary = get_label_info(_webp_target, "root_out_dir") + "/cwebp" 2422*8975f5c5SAndroid Build Coastguard Worker _deps += [ _webp_target ] 2423*8975f5c5SAndroid Build Coastguard Worker _inputs += [ _webp_binary ] 2424*8975f5c5SAndroid Build Coastguard Worker _args += [ 2425*8975f5c5SAndroid Build Coastguard Worker "--png-to-webp", 2426*8975f5c5SAndroid Build Coastguard Worker "--webp-binary", 2427*8975f5c5SAndroid Build Coastguard Worker rebase_path(_webp_binary, root_build_dir), 2428*8975f5c5SAndroid Build Coastguard Worker ] 2429*8975f5c5SAndroid Build Coastguard Worker } 2430*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resource_exclusion_regex)) { 2431*8975f5c5SAndroid Build Coastguard Worker _args += 2432*8975f5c5SAndroid Build Coastguard Worker [ "--resource-exclusion-regex=${invoker.resource_exclusion_regex}" ] 2433*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resource_exclusion_exceptions)) { 2434*8975f5c5SAndroid Build Coastguard Worker _args += [ "--resource-exclusion-exceptions=${invoker.resource_exclusion_exceptions}" ] 2435*8975f5c5SAndroid Build Coastguard Worker } 2436*8975f5c5SAndroid Build Coastguard Worker } 2437*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resource_values_filter_rules)) { 2438*8975f5c5SAndroid Build Coastguard Worker _args += 2439*8975f5c5SAndroid Build Coastguard Worker [ "--values-filter-rules=${invoker.resource_values_filter_rules}" ] 2440*8975f5c5SAndroid Build Coastguard Worker } 2441*8975f5c5SAndroid Build Coastguard Worker 2442*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.include_resource)) { 2443*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.include_resource ] 2444*8975f5c5SAndroid Build Coastguard Worker _rebased_include_resources = 2445*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.include_resource, root_build_dir) 2446*8975f5c5SAndroid Build Coastguard Worker _args += [ "--include-resources=$_rebased_include_resources" ] 2447*8975f5c5SAndroid Build Coastguard Worker } 2448*8975f5c5SAndroid Build Coastguard Worker 2449*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker._args)) { 2450*8975f5c5SAndroid Build Coastguard Worker _args += invoker._args 2451*8975f5c5SAndroid Build Coastguard Worker } 2452*8975f5c5SAndroid Build Coastguard Worker 2453*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.emit_ids_out_path)) { 2454*8975f5c5SAndroid Build Coastguard Worker _outputs += [ invoker.emit_ids_out_path ] 2455*8975f5c5SAndroid Build Coastguard Worker _rebased_emit_ids_path = 2456*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.emit_ids_out_path, root_out_dir) 2457*8975f5c5SAndroid Build Coastguard Worker _args += [ "--emit-ids-out=$_rebased_emit_ids_path" ] 2458*8975f5c5SAndroid Build Coastguard Worker } 2459*8975f5c5SAndroid Build Coastguard Worker 2460*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resource_ids_provider_dep)) { 2461*8975f5c5SAndroid Build Coastguard Worker _compile_res_dep = 2462*8975f5c5SAndroid Build Coastguard Worker "${invoker.resource_ids_provider_dep}__compile_resources" 2463*8975f5c5SAndroid Build Coastguard Worker _gen_dir = get_label_info(_compile_res_dep, "target_gen_dir") 2464*8975f5c5SAndroid Build Coastguard Worker _name = get_label_info(_compile_res_dep, "name") 2465*8975f5c5SAndroid Build Coastguard Worker _resource_ids_path = "$_gen_dir/$_name.resource_ids" 2466*8975f5c5SAndroid Build Coastguard Worker _inputs += [ _resource_ids_path ] 2467*8975f5c5SAndroid Build Coastguard Worker _rebased_ids_path = rebase_path(_resource_ids_path, root_out_dir) 2468*8975f5c5SAndroid Build Coastguard Worker _args += [ "--use-resource-ids-path=$_rebased_ids_path" ] 2469*8975f5c5SAndroid Build Coastguard Worker _deps += [ _compile_res_dep ] 2470*8975f5c5SAndroid Build Coastguard Worker } 2471*8975f5c5SAndroid Build Coastguard Worker 2472*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.max_sdk_version)) { 2473*8975f5c5SAndroid Build Coastguard Worker _max_sdk_version = invoker.max_sdk_version 2474*8975f5c5SAndroid Build Coastguard Worker _args += [ "--max-sdk-version=$_max_sdk_version" ] 2475*8975f5c5SAndroid Build Coastguard Worker } 2476*8975f5c5SAndroid Build Coastguard Worker 2477*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.manifest_package)) { 2478*8975f5c5SAndroid Build Coastguard Worker _args += [ "--manifest-package=${invoker.manifest_package}" ] 2479*8975f5c5SAndroid Build Coastguard Worker } 2480*8975f5c5SAndroid Build Coastguard Worker 2481*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.is_bundle_module) && invoker.is_bundle_module) { 2482*8975f5c5SAndroid Build Coastguard Worker _args += [ "--is-bundle-module" ] 2483*8975f5c5SAndroid Build Coastguard Worker } 2484*8975f5c5SAndroid Build Coastguard Worker 2485*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.uses_split)) { 2486*8975f5c5SAndroid Build Coastguard Worker assert(invoker.is_bundle_module) 2487*8975f5c5SAndroid Build Coastguard Worker _args += [ "--uses-split=${invoker.uses_split}" ] 2488*8975f5c5SAndroid Build Coastguard Worker } 2489*8975f5c5SAndroid Build Coastguard Worker 2490*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_android_manifest)) { 2491*8975f5c5SAndroid Build Coastguard Worker _expectations_target = 2492*8975f5c5SAndroid Build Coastguard Worker "${invoker.top_target_name}_validate_android_manifest" 2493*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(_expectations_target) { 2494*8975f5c5SAndroid Build Coastguard Worker _actual_file = "${invoker.android_manifest}.normalized" 2495*8975f5c5SAndroid Build Coastguard Worker _failure_file = 2496*8975f5c5SAndroid Build Coastguard Worker "$expectations_failure_dir/" + 2497*8975f5c5SAndroid Build Coastguard Worker string_replace(invoker.expected_android_manifest, "/", "_") 2498*8975f5c5SAndroid Build Coastguard Worker inputs = [ 2499*8975f5c5SAndroid Build Coastguard Worker invoker.android_manifest, 2500*8975f5c5SAndroid Build Coastguard Worker invoker.expected_android_manifest, 2501*8975f5c5SAndroid Build Coastguard Worker ] + _common_inputs 2502*8975f5c5SAndroid Build Coastguard Worker outputs = [ 2503*8975f5c5SAndroid Build Coastguard Worker _actual_file, 2504*8975f5c5SAndroid Build Coastguard Worker _failure_file, 2505*8975f5c5SAndroid Build Coastguard Worker ] 2506*8975f5c5SAndroid Build Coastguard Worker deps = [ 2507*8975f5c5SAndroid Build Coastguard Worker invoker.android_manifest_dep, 2508*8975f5c5SAndroid Build Coastguard Worker invoker.build_config_dep, 2509*8975f5c5SAndroid Build Coastguard Worker ] 2510*8975f5c5SAndroid Build Coastguard Worker script = _script 2511*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 2512*8975f5c5SAndroid Build Coastguard Worker "--expected-file", 2513*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_android_manifest, root_build_dir), 2514*8975f5c5SAndroid Build Coastguard Worker "--actual-file", 2515*8975f5c5SAndroid Build Coastguard Worker rebase_path(_actual_file, root_build_dir), 2516*8975f5c5SAndroid Build Coastguard Worker "--failure-file", 2517*8975f5c5SAndroid Build Coastguard Worker rebase_path(_failure_file, root_build_dir), 2518*8975f5c5SAndroid Build Coastguard Worker "--only-verify-expectations", 2519*8975f5c5SAndroid Build Coastguard Worker ] 2520*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_android_manifest_base)) { 2521*8975f5c5SAndroid Build Coastguard Worker args += [ 2522*8975f5c5SAndroid Build Coastguard Worker "--expected-file-base", 2523*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_android_manifest_base, root_build_dir), 2524*8975f5c5SAndroid Build Coastguard Worker ] 2525*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.expected_android_manifest_base ] 2526*8975f5c5SAndroid Build Coastguard Worker } 2527*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_android_manifest_version_code_offset)) { 2528*8975f5c5SAndroid Build Coastguard Worker args += [ 2529*8975f5c5SAndroid Build Coastguard Worker "--verification-version-code-offset", 2530*8975f5c5SAndroid Build Coastguard Worker invoker.expected_android_manifest_version_code_offset, 2531*8975f5c5SAndroid Build Coastguard Worker ] 2532*8975f5c5SAndroid Build Coastguard Worker } 2533*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_android_manifest_library_version_offset)) { 2534*8975f5c5SAndroid Build Coastguard Worker args += [ 2535*8975f5c5SAndroid Build Coastguard Worker "--verification-library-version-offset", 2536*8975f5c5SAndroid Build Coastguard Worker invoker.expected_android_manifest_library_version_offset, 2537*8975f5c5SAndroid Build Coastguard Worker ] 2538*8975f5c5SAndroid Build Coastguard Worker } 2539*8975f5c5SAndroid Build Coastguard Worker if (fail_on_android_expectations) { 2540*8975f5c5SAndroid Build Coastguard Worker args += [ "--fail-on-expectations" ] 2541*8975f5c5SAndroid Build Coastguard Worker } 2542*8975f5c5SAndroid Build Coastguard Worker } 2543*8975f5c5SAndroid Build Coastguard Worker _deps += [ ":$_expectations_target" ] 2544*8975f5c5SAndroid Build Coastguard Worker } 2545*8975f5c5SAndroid Build Coastguard Worker 2546*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 2547*8975f5c5SAndroid Build Coastguard Worker script = _script 2548*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/${target_name}.d" 2549*8975f5c5SAndroid Build Coastguard Worker inputs = _inputs 2550*8975f5c5SAndroid Build Coastguard Worker outputs = _outputs 2551*8975f5c5SAndroid Build Coastguard Worker deps = _deps 2552*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 2553*8975f5c5SAndroid Build Coastguard Worker "--depfile", 2554*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 2555*8975f5c5SAndroid Build Coastguard Worker ] 2556*8975f5c5SAndroid Build Coastguard Worker } 2557*8975f5c5SAndroid Build Coastguard Worker } 2558*8975f5c5SAndroid Build Coastguard Worker 2559*8975f5c5SAndroid Build Coastguard Worker # A template that is used to optimize compiled resources using aapt2 optimize. 2560*8975f5c5SAndroid Build Coastguard Worker # 2561*8975f5c5SAndroid Build Coastguard Worker # proto_input_path: 2562*8975f5c5SAndroid Build Coastguard Worker # Path to input compiled .proto.ap_ file. 2563*8975f5c5SAndroid Build Coastguard Worker # 2564*8975f5c5SAndroid Build Coastguard Worker # short_resource_paths: (optional) 2565*8975f5c5SAndroid Build Coastguard Worker # Rename the paths within a the apk to be randomly generated short 2566*8975f5c5SAndroid Build Coastguard Worker # strings to reduce binary size. 2567*8975f5c5SAndroid Build Coastguard Worker # 2568*8975f5c5SAndroid Build Coastguard Worker # strip_resource_names: (optional) 2569*8975f5c5SAndroid Build Coastguard Worker # Strip resource names from the resources table of the apk. 2570*8975f5c5SAndroid Build Coastguard Worker # 2571*8975f5c5SAndroid Build Coastguard Worker # resources_configs_paths: (optional) 2572*8975f5c5SAndroid Build Coastguard Worker # List of resource configs to use for optimization. 2573*8975f5c5SAndroid Build Coastguard Worker # 2574*8975f5c5SAndroid Build Coastguard Worker # optimized_proto_output: 2575*8975f5c5SAndroid Build Coastguard Worker # Path to output optimized .proto.ap_ file. 2576*8975f5c5SAndroid Build Coastguard Worker # 2577*8975f5c5SAndroid Build Coastguard Worker # resources_path_map_out_path: (optional): 2578*8975f5c5SAndroid Build Coastguard Worker # Path for the generated map between original resource paths and 2579*8975f5c5SAndroid Build Coastguard Worker # shortened resource paths. 2580*8975f5c5SAndroid Build Coastguard Worker template("optimize_resources") { 2581*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 2582*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 2583*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, [ "deps" ]) 2584*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/optimize_resources.py" 2585*8975f5c5SAndroid Build Coastguard Worker inputs = [ 2586*8975f5c5SAndroid Build Coastguard Worker android_sdk_tools_bundle_aapt2, 2587*8975f5c5SAndroid Build Coastguard Worker invoker.r_text_path, 2588*8975f5c5SAndroid Build Coastguard Worker ] 2589*8975f5c5SAndroid Build Coastguard Worker outputs = [] 2590*8975f5c5SAndroid Build Coastguard Worker args = [ 2591*8975f5c5SAndroid Build Coastguard Worker "--aapt2-path", 2592*8975f5c5SAndroid Build Coastguard Worker rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir), 2593*8975f5c5SAndroid Build Coastguard Worker "--r-text-in", 2594*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.r_text_path, root_build_dir), 2595*8975f5c5SAndroid Build Coastguard Worker ] 2596*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.optimized_proto_output)) { 2597*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.proto_input_path ] 2598*8975f5c5SAndroid Build Coastguard Worker outputs += [ invoker.optimized_proto_output ] 2599*8975f5c5SAndroid Build Coastguard Worker args += [ 2600*8975f5c5SAndroid Build Coastguard Worker "--input-path", 2601*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proto_input_path, root_build_dir), 2602*8975f5c5SAndroid Build Coastguard Worker "--optimized-output-path", 2603*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.optimized_proto_output, root_build_dir), 2604*8975f5c5SAndroid Build Coastguard Worker ] 2605*8975f5c5SAndroid Build Coastguard Worker } else { 2606*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.arsc_input_path ] 2607*8975f5c5SAndroid Build Coastguard Worker outputs += [ invoker.optimized_arsc_output ] 2608*8975f5c5SAndroid Build Coastguard Worker args += [ 2609*8975f5c5SAndroid Build Coastguard Worker "--input-path", 2610*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.arsc_input_path, root_build_dir), 2611*8975f5c5SAndroid Build Coastguard Worker "--optimized-output-path", 2612*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.optimized_arsc_output, root_build_dir), 2613*8975f5c5SAndroid Build Coastguard Worker ] 2614*8975f5c5SAndroid Build Coastguard Worker } 2615*8975f5c5SAndroid Build Coastguard Worker 2616*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resources_config_paths)) { 2617*8975f5c5SAndroid Build Coastguard Worker inputs += invoker.resources_config_paths 2618*8975f5c5SAndroid Build Coastguard Worker _rebased_resource_configs = 2619*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.resources_config_paths, root_build_dir) 2620*8975f5c5SAndroid Build Coastguard Worker args += [ "--resources-config-paths=${_rebased_resource_configs}" ] 2621*8975f5c5SAndroid Build Coastguard Worker } 2622*8975f5c5SAndroid Build Coastguard Worker 2623*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.short_resource_paths) && 2624*8975f5c5SAndroid Build Coastguard Worker invoker.short_resource_paths) { 2625*8975f5c5SAndroid Build Coastguard Worker args += [ "--short-resource-paths" ] 2626*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resources_path_map_out_path)) { 2627*8975f5c5SAndroid Build Coastguard Worker outputs += [ invoker.resources_path_map_out_path ] 2628*8975f5c5SAndroid Build Coastguard Worker args += [ 2629*8975f5c5SAndroid Build Coastguard Worker "--resources-path-map-out-path", 2630*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.resources_path_map_out_path, root_build_dir), 2631*8975f5c5SAndroid Build Coastguard Worker ] 2632*8975f5c5SAndroid Build Coastguard Worker } 2633*8975f5c5SAndroid Build Coastguard Worker } 2634*8975f5c5SAndroid Build Coastguard Worker 2635*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.strip_resource_names) && 2636*8975f5c5SAndroid Build Coastguard Worker invoker.strip_resource_names) { 2637*8975f5c5SAndroid Build Coastguard Worker args += [ "--strip-resource-names" ] 2638*8975f5c5SAndroid Build Coastguard Worker } 2639*8975f5c5SAndroid Build Coastguard Worker } 2640*8975f5c5SAndroid Build Coastguard Worker } 2641*8975f5c5SAndroid Build Coastguard Worker 2642*8975f5c5SAndroid Build Coastguard Worker # A template that is used to find unused resources. 2643*8975f5c5SAndroid Build Coastguard Worker template("unused_resources") { 2644*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 2645*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 2646*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/unused_resources.py" 2647*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/${target_name}.d" 2648*8975f5c5SAndroid Build Coastguard Worker _unused_resources_script = "$root_build_dir/bin/helper/unused_resources" 2649*8975f5c5SAndroid Build Coastguard Worker inputs = [ _unused_resources_script ] + java_paths_for_inputs 2650*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output_config ] 2651*8975f5c5SAndroid Build Coastguard Worker if (!defined(deps)) { 2652*8975f5c5SAndroid Build Coastguard Worker deps = [] 2653*8975f5c5SAndroid Build Coastguard Worker } 2654*8975f5c5SAndroid Build Coastguard Worker deps += [ "//build/android/unused_resources:unused_resources" ] 2655*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 2656*8975f5c5SAndroid Build Coastguard Worker args = [ 2657*8975f5c5SAndroid Build Coastguard Worker "--script", 2658*8975f5c5SAndroid Build Coastguard Worker rebase_path(_unused_resources_script, root_build_dir), 2659*8975f5c5SAndroid Build Coastguard Worker "--output-config", 2660*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_config, root_build_dir), 2661*8975f5c5SAndroid Build Coastguard Worker "--r-text-in=@FileArg($_rebased_build_config:deps_info:r_text_path)", 2662*8975f5c5SAndroid Build Coastguard Worker "--dependencies-res-zips=@FileArg($_rebased_build_config:deps_info:dependency_zips)", 2663*8975f5c5SAndroid Build Coastguard Worker "--depfile", 2664*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 2665*8975f5c5SAndroid Build Coastguard Worker ] 2666*8975f5c5SAndroid Build Coastguard Worker 2667*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_mapping_path)) { 2668*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.proguard_mapping_path ] 2669*8975f5c5SAndroid Build Coastguard Worker args += [ 2670*8975f5c5SAndroid Build Coastguard Worker "--proguard-mapping", 2671*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_mapping_path, root_build_dir), 2672*8975f5c5SAndroid Build Coastguard Worker ] 2673*8975f5c5SAndroid Build Coastguard Worker } 2674*8975f5c5SAndroid Build Coastguard Worker 2675*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.output_r_txt)) { 2676*8975f5c5SAndroid Build Coastguard Worker outputs += [ invoker.output_r_txt ] 2677*8975f5c5SAndroid Build Coastguard Worker args += [ 2678*8975f5c5SAndroid Build Coastguard Worker "--r-text-out", 2679*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_r_txt, root_build_dir), 2680*8975f5c5SAndroid Build Coastguard Worker ] 2681*8975f5c5SAndroid Build Coastguard Worker } 2682*8975f5c5SAndroid Build Coastguard Worker 2683*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.all_module_build_configs)) { 2684*8975f5c5SAndroid Build Coastguard Worker foreach(_build_config, invoker.all_module_build_configs) { 2685*8975f5c5SAndroid Build Coastguard Worker inputs += [ _build_config ] 2686*8975f5c5SAndroid Build Coastguard Worker _rebased_module_build_config = 2687*8975f5c5SAndroid Build Coastguard Worker rebase_path(_build_config, root_build_dir) 2688*8975f5c5SAndroid Build Coastguard Worker args += [ 2689*8975f5c5SAndroid Build Coastguard Worker "--dexes=@FileArg($_rebased_module_build_config:final_dex:path)", 2690*8975f5c5SAndroid Build Coastguard Worker "--android-manifests=@FileArg($_rebased_module_build_config:deps_info:merged_android_manifest)", 2691*8975f5c5SAndroid Build Coastguard Worker ] 2692*8975f5c5SAndroid Build Coastguard Worker } 2693*8975f5c5SAndroid Build Coastguard Worker } else { 2694*8975f5c5SAndroid Build Coastguard Worker args += [ 2695*8975f5c5SAndroid Build Coastguard Worker "--dexes=@FileArg($_rebased_build_config:final_dex:path)", 2696*8975f5c5SAndroid Build Coastguard Worker "--android-manifests=@FileArg($_rebased_build_config:deps_info:merged_android_manifest)", 2697*8975f5c5SAndroid Build Coastguard Worker ] 2698*8975f5c5SAndroid Build Coastguard Worker } 2699*8975f5c5SAndroid Build Coastguard Worker } 2700*8975f5c5SAndroid Build Coastguard Worker } 2701*8975f5c5SAndroid Build Coastguard Worker 2702*8975f5c5SAndroid Build Coastguard Worker # Create an .jar.info file by merging several .jar.info files into one. 2703*8975f5c5SAndroid Build Coastguard Worker # 2704*8975f5c5SAndroid Build Coastguard Worker # Variables: 2705*8975f5c5SAndroid Build Coastguard Worker # build_config: Path to APK's build config file. Used to extract the 2706*8975f5c5SAndroid Build Coastguard Worker # list of input .jar files from its dependencies. 2707*8975f5c5SAndroid Build Coastguard Worker # name: Name of the apk or app bundle (e.g. "Foo.apk"). 2708*8975f5c5SAndroid Build Coastguard Worker # res_size_info_path: Path to input .ap_.info file (for apks). 2709*8975f5c5SAndroid Build Coastguard Worker # 2710*8975f5c5SAndroid Build Coastguard Worker template("create_size_info_files") { 2711*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 2712*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 2713*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/create_size_info_files.py" 2714*8975f5c5SAndroid Build Coastguard Worker _jar_info_path = "$root_build_dir/size-info/${invoker.name}.jar.info" 2715*8975f5c5SAndroid Build Coastguard Worker _pak_info_path = "$root_build_dir/size-info/${invoker.name}.pak.info" 2716*8975f5c5SAndroid Build Coastguard Worker _res_info_path = "$root_build_dir/size-info/${invoker.name}.res.info" 2717*8975f5c5SAndroid Build Coastguard Worker outputs = [ 2718*8975f5c5SAndroid Build Coastguard Worker _jar_info_path, 2719*8975f5c5SAndroid Build Coastguard Worker _pak_info_path, 2720*8975f5c5SAndroid Build Coastguard Worker _res_info_path, 2721*8975f5c5SAndroid Build Coastguard Worker ] 2722*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 2723*8975f5c5SAndroid Build Coastguard Worker args = [ 2724*8975f5c5SAndroid Build Coastguard Worker "--depfile", 2725*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 2726*8975f5c5SAndroid Build Coastguard Worker "--jar-info-path", 2727*8975f5c5SAndroid Build Coastguard Worker rebase_path(_jar_info_path, root_build_dir), 2728*8975f5c5SAndroid Build Coastguard Worker "--pak-info-path", 2729*8975f5c5SAndroid Build Coastguard Worker rebase_path(_pak_info_path, root_build_dir), 2730*8975f5c5SAndroid Build Coastguard Worker "--res-info-path", 2731*8975f5c5SAndroid Build Coastguard Worker rebase_path(_res_info_path, root_build_dir), 2732*8975f5c5SAndroid Build Coastguard Worker ] 2733*8975f5c5SAndroid Build Coastguard Worker _is_bundle = defined(invoker.module_build_configs) 2734*8975f5c5SAndroid Build Coastguard Worker if (_is_bundle) { 2735*8975f5c5SAndroid Build Coastguard Worker inputs = invoker.module_build_configs 2736*8975f5c5SAndroid Build Coastguard Worker foreach(_build_config, invoker.module_build_configs) { 2737*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 2738*8975f5c5SAndroid Build Coastguard Worker args += [ 2739*8975f5c5SAndroid Build Coastguard Worker "--jar-files=@FileArg($_rebased_build_config:deps_info:unprocessed_jar_path)", 2740*8975f5c5SAndroid Build Coastguard Worker "--jar-files=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)", 2741*8975f5c5SAndroid Build Coastguard Worker "--in-res-info-path=@FileArg($_rebased_build_config:deps_info:res_size_info)", 2742*8975f5c5SAndroid Build Coastguard Worker "--assets=@FileArg($_rebased_build_config:deps_info:assets)", 2743*8975f5c5SAndroid Build Coastguard Worker "--uncompressed-assets=@FileArg($_rebased_build_config:deps_info:uncompressed_assets)", 2744*8975f5c5SAndroid Build Coastguard Worker ] 2745*8975f5c5SAndroid Build Coastguard Worker } 2746*8975f5c5SAndroid Build Coastguard Worker } else { 2747*8975f5c5SAndroid Build Coastguard Worker inputs = [ 2748*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 2749*8975f5c5SAndroid Build Coastguard Worker invoker.res_size_info_path, 2750*8975f5c5SAndroid Build Coastguard Worker ] 2751*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = 2752*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.build_config, root_build_dir) 2753*8975f5c5SAndroid Build Coastguard Worker args += [ 2754*8975f5c5SAndroid Build Coastguard Worker "--jar-files=@FileArg($_rebased_build_config:deps_info:unprocessed_jar_path)", 2755*8975f5c5SAndroid Build Coastguard Worker "--jar-files=@FileArg($_rebased_build_config:deps_info:javac_full_classpath)", 2756*8975f5c5SAndroid Build Coastguard Worker "--in-res-info-path", 2757*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.res_size_info_path, root_build_dir), 2758*8975f5c5SAndroid Build Coastguard Worker "--assets=@FileArg($_rebased_build_config:deps_info:assets)", 2759*8975f5c5SAndroid Build Coastguard Worker "--uncompressed-assets=@FileArg($_rebased_build_config:deps_info:uncompressed_assets)", 2760*8975f5c5SAndroid Build Coastguard Worker ] 2761*8975f5c5SAndroid Build Coastguard Worker } 2762*8975f5c5SAndroid Build Coastguard Worker } 2763*8975f5c5SAndroid Build Coastguard Worker } 2764*8975f5c5SAndroid Build Coastguard Worker 2765*8975f5c5SAndroid Build Coastguard Worker template("create_binary_profile") { 2766*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 2767*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 2768*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, [ "deps" ]) 2769*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/binary_baseline_profile.py" 2770*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 2771*8975f5c5SAndroid Build Coastguard Worker outputs = [ 2772*8975f5c5SAndroid Build Coastguard Worker invoker.binary_baseline_profile_path, 2773*8975f5c5SAndroid Build Coastguard Worker invoker.binary_baseline_profile_metadata_path, 2774*8975f5c5SAndroid Build Coastguard Worker ] 2775*8975f5c5SAndroid Build Coastguard Worker _profgen_path = 2776*8975f5c5SAndroid Build Coastguard Worker "$public_android_sdk_root/cmdline-tools/latest/bin/profgen" 2777*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 2778*8975f5c5SAndroid Build Coastguard Worker inputs = [ 2779*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 2780*8975f5c5SAndroid Build Coastguard Worker invoker.input_profile_path, 2781*8975f5c5SAndroid Build Coastguard Worker _profgen_path, 2782*8975f5c5SAndroid Build Coastguard Worker ] 2783*8975f5c5SAndroid Build Coastguard Worker args = [ 2784*8975f5c5SAndroid Build Coastguard Worker "--profgen", 2785*8975f5c5SAndroid Build Coastguard Worker rebase_path(_profgen_path, root_build_dir), 2786*8975f5c5SAndroid Build Coastguard Worker "--output-profile", 2787*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.binary_baseline_profile_path, root_build_dir), 2788*8975f5c5SAndroid Build Coastguard Worker "--output-metadata", 2789*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.binary_baseline_profile_metadata_path, 2790*8975f5c5SAndroid Build Coastguard Worker root_build_dir), 2791*8975f5c5SAndroid Build Coastguard Worker "--dex=@FileArg($_rebased_build_config:final_dex:path)", 2792*8975f5c5SAndroid Build Coastguard Worker "--input-profile-path", 2793*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_profile_path, root_build_dir), 2794*8975f5c5SAndroid Build Coastguard Worker "--depfile", 2795*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 2796*8975f5c5SAndroid Build Coastguard Worker ] 2797*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.proguard_mapping_path)) { 2798*8975f5c5SAndroid Build Coastguard Worker args += [ 2799*8975f5c5SAndroid Build Coastguard Worker "--proguard-mapping", 2800*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.proguard_mapping_path, root_build_dir), 2801*8975f5c5SAndroid Build Coastguard Worker ] 2802*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.proguard_mapping_path ] 2803*8975f5c5SAndroid Build Coastguard Worker } 2804*8975f5c5SAndroid Build Coastguard Worker } 2805*8975f5c5SAndroid Build Coastguard Worker } 2806*8975f5c5SAndroid Build Coastguard Worker 2807*8975f5c5SAndroid Build Coastguard Worker # Creates a signed and aligned .apk. 2808*8975f5c5SAndroid Build Coastguard Worker # 2809*8975f5c5SAndroid Build Coastguard Worker # Variables 2810*8975f5c5SAndroid Build Coastguard Worker # apk_name: (optional) APK name (without .apk suffix). If provided, will 2811*8975f5c5SAndroid Build Coastguard Worker # be used to generate .info files later used by the supersize tool. 2812*8975f5c5SAndroid Build Coastguard Worker # assets_build_config: Path to android_apk .build_config.json containing merged 2813*8975f5c5SAndroid Build Coastguard Worker # asset information. 2814*8975f5c5SAndroid Build Coastguard Worker # deps: Specifies the dependencies of this target. 2815*8975f5c5SAndroid Build Coastguard Worker # dex_path: Path to classes.dex file to include (optional). 2816*8975f5c5SAndroid Build Coastguard Worker # expected_libs_and_assets: Verify the list of included native libraries 2817*8975f5c5SAndroid Build Coastguard Worker # and assets is consistent with the given expectation file. 2818*8975f5c5SAndroid Build Coastguard Worker # expected_libs_and_assets_base: Treat expected_libs_and_assets as a diff 2819*8975f5c5SAndroid Build Coastguard Worker # with this file as the base. 2820*8975f5c5SAndroid Build Coastguard Worker # packaged_resources_path: Path to .ap_ to use. 2821*8975f5c5SAndroid Build Coastguard Worker # output_apk_path: Output path for the generated .apk. 2822*8975f5c5SAndroid Build Coastguard Worker # min_sdk_version: The minimum Android SDK version this target supports. 2823*8975f5c5SAndroid Build Coastguard Worker # native_lib_placeholders: List of placeholder filenames to add to the apk 2824*8975f5c5SAndroid Build Coastguard Worker # (optional). 2825*8975f5c5SAndroid Build Coastguard Worker # secondary_native_lib_placeholders: List of placeholder filenames to add to 2826*8975f5c5SAndroid Build Coastguard Worker # the apk for the secondary ABI (optional). 2827*8975f5c5SAndroid Build Coastguard Worker # loadable_modules: List of native libraries. 2828*8975f5c5SAndroid Build Coastguard Worker # native_libs_filearg: @FileArg() of additionally native libraries. 2829*8975f5c5SAndroid Build Coastguard Worker # secondary_abi_loadable_modules: (optional) List of native libraries for 2830*8975f5c5SAndroid Build Coastguard Worker # secondary ABI. 2831*8975f5c5SAndroid Build Coastguard Worker # secondary_abi_native_libs_filearg: (optional). @FileArg() of additional 2832*8975f5c5SAndroid Build Coastguard Worker # secondary ABI native libs. 2833*8975f5c5SAndroid Build Coastguard Worker # keystore_path: Path to keystore to use for signing. 2834*8975f5c5SAndroid Build Coastguard Worker # keystore_name: Key alias to use. 2835*8975f5c5SAndroid Build Coastguard Worker # keystore_password: Keystore password. 2836*8975f5c5SAndroid Build Coastguard Worker template("package_apk") { 2837*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "public_deps" ]) 2838*8975f5c5SAndroid Build Coastguard Worker _is_robolectric_apk = 2839*8975f5c5SAndroid Build Coastguard Worker defined(invoker.is_robolectric_apk) && invoker.is_robolectric_apk 2840*8975f5c5SAndroid Build Coastguard Worker _deps = invoker.deps 2841*8975f5c5SAndroid Build Coastguard Worker _native_lib_placeholders = [] 2842*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.native_lib_placeholders)) { 2843*8975f5c5SAndroid Build Coastguard Worker _native_lib_placeholders = invoker.native_lib_placeholders 2844*8975f5c5SAndroid Build Coastguard Worker } 2845*8975f5c5SAndroid Build Coastguard Worker _secondary_native_lib_placeholders = [] 2846*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.secondary_native_lib_placeholders)) { 2847*8975f5c5SAndroid Build Coastguard Worker _secondary_native_lib_placeholders = 2848*8975f5c5SAndroid Build Coastguard Worker invoker.secondary_native_lib_placeholders 2849*8975f5c5SAndroid Build Coastguard Worker } 2850*8975f5c5SAndroid Build Coastguard Worker 2851*8975f5c5SAndroid Build Coastguard Worker _script = "//build/android/gyp/apkbuilder.py" 2852*8975f5c5SAndroid Build Coastguard Worker 2853*8975f5c5SAndroid Build Coastguard Worker _inputs = [ invoker.packaged_resources_path ] 2854*8975f5c5SAndroid Build Coastguard Worker 2855*8975f5c5SAndroid Build Coastguard Worker _outputs = [ invoker.output_apk_path ] 2856*8975f5c5SAndroid Build Coastguard Worker _data = [ invoker.output_apk_path ] 2857*8975f5c5SAndroid Build Coastguard Worker 2858*8975f5c5SAndroid Build Coastguard Worker _rebased_compiled_resources_path = 2859*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.packaged_resources_path, root_build_dir) 2860*8975f5c5SAndroid Build Coastguard Worker _rebased_packaged_apk_path = 2861*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_apk_path, root_build_dir) 2862*8975f5c5SAndroid Build Coastguard Worker _args = [ 2863*8975f5c5SAndroid Build Coastguard Worker "--resource-apk=$_rebased_compiled_resources_path", 2864*8975f5c5SAndroid Build Coastguard Worker "--output-apk=$_rebased_packaged_apk_path", 2865*8975f5c5SAndroid Build Coastguard Worker "--min-sdk-version=${invoker.min_sdk_version}", 2866*8975f5c5SAndroid Build Coastguard Worker ] 2867*8975f5c5SAndroid Build Coastguard Worker 2868*8975f5c5SAndroid Build Coastguard Worker # system_image_stub_apk does not use a build_config.json. 2869*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.build_config)) { 2870*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.build_config ] 2871*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 2872*8975f5c5SAndroid Build Coastguard Worker _args += [ 2873*8975f5c5SAndroid Build Coastguard Worker "--assets=@FileArg($_rebased_build_config:deps_info:assets)", 2874*8975f5c5SAndroid Build Coastguard Worker "--uncompressed-assets=@FileArg($_rebased_build_config:deps_info:uncompressed_assets)", 2875*8975f5c5SAndroid Build Coastguard Worker ] 2876*8975f5c5SAndroid Build Coastguard Worker if (!_is_robolectric_apk) { 2877*8975f5c5SAndroid Build Coastguard Worker _args += [ "--java-resources=@FileArg($_rebased_build_config:java_resources_jars)" ] 2878*8975f5c5SAndroid Build Coastguard Worker } 2879*8975f5c5SAndroid Build Coastguard Worker } 2880*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.extra_assets)) { 2881*8975f5c5SAndroid Build Coastguard Worker _args += [ "--assets=${invoker.extra_assets}" ] 2882*8975f5c5SAndroid Build Coastguard Worker } 2883*8975f5c5SAndroid Build Coastguard Worker if (!_is_robolectric_apk) { 2884*8975f5c5SAndroid Build Coastguard Worker _apksigner = "$android_sdk_build_tools/lib/apksigner.jar" 2885*8975f5c5SAndroid Build Coastguard Worker _zipalign = "$android_sdk_build_tools/zipalign" 2886*8975f5c5SAndroid Build Coastguard Worker _keystore_path = android_keystore_path 2887*8975f5c5SAndroid Build Coastguard Worker _keystore_name = android_keystore_name 2888*8975f5c5SAndroid Build Coastguard Worker _keystore_password = android_keystore_password 2889*8975f5c5SAndroid Build Coastguard Worker 2890*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.keystore_path)) { 2891*8975f5c5SAndroid Build Coastguard Worker _keystore_path = invoker.keystore_path 2892*8975f5c5SAndroid Build Coastguard Worker _keystore_name = invoker.keystore_name 2893*8975f5c5SAndroid Build Coastguard Worker _keystore_password = invoker.keystore_password 2894*8975f5c5SAndroid Build Coastguard Worker } 2895*8975f5c5SAndroid Build Coastguard Worker 2896*8975f5c5SAndroid Build Coastguard Worker _inputs += [ 2897*8975f5c5SAndroid Build Coastguard Worker _apksigner, 2898*8975f5c5SAndroid Build Coastguard Worker _zipalign, 2899*8975f5c5SAndroid Build Coastguard Worker _keystore_path, 2900*8975f5c5SAndroid Build Coastguard Worker ] 2901*8975f5c5SAndroid Build Coastguard Worker _args += [ 2902*8975f5c5SAndroid Build Coastguard Worker "--apksigner-jar", 2903*8975f5c5SAndroid Build Coastguard Worker rebase_path(_apksigner, root_build_dir), 2904*8975f5c5SAndroid Build Coastguard Worker "--zipalign-path", 2905*8975f5c5SAndroid Build Coastguard Worker rebase_path(_zipalign, root_build_dir), 2906*8975f5c5SAndroid Build Coastguard Worker "--key-path", 2907*8975f5c5SAndroid Build Coastguard Worker rebase_path(_keystore_path, root_build_dir), 2908*8975f5c5SAndroid Build Coastguard Worker "--key-name", 2909*8975f5c5SAndroid Build Coastguard Worker _keystore_name, 2910*8975f5c5SAndroid Build Coastguard Worker "--key-passwd", 2911*8975f5c5SAndroid Build Coastguard Worker _keystore_password, 2912*8975f5c5SAndroid Build Coastguard Worker ] 2913*8975f5c5SAndroid Build Coastguard Worker if (is_official_build) { 2914*8975f5c5SAndroid Build Coastguard Worker _args += [ "--best-compression" ] 2915*8975f5c5SAndroid Build Coastguard Worker } 2916*8975f5c5SAndroid Build Coastguard Worker } 2917*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.uncompress_dex)) { 2918*8975f5c5SAndroid Build Coastguard Worker _uncompress_dex = invoker.uncompress_dex 2919*8975f5c5SAndroid Build Coastguard Worker } else { 2920*8975f5c5SAndroid Build Coastguard Worker # Uncompressed dex support started on Android P. 2921*8975f5c5SAndroid Build Coastguard Worker _uncompress_dex = invoker.min_sdk_version >= 28 2922*8975f5c5SAndroid Build Coastguard Worker } 2923*8975f5c5SAndroid Build Coastguard Worker 2924*8975f5c5SAndroid Build Coastguard Worker if (_uncompress_dex) { 2925*8975f5c5SAndroid Build Coastguard Worker _args += [ "--uncompress-dex" ] 2926*8975f5c5SAndroid Build Coastguard Worker } 2927*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.library_always_compress)) { 2928*8975f5c5SAndroid Build Coastguard Worker _args += 2929*8975f5c5SAndroid Build Coastguard Worker [ "--library-always-compress=${invoker.library_always_compress}" ] 2930*8975f5c5SAndroid Build Coastguard Worker } 2931*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.dex_path)) { 2932*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.dex_path ] 2933*8975f5c5SAndroid Build Coastguard Worker _args += [ 2934*8975f5c5SAndroid Build Coastguard Worker "--dex-file", 2935*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.dex_path, root_build_dir), 2936*8975f5c5SAndroid Build Coastguard Worker ] 2937*8975f5c5SAndroid Build Coastguard Worker } 2938*8975f5c5SAndroid Build Coastguard Worker if ((defined(invoker.loadable_modules) && invoker.loadable_modules != []) || 2939*8975f5c5SAndroid Build Coastguard Worker defined(invoker.native_libs_filearg) || 2940*8975f5c5SAndroid Build Coastguard Worker _native_lib_placeholders != []) { 2941*8975f5c5SAndroid Build Coastguard Worker _args += [ "--android-abi=$android_app_abi" ] 2942*8975f5c5SAndroid Build Coastguard Worker } 2943*8975f5c5SAndroid Build Coastguard Worker if (defined(android_app_secondary_abi)) { 2944*8975f5c5SAndroid Build Coastguard Worker _args += [ "--secondary-android-abi=$android_app_secondary_abi" ] 2945*8975f5c5SAndroid Build Coastguard Worker } 2946*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.loadable_modules) && invoker.loadable_modules != []) { 2947*8975f5c5SAndroid Build Coastguard Worker _inputs += invoker.loadable_modules 2948*8975f5c5SAndroid Build Coastguard Worker _rebased_loadable_modules = 2949*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.loadable_modules, root_build_dir) 2950*8975f5c5SAndroid Build Coastguard Worker _args += [ "--native-libs=$_rebased_loadable_modules" ] 2951*8975f5c5SAndroid Build Coastguard Worker } 2952*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.native_libs_filearg)) { 2953*8975f5c5SAndroid Build Coastguard Worker _args += [ "--native-libs=${invoker.native_libs_filearg}" ] 2954*8975f5c5SAndroid Build Coastguard Worker } 2955*8975f5c5SAndroid Build Coastguard Worker if (_native_lib_placeholders != []) { 2956*8975f5c5SAndroid Build Coastguard Worker _args += [ "--native-lib-placeholders=$_native_lib_placeholders" ] 2957*8975f5c5SAndroid Build Coastguard Worker } 2958*8975f5c5SAndroid Build Coastguard Worker 2959*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.secondary_abi_native_libs_filearg)) { 2960*8975f5c5SAndroid Build Coastguard Worker _args += [ 2961*8975f5c5SAndroid Build Coastguard Worker "--secondary-native-libs=${invoker.secondary_abi_native_libs_filearg}", 2962*8975f5c5SAndroid Build Coastguard Worker ] 2963*8975f5c5SAndroid Build Coastguard Worker } 2964*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.secondary_abi_loadable_modules)) { 2965*8975f5c5SAndroid Build Coastguard Worker _inputs += invoker.secondary_abi_loadable_modules 2966*8975f5c5SAndroid Build Coastguard Worker _rebased_secondary_abi_loadable_modules = 2967*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.secondary_abi_loadable_modules, root_build_dir) 2968*8975f5c5SAndroid Build Coastguard Worker _args += 2969*8975f5c5SAndroid Build Coastguard Worker [ "--secondary-native-libs=$_rebased_secondary_abi_loadable_modules" ] 2970*8975f5c5SAndroid Build Coastguard Worker } 2971*8975f5c5SAndroid Build Coastguard Worker if (_secondary_native_lib_placeholders != []) { 2972*8975f5c5SAndroid Build Coastguard Worker _args += [ "--secondary-native-lib-placeholders=$_secondary_native_lib_placeholders" ] 2973*8975f5c5SAndroid Build Coastguard Worker } 2974*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 2975*8975f5c5SAndroid Build Coastguard Worker _args += [ "--warnings-as-errors" ] 2976*8975f5c5SAndroid Build Coastguard Worker } 2977*8975f5c5SAndroid Build Coastguard Worker 2978*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_libs_and_assets)) { 2979*8975f5c5SAndroid Build Coastguard Worker _expectations_target = 2980*8975f5c5SAndroid Build Coastguard Worker "${invoker.top_target_name}_validate_libs_and_assets" 2981*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(_expectations_target) { 2982*8975f5c5SAndroid Build Coastguard Worker _actual_file = "$target_gen_dir/$target_name.libs_and_assets" 2983*8975f5c5SAndroid Build Coastguard Worker _failure_file = 2984*8975f5c5SAndroid Build Coastguard Worker "$expectations_failure_dir/" + 2985*8975f5c5SAndroid Build Coastguard Worker string_replace(invoker.expected_libs_and_assets, "/", "_") 2986*8975f5c5SAndroid Build Coastguard Worker inputs = [ invoker.expected_libs_and_assets ] 2987*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.build_config)) { 2988*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.build_config ] 2989*8975f5c5SAndroid Build Coastguard Worker } 2990*8975f5c5SAndroid Build Coastguard Worker deps = [ invoker.build_config_dep ] 2991*8975f5c5SAndroid Build Coastguard Worker outputs = [ 2992*8975f5c5SAndroid Build Coastguard Worker _actual_file, 2993*8975f5c5SAndroid Build Coastguard Worker _failure_file, 2994*8975f5c5SAndroid Build Coastguard Worker ] 2995*8975f5c5SAndroid Build Coastguard Worker script = _script 2996*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 2997*8975f5c5SAndroid Build Coastguard Worker "--expected-file", 2998*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_libs_and_assets, root_build_dir), 2999*8975f5c5SAndroid Build Coastguard Worker "--actual-file", 3000*8975f5c5SAndroid Build Coastguard Worker rebase_path(_actual_file, root_build_dir), 3001*8975f5c5SAndroid Build Coastguard Worker "--failure-file", 3002*8975f5c5SAndroid Build Coastguard Worker rebase_path(_failure_file, root_build_dir), 3003*8975f5c5SAndroid Build Coastguard Worker "--only-verify-expectations", 3004*8975f5c5SAndroid Build Coastguard Worker ] 3005*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_libs_and_assets_base)) { 3006*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.expected_libs_and_assets_base ] 3007*8975f5c5SAndroid Build Coastguard Worker args += [ 3008*8975f5c5SAndroid Build Coastguard Worker "--expected-file-base", 3009*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_libs_and_assets_base, root_build_dir), 3010*8975f5c5SAndroid Build Coastguard Worker ] 3011*8975f5c5SAndroid Build Coastguard Worker } 3012*8975f5c5SAndroid Build Coastguard Worker if (fail_on_android_expectations) { 3013*8975f5c5SAndroid Build Coastguard Worker args += [ "--fail-on-expectations" ] 3014*8975f5c5SAndroid Build Coastguard Worker } 3015*8975f5c5SAndroid Build Coastguard Worker } 3016*8975f5c5SAndroid Build Coastguard Worker _deps += [ ":$_expectations_target" ] 3017*8975f5c5SAndroid Build Coastguard Worker } 3018*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 3019*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 3020*8975f5c5SAndroid Build Coastguard Worker inputs = _inputs 3021*8975f5c5SAndroid Build Coastguard Worker deps = _deps 3022*8975f5c5SAndroid Build Coastguard Worker data = _data 3023*8975f5c5SAndroid Build Coastguard Worker outputs = _outputs 3024*8975f5c5SAndroid Build Coastguard Worker script = _script 3025*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 3026*8975f5c5SAndroid Build Coastguard Worker "--depfile", 3027*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 3028*8975f5c5SAndroid Build Coastguard Worker ] 3029*8975f5c5SAndroid Build Coastguard Worker } 3030*8975f5c5SAndroid Build Coastguard Worker } 3031*8975f5c5SAndroid Build Coastguard Worker 3032*8975f5c5SAndroid Build Coastguard Worker # Compile Java source files into a .jar file, potentially using an 3033*8975f5c5SAndroid Build Coastguard Worker # annotation processor, and/or the errorprone compiler. Also includes Kotlin 3034*8975f5c5SAndroid Build Coastguard Worker # source files in the resulting info file. 3035*8975f5c5SAndroid Build Coastguard Worker # 3036*8975f5c5SAndroid Build Coastguard Worker # Note that the only way to specify custom annotation processors is 3037*8975f5c5SAndroid Build Coastguard Worker # by using build_config to point to a file that corresponds to a java-related 3038*8975f5c5SAndroid Build Coastguard Worker # target that includes javac:processor_classes entries (i.e. there is no 3039*8975f5c5SAndroid Build Coastguard Worker # variable here that can be used for this purpose). 3040*8975f5c5SAndroid Build Coastguard Worker # 3041*8975f5c5SAndroid Build Coastguard Worker # Note also the peculiar use of source_files / target_sources_file. The content 3042*8975f5c5SAndroid Build Coastguard Worker # of the source_files list and the source files in target_sources_file file must 3043*8975f5c5SAndroid Build Coastguard Worker # match exactly. 3044*8975f5c5SAndroid Build Coastguard Worker # 3045*8975f5c5SAndroid Build Coastguard Worker # Variables: 3046*8975f5c5SAndroid Build Coastguard Worker # main_target_name: Used when extracting srcjars for codesearch. 3047*8975f5c5SAndroid Build Coastguard Worker # source_files: Optional list of Java and Kotlin source file paths. 3048*8975f5c5SAndroid Build Coastguard Worker # srcjar_deps: Optional list of .srcjar dependencies (not file paths). 3049*8975f5c5SAndroid Build Coastguard Worker # The corresponding source files they contain will be compiled too. 3050*8975f5c5SAndroid Build Coastguard Worker # target_sources_file: Optional path to file containing list of source file 3051*8975f5c5SAndroid Build Coastguard Worker # paths. This must always be provided if java_files is not empty and the 3052*8975f5c5SAndroid Build Coastguard Worker # .java files in it must match the list of java_files exactly. 3053*8975f5c5SAndroid Build Coastguard Worker # build_config: Path to the .build_config.json file of the corresponding 3054*8975f5c5SAndroid Build Coastguard Worker # java_library_impl() target. The following entries will be used by this 3055*8975f5c5SAndroid Build Coastguard Worker # template: javac:srcjars, deps_info:javac_full_classpath, 3056*8975f5c5SAndroid Build Coastguard Worker # deps_info:javac_full_interface_classpath, javac:processor_classpath, 3057*8975f5c5SAndroid Build Coastguard Worker # javac:processor_classes 3058*8975f5c5SAndroid Build Coastguard Worker # javac_jar_path: Path to the final output .jar file. 3059*8975f5c5SAndroid Build Coastguard Worker # javac_args: Optional list of extra arguments to pass to javac. 3060*8975f5c5SAndroid Build Coastguard Worker # chromium_code: Whether this corresponds to Chromium-specific sources. 3061*8975f5c5SAndroid Build Coastguard Worker # requires_android: True if these sources can only run on Android. 3062*8975f5c5SAndroid Build Coastguard Worker # additional_jar_files: Optional list of files to copy into the resulting 3063*8975f5c5SAndroid Build Coastguard Worker # .jar file (by default, only .class files are put there). Each entry 3064*8975f5c5SAndroid Build Coastguard Worker # has the 'srcPath:dstPath' format. 3065*8975f5c5SAndroid Build Coastguard Worker # enable_errorprone: If True, use the errorprone compiler to check for 3066*8975f5c5SAndroid Build Coastguard Worker # error-prone constructs in the language. If not provided, whether this is 3067*8975f5c5SAndroid Build Coastguard Worker # enabled depends on chromium_code and the global 3068*8975f5c5SAndroid Build Coastguard Worker # use_errorprone_java_compiler variable. 3069*8975f5c5SAndroid Build Coastguard Worker # enable_nullaway: If True, enable @Nullable checking via NullAway. 3070*8975f5c5SAndroid Build Coastguard Worker # use_turbine: If True, compile headers using turbine.py. 3071*8975f5c5SAndroid Build Coastguard Worker # apk_name: Optional APK name. If provided, will tell compile_java.py to also 3072*8975f5c5SAndroid Build Coastguard Worker # generate an .apk.jar.info file under size-info/${apk_name}.apk.jar.info 3073*8975f5c5SAndroid Build Coastguard Worker # processor_args_javac: List of annotation processor arguments, each one 3074*8975f5c5SAndroid Build Coastguard Worker # will be passed to javac as -A<entry>. 3075*8975f5c5SAndroid Build Coastguard Worker # deps: Dependencies for the corresponding target. 3076*8975f5c5SAndroid Build Coastguard Worker # testonly: Usual meaning (should be True for test-only targets) 3077*8975f5c5SAndroid Build Coastguard Worker # 3078*8975f5c5SAndroid Build Coastguard Worker # [1] https://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html 3079*8975f5c5SAndroid Build Coastguard Worker # 3080*8975f5c5SAndroid Build Coastguard Worker template("compile_java") { 3081*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 3082*8975f5c5SAndroid Build Coastguard Worker 3083*8975f5c5SAndroid Build Coastguard Worker _build_config = invoker.build_config 3084*8975f5c5SAndroid Build Coastguard Worker _chromium_code = invoker.chromium_code 3085*8975f5c5SAndroid Build Coastguard Worker 3086*8975f5c5SAndroid Build Coastguard Worker _processor_args = [] 3087*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.processor_args_javac)) { 3088*8975f5c5SAndroid Build Coastguard Worker _processor_args = invoker.processor_args_javac 3089*8975f5c5SAndroid Build Coastguard Worker } 3090*8975f5c5SAndroid Build Coastguard Worker 3091*8975f5c5SAndroid Build Coastguard Worker _additional_jar_files = [] 3092*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.additional_jar_files)) { 3093*8975f5c5SAndroid Build Coastguard Worker _additional_jar_files = invoker.additional_jar_files 3094*8975f5c5SAndroid Build Coastguard Worker } 3095*8975f5c5SAndroid Build Coastguard Worker 3096*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps = [] 3097*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjar_deps)) { 3098*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps = invoker.srcjar_deps 3099*8975f5c5SAndroid Build Coastguard Worker } 3100*8975f5c5SAndroid Build Coastguard Worker 3101*8975f5c5SAndroid Build Coastguard Worker _java_srcjars = [] 3102*8975f5c5SAndroid Build Coastguard Worker foreach(dep, _srcjar_deps) { 3103*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(dep, "target_gen_dir") 3104*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(dep, "name") 3105*8975f5c5SAndroid Build Coastguard Worker _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] 3106*8975f5c5SAndroid Build Coastguard Worker } 3107*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjars)) { 3108*8975f5c5SAndroid Build Coastguard Worker _java_srcjars += invoker.srcjars 3109*8975f5c5SAndroid Build Coastguard Worker } 3110*8975f5c5SAndroid Build Coastguard Worker 3111*8975f5c5SAndroid Build Coastguard Worker # generated_jar_path is an output when use_turbine and an input otherwise. 3112*8975f5c5SAndroid Build Coastguard Worker if (!invoker.use_turbine && defined(invoker.generated_jar_path)) { 3113*8975f5c5SAndroid Build Coastguard Worker _java_srcjars += [ invoker.generated_jar_path ] 3114*8975f5c5SAndroid Build Coastguard Worker } 3115*8975f5c5SAndroid Build Coastguard Worker 3116*8975f5c5SAndroid Build Coastguard Worker _javac_args = [] 3117*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.javac_args)) { 3118*8975f5c5SAndroid Build Coastguard Worker _javac_args = invoker.javac_args 3119*8975f5c5SAndroid Build Coastguard Worker } 3120*8975f5c5SAndroid Build Coastguard Worker 3121*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 3122*8975f5c5SAndroid Build Coastguard Worker if (invoker.use_turbine) { 3123*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/turbine.py" 3124*8975f5c5SAndroid Build Coastguard Worker inputs = [ 3125*8975f5c5SAndroid Build Coastguard Worker "//third_party/jdk/current/bin/java", 3126*8975f5c5SAndroid Build Coastguard Worker android_sdk_jar, 3127*8975f5c5SAndroid Build Coastguard Worker ] 3128*8975f5c5SAndroid Build Coastguard Worker } else { 3129*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/compile_java.py" 3130*8975f5c5SAndroid Build Coastguard Worker inputs = javac_paths_for_inputs 3131*8975f5c5SAndroid Build Coastguard Worker } 3132*8975f5c5SAndroid Build Coastguard Worker 3133*8975f5c5SAndroid Build Coastguard Worker if (target_name == "chrome_java__header") { 3134*8975f5c5SAndroid Build Coastguard Worker # Regression test for: https://crbug.com/1154302 3135*8975f5c5SAndroid Build Coastguard Worker # Ensures that header jars never depend on non-header jars. 3136*8975f5c5SAndroid Build Coastguard Worker assert_no_deps = [ "//base:base_java__compile_java" ] 3137*8975f5c5SAndroid Build Coastguard Worker } 3138*8975f5c5SAndroid Build Coastguard Worker 3139*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 3140*8975f5c5SAndroid Build Coastguard Worker deps = _srcjar_deps 3141*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 3142*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 3143*8975f5c5SAndroid Build Coastguard Worker } 3144*8975f5c5SAndroid Build Coastguard Worker 3145*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output_jar_path ] 3146*8975f5c5SAndroid Build Coastguard Worker if (!invoker.enable_errorprone && !invoker.use_turbine) { 3147*8975f5c5SAndroid Build Coastguard Worker outputs += [ invoker.output_jar_path + ".info" ] 3148*8975f5c5SAndroid Build Coastguard Worker } 3149*8975f5c5SAndroid Build Coastguard Worker inputs += invoker.source_files + _java_srcjars + [ 3150*8975f5c5SAndroid Build Coastguard Worker "$android_sdk/optional/android.test.base.jar", 3151*8975f5c5SAndroid Build Coastguard Worker "$android_sdk/optional/org.apache.http.legacy.jar", 3152*8975f5c5SAndroid Build Coastguard Worker _build_config, 3153*8975f5c5SAndroid Build Coastguard Worker ] + java_paths_for_inputs 3154*8975f5c5SAndroid Build Coastguard Worker 3155*8975f5c5SAndroid Build Coastguard Worker if (invoker.source_files != []) { 3156*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.target_sources_file ] 3157*8975f5c5SAndroid Build Coastguard Worker } 3158*8975f5c5SAndroid Build Coastguard Worker 3159*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 3160*8975f5c5SAndroid Build Coastguard Worker _rebased_output_jar_path = 3161*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_jar_path, root_build_dir) 3162*8975f5c5SAndroid Build Coastguard Worker _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) 3163*8975f5c5SAndroid Build Coastguard Worker _rebased_depfile = rebase_path(depfile, root_build_dir) 3164*8975f5c5SAndroid Build Coastguard Worker _rebased_generated_dir = rebase_path( 3165*8975f5c5SAndroid Build Coastguard Worker "$target_gen_dir/${invoker.main_target_name}/generated_java", 3166*8975f5c5SAndroid Build Coastguard Worker root_build_dir) 3167*8975f5c5SAndroid Build Coastguard Worker args = [ 3168*8975f5c5SAndroid Build Coastguard Worker "--depfile=$_rebased_depfile", 3169*8975f5c5SAndroid Build Coastguard Worker "--generated-dir=$_rebased_generated_dir", 3170*8975f5c5SAndroid Build Coastguard Worker "--jar-path=$_rebased_output_jar_path", 3171*8975f5c5SAndroid Build Coastguard Worker "--java-srcjars=$_rebased_java_srcjars", 3172*8975f5c5SAndroid Build Coastguard Worker "--target-name", 3173*8975f5c5SAndroid Build Coastguard Worker get_label_info(":${target_name}", "label_no_toolchain"), 3174*8975f5c5SAndroid Build Coastguard Worker ] 3175*8975f5c5SAndroid Build Coastguard Worker 3176*8975f5c5SAndroid Build Coastguard Worker # SDK jar must be first on classpath. 3177*8975f5c5SAndroid Build Coastguard Worker if (invoker.include_android_sdk) { 3178*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=@FileArg($_rebased_build_config:android:sdk_interface_jars)" ] 3179*8975f5c5SAndroid Build Coastguard Worker } 3180*8975f5c5SAndroid Build Coastguard Worker 3181*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.header_jar_path)) { 3182*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.header_jar_path ] 3183*8975f5c5SAndroid Build Coastguard Worker args += [ 3184*8975f5c5SAndroid Build Coastguard Worker "--header-jar", 3185*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.header_jar_path, root_build_dir), 3186*8975f5c5SAndroid Build Coastguard Worker ] 3187*8975f5c5SAndroid Build Coastguard Worker _header_jar_classpath = 3188*8975f5c5SAndroid Build Coastguard Worker [ rebase_path(invoker.header_jar_path, root_build_dir) ] 3189*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=$_header_jar_classpath" ] 3190*8975f5c5SAndroid Build Coastguard Worker } 3191*8975f5c5SAndroid Build Coastguard Worker 3192*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.kotlin_jar_path)) { 3193*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.kotlin_jar_path ] 3194*8975f5c5SAndroid Build Coastguard Worker _rebased_kotlin_jar_path = 3195*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.kotlin_jar_path, root_build_dir) 3196*8975f5c5SAndroid Build Coastguard Worker args += [ 3197*8975f5c5SAndroid Build Coastguard Worker "--kotlin-jar-path=$_rebased_kotlin_jar_path", 3198*8975f5c5SAndroid Build Coastguard Worker "--classpath=$_rebased_kotlin_jar_path", 3199*8975f5c5SAndroid Build Coastguard Worker ] 3200*8975f5c5SAndroid Build Coastguard Worker } 3201*8975f5c5SAndroid Build Coastguard Worker 3202*8975f5c5SAndroid Build Coastguard Worker if (invoker.use_turbine) { 3203*8975f5c5SAndroid Build Coastguard Worker # Prefer direct deps for turbine as much as possible. 3204*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=@FileArg($_rebased_build_config:javac:interface_classpath)" ] 3205*8975f5c5SAndroid Build Coastguard Worker } else { 3206*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)" ] 3207*8975f5c5SAndroid Build Coastguard Worker } 3208*8975f5c5SAndroid Build Coastguard Worker 3209*8975f5c5SAndroid Build Coastguard Worker if (invoker.use_turbine) { 3210*8975f5c5SAndroid Build Coastguard Worker args += [ 3211*8975f5c5SAndroid Build Coastguard Worker "--processorpath=@FileArg($_rebased_build_config:javac:processor_classpath)", 3212*8975f5c5SAndroid Build Coastguard Worker "--processors=@FileArg($_rebased_build_config:javac:processor_classes)", 3213*8975f5c5SAndroid Build Coastguard Worker ] 3214*8975f5c5SAndroid Build Coastguard Worker } 3215*8975f5c5SAndroid Build Coastguard Worker 3216*8975f5c5SAndroid Build Coastguard Worker if (invoker.use_turbine) { 3217*8975f5c5SAndroid Build Coastguard Worker _turbine_jar_path = "//third_party/turbine/cipd/turbine.jar" 3218*8975f5c5SAndroid Build Coastguard Worker inputs += [ _turbine_jar_path ] 3219*8975f5c5SAndroid Build Coastguard Worker outputs += [ invoker.generated_jar_path ] 3220*8975f5c5SAndroid Build Coastguard Worker args += [ 3221*8975f5c5SAndroid Build Coastguard Worker "--turbine-jar-path", 3222*8975f5c5SAndroid Build Coastguard Worker rebase_path(_turbine_jar_path, root_build_dir), 3223*8975f5c5SAndroid Build Coastguard Worker "--generated-jar-path", 3224*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.generated_jar_path, root_build_dir), 3225*8975f5c5SAndroid Build Coastguard Worker ] 3226*8975f5c5SAndroid Build Coastguard Worker } 3227*8975f5c5SAndroid Build Coastguard Worker 3228*8975f5c5SAndroid Build Coastguard Worker # Flag enable_kythe_annotations requires 3229*8975f5c5SAndroid Build Coastguard Worker # checkout_android_prebuilts_build_tools=True in .gclient. 3230*8975f5c5SAndroid Build Coastguard Worker if (enable_kythe_annotations && !invoker.enable_errorprone) { 3231*8975f5c5SAndroid Build Coastguard Worker args += [ "--enable-kythe-annotations" ] 3232*8975f5c5SAndroid Build Coastguard Worker } 3233*8975f5c5SAndroid Build Coastguard Worker if (_chromium_code) { 3234*8975f5c5SAndroid Build Coastguard Worker args += [ "--chromium-code=1" ] 3235*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 3236*8975f5c5SAndroid Build Coastguard Worker args += [ "--warnings-as-errors" ] 3237*8975f5c5SAndroid Build Coastguard Worker } 3238*8975f5c5SAndroid Build Coastguard Worker } 3239*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.jar_excluded_patterns)) { 3240*8975f5c5SAndroid Build Coastguard Worker args += [ "--jar-info-exclude-globs=${invoker.jar_excluded_patterns}" ] 3241*8975f5c5SAndroid Build Coastguard Worker } 3242*8975f5c5SAndroid Build Coastguard Worker 3243*8975f5c5SAndroid Build Coastguard Worker if (invoker.enable_errorprone) { 3244*8975f5c5SAndroid Build Coastguard Worker # Our custom plugin pulls in the main errorprone dep transitively. 3245*8975f5c5SAndroid Build Coastguard Worker _errorprone_dep = "//tools/android/errorprone_plugin:errorprone_plugin" 3246*8975f5c5SAndroid Build Coastguard Worker deps += [ _errorprone_dep ] 3247*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(_errorprone_dep, "target_gen_dir") 3248*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(_errorprone_dep, "name") 3249*8975f5c5SAndroid Build Coastguard Worker _rebased_errorprone_buildconfig = 3250*8975f5c5SAndroid Build Coastguard Worker rebase_path("$_dep_gen_dir/$_dep_name.build_config.json", 3251*8975f5c5SAndroid Build Coastguard Worker root_build_dir) 3252*8975f5c5SAndroid Build Coastguard Worker args += [ 3253*8975f5c5SAndroid Build Coastguard Worker "--processorpath=@FileArg($_rebased_errorprone_buildconfig:deps_info:host_classpath)", 3254*8975f5c5SAndroid Build Coastguard Worker "--enable-errorprone", 3255*8975f5c5SAndroid Build Coastguard Worker ] 3256*8975f5c5SAndroid Build Coastguard Worker inputs += [ 3257*8975f5c5SAndroid Build Coastguard Worker # errorprone requires the plugin directory to detect src dir. 3258*8975f5c5SAndroid Build Coastguard Worker # https://source.chromium.org/chromium/chromium/src/+/main:tools/android/errorprone_plugin/src/org/chromium/tools/errorprone/plugin/UseNetworkAnnotations.java;l=84;drc=dfd88085261b662a5c0a1abea1a3b120b08e8e48 3259*8975f5c5SAndroid Build Coastguard Worker "//tools/android/errorprone_plugin/OWNERS", 3260*8975f5c5SAndroid Build Coastguard Worker ] 3261*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.enable_nullaway) && invoker.enable_nullaway) { 3262*8975f5c5SAndroid Build Coastguard Worker inputs += [ _nullaway_jar ] 3263*8975f5c5SAndroid Build Coastguard Worker args += [ 3264*8975f5c5SAndroid Build Coastguard Worker "--processorpath=$_rebased_nullaway_jar", 3265*8975f5c5SAndroid Build Coastguard Worker "--enable-nullaway", 3266*8975f5c5SAndroid Build Coastguard Worker ] 3267*8975f5c5SAndroid Build Coastguard Worker } 3268*8975f5c5SAndroid Build Coastguard Worker if (defined(testonly) && testonly) { 3269*8975f5c5SAndroid Build Coastguard Worker args += [ "--testonly" ] 3270*8975f5c5SAndroid Build Coastguard Worker } 3271*8975f5c5SAndroid Build Coastguard Worker } 3272*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.skip_build_server) && invoker.skip_build_server) { 3273*8975f5c5SAndroid Build Coastguard Worker # Nocompile tests need lint to fail through ninja. 3274*8975f5c5SAndroid Build Coastguard Worker args += [ "--skip-build-server" ] 3275*8975f5c5SAndroid Build Coastguard Worker } else if (android_static_analysis == "build_server") { 3276*8975f5c5SAndroid Build Coastguard Worker args += [ "--use-build-server" ] 3277*8975f5c5SAndroid Build Coastguard Worker if (experimental_build_server) { 3278*8975f5c5SAndroid Build Coastguard Worker args += [ "--experimental-build-server" ] 3279*8975f5c5SAndroid Build Coastguard Worker } 3280*8975f5c5SAndroid Build Coastguard Worker } 3281*8975f5c5SAndroid Build Coastguard Worker 3282*8975f5c5SAndroid Build Coastguard Worker foreach(e, _processor_args) { 3283*8975f5c5SAndroid Build Coastguard Worker args += [ "--processor-arg=" + e ] 3284*8975f5c5SAndroid Build Coastguard Worker } 3285*8975f5c5SAndroid Build Coastguard Worker 3286*8975f5c5SAndroid Build Coastguard Worker foreach(file_tuple, _additional_jar_files) { 3287*8975f5c5SAndroid Build Coastguard Worker # Each element is of length two, [ path_to_file, path_to_put_in_jar ] 3288*8975f5c5SAndroid Build Coastguard Worker inputs += [ file_tuple[0] ] 3289*8975f5c5SAndroid Build Coastguard Worker args += 3290*8975f5c5SAndroid Build Coastguard Worker [ "--additional-jar-file=" + 3291*8975f5c5SAndroid Build Coastguard Worker rebase_path(file_tuple[0], root_build_dir) + ":" + file_tuple[1] ] 3292*8975f5c5SAndroid Build Coastguard Worker } 3293*8975f5c5SAndroid Build Coastguard Worker if (invoker.source_files != []) { 3294*8975f5c5SAndroid Build Coastguard Worker args += 3295*8975f5c5SAndroid Build Coastguard Worker [ "@" + rebase_path(invoker.target_sources_file, root_build_dir) ] 3296*8975f5c5SAndroid Build Coastguard Worker } 3297*8975f5c5SAndroid Build Coastguard Worker foreach(e, _javac_args) { 3298*8975f5c5SAndroid Build Coastguard Worker args += [ "--javac-arg=" + e ] 3299*8975f5c5SAndroid Build Coastguard Worker } 3300*8975f5c5SAndroid Build Coastguard Worker } 3301*8975f5c5SAndroid Build Coastguard Worker } 3302*8975f5c5SAndroid Build Coastguard Worker 3303*8975f5c5SAndroid Build Coastguard Worker # Compile Kotlin source files into .class files and store them in a .jar. 3304*8975f5c5SAndroid Build Coastguard Worker # This explicitly does not run annotation processing on the Kotlin files. 3305*8975f5c5SAndroid Build Coastguard Worker # Java files and srcjars are also passed to kotlinc for reference, although 3306*8975f5c5SAndroid Build Coastguard Worker # no .class files will be generated for any Java files. A subsequent call to 3307*8975f5c5SAndroid Build Coastguard Worker # javac will be required to actually compile Java files into .class files. 3308*8975f5c5SAndroid Build Coastguard Worker # 3309*8975f5c5SAndroid Build Coastguard Worker # This action also creates a "header" .jar file for the Kotlin source files. 3310*8975f5c5SAndroid Build Coastguard Worker # It is similar to using turbine to create headers for Java files, but since 3311*8975f5c5SAndroid Build Coastguard Worker # turbine does not support Kotlin files, this is done via a plugin for 3312*8975f5c5SAndroid Build Coastguard Worker # kotlinc instead, at the same time as compilation (whereas turbine is run as 3313*8975f5c5SAndroid Build Coastguard Worker # a separate action before javac compilation). 3314*8975f5c5SAndroid Build Coastguard Worker template("compile_kt") { 3315*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 3316*8975f5c5SAndroid Build Coastguard Worker 3317*8975f5c5SAndroid Build Coastguard Worker _build_config = invoker.build_config 3318*8975f5c5SAndroid Build Coastguard Worker _chromium_code = invoker.chromium_code 3319*8975f5c5SAndroid Build Coastguard Worker 3320*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps = [] 3321*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjar_deps)) { 3322*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps = invoker.srcjar_deps 3323*8975f5c5SAndroid Build Coastguard Worker } 3324*8975f5c5SAndroid Build Coastguard Worker 3325*8975f5c5SAndroid Build Coastguard Worker _java_srcjars = [] 3326*8975f5c5SAndroid Build Coastguard Worker foreach(dep, _srcjar_deps) { 3327*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(dep, "target_gen_dir") 3328*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(dep, "name") 3329*8975f5c5SAndroid Build Coastguard Worker _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] 3330*8975f5c5SAndroid Build Coastguard Worker } 3331*8975f5c5SAndroid Build Coastguard Worker 3332*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjars)) { 3333*8975f5c5SAndroid Build Coastguard Worker _java_srcjars += invoker.srcjars 3334*8975f5c5SAndroid Build Coastguard Worker } 3335*8975f5c5SAndroid Build Coastguard Worker 3336*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 3337*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/compile_kt.py" 3338*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 3339*8975f5c5SAndroid Build Coastguard Worker deps = _srcjar_deps 3340*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 3341*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 3342*8975f5c5SAndroid Build Coastguard Worker } 3343*8975f5c5SAndroid Build Coastguard Worker 3344*8975f5c5SAndroid Build Coastguard Worker outputs = [ 3345*8975f5c5SAndroid Build Coastguard Worker invoker.output_jar_path, 3346*8975f5c5SAndroid Build Coastguard Worker invoker.output_interface_jar_path, 3347*8975f5c5SAndroid Build Coastguard Worker ] 3348*8975f5c5SAndroid Build Coastguard Worker inputs = kotlinc_paths_for_inputs + java_paths_for_inputs + 3349*8975f5c5SAndroid Build Coastguard Worker invoker.source_files + _java_srcjars + 3350*8975f5c5SAndroid Build Coastguard Worker [ 3351*8975f5c5SAndroid Build Coastguard Worker _build_config, 3352*8975f5c5SAndroid Build Coastguard Worker invoker.target_sources_file, 3353*8975f5c5SAndroid Build Coastguard Worker ] 3354*8975f5c5SAndroid Build Coastguard Worker 3355*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 3356*8975f5c5SAndroid Build Coastguard Worker _rebased_output_jar_path = 3357*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_jar_path, root_build_dir) 3358*8975f5c5SAndroid Build Coastguard Worker _rebased_output_interface_jar_path = 3359*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_interface_jar_path, root_build_dir) 3360*8975f5c5SAndroid Build Coastguard Worker _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) 3361*8975f5c5SAndroid Build Coastguard Worker _rebased_depfile = rebase_path(depfile, root_build_dir) 3362*8975f5c5SAndroid Build Coastguard Worker _rebased_generated_dir = rebase_path( 3363*8975f5c5SAndroid Build Coastguard Worker "$target_gen_dir/${invoker.main_target_name}/generated_java", 3364*8975f5c5SAndroid Build Coastguard Worker root_build_dir) 3365*8975f5c5SAndroid Build Coastguard Worker args = [ 3366*8975f5c5SAndroid Build Coastguard Worker "--depfile=$_rebased_depfile", 3367*8975f5c5SAndroid Build Coastguard Worker "--generated-dir=$_rebased_generated_dir", 3368*8975f5c5SAndroid Build Coastguard Worker "--jar-path=$_rebased_output_jar_path", 3369*8975f5c5SAndroid Build Coastguard Worker "--interface-jar-path=$_rebased_output_interface_jar_path", 3370*8975f5c5SAndroid Build Coastguard Worker "--java-srcjars=$_rebased_java_srcjars", 3371*8975f5c5SAndroid Build Coastguard Worker ] 3372*8975f5c5SAndroid Build Coastguard Worker 3373*8975f5c5SAndroid Build Coastguard Worker # SDK jar must be first on classpath. 3374*8975f5c5SAndroid Build Coastguard Worker if (invoker.include_android_sdk) { 3375*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=@FileArg($_rebased_build_config:android:sdk_interface_jars)" ] 3376*8975f5c5SAndroid Build Coastguard Worker } 3377*8975f5c5SAndroid Build Coastguard Worker 3378*8975f5c5SAndroid Build Coastguard Worker args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)" ] 3379*8975f5c5SAndroid Build Coastguard Worker 3380*8975f5c5SAndroid Build Coastguard Worker if (_chromium_code) { 3381*8975f5c5SAndroid Build Coastguard Worker args += [ "--chromium-code" ] 3382*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 3383*8975f5c5SAndroid Build Coastguard Worker args += [ "--warnings-as-errors" ] 3384*8975f5c5SAndroid Build Coastguard Worker } 3385*8975f5c5SAndroid Build Coastguard Worker } 3386*8975f5c5SAndroid Build Coastguard Worker 3387*8975f5c5SAndroid Build Coastguard Worker args += [ "@" + rebase_path(invoker.target_sources_file, root_build_dir) ] 3388*8975f5c5SAndroid Build Coastguard Worker } 3389*8975f5c5SAndroid Build Coastguard Worker } 3390*8975f5c5SAndroid Build Coastguard Worker 3391*8975f5c5SAndroid Build Coastguard Worker # Create an interface jar from a normal jar. 3392*8975f5c5SAndroid Build Coastguard Worker # 3393*8975f5c5SAndroid Build Coastguard Worker # Variables 3394*8975f5c5SAndroid Build Coastguard Worker # input_jar: Path to input .jar. 3395*8975f5c5SAndroid Build Coastguard Worker # output_jar: Path to output .ijar. 3396*8975f5c5SAndroid Build Coastguard Worker # 3397*8975f5c5SAndroid Build Coastguard Worker template("generate_interface_jar") { 3398*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 3399*8975f5c5SAndroid Build Coastguard Worker _ijar_target = "//third_party/ijar:ijar($host_toolchain)" 3400*8975f5c5SAndroid Build Coastguard Worker _ijar_executable = get_label_info(_ijar_target, "root_out_dir") + "/ijar" 3401*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 3402*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ 3403*8975f5c5SAndroid Build Coastguard Worker "data", 3404*8975f5c5SAndroid Build Coastguard Worker "data_deps", 3405*8975f5c5SAndroid Build Coastguard Worker "public_deps", 3406*8975f5c5SAndroid Build Coastguard Worker ]) 3407*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/ijar.py" 3408*8975f5c5SAndroid Build Coastguard Worker deps = [ _ijar_target ] 3409*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 3410*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 3411*8975f5c5SAndroid Build Coastguard Worker } 3412*8975f5c5SAndroid Build Coastguard Worker inputs = [ 3413*8975f5c5SAndroid Build Coastguard Worker invoker.input_jar, 3414*8975f5c5SAndroid Build Coastguard Worker _ijar_executable, 3415*8975f5c5SAndroid Build Coastguard Worker ] 3416*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.inputs)) { 3417*8975f5c5SAndroid Build Coastguard Worker inputs += invoker.inputs 3418*8975f5c5SAndroid Build Coastguard Worker } 3419*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output_jar ] 3420*8975f5c5SAndroid Build Coastguard Worker args = [ 3421*8975f5c5SAndroid Build Coastguard Worker rebase_path(_ijar_executable, root_build_dir), 3422*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input_jar, root_build_dir), 3423*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output_jar, root_build_dir), 3424*8975f5c5SAndroid Build Coastguard Worker ] 3425*8975f5c5SAndroid Build Coastguard Worker } 3426*8975f5c5SAndroid Build Coastguard Worker } 3427*8975f5c5SAndroid Build Coastguard Worker 3428*8975f5c5SAndroid Build Coastguard Worker # A rule that will handle multiple Java-related targets. 3429*8975f5c5SAndroid Build Coastguard Worker # 3430*8975f5c5SAndroid Build Coastguard Worker # The caller can provide a list of source files with 'java_files' 3431*8975f5c5SAndroid Build Coastguard Worker # and 'srcjar_deps', or a prebuilt .jar file through 'jar_path'. 3432*8975f5c5SAndroid Build Coastguard Worker # 3433*8975f5c5SAndroid Build Coastguard Worker # In the case of a 'java_binary' target type, it can even provide none of 3434*8975f5c5SAndroid Build Coastguard Worker # that (and the rule will just generate its wrapper script). 3435*8975f5c5SAndroid Build Coastguard Worker # 3436*8975f5c5SAndroid Build Coastguard Worker # The template will process the input .jar file (either the prebuilt one, 3437*8975f5c5SAndroid Build Coastguard Worker # or the result of compiling the sources), for example to apply Proguard, 3438*8975f5c5SAndroid Build Coastguard Worker # but also other ranges of bytecode-level rewriting schemes. 3439*8975f5c5SAndroid Build Coastguard Worker # 3440*8975f5c5SAndroid Build Coastguard Worker # Variables: 3441*8975f5c5SAndroid Build Coastguard Worker # type: type of Java target, valid values: 'java_library', 'java_binary', 3442*8975f5c5SAndroid Build Coastguard Worker # 'robolectric_binary', 'java_annotation_processor', and 'android_apk' 3443*8975f5c5SAndroid Build Coastguard Worker # main_target_name: optional. If provided, overrides target_name when 3444*8975f5c5SAndroid Build Coastguard Worker # creating sub-targets (e.g. "${main_target_name}__dex") and 3445*8975f5c5SAndroid Build Coastguard Worker # some output files (e.g. "${main_target_name}.sources"). Only used 3446*8975f5c5SAndroid Build Coastguard Worker # for 'android_apk' types at the moment, where main_target_name will 3447*8975f5c5SAndroid Build Coastguard Worker # be the name of the main APK target. 3448*8975f5c5SAndroid Build Coastguard Worker # supports_android: Optional. True if target can run on Android. 3449*8975f5c5SAndroid Build Coastguard Worker # requires_android: Optional. True if target can only run on Android. 3450*8975f5c5SAndroid Build Coastguard Worker # source_files: Optional list of Java source file paths for this target. 3451*8975f5c5SAndroid Build Coastguard Worker # javac_args: Optional list of extra arguments to pass to javac. 3452*8975f5c5SAndroid Build Coastguard Worker # errorprone_args: Optional list of extra arguments to pass to. 3453*8975f5c5SAndroid Build Coastguard Worker # srcjar_deps: Optional list of .srcjar targets (not file paths). The Java 3454*8975f5c5SAndroid Build Coastguard Worker # source files they contain will also be compiled for this target. 3455*8975f5c5SAndroid Build Coastguard Worker # target_sources_file: Optional path to a file which will be written with 3456*8975f5c5SAndroid Build Coastguard Worker # the content of source_files. If not provided, the file will be written 3457*8975f5c5SAndroid Build Coastguard Worker # under $target_gen_dir/$main_target_name.sources. Ignored if 3458*8975f5c5SAndroid Build Coastguard Worker # sources_files is empty. If not 3459*8975f5c5SAndroid Build Coastguard Worker # jar_path: Optional path to a prebuilt .jar file for this target. 3460*8975f5c5SAndroid Build Coastguard Worker # Mutually exclusive with java_files and srcjar_deps. 3461*8975f5c5SAndroid Build Coastguard Worker # output_name: Optional output name for the final jar path. Used to 3462*8975f5c5SAndroid Build Coastguard Worker # determine the name of the final jar. Default is to use the same 3463*8975f5c5SAndroid Build Coastguard Worker # name as jar_path, if provided, or main_target_name. 3464*8975f5c5SAndroid Build Coastguard Worker # main_class: Main Java class name for 'java_binary', 'robolectric_binary' and 3465*8975f5c5SAndroid Build Coastguard Worker # 'java_annotation_processor' target types. Should not be set for other 3466*8975f5c5SAndroid Build Coastguard Worker # ones. 3467*8975f5c5SAndroid Build Coastguard Worker # deps: Dependencies for this target. 3468*8975f5c5SAndroid Build Coastguard Worker # public_deps: Dependencies that this target exposes as part of its public API. 3469*8975f5c5SAndroid Build Coastguard Worker # public_deps do not need to be listed in both the 'deps' and 'public_deps' lists. 3470*8975f5c5SAndroid Build Coastguard Worker # testonly: True iff target should only be used for tests. 3471*8975f5c5SAndroid Build Coastguard Worker # chromium_code: Optional. Whether this is Chromium-specific code. If not 3472*8975f5c5SAndroid Build Coastguard Worker # provided, this is determined automatically, based on the location of 3473*8975f5c5SAndroid Build Coastguard Worker # the source files (i.e. anything under third_party/ is not 3474*8975f5c5SAndroid Build Coastguard Worker # Chromium-specific unless it is in a 'chromium' sub-directory). 3475*8975f5c5SAndroid Build Coastguard Worker # jacoco_never_instrument: Optional. If provided, whether to forbid 3476*8975f5c5SAndroid Build Coastguard Worker # instrumentation with the Jacoco coverage processor. If not provided, 3477*8975f5c5SAndroid Build Coastguard Worker # this is controlled by the global use_jacoco_coverage build arg variable 3478*8975f5c5SAndroid Build Coastguard Worker # and only used for non-test Chromium code. 3479*8975f5c5SAndroid Build Coastguard Worker # include_android_sdk: Optional. Whether or not the android SDK dep 3480*8975f5c5SAndroid Build Coastguard Worker # should be added to deps. Defaults to true for non-system libraries 3481*8975f5c5SAndroid Build Coastguard Worker # that support android. 3482*8975f5c5SAndroid Build Coastguard Worker # alternative_android_sdk_dep: Optional. Alternative Android system 3483*8975f5c5SAndroid Build Coastguard Worker # android java target to use. 3484*8975f5c5SAndroid Build Coastguard Worker # annotation_processor_deps: Optional list of dependencies corresponding 3485*8975f5c5SAndroid Build Coastguard Worker # to annotation processors used to compile these sources. 3486*8975f5c5SAndroid Build Coastguard Worker # input_jars_paths: Optional list of additional .jar file paths, which will 3487*8975f5c5SAndroid Build Coastguard Worker # be added to the compile-time classpath when building this target (but 3488*8975f5c5SAndroid Build Coastguard Worker # not to the runtime classpath). 3489*8975f5c5SAndroid Build Coastguard Worker # gradle_treat_as_prebuilt: Cause generate_gradle.py to reference this 3490*8975f5c5SAndroid Build Coastguard Worker # library via its built .jar rather than including its .java sources. 3491*8975f5c5SAndroid Build Coastguard Worker # proguard_enabled: Optional. True to enable ProGuard obfuscation. 3492*8975f5c5SAndroid Build Coastguard Worker # proguard_configs: Optional list of additional proguard config file paths. 3493*8975f5c5SAndroid Build Coastguard Worker # is_robolectric: Optional. If True, this is a host side android test binary 3494*8975f5c5SAndroid Build Coastguard Worker # which is allowed to depend on other android targets. 3495*8975f5c5SAndroid Build Coastguard Worker # include_java_resources: Optional. If True, include Java (not Android) 3496*8975f5c5SAndroid Build Coastguard Worker # resources into final .jar file. 3497*8975f5c5SAndroid Build Coastguard Worker # jar_excluded_patterns: Optional list of .class file patterns to exclude 3498*8975f5c5SAndroid Build Coastguard Worker # from the final .jar file. 3499*8975f5c5SAndroid Build Coastguard Worker # jar_included_patterns: Optional list of .class file patterns to include 3500*8975f5c5SAndroid Build Coastguard Worker # in the final .jar file. jar_excluded_patterns take precedence over this. 3501*8975f5c5SAndroid Build Coastguard Worker # low_classpath_priority: Indicates that the library should be placed at the 3502*8975f5c5SAndroid Build Coastguard Worker # end of the classpath. The default classpath order has libraries ordered 3503*8975f5c5SAndroid Build Coastguard Worker # before the libraries that they depend on. 'low_classpath_priority' is 3504*8975f5c5SAndroid Build Coastguard Worker # useful when one java_library() overrides another via 3505*8975f5c5SAndroid Build Coastguard Worker # 'jar_excluded_patterns' and the overriding library does not depend on the 3506*8975f5c5SAndroid Build Coastguard Worker # overridee. 3507*8975f5c5SAndroid Build Coastguard Worker # 3508*8975f5c5SAndroid Build Coastguard Worker # For 'android_apk' and 'android_app_bundle_module' targets only: 3509*8975f5c5SAndroid Build Coastguard Worker # 3510*8975f5c5SAndroid Build Coastguard Worker # apk_path: Path to the final APK file. 3511*8975f5c5SAndroid Build Coastguard Worker # android_manifest: Path to AndroidManifest.xml file for the APK. 3512*8975f5c5SAndroid Build Coastguard Worker # android_manifest_dep: Optional. Dependency target that generates 3513*8975f5c5SAndroid Build Coastguard Worker # android_manifest. 3514*8975f5c5SAndroid Build Coastguard Worker # apk_under_test: For 'android_apk' targets used to test other APKs, 3515*8975f5c5SAndroid Build Coastguard Worker # this is the target name of APK being tested. 3516*8975f5c5SAndroid Build Coastguard Worker # incremental_apk_path: Path to the incremental APK. 3517*8975f5c5SAndroid Build Coastguard Worker # incremental_install_json_path: Path to the incremental install json. 3518*8975f5c5SAndroid Build Coastguard Worker # native_lib_placeholders: Optional. List of placeholder filenames to add to 3519*8975f5c5SAndroid Build Coastguard Worker # the APK. 3520*8975f5c5SAndroid Build Coastguard Worker # proguard_mapping_path: Path to .mapping file produced from ProGuard step. 3521*8975f5c5SAndroid Build Coastguard Worker # shared_libraries_runtime_deps_file: Optional. Path to a file listing the 3522*8975f5c5SAndroid Build Coastguard Worker # native shared libraries required at runtime by the APK. 3523*8975f5c5SAndroid Build Coastguard Worker # secondary_abi_shared_libraries_runtime_deps_file: 3524*8975f5c5SAndroid Build Coastguard Worker # secondary_native_lib_placeholders: Optional. List of placeholder filenames 3525*8975f5c5SAndroid Build Coastguard Worker # to add to the APK for the secondary ABI. 3526*8975f5c5SAndroid Build Coastguard Worker # loadable_modules: Optional list of extra native libraries to 3527*8975f5c5SAndroid Build Coastguard Worker # be stored in the APK. 3528*8975f5c5SAndroid Build Coastguard Worker # secondary_abi_loadable_modules: Optional list of native libraries for 3529*8975f5c5SAndroid Build Coastguard Worker # secondary ABI. 3530*8975f5c5SAndroid Build Coastguard Worker # proto_resources_path: The path of an zip archive containing the APK's 3531*8975f5c5SAndroid Build Coastguard Worker # resources compiled to the protocol buffer format (instead of regular 3532*8975f5c5SAndroid Build Coastguard Worker # binary xml + resources.arsc). 3533*8975f5c5SAndroid Build Coastguard Worker # r_text_path: The path of the R.txt file generated when compiling the 3534*8975f5c5SAndroid Build Coastguard Worker # resources for this target. 3535*8975f5c5SAndroid Build Coastguard Worker # module_pathmap_path: The path of the pathmap file generated when compiling 3536*8975f5c5SAndroid Build Coastguard Worker # the resources for the bundle module, if path shortening is enabled. 3537*8975f5c5SAndroid Build Coastguard Worker # base_allowlist_rtxt_path: The path of the R.txt file containing the 3538*8975f5c5SAndroid Build Coastguard Worker # list of string resources to keep in the base split APK for any bundle 3539*8975f5c5SAndroid Build Coastguard Worker # that uses this target. 3540*8975f5c5SAndroid Build Coastguard Worker # 3541*8975f5c5SAndroid Build Coastguard Worker # For 'java_binary' and 'robolectric_binary' targets only. Ignored by others: 3542*8975f5c5SAndroid Build Coastguard Worker # 3543*8975f5c5SAndroid Build Coastguard Worker # wrapper_script_name: Optional name for the generated wrapper script. 3544*8975f5c5SAndroid Build Coastguard Worker # Default is main target name. 3545*8975f5c5SAndroid Build Coastguard Worker # wrapper_script_args: Optional list of extra arguments used by the 3546*8975f5c5SAndroid Build Coastguard Worker # generated wrapper script. 3547*8975f5c5SAndroid Build Coastguard Worker # 3548*8975f5c5SAndroid Build Coastguard Worker template("java_library_impl") { 3549*8975f5c5SAndroid Build Coastguard Worker # TODO(crbug.com/40114668): Remove. 3550*8975f5c5SAndroid Build Coastguard Worker not_needed(invoker, [ "no_build_hooks" ]) 3551*8975f5c5SAndroid Build Coastguard Worker 3552*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, [ "testonly" ]) 3553*8975f5c5SAndroid Build Coastguard Worker _is_prebuilt = defined(invoker.jar_path) 3554*8975f5c5SAndroid Build Coastguard Worker _type = invoker.type 3555*8975f5c5SAndroid Build Coastguard Worker _is_annotation_processor = _type == "java_annotation_processor" 3556*8975f5c5SAndroid Build Coastguard Worker _is_java_binary = _type == "java_binary" || _type == "robolectric_binary" 3557*8975f5c5SAndroid Build Coastguard Worker _is_library = _type == "java_library" 3558*8975f5c5SAndroid Build Coastguard Worker _supports_android = 3559*8975f5c5SAndroid Build Coastguard Worker defined(invoker.supports_android) && invoker.supports_android 3560*8975f5c5SAndroid Build Coastguard Worker _requires_android = 3561*8975f5c5SAndroid Build Coastguard Worker defined(invoker.requires_android) && invoker.requires_android 3562*8975f5c5SAndroid Build Coastguard Worker _supports_host = !_requires_android 3563*8975f5c5SAndroid Build Coastguard Worker if (_is_java_binary || _is_annotation_processor) { 3564*8975f5c5SAndroid Build Coastguard Worker assert(!_requires_android && !_supports_android) 3565*8975f5c5SAndroid Build Coastguard Worker } 3566*8975f5c5SAndroid Build Coastguard Worker 3567*8975f5c5SAndroid Build Coastguard Worker _bypass_platform_checks = defined(invoker.bypass_platform_checks) && 3568*8975f5c5SAndroid Build Coastguard Worker invoker.bypass_platform_checks 3569*8975f5c5SAndroid Build Coastguard Worker _is_robolectric = defined(invoker.is_robolectric) && invoker.is_robolectric 3570*8975f5c5SAndroid Build Coastguard Worker 3571*8975f5c5SAndroid Build Coastguard Worker _invoker_deps = [] 3572*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 3573*8975f5c5SAndroid Build Coastguard Worker _invoker_deps += invoker.deps 3574*8975f5c5SAndroid Build Coastguard Worker } 3575*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.public_deps)) { 3576*8975f5c5SAndroid Build Coastguard Worker _invoker_deps += invoker.public_deps 3577*8975f5c5SAndroid Build Coastguard Worker } 3578*8975f5c5SAndroid Build Coastguard Worker 3579*8975f5c5SAndroid Build Coastguard Worker _main_target_name = target_name 3580*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.main_target_name)) { 3581*8975f5c5SAndroid Build Coastguard Worker _main_target_name = invoker.main_target_name 3582*8975f5c5SAndroid Build Coastguard Worker } 3583*8975f5c5SAndroid Build Coastguard Worker 3584*8975f5c5SAndroid Build Coastguard Worker _source_files = [] 3585*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.sources)) { 3586*8975f5c5SAndroid Build Coastguard Worker _source_files = invoker.sources 3587*8975f5c5SAndroid Build Coastguard Worker } 3588*8975f5c5SAndroid Build Coastguard Worker 3589*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps = [] 3590*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjar_deps)) { 3591*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps = invoker.srcjar_deps 3592*8975f5c5SAndroid Build Coastguard Worker } 3593*8975f5c5SAndroid Build Coastguard Worker _srcjars = [] 3594*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjars)) { 3595*8975f5c5SAndroid Build Coastguard Worker _srcjars = invoker.srcjars 3596*8975f5c5SAndroid Build Coastguard Worker } 3597*8975f5c5SAndroid Build Coastguard Worker _has_sources = _source_files != [] || _srcjar_deps != [] || _srcjars != [] 3598*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt || _has_sources) { 3599*8975f5c5SAndroid Build Coastguard Worker # This allows us to use jar_excluded_patterns and prevent even the 3600*8975f5c5SAndroid Build Coastguard Worker # interface jars from having these classes. This means that, with this 3601*8975f5c5SAndroid Build Coastguard Worker # flag, nobody depending on this java library will be able to see these 3602*8975f5c5SAndroid Build Coastguard Worker # classes. These excluded classes are only used for the exact target they 3603*8975f5c5SAndroid Build Coastguard Worker # are compiled in. We do this by not making a header jar, and replacing 3604*8975f5c5SAndroid Build Coastguard Worker # all usages of the header jar with the processed (post-exclusion) jar. 3605*8975f5c5SAndroid Build Coastguard Worker _skip_header_jar = 3606*8975f5c5SAndroid Build Coastguard Worker defined(invoker.prevent_excluded_classes_from_classpath) && 3607*8975f5c5SAndroid Build Coastguard Worker invoker.prevent_excluded_classes_from_classpath 3608*8975f5c5SAndroid Build Coastguard Worker } 3609*8975f5c5SAndroid Build Coastguard Worker 3610*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt) { 3611*8975f5c5SAndroid Build Coastguard Worker assert(!_has_sources) 3612*8975f5c5SAndroid Build Coastguard Worker } else { 3613*8975f5c5SAndroid Build Coastguard Worker # Allow java_binary to not specify any sources. This is needed when a prebuilt 3614*8975f5c5SAndroid Build Coastguard Worker # is needed as a library as well as a binary. 3615*8975f5c5SAndroid Build Coastguard Worker assert(_is_annotation_processor || _is_java_binary || _has_sources) 3616*8975f5c5SAndroid Build Coastguard Worker } 3617*8975f5c5SAndroid Build Coastguard Worker 3618*8975f5c5SAndroid Build Coastguard Worker if (_is_java_binary) { 3619*8975f5c5SAndroid Build Coastguard Worker assert(defined(invoker.main_class), "${_type}() must set main_class") 3620*8975f5c5SAndroid Build Coastguard Worker } else if (_is_annotation_processor) { 3621*8975f5c5SAndroid Build Coastguard Worker assert(defined(invoker.main_class), 3622*8975f5c5SAndroid Build Coastguard Worker "java_annotation_processor() must set main_class") 3623*8975f5c5SAndroid Build Coastguard Worker } else { 3624*8975f5c5SAndroid Build Coastguard Worker assert(!defined(invoker.main_class), 3625*8975f5c5SAndroid Build Coastguard Worker "main_class cannot be used for target of type ${_type}") 3626*8975f5c5SAndroid Build Coastguard Worker } 3627*8975f5c5SAndroid Build Coastguard Worker 3628*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.chromium_code)) { 3629*8975f5c5SAndroid Build Coastguard Worker _chromium_code = invoker.chromium_code 3630*8975f5c5SAndroid Build Coastguard Worker } else { 3631*8975f5c5SAndroid Build Coastguard Worker # Default based on whether target is in third_party. 3632*8975f5c5SAndroid Build Coastguard Worker _chromium_code = 3633*8975f5c5SAndroid Build Coastguard Worker filter_exclude([ get_label_info(":$_main_target_name", "dir") ], 3634*8975f5c5SAndroid Build Coastguard Worker [ "*\bthird_party\b*" ]) != [] 3635*8975f5c5SAndroid Build Coastguard Worker if (!_chromium_code && !_is_prebuilt && _source_files != []) { 3636*8975f5c5SAndroid Build Coastguard Worker # Unless third_party code has an org.chromium file in it. 3637*8975f5c5SAndroid Build Coastguard Worker _chromium_code = 3638*8975f5c5SAndroid Build Coastguard Worker filter_exclude(_source_files, [ "*\bchromium\b*" ]) != _source_files 3639*8975f5c5SAndroid Build Coastguard Worker } 3640*8975f5c5SAndroid Build Coastguard Worker } 3641*8975f5c5SAndroid Build Coastguard Worker 3642*8975f5c5SAndroid Build Coastguard Worker # Define build_config_deps which will be a list of targets required to 3643*8975f5c5SAndroid Build Coastguard Worker # build the _build_config. 3644*8975f5c5SAndroid Build Coastguard Worker _build_config = "$target_gen_dir/$_main_target_name.build_config.json" 3645*8975f5c5SAndroid Build Coastguard Worker _build_config_target_name = 3646*8975f5c5SAndroid Build Coastguard Worker "${_main_target_name}$build_config_target_suffix" 3647*8975f5c5SAndroid Build Coastguard Worker 3648*8975f5c5SAndroid Build Coastguard Worker # The only target that might have no prebuilt and no sources is a java_binary. 3649*8975f5c5SAndroid Build Coastguard Worker _build_host_jar = false 3650*8975f5c5SAndroid Build Coastguard Worker _build_device_jar = false 3651*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt || _has_sources) { 3652*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.output_name)) { 3653*8975f5c5SAndroid Build Coastguard Worker _output_name = invoker.output_name 3654*8975f5c5SAndroid Build Coastguard Worker } else { 3655*8975f5c5SAndroid Build Coastguard Worker _output_name = _main_target_name 3656*8975f5c5SAndroid Build Coastguard Worker } 3657*8975f5c5SAndroid Build Coastguard Worker 3658*8975f5c5SAndroid Build Coastguard Worker _build_host_jar = _is_java_binary || _is_annotation_processor || 3659*8975f5c5SAndroid Build Coastguard Worker _type == "java_library" || _type == "dist_jar" 3660*8975f5c5SAndroid Build Coastguard Worker _build_device_jar = _type != "system_java_library" && _supports_android 3661*8975f5c5SAndroid Build Coastguard Worker 3662*8975f5c5SAndroid Build Coastguard Worker _jacoco_instrument = 3663*8975f5c5SAndroid Build Coastguard Worker use_jacoco_coverage && _chromium_code && _source_files != [] && 3664*8975f5c5SAndroid Build Coastguard Worker _build_device_jar && (!defined(invoker.testonly) || !invoker.testonly) 3665*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.jacoco_never_instrument)) { 3666*8975f5c5SAndroid Build Coastguard Worker _jacoco_instrument = 3667*8975f5c5SAndroid Build Coastguard Worker !invoker.jacoco_never_instrument && _jacoco_instrument 3668*8975f5c5SAndroid Build Coastguard Worker } 3669*8975f5c5SAndroid Build Coastguard Worker if (_jacoco_instrument) { 3670*8975f5c5SAndroid Build Coastguard Worker _invoker_deps += [ _jacoco_dep ] 3671*8975f5c5SAndroid Build Coastguard Worker } 3672*8975f5c5SAndroid Build Coastguard Worker 3673*8975f5c5SAndroid Build Coastguard Worker if (_build_host_jar) { 3674*8975f5c5SAndroid Build Coastguard Worker # Jar files can be needed at runtime (by Robolectric tests or java binaries), 3675*8975f5c5SAndroid Build Coastguard Worker # so do not put them under obj/. 3676*8975f5c5SAndroid Build Coastguard Worker # TODO(agrieve): I suspect it would be better to use dist_jar for java_binary 3677*8975f5c5SAndroid Build Coastguard Worker # rather than archiving unnecessary .jar files within lib.java. 3678*8975f5c5SAndroid Build Coastguard Worker _target_dir_name = get_label_info(":$_main_target_name", "dir") 3679*8975f5c5SAndroid Build Coastguard Worker _host_processed_jar_path = 3680*8975f5c5SAndroid Build Coastguard Worker "$root_out_dir/lib.java$_target_dir_name/$_output_name.jar" 3681*8975f5c5SAndroid Build Coastguard Worker } 3682*8975f5c5SAndroid Build Coastguard Worker if (_build_device_jar) { 3683*8975f5c5SAndroid Build Coastguard Worker _dex_path = "$target_out_dir/$_main_target_name.dex.jar" 3684*8975f5c5SAndroid Build Coastguard Worker _enable_desugar = 3685*8975f5c5SAndroid Build Coastguard Worker !defined(invoker.enable_desugar) || invoker.enable_desugar 3686*8975f5c5SAndroid Build Coastguard Worker 3687*8975f5c5SAndroid Build Coastguard Worker # Build speed optimization: Skip "process device" step if the step 3688*8975f5c5SAndroid Build Coastguard Worker # would be just a copy and avoid the copy. 3689*8975f5c5SAndroid Build Coastguard Worker _process_device_jar = 3690*8975f5c5SAndroid Build Coastguard Worker defined(invoker.bytecode_rewriter_target) || _jacoco_instrument || 3691*8975f5c5SAndroid Build Coastguard Worker defined(invoker.jar_excluded_patterns) || 3692*8975f5c5SAndroid Build Coastguard Worker defined(invoker.jar_included_patterns) 3693*8975f5c5SAndroid Build Coastguard Worker if (!_process_device_jar && _is_prebuilt) { 3694*8975f5c5SAndroid Build Coastguard Worker _device_processed_jar_path = invoker.jar_path 3695*8975f5c5SAndroid Build Coastguard Worker } else { 3696*8975f5c5SAndroid Build Coastguard Worker _device_processed_jar_path = 3697*8975f5c5SAndroid Build Coastguard Worker "$target_out_dir/$_output_name.processed.jar" 3698*8975f5c5SAndroid Build Coastguard Worker } 3699*8975f5c5SAndroid Build Coastguard Worker } 3700*8975f5c5SAndroid Build Coastguard Worker 3701*8975f5c5SAndroid Build Coastguard Worker # For static libraries, the javac jar output is created at the intermediate 3702*8975f5c5SAndroid Build Coastguard Worker # path so that it can be processed by another target and moved to the final 3703*8975f5c5SAndroid Build Coastguard Worker # spot that the .build_config.json knows about. Technically this should be done 3704*8975f5c5SAndroid Build Coastguard Worker # for the ijar as well, but this is only used for APK targets where 3705*8975f5c5SAndroid Build Coastguard Worker # the ijar path isn't actually used. 3706*8975f5c5SAndroid Build Coastguard Worker if (_has_sources) { 3707*8975f5c5SAndroid Build Coastguard Worker _final_ijar_path = "$target_out_dir/$_output_name.turbine.jar" 3708*8975f5c5SAndroid Build Coastguard Worker } else { 3709*8975f5c5SAndroid Build Coastguard Worker _final_ijar_path = "$target_out_dir/$_output_name.ijar.jar" 3710*8975f5c5SAndroid Build Coastguard Worker } 3711*8975f5c5SAndroid Build Coastguard Worker 3712*8975f5c5SAndroid Build Coastguard Worker if (_has_sources) { 3713*8975f5c5SAndroid Build Coastguard Worker if (_build_device_jar && !_process_device_jar) { 3714*8975f5c5SAndroid Build Coastguard Worker _javac_jar_path = _device_processed_jar_path 3715*8975f5c5SAndroid Build Coastguard Worker } else { 3716*8975f5c5SAndroid Build Coastguard Worker _javac_jar_path = "$target_out_dir/$_main_target_name.javac.jar" 3717*8975f5c5SAndroid Build Coastguard Worker } 3718*8975f5c5SAndroid Build Coastguard Worker _generated_jar_path = 3719*8975f5c5SAndroid Build Coastguard Worker "$target_gen_dir/$_main_target_name.generated.srcjar" 3720*8975f5c5SAndroid Build Coastguard Worker } 3721*8975f5c5SAndroid Build Coastguard Worker 3722*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt) { 3723*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_path = invoker.jar_path 3724*8975f5c5SAndroid Build Coastguard Worker } else { 3725*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_path = _javac_jar_path 3726*8975f5c5SAndroid Build Coastguard Worker } 3727*8975f5c5SAndroid Build Coastguard Worker } 3728*8975f5c5SAndroid Build Coastguard Worker 3729*8975f5c5SAndroid Build Coastguard Worker _java_assetres_deps = filter_include(_invoker_deps, java_resource_patterns) 3730*8975f5c5SAndroid Build Coastguard Worker 3731*8975f5c5SAndroid Build Coastguard Worker # Cannot use minus operator because it does not work when the operand has 3732*8975f5c5SAndroid Build Coastguard Worker # repeated entries. 3733*8975f5c5SAndroid Build Coastguard Worker _invoker_deps_minus_assetres = 3734*8975f5c5SAndroid Build Coastguard Worker filter_exclude(_invoker_deps, _java_assetres_deps) 3735*8975f5c5SAndroid Build Coastguard Worker _lib_deps = 3736*8975f5c5SAndroid Build Coastguard Worker filter_include(_invoker_deps_minus_assetres, java_library_patterns) 3737*8975f5c5SAndroid Build Coastguard Worker _non_java_deps = filter_exclude(_invoker_deps_minus_assetres, _lib_deps) 3738*8975f5c5SAndroid Build Coastguard Worker 3739*8975f5c5SAndroid Build Coastguard Worker _java_header_deps = [] # Turbine / ijar 3740*8975f5c5SAndroid Build Coastguard Worker 3741*8975f5c5SAndroid Build Coastguard Worker # It would be more ideal to split this into __host and __javac, but we 3742*8975f5c5SAndroid Build Coastguard Worker # combine the two concepts to save on a group() target. 3743*8975f5c5SAndroid Build Coastguard Worker _java_host_deps = [] # Processed host .jar + javac .jar. 3744*8975f5c5SAndroid Build Coastguard Worker _java_validate_deps = [] # Bytecode checker & errorprone. 3745*8975f5c5SAndroid Build Coastguard Worker 3746*8975f5c5SAndroid Build Coastguard Worker foreach(_lib_dep, _lib_deps) { 3747*8975f5c5SAndroid Build Coastguard Worker # Expand //foo/java -> //foo/java:java 3748*8975f5c5SAndroid Build Coastguard Worker _lib_dep = get_label_info(_lib_dep, "label_no_toolchain") 3749*8975f5c5SAndroid Build Coastguard Worker _java_assetres_deps += [ "${_lib_dep}__assetres" ] 3750*8975f5c5SAndroid Build Coastguard Worker _java_header_deps += [ "${_lib_dep}__header" ] 3751*8975f5c5SAndroid Build Coastguard Worker _java_host_deps += [ "${_lib_dep}__host" ] 3752*8975f5c5SAndroid Build Coastguard Worker _java_validate_deps += [ "${_lib_dep}__validate" ] 3753*8975f5c5SAndroid Build Coastguard Worker } 3754*8975f5c5SAndroid Build Coastguard Worker 3755*8975f5c5SAndroid Build Coastguard Worker # APK and base module targets are special because: 3756*8975f5c5SAndroid Build Coastguard Worker # 1) They do not follow java target naming scheme (since they are not 3757*8975f5c5SAndroid Build Coastguard Worker # generally deps, there is no need for them to). 3758*8975f5c5SAndroid Build Coastguard Worker # 2) They do not bother to define a __host target. 3759*8975f5c5SAndroid Build Coastguard Worker # Since __host is used as an indirect dep for the compile_java artifacts, 3760*8975f5c5SAndroid Build Coastguard Worker # add the __compile_java target directly for them. 3761*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_under_test)) { 3762*8975f5c5SAndroid Build Coastguard Worker _java_assetres_deps += [ "${invoker.apk_under_test}__java__assetres" ] 3763*8975f5c5SAndroid Build Coastguard Worker _java_header_deps += [ "${invoker.apk_under_test}__java__header" ] 3764*8975f5c5SAndroid Build Coastguard Worker _java_validate_deps += [ "${invoker.apk_under_test}__java__validate" ] 3765*8975f5c5SAndroid Build Coastguard Worker _java_host_deps += [ "${invoker.apk_under_test}__compile_java" ] 3766*8975f5c5SAndroid Build Coastguard Worker } 3767*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.base_module_target)) { 3768*8975f5c5SAndroid Build Coastguard Worker _java_assetres_deps += [ "${invoker.base_module_target}__java__assetres" ] 3769*8975f5c5SAndroid Build Coastguard Worker _java_header_deps += [ "${invoker.base_module_target}__java__header" ] 3770*8975f5c5SAndroid Build Coastguard Worker _java_validate_deps += [ "${invoker.base_module_target}__java__validate" ] 3771*8975f5c5SAndroid Build Coastguard Worker _java_host_deps += [ "${invoker.base_module_target}__compile_java" ] 3772*8975f5c5SAndroid Build Coastguard Worker } 3773*8975f5c5SAndroid Build Coastguard Worker 3774*8975f5c5SAndroid Build Coastguard Worker not_needed([ "_non_java_deps" ]) 3775*8975f5c5SAndroid Build Coastguard Worker 3776*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt || _has_sources) { 3777*8975f5c5SAndroid Build Coastguard Worker # Classpath deps are used for header and dex targets, they do not need 3778*8975f5c5SAndroid Build Coastguard Worker # __assetres deps. 3779*8975f5c5SAndroid Build Coastguard Worker # _non_java_deps are needed for input_jars_paths that are generated. 3780*8975f5c5SAndroid Build Coastguard Worker _header_classpath_deps = 3781*8975f5c5SAndroid Build Coastguard Worker _java_header_deps + _non_java_deps + [ ":$_build_config_target_name" ] 3782*8975f5c5SAndroid Build Coastguard Worker 3783*8975f5c5SAndroid Build Coastguard Worker _javac_classpath_deps = 3784*8975f5c5SAndroid Build Coastguard Worker _java_host_deps + _non_java_deps + [ ":$_build_config_target_name" ] 3785*8975f5c5SAndroid Build Coastguard Worker 3786*8975f5c5SAndroid Build Coastguard Worker _include_android_sdk = _build_device_jar 3787*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.include_android_sdk)) { 3788*8975f5c5SAndroid Build Coastguard Worker _include_android_sdk = invoker.include_android_sdk 3789*8975f5c5SAndroid Build Coastguard Worker } 3790*8975f5c5SAndroid Build Coastguard Worker if (_include_android_sdk) { 3791*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.alternative_android_sdk_dep)) { 3792*8975f5c5SAndroid Build Coastguard Worker _android_sdk_dep = invoker.alternative_android_sdk_dep 3793*8975f5c5SAndroid Build Coastguard Worker } else { 3794*8975f5c5SAndroid Build Coastguard Worker _android_sdk_dep = default_android_sdk_dep 3795*8975f5c5SAndroid Build Coastguard Worker } 3796*8975f5c5SAndroid Build Coastguard Worker 3797*8975f5c5SAndroid Build Coastguard Worker _header_classpath_deps += [ "${_android_sdk_dep}__header" ] 3798*8975f5c5SAndroid Build Coastguard Worker _javac_classpath_deps += [ "${_android_sdk_dep}" ] 3799*8975f5c5SAndroid Build Coastguard Worker } 3800*8975f5c5SAndroid Build Coastguard Worker } 3801*8975f5c5SAndroid Build Coastguard Worker 3802*8975f5c5SAndroid Build Coastguard Worker # Often needed, but too hard to figure out when ahead of time. 3803*8975f5c5SAndroid Build Coastguard Worker not_needed([ 3804*8975f5c5SAndroid Build Coastguard Worker "_header_classpath_deps", 3805*8975f5c5SAndroid Build Coastguard Worker "_javac_classpath_deps", 3806*8975f5c5SAndroid Build Coastguard Worker ]) 3807*8975f5c5SAndroid Build Coastguard Worker 3808*8975f5c5SAndroid Build Coastguard Worker if (_source_files != []) { 3809*8975f5c5SAndroid Build Coastguard Worker _target_sources_file = "$target_gen_dir/$_main_target_name.sources" 3810*8975f5c5SAndroid Build Coastguard Worker write_file(_target_sources_file, 3811*8975f5c5SAndroid Build Coastguard Worker rebase_path(_source_files, root_build_dir)) 3812*8975f5c5SAndroid Build Coastguard Worker } 3813*8975f5c5SAndroid Build Coastguard Worker 3814*8975f5c5SAndroid Build Coastguard Worker write_build_config(_build_config_target_name) { 3815*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 3816*8975f5c5SAndroid Build Coastguard Worker [ 3817*8975f5c5SAndroid Build Coastguard Worker "aar_path", 3818*8975f5c5SAndroid Build Coastguard Worker "annotation_processor_deps", 3819*8975f5c5SAndroid Build Coastguard Worker "base_allowlist_rtxt_path", 3820*8975f5c5SAndroid Build Coastguard Worker "gradle_treat_as_prebuilt", 3821*8975f5c5SAndroid Build Coastguard Worker "input_jars_paths", 3822*8975f5c5SAndroid Build Coastguard Worker "preferred_dep", 3823*8975f5c5SAndroid Build Coastguard Worker "low_classpath_priority", 3824*8975f5c5SAndroid Build Coastguard Worker "main_class", 3825*8975f5c5SAndroid Build Coastguard Worker "mergeable_android_manifests", 3826*8975f5c5SAndroid Build Coastguard Worker "module_name", 3827*8975f5c5SAndroid Build Coastguard Worker "parent_module_target", 3828*8975f5c5SAndroid Build Coastguard Worker "proguard_configs", 3829*8975f5c5SAndroid Build Coastguard Worker "proguard_enabled", 3830*8975f5c5SAndroid Build Coastguard Worker "proguard_mapping_path", 3831*8975f5c5SAndroid Build Coastguard Worker "public_target_label", 3832*8975f5c5SAndroid Build Coastguard Worker "r_text_path", 3833*8975f5c5SAndroid Build Coastguard Worker "suffix_apk_assets_used_by", 3834*8975f5c5SAndroid Build Coastguard Worker "type", 3835*8975f5c5SAndroid Build Coastguard Worker "version_code", 3836*8975f5c5SAndroid Build Coastguard Worker "version_name", 3837*8975f5c5SAndroid Build Coastguard Worker ]) 3838*8975f5c5SAndroid Build Coastguard Worker if (_type == "android_apk" || _type == "android_app_bundle_module") { 3839*8975f5c5SAndroid Build Coastguard Worker forward_variables_from( 3840*8975f5c5SAndroid Build Coastguard Worker invoker, 3841*8975f5c5SAndroid Build Coastguard Worker [ 3842*8975f5c5SAndroid Build Coastguard Worker "android_manifest", 3843*8975f5c5SAndroid Build Coastguard Worker "android_manifest_dep", 3844*8975f5c5SAndroid Build Coastguard Worker "merged_android_manifest", 3845*8975f5c5SAndroid Build Coastguard Worker "final_dex_path", 3846*8975f5c5SAndroid Build Coastguard Worker "loadable_modules", 3847*8975f5c5SAndroid Build Coastguard Worker "native_lib_placeholders", 3848*8975f5c5SAndroid Build Coastguard Worker "res_size_info_path", 3849*8975f5c5SAndroid Build Coastguard Worker "secondary_abi_loadable_modules", 3850*8975f5c5SAndroid Build Coastguard Worker "secondary_abi_shared_libraries_runtime_deps_file", 3851*8975f5c5SAndroid Build Coastguard Worker "secondary_native_lib_placeholders", 3852*8975f5c5SAndroid Build Coastguard Worker "shared_libraries_runtime_deps_file", 3853*8975f5c5SAndroid Build Coastguard Worker "library_always_compress", 3854*8975f5c5SAndroid Build Coastguard Worker ]) 3855*8975f5c5SAndroid Build Coastguard Worker } 3856*8975f5c5SAndroid Build Coastguard Worker if (_type == "android_apk") { 3857*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 3858*8975f5c5SAndroid Build Coastguard Worker [ 3859*8975f5c5SAndroid Build Coastguard Worker "apk_path", 3860*8975f5c5SAndroid Build Coastguard Worker "apk_under_test", 3861*8975f5c5SAndroid Build Coastguard Worker "incremental_apk_path", 3862*8975f5c5SAndroid Build Coastguard Worker "incremental_install_json_path", 3863*8975f5c5SAndroid Build Coastguard Worker ]) 3864*8975f5c5SAndroid Build Coastguard Worker } 3865*8975f5c5SAndroid Build Coastguard Worker if (_type == "android_app_bundle_module") { 3866*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 3867*8975f5c5SAndroid Build Coastguard Worker [ 3868*8975f5c5SAndroid Build Coastguard Worker "add_view_trace_events", 3869*8975f5c5SAndroid Build Coastguard Worker "base_module_target", 3870*8975f5c5SAndroid Build Coastguard Worker "module_pathmap_path", 3871*8975f5c5SAndroid Build Coastguard Worker "proto_resources_path", 3872*8975f5c5SAndroid Build Coastguard Worker ]) 3873*8975f5c5SAndroid Build Coastguard Worker } 3874*8975f5c5SAndroid Build Coastguard Worker chromium_code = _chromium_code 3875*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 3876*8975f5c5SAndroid Build Coastguard Worker is_prebuilt = _is_prebuilt 3877*8975f5c5SAndroid Build Coastguard Worker 3878*8975f5c5SAndroid Build Coastguard Worker # Specifically avoid passing in invoker.base_module_target as one of the 3879*8975f5c5SAndroid Build Coastguard Worker # possible_config_deps. 3880*8975f5c5SAndroid Build Coastguard Worker possible_config_deps = [] 3881*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 3882*8975f5c5SAndroid Build Coastguard Worker possible_config_deps = invoker.deps 3883*8975f5c5SAndroid Build Coastguard Worker } 3884*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.public_deps)) { 3885*8975f5c5SAndroid Build Coastguard Worker possible_config_public_deps = invoker.public_deps 3886*8975f5c5SAndroid Build Coastguard Worker } 3887*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.asset_deps)) { 3888*8975f5c5SAndroid Build Coastguard Worker possible_config_deps += invoker.asset_deps 3889*8975f5c5SAndroid Build Coastguard Worker } 3890*8975f5c5SAndroid Build Coastguard Worker if (defined(apk_under_test)) { 3891*8975f5c5SAndroid Build Coastguard Worker possible_config_deps += [ apk_under_test ] 3892*8975f5c5SAndroid Build Coastguard Worker } 3893*8975f5c5SAndroid Build Coastguard Worker if (defined(_jacoco_instrument) && _jacoco_instrument) { 3894*8975f5c5SAndroid Build Coastguard Worker possible_config_deps += [ _jacoco_dep ] 3895*8975f5c5SAndroid Build Coastguard Worker } 3896*8975f5c5SAndroid Build Coastguard Worker if (defined(_android_sdk_dep)) { 3897*8975f5c5SAndroid Build Coastguard Worker possible_config_deps += [ _android_sdk_dep ] 3898*8975f5c5SAndroid Build Coastguard Worker } 3899*8975f5c5SAndroid Build Coastguard Worker 3900*8975f5c5SAndroid Build Coastguard Worker supports_android = _supports_android 3901*8975f5c5SAndroid Build Coastguard Worker requires_android = _requires_android 3902*8975f5c5SAndroid Build Coastguard Worker is_robolectric = _is_robolectric 3903*8975f5c5SAndroid Build Coastguard Worker bypass_platform_checks = _bypass_platform_checks 3904*8975f5c5SAndroid Build Coastguard Worker 3905*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resources_package)) { 3906*8975f5c5SAndroid Build Coastguard Worker custom_package = invoker.resources_package 3907*8975f5c5SAndroid Build Coastguard Worker } 3908*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt || _has_sources) { 3909*8975f5c5SAndroid Build Coastguard Worker if (_skip_header_jar) { 3910*8975f5c5SAndroid Build Coastguard Worker # We are tricking everything that is looking for an ijar into looking 3911*8975f5c5SAndroid Build Coastguard Worker # at the processed jar path, which is has the excluded classes 3912*8975f5c5SAndroid Build Coastguard Worker # removed. 3913*8975f5c5SAndroid Build Coastguard Worker ijar_path = _device_processed_jar_path 3914*8975f5c5SAndroid Build Coastguard Worker } else { 3915*8975f5c5SAndroid Build Coastguard Worker ijar_path = _final_ijar_path 3916*8975f5c5SAndroid Build Coastguard Worker } 3917*8975f5c5SAndroid Build Coastguard Worker unprocessed_jar_path = _unprocessed_jar_path 3918*8975f5c5SAndroid Build Coastguard Worker } 3919*8975f5c5SAndroid Build Coastguard Worker if (_build_host_jar) { 3920*8975f5c5SAndroid Build Coastguard Worker host_jar_path = _host_processed_jar_path 3921*8975f5c5SAndroid Build Coastguard Worker } 3922*8975f5c5SAndroid Build Coastguard Worker if (_build_device_jar) { 3923*8975f5c5SAndroid Build Coastguard Worker device_jar_path = _device_processed_jar_path 3924*8975f5c5SAndroid Build Coastguard Worker dex_path = _dex_path 3925*8975f5c5SAndroid Build Coastguard Worker } 3926*8975f5c5SAndroid Build Coastguard Worker if (_source_files != []) { 3927*8975f5c5SAndroid Build Coastguard Worker target_sources_file = _target_sources_file 3928*8975f5c5SAndroid Build Coastguard Worker } 3929*8975f5c5SAndroid Build Coastguard Worker 3930*8975f5c5SAndroid Build Coastguard Worker bundled_srcjars = [] 3931*8975f5c5SAndroid Build Coastguard Worker foreach(d, _srcjar_deps) { 3932*8975f5c5SAndroid Build Coastguard Worker _dep_gen_dir = get_label_info(d, "target_gen_dir") 3933*8975f5c5SAndroid Build Coastguard Worker _dep_name = get_label_info(d, "name") 3934*8975f5c5SAndroid Build Coastguard Worker bundled_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] 3935*8975f5c5SAndroid Build Coastguard Worker } 3936*8975f5c5SAndroid Build Coastguard Worker bundled_srcjars += _srcjars 3937*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.include_java_resources) && 3938*8975f5c5SAndroid Build Coastguard Worker invoker.include_java_resources) { 3939*8975f5c5SAndroid Build Coastguard Worker java_resources_jar = _unprocessed_jar_path 3940*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.jar_path)) { 3941*8975f5c5SAndroid Build Coastguard Worker # Use original jar_path because _jar_path points to a library without 3942*8975f5c5SAndroid Build Coastguard Worker # resources. 3943*8975f5c5SAndroid Build Coastguard Worker } else { 3944*8975f5c5SAndroid Build Coastguard Worker java_resources_jar = _device_processed_jar_path 3945*8975f5c5SAndroid Build Coastguard Worker } 3946*8975f5c5SAndroid Build Coastguard Worker } 3947*8975f5c5SAndroid Build Coastguard Worker } 3948*8975f5c5SAndroid Build Coastguard Worker 3949*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt || _has_sources) { 3950*8975f5c5SAndroid Build Coastguard Worker _header_target_name = "${target_name}__header" 3951*8975f5c5SAndroid Build Coastguard Worker } 3952*8975f5c5SAndroid Build Coastguard Worker 3953*8975f5c5SAndroid Build Coastguard Worker if (_has_sources) { 3954*8975f5c5SAndroid Build Coastguard Worker _kt_files = filter_include(_source_files, [ "*.kt" ]) 3955*8975f5c5SAndroid Build Coastguard Worker _java_files = filter_exclude(_source_files, [ "*.kt" ]) 3956*8975f5c5SAndroid Build Coastguard Worker 3957*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.enable_errorprone)) { 3958*8975f5c5SAndroid Build Coastguard Worker _enable_errorprone = invoker.enable_errorprone 3959*8975f5c5SAndroid Build Coastguard Worker } else { 3960*8975f5c5SAndroid Build Coastguard Worker _enable_errorprone = 3961*8975f5c5SAndroid Build Coastguard Worker _java_files != [] && _chromium_code && use_errorprone_java_compiler 3962*8975f5c5SAndroid Build Coastguard Worker } 3963*8975f5c5SAndroid Build Coastguard Worker if (_enable_errorprone) { 3964*8975f5c5SAndroid Build Coastguard Worker # Rely on the header jar to provide all .class files so that it is 3965*8975f5c5SAndroid Build Coastguard Worker # safe to omit generated files entirely for errorprone. 3966*8975f5c5SAndroid Build Coastguard Worker _errorprone_source_files = 3967*8975f5c5SAndroid Build Coastguard Worker filter_exclude(_java_files, [ "$root_gen_dir*" ]) 3968*8975f5c5SAndroid Build Coastguard Worker _enable_errorprone = 3969*8975f5c5SAndroid Build Coastguard Worker _enable_errorprone && _errorprone_source_files != [] 3970*8975f5c5SAndroid Build Coastguard Worker } 3971*8975f5c5SAndroid Build Coastguard Worker 3972*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.resources_package) && _type == "java_library") { 3973*8975f5c5SAndroid Build Coastguard Worker # TODO(crbug.com/40821816): remove _bypass_platform_checks from the list 3974*8975f5c5SAndroid Build Coastguard Worker # once all robolectric targets have migrated to robolectric_library. 3975*8975f5c5SAndroid Build Coastguard Worker assert(_requires_android || _bypass_platform_checks || _is_robolectric, 3976*8975f5c5SAndroid Build Coastguard Worker "Setting resources_package applicable only for " + 3977*8975f5c5SAndroid Build Coastguard Worker "android_library(), or robolectric_library(). " + 3978*8975f5c5SAndroid Build Coastguard Worker "Target=$target_name") 3979*8975f5c5SAndroid Build Coastguard Worker 3980*8975f5c5SAndroid Build Coastguard Worker # Serves double purpose: Generating R.java, as well as being the 3981*8975f5c5SAndroid Build Coastguard Worker #__assetres target (instead of using a separate group). 3982*8975f5c5SAndroid Build Coastguard Worker _fake_rjava_target = "${target_name}__assetres" 3983*8975f5c5SAndroid Build Coastguard Worker generate_r_java(_fake_rjava_target) { 3984*8975f5c5SAndroid Build Coastguard Worker deps = [ ":$_build_config_target_name" ] + _java_assetres_deps + 3985*8975f5c5SAndroid Build Coastguard Worker _non_java_deps 3986*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 3987*8975f5c5SAndroid Build Coastguard Worker 3988*8975f5c5SAndroid Build Coastguard Worker # Filepath has to be exactly this because compile_java looks for the 3989*8975f5c5SAndroid Build Coastguard Worker # srcjar of srcjar_deps at this location $gen_dir/$target_name.srcjar 3990*8975f5c5SAndroid Build Coastguard Worker srcjar_path = "$target_gen_dir/$target_name.srcjar" 3991*8975f5c5SAndroid Build Coastguard Worker package = invoker.resources_package 3992*8975f5c5SAndroid Build Coastguard Worker } 3993*8975f5c5SAndroid Build Coastguard Worker _srcjar_deps += [ ":$_fake_rjava_target" ] 3994*8975f5c5SAndroid Build Coastguard Worker } 3995*8975f5c5SAndroid Build Coastguard Worker 3996*8975f5c5SAndroid Build Coastguard Worker if (_kt_files != []) { 3997*8975f5c5SAndroid Build Coastguard Worker _kt_allowlist = [ 3998*8975f5c5SAndroid Build Coastguard Worker "android/java/src/org/chromium/chrome/browser/tabmodel/AsyncTabParamsManagerImpl.kt", 3999*8975f5c5SAndroid Build Coastguard Worker "java/androidx/core/os/BuildCompat.kt", 4000*8975f5c5SAndroid Build Coastguard Worker "webengine_shell_apk/src/org/chromium/webengine/shell/*.kt", 4001*8975f5c5SAndroid Build Coastguard Worker ] 4002*8975f5c5SAndroid Build Coastguard Worker _found_kt = filter_exclude(_kt_files, _kt_allowlist) 4003*8975f5c5SAndroid Build Coastguard Worker assert( 4004*8975f5c5SAndroid Build Coastguard Worker _found_kt == [], 4005*8975f5c5SAndroid Build Coastguard Worker "Only a files in the allowlist can be included for now. Feel " + "free to remove this assert when experimenting locally. Found: $_found_kt") 4006*8975f5c5SAndroid Build Coastguard Worker _compile_kt_target_name = "${_main_target_name}__compile_kt" 4007*8975f5c5SAndroid Build Coastguard Worker _kotlinc_jar_path = "$target_out_dir/$_output_name.kotlinc.jar" 4008*8975f5c5SAndroid Build Coastguard Worker _kotlin_interface_jar_path = 4009*8975f5c5SAndroid Build Coastguard Worker "$target_out_dir/$_output_name.kt-jvm-abi.jar" 4010*8975f5c5SAndroid Build Coastguard Worker assert(filter_include(_lib_deps, [ _kotlin_stdlib_dep ]) != [], 4011*8975f5c5SAndroid Build Coastguard Worker "${_main_target_name} is missing dep: $_kotlin_stdlib_dep") 4012*8975f5c5SAndroid Build Coastguard Worker compile_kt(_compile_kt_target_name) { 4013*8975f5c5SAndroid Build Coastguard Worker deps = _header_classpath_deps 4014*8975f5c5SAndroid Build Coastguard Worker output_jar_path = _kotlinc_jar_path 4015*8975f5c5SAndroid Build Coastguard Worker output_interface_jar_path = _kotlin_interface_jar_path 4016*8975f5c5SAndroid Build Coastguard Worker main_target_name = _main_target_name 4017*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 4018*8975f5c5SAndroid Build Coastguard Worker srcjar_deps = _srcjar_deps 4019*8975f5c5SAndroid Build Coastguard Worker source_files = _source_files 4020*8975f5c5SAndroid Build Coastguard Worker target_sources_file = _target_sources_file 4021*8975f5c5SAndroid Build Coastguard Worker chromium_code = _chromium_code 4022*8975f5c5SAndroid Build Coastguard Worker include_android_sdk = _is_robolectric || _requires_android 4023*8975f5c5SAndroid Build Coastguard Worker } 4024*8975f5c5SAndroid Build Coastguard Worker } 4025*8975f5c5SAndroid Build Coastguard Worker 4026*8975f5c5SAndroid Build Coastguard Worker template("compile_java_helper") { 4027*8975f5c5SAndroid Build Coastguard Worker _enable_errorprone = 4028*8975f5c5SAndroid Build Coastguard Worker defined(invoker.enable_errorprone) && invoker.enable_errorprone 4029*8975f5c5SAndroid Build Coastguard Worker compile_java(target_name) { 4030*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4031*8975f5c5SAndroid Build Coastguard Worker "*", 4032*8975f5c5SAndroid Build Coastguard Worker TESTONLY_AND_VISIBILITY + [ "deps" ]) 4033*8975f5c5SAndroid Build Coastguard Worker deps = _header_classpath_deps 4034*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 4035*8975f5c5SAndroid Build Coastguard Worker deps += invoker.deps 4036*8975f5c5SAndroid Build Coastguard Worker } 4037*8975f5c5SAndroid Build Coastguard Worker output_jar_path = invoker.output_jar_path 4038*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.kotlin_jar_path)) { 4039*8975f5c5SAndroid Build Coastguard Worker deps += [ ":$_compile_kt_target_name" ] 4040*8975f5c5SAndroid Build Coastguard Worker kotlin_jar_path = invoker.kotlin_jar_path 4041*8975f5c5SAndroid Build Coastguard Worker } 4042*8975f5c5SAndroid Build Coastguard Worker enable_errorprone = _enable_errorprone 4043*8975f5c5SAndroid Build Coastguard Worker use_turbine = defined(invoker.use_turbine) && invoker.use_turbine 4044*8975f5c5SAndroid Build Coastguard Worker 4045*8975f5c5SAndroid Build Coastguard Worker main_target_name = _main_target_name 4046*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 4047*8975f5c5SAndroid Build Coastguard Worker 4048*8975f5c5SAndroid Build Coastguard Worker if (_enable_errorprone) { 4049*8975f5c5SAndroid Build Coastguard Worker source_files = _errorprone_source_files 4050*8975f5c5SAndroid Build Coastguard Worker } else { 4051*8975f5c5SAndroid Build Coastguard Worker source_files = _source_files 4052*8975f5c5SAndroid Build Coastguard Worker srcjar_deps = _srcjar_deps 4053*8975f5c5SAndroid Build Coastguard Worker } 4054*8975f5c5SAndroid Build Coastguard Worker 4055*8975f5c5SAndroid Build Coastguard Worker if (source_files != []) { 4056*8975f5c5SAndroid Build Coastguard Worker target_sources_file = _target_sources_file 4057*8975f5c5SAndroid Build Coastguard Worker } 4058*8975f5c5SAndroid Build Coastguard Worker chromium_code = _chromium_code 4059*8975f5c5SAndroid Build Coastguard Worker include_android_sdk = _is_robolectric || _requires_android 4060*8975f5c5SAndroid Build Coastguard Worker } 4061*8975f5c5SAndroid Build Coastguard Worker } 4062*8975f5c5SAndroid Build Coastguard Worker _compile_java_forward_variables = [ 4063*8975f5c5SAndroid Build Coastguard Worker "additional_jar_files", 4064*8975f5c5SAndroid Build Coastguard Worker "apk_name", 4065*8975f5c5SAndroid Build Coastguard Worker "jar_excluded_patterns", 4066*8975f5c5SAndroid Build Coastguard Worker "javac_args", 4067*8975f5c5SAndroid Build Coastguard Worker "processor_args_javac", 4068*8975f5c5SAndroid Build Coastguard Worker "skip_build_server", 4069*8975f5c5SAndroid Build Coastguard Worker "srcjars", 4070*8975f5c5SAndroid Build Coastguard Worker ] 4071*8975f5c5SAndroid Build Coastguard Worker 4072*8975f5c5SAndroid Build Coastguard Worker if (!_skip_header_jar) { 4073*8975f5c5SAndroid Build Coastguard Worker _annotation_processor_deps = [] 4074*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.annotation_processor_deps)) { 4075*8975f5c5SAndroid Build Coastguard Worker _annotation_processor_deps = invoker.annotation_processor_deps 4076*8975f5c5SAndroid Build Coastguard Worker } 4077*8975f5c5SAndroid Build Coastguard Worker 4078*8975f5c5SAndroid Build Coastguard Worker compile_java_helper(_header_target_name) { 4079*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, _compile_java_forward_variables) 4080*8975f5c5SAndroid Build Coastguard Worker use_turbine = true 4081*8975f5c5SAndroid Build Coastguard Worker output_jar_path = _final_ijar_path 4082*8975f5c5SAndroid Build Coastguard Worker generated_jar_path = _generated_jar_path 4083*8975f5c5SAndroid Build Coastguard Worker deps = _annotation_processor_deps 4084*8975f5c5SAndroid Build Coastguard Worker if (_kt_files != []) { 4085*8975f5c5SAndroid Build Coastguard Worker kotlin_jar_path = _kotlin_interface_jar_path 4086*8975f5c5SAndroid Build Coastguard Worker } 4087*8975f5c5SAndroid Build Coastguard Worker } 4088*8975f5c5SAndroid Build Coastguard Worker } 4089*8975f5c5SAndroid Build Coastguard Worker 4090*8975f5c5SAndroid Build Coastguard Worker _compile_java_target = "${_main_target_name}__compile_java" 4091*8975f5c5SAndroid Build Coastguard Worker compile_java_helper(_compile_java_target) { 4092*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, _compile_java_forward_variables) 4093*8975f5c5SAndroid Build Coastguard Worker output_jar_path = _javac_jar_path 4094*8975f5c5SAndroid Build Coastguard Worker if (!_skip_header_jar) { 4095*8975f5c5SAndroid Build Coastguard Worker deps = [ ":$_header_target_name" ] 4096*8975f5c5SAndroid Build Coastguard Worker header_jar_path = _final_ijar_path 4097*8975f5c5SAndroid Build Coastguard Worker generated_jar_path = _generated_jar_path 4098*8975f5c5SAndroid Build Coastguard Worker } 4099*8975f5c5SAndroid Build Coastguard Worker if (_kt_files != []) { 4100*8975f5c5SAndroid Build Coastguard Worker kotlin_jar_path = _kotlinc_jar_path 4101*8975f5c5SAndroid Build Coastguard Worker } 4102*8975f5c5SAndroid Build Coastguard Worker } 4103*8975f5c5SAndroid Build Coastguard Worker 4104*8975f5c5SAndroid Build Coastguard Worker if (_enable_errorprone) { 4105*8975f5c5SAndroid Build Coastguard Worker _compile_java_errorprone_target = "${_main_target_name}__errorprone" 4106*8975f5c5SAndroid Build Coastguard Worker compile_java_helper(_compile_java_errorprone_target) { 4107*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, _compile_java_forward_variables) 4108*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, [ "enable_nullaway" ]) 4109*8975f5c5SAndroid Build Coastguard Worker enable_errorprone = true 4110*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.errorprone_args)) { 4111*8975f5c5SAndroid Build Coastguard Worker if (!defined(javac_args)) { 4112*8975f5c5SAndroid Build Coastguard Worker javac_args = [] 4113*8975f5c5SAndroid Build Coastguard Worker } 4114*8975f5c5SAndroid Build Coastguard Worker javac_args += invoker.errorprone_args 4115*8975f5c5SAndroid Build Coastguard Worker } 4116*8975f5c5SAndroid Build Coastguard Worker if (_kt_files != []) { 4117*8975f5c5SAndroid Build Coastguard Worker kotlin_jar_path = _kotlinc_jar_path 4118*8975f5c5SAndroid Build Coastguard Worker } 4119*8975f5c5SAndroid Build Coastguard Worker if (!_skip_header_jar) { 4120*8975f5c5SAndroid Build Coastguard Worker deps = [ ":$_header_target_name" ] 4121*8975f5c5SAndroid Build Coastguard Worker header_jar_path = _final_ijar_path 4122*8975f5c5SAndroid Build Coastguard Worker generated_jar_path = _generated_jar_path 4123*8975f5c5SAndroid Build Coastguard Worker } 4124*8975f5c5SAndroid Build Coastguard Worker output_jar_path = "$target_out_dir/$target_name.errorprone.stamp" 4125*8975f5c5SAndroid Build Coastguard Worker } 4126*8975f5c5SAndroid Build Coastguard Worker _java_validate_deps += [ ":$_compile_java_errorprone_target" ] 4127*8975f5c5SAndroid Build Coastguard Worker } else { 4128*8975f5c5SAndroid Build Coastguard Worker not_needed(invoker, [ "enable_nullaway" ]) 4129*8975f5c5SAndroid Build Coastguard Worker } 4130*8975f5c5SAndroid Build Coastguard Worker } # _has_sources 4131*8975f5c5SAndroid Build Coastguard Worker 4132*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt || _build_device_jar || _build_host_jar) { 4133*8975f5c5SAndroid Build Coastguard Worker if (_has_sources) { 4134*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_deps = [ ":$_compile_java_target" ] 4135*8975f5c5SAndroid Build Coastguard Worker } else { 4136*8975f5c5SAndroid Build Coastguard Worker # jars might be generated by a dep. 4137*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_deps = _non_java_deps 4138*8975f5c5SAndroid Build Coastguard Worker } 4139*8975f5c5SAndroid Build Coastguard Worker } 4140*8975f5c5SAndroid Build Coastguard Worker 4141*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.bytecode_rewriter_target)) { 4142*8975f5c5SAndroid Build Coastguard Worker assert(_build_host_jar || _build_device_jar, 4143*8975f5c5SAndroid Build Coastguard Worker "A host or device jar must be created to use bytecode rewriting") 4144*8975f5c5SAndroid Build Coastguard Worker 4145*8975f5c5SAndroid Build Coastguard Worker _rewritten_jar = "$target_out_dir/${target_name}_rewritten.jar" 4146*8975f5c5SAndroid Build Coastguard Worker _rewritten_jar_target_name = "${target_name}__rewritten" 4147*8975f5c5SAndroid Build Coastguard Worker _rewriter_path = root_build_dir + "/bin/helper/" + 4148*8975f5c5SAndroid Build Coastguard Worker get_label_info(invoker.bytecode_rewriter_target, "name") 4149*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(_build_config, root_build_dir) 4150*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(_rewritten_jar_target_name) { 4151*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/bytecode_rewriter.py" 4152*8975f5c5SAndroid Build Coastguard Worker inputs = java_paths_for_inputs + [ 4153*8975f5c5SAndroid Build Coastguard Worker _rewriter_path, 4154*8975f5c5SAndroid Build Coastguard Worker _build_config, 4155*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_path, 4156*8975f5c5SAndroid Build Coastguard Worker ] 4157*8975f5c5SAndroid Build Coastguard Worker outputs = [ _rewritten_jar ] 4158*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 4159*8975f5c5SAndroid Build Coastguard Worker args = [ 4160*8975f5c5SAndroid Build Coastguard Worker "--depfile", 4161*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 4162*8975f5c5SAndroid Build Coastguard Worker "--script", 4163*8975f5c5SAndroid Build Coastguard Worker rebase_path(_rewriter_path, root_build_dir), 4164*8975f5c5SAndroid Build Coastguard Worker "--classpath", 4165*8975f5c5SAndroid Build Coastguard Worker "@FileArg($_rebased_build_config:deps_info:javac_full_classpath)", 4166*8975f5c5SAndroid Build Coastguard Worker "--classpath", 4167*8975f5c5SAndroid Build Coastguard Worker "@FileArg($_rebased_build_config:android:sdk_jars)", 4168*8975f5c5SAndroid Build Coastguard Worker "--input-jar", 4169*8975f5c5SAndroid Build Coastguard Worker rebase_path(_unprocessed_jar_path, root_build_dir), 4170*8975f5c5SAndroid Build Coastguard Worker "--output-jar", 4171*8975f5c5SAndroid Build Coastguard Worker rebase_path(_rewritten_jar, root_build_dir), 4172*8975f5c5SAndroid Build Coastguard Worker ] 4173*8975f5c5SAndroid Build Coastguard Worker deps = _unprocessed_jar_deps + _javac_classpath_deps + 4174*8975f5c5SAndroid Build Coastguard Worker [ invoker.bytecode_rewriter_target ] 4175*8975f5c5SAndroid Build Coastguard Worker } 4176*8975f5c5SAndroid Build Coastguard Worker 4177*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_deps = [] 4178*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_deps = [ ":$_rewritten_jar_target_name" ] 4179*8975f5c5SAndroid Build Coastguard Worker _unprocessed_jar_path = _rewritten_jar 4180*8975f5c5SAndroid Build Coastguard Worker } 4181*8975f5c5SAndroid Build Coastguard Worker 4182*8975f5c5SAndroid Build Coastguard Worker if (_is_prebuilt) { 4183*8975f5c5SAndroid Build Coastguard Worker generate_interface_jar(_header_target_name) { 4184*8975f5c5SAndroid Build Coastguard Worker # Always used the unfiltered .jar to create the interface jar so that 4185*8975f5c5SAndroid Build Coastguard Worker # other targets will resolve filtered classes when depending on 4186*8975f5c5SAndroid Build Coastguard Worker # BuildConfig, NativeLibraries, etc. 4187*8975f5c5SAndroid Build Coastguard Worker input_jar = _unprocessed_jar_path 4188*8975f5c5SAndroid Build Coastguard Worker output_jar = _final_ijar_path 4189*8975f5c5SAndroid Build Coastguard Worker 4190*8975f5c5SAndroid Build Coastguard Worker # ijar needs only _unprocessed_jar_deps, but this also needs to export 4191*8975f5c5SAndroid Build Coastguard Worker # __header target from deps. 4192*8975f5c5SAndroid Build Coastguard Worker deps = _unprocessed_jar_deps + _java_header_deps 4193*8975f5c5SAndroid Build Coastguard Worker } 4194*8975f5c5SAndroid Build Coastguard Worker } 4195*8975f5c5SAndroid Build Coastguard Worker 4196*8975f5c5SAndroid Build Coastguard Worker if (_build_host_jar || _build_device_jar) { 4197*8975f5c5SAndroid Build Coastguard Worker _enable_bytecode_checks = 4198*8975f5c5SAndroid Build Coastguard Worker (!defined(invoker.enable_bytecode_checks) || 4199*8975f5c5SAndroid Build Coastguard Worker invoker.enable_bytecode_checks) && !_is_prebuilt && 4200*8975f5c5SAndroid Build Coastguard Worker android_static_analysis != "off" 4201*8975f5c5SAndroid Build Coastguard Worker if (_enable_bytecode_checks) { 4202*8975f5c5SAndroid Build Coastguard Worker _validate_target_name = "${target_name}__validate" 4203*8975f5c5SAndroid Build Coastguard Worker bytecode_processor(_validate_target_name) { 4204*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, [ "missing_classes_allowlist" ]) 4205*8975f5c5SAndroid Build Coastguard Worker deps = _unprocessed_jar_deps + _javac_classpath_deps + 4206*8975f5c5SAndroid Build Coastguard Worker [ ":$_build_config_target_name" ] 4207*8975f5c5SAndroid Build Coastguard Worker data_deps = _java_validate_deps 4208*8975f5c5SAndroid Build Coastguard Worker if (defined(_compile_java_errorprone_target)) { 4209*8975f5c5SAndroid Build Coastguard Worker data_deps += [ ":$_compile_java_errorprone_target" ] 4210*8975f5c5SAndroid Build Coastguard Worker } 4211*8975f5c5SAndroid Build Coastguard Worker 4212*8975f5c5SAndroid Build Coastguard Worker include_android_sdk = _requires_android || _is_robolectric 4213*8975f5c5SAndroid Build Coastguard Worker target_label = 4214*8975f5c5SAndroid Build Coastguard Worker get_label_info(":${invoker.target_name}", "label_no_toolchain") 4215*8975f5c5SAndroid Build Coastguard Worker input_jar = _unprocessed_jar_path 4216*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 4217*8975f5c5SAndroid Build Coastguard Worker } 4218*8975f5c5SAndroid Build Coastguard Worker } else { 4219*8975f5c5SAndroid Build Coastguard Worker not_needed(invoker, [ "missing_classes_allowlist" ]) 4220*8975f5c5SAndroid Build Coastguard Worker } 4221*8975f5c5SAndroid Build Coastguard Worker 4222*8975f5c5SAndroid Build Coastguard Worker if (_build_host_jar) { 4223*8975f5c5SAndroid Build Coastguard Worker _process_host_jar_target_name = "${target_name}__host" 4224*8975f5c5SAndroid Build Coastguard Worker process_java_library(_process_host_jar_target_name) { 4225*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4226*8975f5c5SAndroid Build Coastguard Worker [ 4227*8975f5c5SAndroid Build Coastguard Worker "jar_excluded_patterns", 4228*8975f5c5SAndroid Build Coastguard Worker "jar_included_patterns", 4229*8975f5c5SAndroid Build Coastguard Worker ]) 4230*8975f5c5SAndroid Build Coastguard Worker 4231*8975f5c5SAndroid Build Coastguard Worker # Robolectric tests require these to be on swarming. 4232*8975f5c5SAndroid Build Coastguard Worker data = [ _host_processed_jar_path ] 4233*8975f5c5SAndroid Build Coastguard Worker input_jar_path = _unprocessed_jar_path 4234*8975f5c5SAndroid Build Coastguard Worker deps = _unprocessed_jar_deps + _javac_classpath_deps 4235*8975f5c5SAndroid Build Coastguard Worker output_jar_path = _host_processed_jar_path 4236*8975f5c5SAndroid Build Coastguard Worker jacoco_instrument = _jacoco_instrument 4237*8975f5c5SAndroid Build Coastguard Worker if (_jacoco_instrument) { 4238*8975f5c5SAndroid Build Coastguard Worker source_files = _source_files 4239*8975f5c5SAndroid Build Coastguard Worker target_sources_file = _target_sources_file 4240*8975f5c5SAndroid Build Coastguard Worker } 4241*8975f5c5SAndroid Build Coastguard Worker 4242*8975f5c5SAndroid Build Coastguard Worker # _java_host_deps isn't necessary for process_java_library(), but is 4243*8975f5c5SAndroid Build Coastguard Worker # necessary so that this target can be used to depend on transitive 4244*8975f5c5SAndroid Build Coastguard Worker # __device targets without the need to create a separate group() 4245*8975f5c5SAndroid Build Coastguard Worker # target. This trade-off works because process_java_library is fast. 4246*8975f5c5SAndroid Build Coastguard Worker deps += _java_host_deps 4247*8975f5c5SAndroid Build Coastguard Worker 4248*8975f5c5SAndroid Build Coastguard Worker # Add runtime_deps here since robolectric_binary does not depend on top-level group. 4249*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.data)) { 4250*8975f5c5SAndroid Build Coastguard Worker data += invoker.data 4251*8975f5c5SAndroid Build Coastguard Worker } 4252*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.data_deps)) { 4253*8975f5c5SAndroid Build Coastguard Worker data_deps = invoker.data_deps 4254*8975f5c5SAndroid Build Coastguard Worker } 4255*8975f5c5SAndroid Build Coastguard Worker } 4256*8975f5c5SAndroid Build Coastguard Worker } 4257*8975f5c5SAndroid Build Coastguard Worker 4258*8975f5c5SAndroid Build Coastguard Worker if (_build_device_jar) { 4259*8975f5c5SAndroid Build Coastguard Worker if (_process_device_jar) { 4260*8975f5c5SAndroid Build Coastguard Worker _process_device_jar_target_name = "${target_name}__process_device" 4261*8975f5c5SAndroid Build Coastguard Worker process_java_library(_process_device_jar_target_name) { 4262*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4263*8975f5c5SAndroid Build Coastguard Worker [ 4264*8975f5c5SAndroid Build Coastguard Worker "jar_excluded_patterns", 4265*8975f5c5SAndroid Build Coastguard Worker "jar_included_patterns", 4266*8975f5c5SAndroid Build Coastguard Worker ]) 4267*8975f5c5SAndroid Build Coastguard Worker input_jar_path = _unprocessed_jar_path 4268*8975f5c5SAndroid Build Coastguard Worker 4269*8975f5c5SAndroid Build Coastguard Worker deps = _unprocessed_jar_deps + _javac_classpath_deps 4270*8975f5c5SAndroid Build Coastguard Worker output_jar_path = _device_processed_jar_path 4271*8975f5c5SAndroid Build Coastguard Worker jacoco_instrument = _jacoco_instrument 4272*8975f5c5SAndroid Build Coastguard Worker if (_jacoco_instrument) { 4273*8975f5c5SAndroid Build Coastguard Worker source_files = _source_files 4274*8975f5c5SAndroid Build Coastguard Worker target_sources_file = _target_sources_file 4275*8975f5c5SAndroid Build Coastguard Worker } 4276*8975f5c5SAndroid Build Coastguard Worker } 4277*8975f5c5SAndroid Build Coastguard Worker _process_device_jar_deps = [ ":${_process_device_jar_target_name}" ] 4278*8975f5c5SAndroid Build Coastguard Worker } else { 4279*8975f5c5SAndroid Build Coastguard Worker assert(_unprocessed_jar_path == _device_processed_jar_path) 4280*8975f5c5SAndroid Build Coastguard Worker _process_device_jar_deps = _unprocessed_jar_deps 4281*8975f5c5SAndroid Build Coastguard Worker } 4282*8975f5c5SAndroid Build Coastguard Worker 4283*8975f5c5SAndroid Build Coastguard Worker if (_skip_header_jar) { 4284*8975f5c5SAndroid Build Coastguard Worker group(_header_target_name) { 4285*8975f5c5SAndroid Build Coastguard Worker public_deps = [ ":$_process_device_jar_target_name" ] 4286*8975f5c5SAndroid Build Coastguard Worker } 4287*8975f5c5SAndroid Build Coastguard Worker } 4288*8975f5c5SAndroid Build Coastguard Worker 4289*8975f5c5SAndroid Build Coastguard Worker _dex_target_name = "${target_name}__dex" 4290*8975f5c5SAndroid Build Coastguard Worker dex(_dex_target_name) { 4291*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4292*8975f5c5SAndroid Build Coastguard Worker [ 4293*8975f5c5SAndroid Build Coastguard Worker "proguard_enable_obfuscation", 4294*8975f5c5SAndroid Build Coastguard Worker "repackage_classes", 4295*8975f5c5SAndroid Build Coastguard Worker ]) 4296*8975f5c5SAndroid Build Coastguard Worker input_class_jars = [ _device_processed_jar_path ] 4297*8975f5c5SAndroid Build Coastguard Worker enable_desugar = _enable_desugar 4298*8975f5c5SAndroid Build Coastguard Worker ignore_desugar_missing_deps = !_enable_bytecode_checks 4299*8975f5c5SAndroid Build Coastguard Worker 4300*8975f5c5SAndroid Build Coastguard Worker # There's no value in per-class dexing prebuilts since they never 4301*8975f5c5SAndroid Build Coastguard Worker # change just one class at a time. 4302*8975f5c5SAndroid Build Coastguard Worker disable_incremental = _is_prebuilt 4303*8975f5c5SAndroid Build Coastguard Worker output = _dex_path 4304*8975f5c5SAndroid Build Coastguard Worker deps = _process_device_jar_deps 4305*8975f5c5SAndroid Build Coastguard Worker 4306*8975f5c5SAndroid Build Coastguard Worker if (enable_desugar) { 4307*8975f5c5SAndroid Build Coastguard Worker # Desugaring with D8 requires full classpath. 4308*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 4309*8975f5c5SAndroid Build Coastguard Worker unprocessed_jar_path = _unprocessed_jar_path 4310*8975f5c5SAndroid Build Coastguard Worker deps += _header_classpath_deps + _unprocessed_jar_deps 4311*8975f5c5SAndroid Build Coastguard Worker } 4312*8975f5c5SAndroid Build Coastguard Worker 4313*8975f5c5SAndroid Build Coastguard Worker is_library = true 4314*8975f5c5SAndroid Build Coastguard Worker 4315*8975f5c5SAndroid Build Coastguard Worker # proguard_configs listed on java_library targets need to be marked 4316*8975f5c5SAndroid Build Coastguard Worker # as inputs to at least one target so that "gn analyze" will know 4317*8975f5c5SAndroid Build Coastguard Worker # about them. Although this target doesn't use them, it's a convenient spot 4318*8975f5c5SAndroid Build Coastguard Worker # to list them. 4319*8975f5c5SAndroid Build Coastguard Worker # https://crbug.com/827197 4320*8975f5c5SAndroid Build Coastguard Worker if (compute_inputs_for_analyze && defined(invoker.proguard_configs)) { 4321*8975f5c5SAndroid Build Coastguard Worker inputs = invoker.proguard_configs 4322*8975f5c5SAndroid Build Coastguard Worker 4323*8975f5c5SAndroid Build Coastguard Worker # For the aapt-generated proguard rules. 4324*8975f5c5SAndroid Build Coastguard Worker deps += _non_java_deps + _srcjar_deps 4325*8975f5c5SAndroid Build Coastguard Worker } 4326*8975f5c5SAndroid Build Coastguard Worker } 4327*8975f5c5SAndroid Build Coastguard Worker } 4328*8975f5c5SAndroid Build Coastguard Worker } 4329*8975f5c5SAndroid Build Coastguard Worker 4330*8975f5c5SAndroid Build Coastguard Worker if (_is_java_binary) { 4331*8975f5c5SAndroid Build Coastguard Worker # Targets might use the generated script while building, so make it a dep 4332*8975f5c5SAndroid Build Coastguard Worker # rather than a data_dep. 4333*8975f5c5SAndroid Build Coastguard Worker _java_binary_script_target_name = "${target_name}__java_binary_script" 4334*8975f5c5SAndroid Build Coastguard Worker java_binary_script(_java_binary_script_target_name) { 4335*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4336*8975f5c5SAndroid Build Coastguard Worker [ 4337*8975f5c5SAndroid Build Coastguard Worker "tiered_stop_at_level_one", 4338*8975f5c5SAndroid Build Coastguard Worker "main_class", 4339*8975f5c5SAndroid Build Coastguard Worker "max_heap_size", 4340*8975f5c5SAndroid Build Coastguard Worker "wrapper_script_args", 4341*8975f5c5SAndroid Build Coastguard Worker ]) 4342*8975f5c5SAndroid Build Coastguard Worker build_config = _build_config 4343*8975f5c5SAndroid Build Coastguard Worker script_name = _main_target_name 4344*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.wrapper_script_name)) { 4345*8975f5c5SAndroid Build Coastguard Worker script_name = invoker.wrapper_script_name 4346*8975f5c5SAndroid Build Coastguard Worker } 4347*8975f5c5SAndroid Build Coastguard Worker deps = [ ":$_build_config_target_name" ] 4348*8975f5c5SAndroid Build Coastguard Worker if (_is_robolectric) { 4349*8975f5c5SAndroid Build Coastguard Worker # For robolectric tests, we add the sdk stub jars so that classes 4350*8975f5c5SAndroid Build Coastguard Worker # that reference Android types can be loaded without throwing 4351*8975f5c5SAndroid Build Coastguard Worker # NoClassDefFoundErrors. The Robolectric sandbox makes these types 4352*8975f5c5SAndroid Build Coastguard Worker # available in non-stub form, but not until test classes are loaded 4353*8975f5c5SAndroid Build Coastguard Worker # into it. Before being loaded into the sandbox, they must be loaded 4354*8975f5c5SAndroid Build Coastguard Worker # outside of it in order to read their annotations (which configure 4355*8975f5c5SAndroid Build Coastguard Worker # the sandbox), and to enumerate test methods. 4356*8975f5c5SAndroid Build Coastguard Worker extra_classpath_jars = [ 4357*8975f5c5SAndroid Build Coastguard Worker android_sdk_jar, 4358*8975f5c5SAndroid Build Coastguard Worker "$android_sdk/optional/android.test.base.jar", 4359*8975f5c5SAndroid Build Coastguard Worker "$android_sdk/optional/android.test.runner.jar", 4360*8975f5c5SAndroid Build Coastguard Worker ] 4361*8975f5c5SAndroid Build Coastguard Worker } 4362*8975f5c5SAndroid Build Coastguard Worker } 4363*8975f5c5SAndroid Build Coastguard Worker } 4364*8975f5c5SAndroid Build Coastguard Worker 4365*8975f5c5SAndroid Build Coastguard Worker if (!defined(_validate_target_name)) { 4366*8975f5c5SAndroid Build Coastguard Worker _validate_target_name = "${target_name}__validate" 4367*8975f5c5SAndroid Build Coastguard Worker 4368*8975f5c5SAndroid Build Coastguard Worker # Allow other targets to depend on this __validate one. 4369*8975f5c5SAndroid Build Coastguard Worker group(_validate_target_name) { 4370*8975f5c5SAndroid Build Coastguard Worker deps = _java_validate_deps 4371*8975f5c5SAndroid Build Coastguard Worker } 4372*8975f5c5SAndroid Build Coastguard Worker } 4373*8975f5c5SAndroid Build Coastguard Worker 4374*8975f5c5SAndroid Build Coastguard Worker if (_supports_host && !defined(_process_host_jar_target_name)) { 4375*8975f5c5SAndroid Build Coastguard Worker group("${target_name}__host") { 4376*8975f5c5SAndroid Build Coastguard Worker deps = _java_host_deps 4377*8975f5c5SAndroid Build Coastguard Worker } 4378*8975f5c5SAndroid Build Coastguard Worker } 4379*8975f5c5SAndroid Build Coastguard Worker 4380*8975f5c5SAndroid Build Coastguard Worker # robolectric_library can depend on java_library, so java_library must 4381*8975f5c5SAndroid Build Coastguard Worker # define __assetres. 4382*8975f5c5SAndroid Build Coastguard Worker if ((_is_library || _supports_android || _is_robolectric) && 4383*8975f5c5SAndroid Build Coastguard Worker !defined(_fake_rjava_target)) { 4384*8975f5c5SAndroid Build Coastguard Worker group("${target_name}__assetres") { 4385*8975f5c5SAndroid Build Coastguard Worker if (_supports_android || _is_robolectric) { 4386*8975f5c5SAndroid Build Coastguard Worker deps = _java_assetres_deps 4387*8975f5c5SAndroid Build Coastguard Worker } 4388*8975f5c5SAndroid Build Coastguard Worker } 4389*8975f5c5SAndroid Build Coastguard Worker } 4390*8975f5c5SAndroid Build Coastguard Worker 4391*8975f5c5SAndroid Build Coastguard Worker # The top-level group is used: 4392*8975f5c5SAndroid Build Coastguard Worker # 1) To allow building the target explicitly via ninja, 4393*8975f5c5SAndroid Build Coastguard Worker # 2) To trigger all analysis deps, 4394*8975f5c5SAndroid Build Coastguard Worker # 3) By custom action() targets that want to use artifacts as inputs. 4395*8975f5c5SAndroid Build Coastguard Worker group(target_name) { 4396*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4397*8975f5c5SAndroid Build Coastguard Worker [ 4398*8975f5c5SAndroid Build Coastguard Worker "assert_no_deps", 4399*8975f5c5SAndroid Build Coastguard Worker "data", 4400*8975f5c5SAndroid Build Coastguard Worker "data_deps", 4401*8975f5c5SAndroid Build Coastguard Worker "visibility", 4402*8975f5c5SAndroid Build Coastguard Worker ]) 4403*8975f5c5SAndroid Build Coastguard Worker if (_requires_android || (_supports_android && _is_library)) { 4404*8975f5c5SAndroid Build Coastguard Worker # For non-robolectric targets, depend on other java target's top-level 4405*8975f5c5SAndroid Build Coastguard Worker # groups so that the __dex step gets depended on. 4406*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4407*8975f5c5SAndroid Build Coastguard Worker [ 4408*8975f5c5SAndroid Build Coastguard Worker "deps", 4409*8975f5c5SAndroid Build Coastguard Worker "public_deps", 4410*8975f5c5SAndroid Build Coastguard Worker ]) 4411*8975f5c5SAndroid Build Coastguard Worker if (!defined(deps)) { 4412*8975f5c5SAndroid Build Coastguard Worker deps = [] 4413*8975f5c5SAndroid Build Coastguard Worker } 4414*8975f5c5SAndroid Build Coastguard Worker if (is_cronet_build) { 4415*8975f5c5SAndroid Build Coastguard Worker _abs_deps = [] 4416*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.deps)) { 4417*8975f5c5SAndroid Build Coastguard Worker foreach(dep, invoker.deps) { 4418*8975f5c5SAndroid Build Coastguard Worker _abs_deps += [ get_label_info(dep, "label_no_toolchain") ] 4419*8975f5c5SAndroid Build Coastguard Worker } 4420*8975f5c5SAndroid Build Coastguard Worker } 4421*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.public_deps)) { 4422*8975f5c5SAndroid Build Coastguard Worker foreach(dep, invoker.public_deps) { 4423*8975f5c5SAndroid Build Coastguard Worker _abs_deps += [ get_label_info(dep, "label_no_toolchain") ] 4424*8975f5c5SAndroid Build Coastguard Worker } 4425*8975f5c5SAndroid Build Coastguard Worker } 4426*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.srcjar_deps)) { 4427*8975f5c5SAndroid Build Coastguard Worker foreach(dep, invoker.srcjar_deps) { 4428*8975f5c5SAndroid Build Coastguard Worker _abs_deps += [ get_label_info(dep, "label_no_toolchain") ] 4429*8975f5c5SAndroid Build Coastguard Worker } 4430*8975f5c5SAndroid Build Coastguard Worker } 4431*8975f5c5SAndroid Build Coastguard Worker _abs_path_source_files = [] 4432*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.sources)) { 4433*8975f5c5SAndroid Build Coastguard Worker foreach(source_file, invoker.sources) { 4434*8975f5c5SAndroid Build Coastguard Worker _abs_path_source_files += 4435*8975f5c5SAndroid Build Coastguard Worker [ get_path_info(source_file, "abspath") ] 4436*8975f5c5SAndroid Build Coastguard Worker } 4437*8975f5c5SAndroid Build Coastguard Worker } 4438*8975f5c5SAndroid Build Coastguard Worker _abs_jar_path = "" 4439*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.jar_path)) { 4440*8975f5c5SAndroid Build Coastguard Worker _abs_jar_path = get_path_info(invoker.jar_path, "abspath") 4441*8975f5c5SAndroid Build Coastguard Worker } 4442*8975f5c5SAndroid Build Coastguard Worker _sdk_version = "current" 4443*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.alternative_android_sdk_dep)) { 4444*8975f5c5SAndroid Build Coastguard Worker _sdk_version = "system_current" 4445*8975f5c5SAndroid Build Coastguard Worker } 4446*8975f5c5SAndroid Build Coastguard Worker 4447*8975f5c5SAndroid Build Coastguard Worker # See crbug/1449896 for more details about the metadata fields 4448*8975f5c5SAndroid Build Coastguard Worker # and why they are added. 4449*8975f5c5SAndroid Build Coastguard Worker metadata = { 4450*8975f5c5SAndroid Build Coastguard Worker jar_path = [ _abs_jar_path ] 4451*8975f5c5SAndroid Build Coastguard Worker source_files = _abs_path_source_files 4452*8975f5c5SAndroid Build Coastguard Worker all_deps = _abs_deps 4453*8975f5c5SAndroid Build Coastguard Worker target_type = [ _type ] 4454*8975f5c5SAndroid Build Coastguard Worker sdk_version = [ _sdk_version ] 4455*8975f5c5SAndroid Build Coastguard Worker } 4456*8975f5c5SAndroid Build Coastguard Worker } 4457*8975f5c5SAndroid Build Coastguard Worker if (!defined(public_deps)) { 4458*8975f5c5SAndroid Build Coastguard Worker public_deps = [] 4459*8975f5c5SAndroid Build Coastguard Worker } 4460*8975f5c5SAndroid Build Coastguard Worker } else { 4461*8975f5c5SAndroid Build Coastguard Worker # For robolectric targets, depend only on non-java deps and the specific 4462*8975f5c5SAndroid Build Coastguard Worker # subtargets below, which will not include __dex. 4463*8975f5c5SAndroid Build Coastguard Worker deps = _non_java_deps 4464*8975f5c5SAndroid Build Coastguard Worker public_deps = [] 4465*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.public_deps)) { 4466*8975f5c5SAndroid Build Coastguard Worker public_deps += 4467*8975f5c5SAndroid Build Coastguard Worker filter_exclude(invoker.public_deps, java_target_patterns) 4468*8975f5c5SAndroid Build Coastguard Worker } 4469*8975f5c5SAndroid Build Coastguard Worker } 4470*8975f5c5SAndroid Build Coastguard Worker if (defined(_jacoco_instrument) && _jacoco_instrument) { 4471*8975f5c5SAndroid Build Coastguard Worker deps += [ _jacoco_dep ] 4472*8975f5c5SAndroid Build Coastguard Worker } 4473*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.apk_under_test)) { 4474*8975f5c5SAndroid Build Coastguard Worker deps += [ invoker.apk_under_test ] 4475*8975f5c5SAndroid Build Coastguard Worker } 4476*8975f5c5SAndroid Build Coastguard Worker if (defined(_process_device_jar_target_name)) { 4477*8975f5c5SAndroid Build Coastguard Worker public_deps += [ ":$_process_device_jar_target_name" ] 4478*8975f5c5SAndroid Build Coastguard Worker } 4479*8975f5c5SAndroid Build Coastguard Worker if (defined(_dex_target_name)) { 4480*8975f5c5SAndroid Build Coastguard Worker public_deps += [ ":$_dex_target_name" ] 4481*8975f5c5SAndroid Build Coastguard Worker } 4482*8975f5c5SAndroid Build Coastguard Worker if (_supports_android && _is_library) { 4483*8975f5c5SAndroid Build Coastguard Worker # Robolectric targets define __assetres, but there's no need to build it 4484*8975f5c5SAndroid Build Coastguard Worker # by default. 4485*8975f5c5SAndroid Build Coastguard Worker public_deps += [ ":${target_name}__assetres" ] 4486*8975f5c5SAndroid Build Coastguard Worker } 4487*8975f5c5SAndroid Build Coastguard Worker if (_supports_host) { 4488*8975f5c5SAndroid Build Coastguard Worker # android_* targets define __host, but there's no need to build it by 4489*8975f5c5SAndroid Build Coastguard Worker # default. 4490*8975f5c5SAndroid Build Coastguard Worker public_deps += [ ":${target_name}__host" ] 4491*8975f5c5SAndroid Build Coastguard Worker } 4492*8975f5c5SAndroid Build Coastguard Worker if (_is_java_binary) { 4493*8975f5c5SAndroid Build Coastguard Worker public_deps += [ ":$_java_binary_script_target_name" ] 4494*8975f5c5SAndroid Build Coastguard Worker } 4495*8975f5c5SAndroid Build Coastguard Worker if (!defined(data_deps)) { 4496*8975f5c5SAndroid Build Coastguard Worker data_deps = [] 4497*8975f5c5SAndroid Build Coastguard Worker } 4498*8975f5c5SAndroid Build Coastguard Worker if (defined(_validate_target_name)) { 4499*8975f5c5SAndroid Build Coastguard Worker data_deps += [ ":$_validate_target_name" ] 4500*8975f5c5SAndroid Build Coastguard Worker } else { 4501*8975f5c5SAndroid Build Coastguard Worker data_deps += _java_validate_deps 4502*8975f5c5SAndroid Build Coastguard Worker } 4503*8975f5c5SAndroid Build Coastguard Worker } 4504*8975f5c5SAndroid Build Coastguard Worker } 4505*8975f5c5SAndroid Build Coastguard Worker} 4506*8975f5c5SAndroid Build Coastguard Worker 4507*8975f5c5SAndroid Build Coastguard Worker# Create a zip archive corresponding to an application bundle module. 4508*8975f5c5SAndroid Build Coastguard Worker# 4509*8975f5c5SAndroid Build Coastguard Worker# Compile all the components of a given android_apk_or_module() target into a 4510*8975f5c5SAndroid Build Coastguard Worker# zip archive suitable to later create an android_app_bundle() target. This 4511*8975f5c5SAndroid Build Coastguard Worker# archive's format is very similar to that on an APK, except for a few 4512*8975f5c5SAndroid Build Coastguard Worker# differences in internal directory layouts, and the fact that resources, as 4513*8975f5c5SAndroid Build Coastguard Worker# well as xml files, are compiled using a protocol-buffer based format (instead 4514*8975f5c5SAndroid Build Coastguard Worker# of the regular binary xml + resources.arsc). 4515*8975f5c5SAndroid Build Coastguard Worker# 4516*8975f5c5SAndroid Build Coastguard Worker# A final application bundle is built from one or more module bundle modules, 4517*8975f5c5SAndroid Build Coastguard Worker# plus some configuration file. 4518*8975f5c5SAndroid Build Coastguard Worker# 4519*8975f5c5SAndroid Build Coastguard Worker# Variables: 4520*8975f5c5SAndroid Build Coastguard Worker# module_zip_path: Output module path. 4521*8975f5c5SAndroid Build Coastguard Worker# build_config: Path to build_config of the android_apk_or_module() target. 4522*8975f5c5SAndroid Build Coastguard Worker# dex_path: If module is proguarded separately from the base module, dex_path 4523*8975f5c5SAndroid Build Coastguard Worker# is the path to its dex file and is passed directly to the creation script. 4524*8975f5c5SAndroid Build Coastguard Worker# Otherwise, dex_path is undefined and we retrieve the module's dex file 4525*8975f5c5SAndroid Build Coastguard Worker# using its build_config. 4526*8975f5c5SAndroid Build Coastguard Worker# expected_libs_and_assets: Verify the list of included native libraries 4527*8975f5c5SAndroid Build Coastguard Worker# and assets is consistent with the given expectation file. 4528*8975f5c5SAndroid Build Coastguard Worker# expected_libs_and_assets_base: Treat expected_libs_and_assets as a diff 4529*8975f5c5SAndroid Build Coastguard Worker# with this file as the base. 4530*8975f5c5SAndroid Build Coastguard Worker# is_multi_abi: If true will add a library placeholder for the missing ABI if 4531*8975f5c5SAndroid Build Coastguard Worker# either the primary or the secondary ABI has no native libraries set. 4532*8975f5c5SAndroid Build Coastguard Worker# module_name: The module's name. 4533*8975f5c5SAndroid Build Coastguard Worker# native_libraries_config: Path to file listing native libraries to be 4534*8975f5c5SAndroid Build Coastguard Worker# packaged into each module. 4535*8975f5c5SAndroid Build Coastguard Worker# proguard_enabled: Optional. True if proguarding is enabled for this 4536*8975f5c5SAndroid Build Coastguard Worker# bundle. Default is to enable this only for release builds. Note that 4537*8975f5c5SAndroid Build Coastguard Worker# this will always perform synchronized proguarding. 4538*8975f5c5SAndroid Build Coastguard Workertemplate("create_android_app_bundle_module") { 4539*8975f5c5SAndroid Build Coastguard Worker _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) 4540*8975f5c5SAndroid Build Coastguard Worker 4541*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4542*8975f5c5SAndroid Build Coastguard Worker _deps = invoker.deps 4543*8975f5c5SAndroid Build Coastguard Worker _script = "//build/android/gyp/apkbuilder.py" 4544*8975f5c5SAndroid Build Coastguard Worker 4545*8975f5c5SAndroid Build Coastguard Worker # NOTE: Compared to the inputs of the "package_apk" template action, 4546*8975f5c5SAndroid Build Coastguard Worker # this list is much smaller, since finalize_apk is never called 4547*8975f5c5SAndroid Build Coastguard Worker # by apkbuild.py --format=bundle-module. This means not using 4548*8975f5c5SAndroid Build Coastguard Worker # apksigner and zipalign as well, nor the keystore. Other 4549*8975f5c5SAndroid Build Coastguard Worker # dependencies like extra native libraries are all pulled from the 4550*8975f5c5SAndroid Build Coastguard Worker # .build_config.json through @FileArg() references (see below) and 4551*8975f5c5SAndroid Build Coastguard Worker # will be listed in the generated depfile instead. 4552*8975f5c5SAndroid Build Coastguard Worker _inputs = [ invoker.build_config ] 4553*8975f5c5SAndroid Build Coastguard Worker _outputs = [ invoker.module_zip_path ] 4554*8975f5c5SAndroid Build Coastguard Worker _args = [ 4555*8975f5c5SAndroid Build Coastguard Worker "--format=bundle-module", 4556*8975f5c5SAndroid Build Coastguard Worker "--output-apk", 4557*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.module_zip_path, root_build_dir), 4558*8975f5c5SAndroid Build Coastguard Worker "--resource-apk=@FileArg(" + 4559*8975f5c5SAndroid Build Coastguard Worker "$_rebased_build_config:deps_info:proto_resources_path)", 4560*8975f5c5SAndroid Build Coastguard Worker "--assets=@FileArg($_rebased_build_config:deps_info:assets)", 4561*8975f5c5SAndroid Build Coastguard Worker "--uncompressed-assets=@FileArg(" + 4562*8975f5c5SAndroid Build Coastguard Worker "$_rebased_build_config:deps_info:uncompressed_assets)", 4563*8975f5c5SAndroid Build Coastguard Worker "--native-libs=@FileArg($_rebased_build_config:native:libraries)", 4564*8975f5c5SAndroid Build Coastguard Worker "--native-libs=@FileArg($_rebased_build_config:native:loadable_modules)", 4565*8975f5c5SAndroid Build Coastguard Worker "--native-lib-placeholders=@FileArg($_rebased_build_config" + 4566*8975f5c5SAndroid Build Coastguard Worker ":native:native_library_placeholders)", 4567*8975f5c5SAndroid Build Coastguard Worker "--secondary-native-lib-placeholders=@FileArg($_rebased_build_config" + 4568*8975f5c5SAndroid Build Coastguard Worker ":native:secondary_native_library_placeholders)", 4569*8975f5c5SAndroid Build Coastguard Worker "--android-abi=$android_app_abi", 4570*8975f5c5SAndroid Build Coastguard Worker "--min-sdk-version=${invoker.min_sdk_version}", 4571*8975f5c5SAndroid Build Coastguard Worker "--library-always-compress=@FileArg($_rebased_build_config:native:library_always_compress)", 4572*8975f5c5SAndroid Build Coastguard Worker ] 4573*8975f5c5SAndroid Build Coastguard Worker if (defined(android_app_secondary_abi)) { 4574*8975f5c5SAndroid Build Coastguard Worker _args += [ 4575*8975f5c5SAndroid Build Coastguard Worker "--secondary-native-libs=@FileArg(" + 4576*8975f5c5SAndroid Build Coastguard Worker "$_rebased_build_config:native:secondary_abi_libraries)", 4577*8975f5c5SAndroid Build Coastguard Worker "--secondary-native-libs=@FileArg(" + 4578*8975f5c5SAndroid Build Coastguard Worker "$_rebased_build_config:native:secondary_abi_loadable_modules)", 4579*8975f5c5SAndroid Build Coastguard Worker "--secondary-android-abi=$android_app_secondary_abi", 4580*8975f5c5SAndroid Build Coastguard Worker ] 4581*8975f5c5SAndroid Build Coastguard Worker } 4582*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.is_multi_abi) && invoker.is_multi_abi) { 4583*8975f5c5SAndroid Build Coastguard Worker _args += [ "--is-multi-abi" ] 4584*8975f5c5SAndroid Build Coastguard Worker } 4585*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.uncompress_dex) && invoker.uncompress_dex) { 4586*8975f5c5SAndroid Build Coastguard Worker _args += [ "--uncompress-dex" ] 4587*8975f5c5SAndroid Build Coastguard Worker } 4588*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.extra_assets)) { 4589*8975f5c5SAndroid Build Coastguard Worker _args += [ "--assets=${invoker.extra_assets}" ] 4590*8975f5c5SAndroid Build Coastguard Worker } 4591*8975f5c5SAndroid Build Coastguard Worker 4592*8975f5c5SAndroid Build Coastguard Worker # Use either provided dex path or build config path based on type of module. 4593*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.dex_path)) { 4594*8975f5c5SAndroid Build Coastguard Worker _inputs += [ invoker.dex_path ] 4595*8975f5c5SAndroid Build Coastguard Worker _rebased_dex_path = rebase_path(invoker.dex_path, root_build_dir) 4596*8975f5c5SAndroid Build Coastguard Worker _args += [ "--dex-file=$_rebased_dex_path" ] 4597*8975f5c5SAndroid Build Coastguard Worker } else { 4598*8975f5c5SAndroid Build Coastguard Worker _args += [ "--dex-file=@FileArg($_rebased_build_config:final_dex:path)" ] 4599*8975f5c5SAndroid Build Coastguard Worker } 4600*8975f5c5SAndroid Build Coastguard Worker 4601*8975f5c5SAndroid Build Coastguard Worker if (treat_warnings_as_errors) { 4602*8975f5c5SAndroid Build Coastguard Worker _args += [ "--warnings-as-errors" ] 4603*8975f5c5SAndroid Build Coastguard Worker } 4604*8975f5c5SAndroid Build Coastguard Worker 4605*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_libs_and_assets)) { 4606*8975f5c5SAndroid Build Coastguard Worker _expectations_target = "${invoker.top_target_name}_validate_libs_and_assets" 4607*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(_expectations_target) { 4608*8975f5c5SAndroid Build Coastguard Worker _actual_file = "$target_gen_dir/$target_name.libs_and_assets" 4609*8975f5c5SAndroid Build Coastguard Worker _failure_file = "$expectations_failure_dir/" + 4610*8975f5c5SAndroid Build Coastguard Worker string_replace(invoker.expected_libs_and_assets, "/", "_") 4611*8975f5c5SAndroid Build Coastguard Worker inputs = [ 4612*8975f5c5SAndroid Build Coastguard Worker invoker.expected_libs_and_assets, 4613*8975f5c5SAndroid Build Coastguard Worker invoker.build_config, 4614*8975f5c5SAndroid Build Coastguard Worker ] 4615*8975f5c5SAndroid Build Coastguard Worker deps = [ invoker.build_config_target ] 4616*8975f5c5SAndroid Build Coastguard Worker outputs = [ 4617*8975f5c5SAndroid Build Coastguard Worker _actual_file, 4618*8975f5c5SAndroid Build Coastguard Worker _failure_file, 4619*8975f5c5SAndroid Build Coastguard Worker ] 4620*8975f5c5SAndroid Build Coastguard Worker script = _script 4621*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 4622*8975f5c5SAndroid Build Coastguard Worker "--expected-file", 4623*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_libs_and_assets, root_build_dir), 4624*8975f5c5SAndroid Build Coastguard Worker "--actual-file", 4625*8975f5c5SAndroid Build Coastguard Worker rebase_path(_actual_file, root_build_dir), 4626*8975f5c5SAndroid Build Coastguard Worker "--failure-file", 4627*8975f5c5SAndroid Build Coastguard Worker rebase_path(_failure_file, root_build_dir), 4628*8975f5c5SAndroid Build Coastguard Worker "--only-verify-expectations", 4629*8975f5c5SAndroid Build Coastguard Worker ] 4630*8975f5c5SAndroid Build Coastguard Worker if (defined(invoker.expected_libs_and_assets_base)) { 4631*8975f5c5SAndroid Build Coastguard Worker inputs += [ invoker.expected_libs_and_assets_base ] 4632*8975f5c5SAndroid Build Coastguard Worker args += [ 4633*8975f5c5SAndroid Build Coastguard Worker "--expected-file-base", 4634*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.expected_libs_and_assets_base, root_build_dir), 4635*8975f5c5SAndroid Build Coastguard Worker ] 4636*8975f5c5SAndroid Build Coastguard Worker } 4637*8975f5c5SAndroid Build Coastguard Worker if (fail_on_android_expectations) { 4638*8975f5c5SAndroid Build Coastguard Worker args += [ "--fail-on-expectations" ] 4639*8975f5c5SAndroid Build Coastguard Worker } 4640*8975f5c5SAndroid Build Coastguard Worker } 4641*8975f5c5SAndroid Build Coastguard Worker _deps += [ ":$_expectations_target" ] 4642*8975f5c5SAndroid Build Coastguard Worker } 4643*8975f5c5SAndroid Build Coastguard Worker 4644*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 4645*8975f5c5SAndroid Build Coastguard Worker deps = _deps 4646*8975f5c5SAndroid Build Coastguard Worker inputs = _inputs 4647*8975f5c5SAndroid Build Coastguard Worker outputs = _outputs 4648*8975f5c5SAndroid Build Coastguard Worker script = _script 4649*8975f5c5SAndroid Build Coastguard Worker depfile = "$target_gen_dir/$target_name.d" 4650*8975f5c5SAndroid Build Coastguard Worker args = _args + [ 4651*8975f5c5SAndroid Build Coastguard Worker "--depfile", 4652*8975f5c5SAndroid Build Coastguard Worker rebase_path(depfile, root_build_dir), 4653*8975f5c5SAndroid Build Coastguard Worker ] 4654*8975f5c5SAndroid Build Coastguard Worker } 4655*8975f5c5SAndroid Build Coastguard Worker} 4656*8975f5c5SAndroid Build Coastguard Worker 4657*8975f5c5SAndroid Build Coastguard Workertemplate("rename_jar_classes") { 4658*8975f5c5SAndroid Build Coastguard Worker action_with_pydeps(target_name) { 4659*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4660*8975f5c5SAndroid Build Coastguard Worker forward_variables_from(invoker, 4661*8975f5c5SAndroid Build Coastguard Worker [ 4662*8975f5c5SAndroid Build Coastguard Worker "deps", 4663*8975f5c5SAndroid Build Coastguard Worker "public_deps", 4664*8975f5c5SAndroid Build Coastguard Worker ]) 4665*8975f5c5SAndroid Build Coastguard Worker script = "//build/android/gyp/rename_java_classes.py" 4666*8975f5c5SAndroid Build Coastguard Worker inputs = [ 4667*8975f5c5SAndroid Build Coastguard Worker _r8_path, 4668*8975f5c5SAndroid Build Coastguard Worker invoker.input, 4669*8975f5c5SAndroid Build Coastguard Worker ] 4670*8975f5c5SAndroid Build Coastguard Worker outputs = [ invoker.output ] 4671*8975f5c5SAndroid Build Coastguard Worker args = [ 4672*8975f5c5SAndroid Build Coastguard Worker "--r8-path", 4673*8975f5c5SAndroid Build Coastguard Worker rebase_path(_r8_path, root_build_dir), 4674*8975f5c5SAndroid Build Coastguard Worker "--input-jar", 4675*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.input, root_build_dir), 4676*8975f5c5SAndroid Build Coastguard Worker "--output-jar", 4677*8975f5c5SAndroid Build Coastguard Worker rebase_path(invoker.output, root_build_dir), 4678*8975f5c5SAndroid Build Coastguard Worker ] 4679*8975f5c5SAndroid Build Coastguard Worker 4680*8975f5c5SAndroid Build Coastguard Worker foreach(_rule, invoker.renaming_rules) { 4681*8975f5c5SAndroid Build Coastguard Worker args += [ 4682*8975f5c5SAndroid Build Coastguard Worker "--map", 4683*8975f5c5SAndroid Build Coastguard Worker _rule, 4684*8975f5c5SAndroid Build Coastguard Worker ] 4685*8975f5c5SAndroid Build Coastguard Worker } 4686*8975f5c5SAndroid Build Coastguard Worker } 4687*8975f5c5SAndroid Build Coastguard Worker} 4688