tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

internal_rules.gni (182078B)


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