rules.gni (199923B)
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 import("//chromium/build/config/android/abi.gni") 6 import("//chromium/build/config/android/copy_ex.gni") 7 import("//chromium/build/config/chrome_build.gni") 8 import("//chromium/build/config/clang/clang.gni") 9 import("//chromium/build/config/rts.gni") 10 import("//chromium/build/config/sanitizers/sanitizers.gni") 11 import("//build_overrides/build.gni") 12 13 assert( 14 is_android || is_robolectric, 15 "current_toolchain=$current_toolchain default_toolchain=$default_toolchain") 16 17 _sanitizer_runtimes = [] 18 if (use_cfi_diag || is_ubsan_any) { 19 _sanitizer_runtimes += [ "$clang_base_path/lib/clang/$clang_version/lib/linux/libclang_rt.ubsan_standalone-$sanitizer_arch-android.so" ] 20 } 21 if (is_asan) { 22 _sanitizer_runtimes += [ "$clang_base_path/lib/clang/$clang_version/lib/linux/libclang_rt.asan-$sanitizer_arch-android.so" ] 23 } 24 25 # Creates a dist directory for a native executable. 26 # 27 # Running a native executable on a device requires all the shared library 28 # dependencies of that executable. To make it easier to install and run such an 29 # executable, this will create a directory containing the native exe and all 30 # it's library dependencies. 31 # 32 # Note: It's usually better to package things as an APK than as a native 33 # executable. 34 # 35 # Variables 36 # dist_dir: Directory for the exe and libraries. Everything in this directory 37 # will be deleted before copying in the exe and libraries. 38 # binary: Path to (stripped) executable. 39 # extra_files: List of extra files to copy in (optional). 40 # 41 # Example 42 # create_native_executable_dist("foo_dist") { 43 # dist_dir = "$root_build_dir/foo_dist" 44 # binary = "$root_build_dir/foo" 45 # deps = [ ":the_thing_that_makes_foo" ] 46 # } 47 template("create_native_executable_dist") { 48 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 49 50 _libraries_list = "${target_gen_dir}/${target_name}_library_dependencies.list" 51 52 _sanitizer_runtimes_target_name = "${target_name}__sanitizer_runtimes" 53 group(_sanitizer_runtimes_target_name) { 54 metadata = { 55 shared_libraries = _sanitizer_runtimes 56 } 57 } 58 59 generated_file("${target_name}__library_list") { 60 forward_variables_from(invoker, [ "deps" ]) 61 if (!defined(deps)) { 62 deps = [] 63 } 64 deps += [ ":${_sanitizer_runtimes_target_name}" ] 65 output_conversion = "json" 66 outputs = [ _libraries_list ] 67 data_keys = [ "shared_libraries" ] 68 walk_keys = [ "shared_libraries_barrier" ] 69 rebase = root_build_dir 70 } 71 72 copy_ex(target_name) { 73 inputs = [ 74 _libraries_list, 75 invoker.binary, 76 ] 77 78 dest = invoker.dist_dir 79 data = [ "${invoker.dist_dir}/" ] 80 81 _rebased_libraries_list = rebase_path(_libraries_list, root_build_dir) 82 _rebased_binaries_list = rebase_path([ invoker.binary ], root_build_dir) 83 args = [ 84 "--clear", 85 "--files=@FileArg($_rebased_libraries_list)", 86 "--files=$_rebased_binaries_list", 87 ] 88 if (defined(invoker.extra_files)) { 89 _rebased_extra_files = rebase_path(invoker.extra_files, root_build_dir) 90 args += [ "--files=$_rebased_extra_files" ] 91 } 92 93 _depfile = "$target_gen_dir/$target_name.d" 94 _stamp_file = "$target_gen_dir/$target_name.stamp" 95 outputs = [ _stamp_file ] 96 args += [ 97 "--depfile", 98 rebase_path(_depfile, root_build_dir), 99 "--stamp", 100 rebase_path(_stamp_file, root_build_dir), 101 ] 102 103 deps = [ ":${target_name}__library_list" ] 104 if (defined(invoker.deps)) { 105 deps += invoker.deps 106 } 107 } 108 } 109 110 if (!is_robolectric && enable_java_templates) { 111 import("//chromium/build/config/android/config.gni") 112 import("//chromium/build/config/android/internal_rules.gni") 113 import("//chromium/build/config/compiler/compiler.gni") 114 import("//chromium/build/config/coverage/coverage.gni") 115 import("//chromium/build/config/profiling/profiling.gni") 116 import("//chromium/build/config/python.gni") 117 import("//chromium/build/config/zip.gni") 118 import("//chromium/build/toolchain/toolchain.gni") 119 120 _BUNDLETOOL_JAR_PATH = 121 "//third_party/android_build_tools/bundletool/cipd/bundletool.jar" 122 123 # Declare a target for c-preprocessor-generated java files 124 # 125 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum 126 # rule instead. 127 # 128 # This target generates java files using the host C pre-processor. Each file in 129 # sources will be compiled using the C pre-processor. If include_path is 130 # specified, it will be passed (with --I) to the pre-processor. 131 # 132 # This target will create a single .srcjar. Adding this target to an 133 # android_library target's srcjar_deps will make the generated java files be 134 # included in that library's final outputs. 135 # 136 # Variables 137 # sources: list of files to be processed by the C pre-processor. For each 138 # file in sources, there will be one .java file in the final .srcjar. For a 139 # file named FooBar.template, a java file will be created with name 140 # FooBar.java. 141 # inputs: additional compile-time dependencies. Any files 142 # `#include`-ed in the templates should be listed here. 143 # defines: List of -D arguments for the preprocessor. 144 # 145 # Example 146 # java_cpp_template("foo_generated_enum") { 147 # sources = [ 148 # "android/java/templates/Foo.template", 149 # ] 150 # inputs = [ 151 # "android/java/templates/native_foo_header.h", 152 # ] 153 # } 154 template("java_cpp_template") { 155 action_with_pydeps(target_name) { 156 forward_variables_from(invoker, 157 [ 158 "data_deps", 159 "deps", 160 "inputs", 161 "public_deps", 162 "sources", 163 "testonly", 164 "visibility", 165 ]) 166 script = "//chromium/build/android/gyp/gcc_preprocess.py" 167 outputs = [ "$target_gen_dir/$target_name.srcjar" ] 168 169 _include_dirs = [ 170 "//", 171 root_gen_dir, 172 ] 173 _rebased_include_dirs = rebase_path(_include_dirs, root_build_dir) 174 args = [ 175 "--include-dirs=$_rebased_include_dirs", 176 "--output", 177 rebase_path(outputs[0], root_build_dir), 178 ] 179 if (defined(invoker.defines)) { 180 foreach(_define, invoker.defines) { 181 args += [ 182 "--define", 183 _define, 184 ] 185 } 186 } 187 args += rebase_path(sources, root_build_dir) 188 } 189 } 190 191 # Declare a target for generating Java classes from C++ enums. 192 # 193 # This target generates Java files from C++ enums using a script. 194 # 195 # This target will create a single .srcjar. Adding this target to an 196 # android_library target's srcjar_deps will make the generated java files be 197 # included in that library's final outputs. 198 # 199 # Variables 200 # sources: list of files to be processed by the script. For each annotated 201 # enum contained in the sources files the script will generate a .java 202 # file with the same name as the name of the enum. 203 # 204 # Example 205 # java_cpp_enum("foo_generated_enum") { 206 # sources = [ 207 # "src/native_foo_header.h", 208 # ] 209 # } 210 template("java_cpp_enum") { 211 action_with_pydeps(target_name) { 212 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "sources" ]) 213 214 # The sources aren't compiled so don't check their dependencies. 215 check_includes = false 216 script = "//chromium/build/android/gyp/java_cpp_enum.py" 217 218 _srcjar_path = "${target_gen_dir}/${target_name}.srcjar" 219 _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir) 220 _rebased_sources = rebase_path(invoker.sources, root_build_dir) 221 222 args = [ "--srcjar=$_rebased_srcjar_path" ] + _rebased_sources 223 outputs = [ _srcjar_path ] 224 } 225 } 226 227 # Declare a target for generating Java classes with string constants matching 228 # those found in C++ files using a python script. 229 # 230 # This target will create a single .srcjar. Adding this target to an 231 # android_library target's srcjar_deps will make the generated java files be 232 # included in that library's final outputs. 233 # 234 # Variables 235 # sources: list of files to be processed by the script. For each string 236 # constant in the source files, the script will add a corresponding 237 # Java string to the specified template file. 238 # Example 239 # java_cpp_strings("foo_switches") { 240 # sources = [ 241 # "src/foo_switches.cc", 242 # ] 243 # template = "src/templates/FooSwitches.java.tmpl 244 # } 245 # 246 # foo_switches.cc: 247 # 248 # // A switch. 249 # const char kASwitch = "a-switch"; 250 # 251 # FooSwitches.java.tmpl 252 # 253 # // Copyright {YEAR} The Chromium Authors 254 # // Use of this source code is governed by a BSD-style license that can be 255 # // found in the LICENSE file. 256 # 257 # // This file is autogenerated by 258 # // {SCRIPT_NAME} 259 # // From 260 # // {SOURCE_PATH}, and 261 # // {TEMPLATE_PATH} 262 # 263 # package my.java.package; 264 # 265 # public abstract class FooSwitches {{ 266 # // ...snip... 267 # {NATIVE_STRINGS} 268 # // ...snip... 269 # }} 270 # 271 # result: 272 # A FooSwitches.java file, defining a class named FooSwitches in the package 273 # my.java.package. 274 template("java_cpp_strings") { 275 action_with_pydeps(target_name) { 276 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "sources" ]) 277 278 # The sources aren't compiled so don't check their dependencies. 279 check_includes = false 280 script = "//chromium/build/android/gyp/java_cpp_strings.py" 281 282 _srcjar_path = "${target_gen_dir}/${target_name}.srcjar" 283 _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir) 284 _rebased_sources = rebase_path(invoker.sources, root_build_dir) 285 _rebased_template = rebase_path(invoker.template, root_build_dir) 286 287 args = [ 288 "--srcjar=$_rebased_srcjar_path", 289 "--template=$_rebased_template", 290 ] 291 args += _rebased_sources 292 sources += [ invoker.template ] 293 294 outputs = [ _srcjar_path ] 295 } 296 } 297 298 # Declare a target for generating Java classes with string constants matching 299 # those found in C++ base::Feature declarations, using a python script. 300 # 301 # This target will create a single .srcjar. Adding this target to an 302 # android_library target's srcjar_deps will make the generated java files be 303 # included in that library's final outputs. 304 # 305 # Variables 306 # sources: list of files to be processed by the script. For each 307 # base::Feature in the source files, the script will add a 308 # corresponding Java string for that feature's name to the 309 # specified template file. 310 # Example 311 # java_cpp_features("foo_features") { 312 # sources = [ 313 # "src/foo_features.cc", 314 # ] 315 # template = "src/templates/FooFeatures.java.tmpl 316 # } 317 # 318 # foo_features.cc: 319 # 320 # // A feature. 321 # BASE_FEATURE(kSomeFeature, "SomeFeature", 322 # base::FEATURE_DISABLED_BY_DEFAULT); 323 # 324 # FooFeatures.java.tmpl 325 # 326 # // Copyright $YEAR The Chromium Authors 327 # // Use of this source code is governed by a BSD-style license that can be 328 # // found in the LICENSE file. 329 # 330 # package my.java.package; 331 # 332 # public final class FooFeatures {{ 333 # // ...snip... 334 # {NATIVE_STRINGS} 335 # // ...snip... 336 # // Do not instantiate this class. 337 # private FooFeatures() {{}} 338 # }} 339 # 340 # result: 341 # A FooFeatures.java file, defining a class named FooFeatures in the package 342 # my.java.package. 343 template("java_cpp_features") { 344 action_with_pydeps(target_name) { 345 forward_variables_from(invoker, 346 TESTONLY_AND_VISIBILITY + [ 347 "deps", 348 "sources", 349 ]) 350 351 # The sources aren't compiled so don't check their dependencies. 352 check_includes = false 353 script = "//chromium/build/android/gyp/java_cpp_features.py" 354 355 _srcjar_path = "${target_gen_dir}/${target_name}.srcjar" 356 _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir) 357 _rebased_sources = rebase_path(invoker.sources, root_build_dir) 358 _rebased_template = rebase_path(invoker.template, root_build_dir) 359 360 args = [ 361 "--srcjar=$_rebased_srcjar_path", 362 "--template=$_rebased_template", 363 ] 364 args += _rebased_sources 365 sources += [ invoker.template ] 366 367 outputs = [ _srcjar_path ] 368 } 369 } 370 371 # Declare a target for processing a Jinja template. 372 # 373 # Variables 374 # input: The template file to be processed. 375 # includes: List of files {% include %}'ed by input. 376 # output: Where to save the result. 377 # variables: (Optional) A list of variables to make available to the template 378 # processing environment, e.g. ["name=foo", "color=red"]. 379 # 380 # Example 381 # jinja_template("chrome_public_manifest") { 382 # input = "java/AndroidManifest.xml" 383 # output = "$target_gen_dir/AndroidManifest.xml" 384 # } 385 template("jinja_template") { 386 action_with_pydeps(target_name) { 387 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 388 inputs = [ invoker.input ] 389 if (defined(invoker.includes)) { 390 inputs += invoker.includes 391 } 392 script = "//chromium/build/android/gyp/jinja_template.py" 393 394 outputs = [ invoker.output ] 395 396 args = [ 397 "--loader-base-dir", 398 rebase_path("//", root_build_dir), 399 "--inputs", 400 rebase_path(invoker.input, root_build_dir), 401 "--output", 402 rebase_path(invoker.output, root_build_dir), 403 "--check-includes", 404 ] 405 if (defined(invoker.includes)) { 406 _rebased_includes = rebase_path(invoker.includes, root_build_dir) 407 args += [ "--includes=$_rebased_includes" ] 408 } 409 if (defined(invoker.variables)) { 410 args += [ "--variables=${invoker.variables}" ] 411 } 412 } 413 } 414 415 # Writes native libraries to a NativeLibaries.java file. 416 # 417 # This target will create a single .srcjar. Adding this target to an 418 # android_library target's srcjar_deps will make the generated java files be 419 # included in that library's final outputs. 420 # 421 # Variables: 422 # native_libraries_list_file: (Optional) Path to file listing all native 423 # libraries to write. 424 # version_number: (Optional) String of expected version of 'main' native 425 # library. 426 # enable_chromium_linker: (Optional) Whether to use the Chromium linker. 427 # use_final_fields: True to use final fields. When false, all other 428 # variables must not be set. 429 template("write_native_libraries_java") { 430 _native_libraries_file = "$target_gen_dir/$target_name.srcjar" 431 if (target_cpu == "arm" || target_cpu == "arm64") { 432 _cpu_family = "CPU_FAMILY_ARM" 433 } else if (target_cpu == "x86" || target_cpu == "x64") { 434 _cpu_family = "CPU_FAMILY_X86" 435 } else if (target_cpu == "mipsel" || target_cpu == "mips64el") { 436 _cpu_family = "CPU_FAMILY_MIPS" 437 } else if (target_cpu == "riscv64") { 438 _cpu_family = "CPU_FAMILY_RISCV" 439 } else { 440 assert(false, "Unsupported CPU family") 441 } 442 443 action_with_pydeps(target_name) { 444 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 445 script = "//chromium/build/android/gyp/write_native_libraries_java.py" 446 outputs = [ _native_libraries_file ] 447 args = [ 448 "--output", 449 rebase_path(_native_libraries_file, root_build_dir), 450 "--cpu-family", 451 _cpu_family, 452 ] 453 if (invoker.use_final_fields) { 454 # Write native_libraries_list_file via depfile rather than specifyin it 455 # as a dep in order allow R8 to run in parallel with native compilation. 456 args += [ "--final" ] 457 if (defined(invoker.native_libraries_list_file)) { 458 depfile = "$target_gen_dir/$target_name.d" 459 args += [ 460 "--native-libraries-list", 461 rebase_path(invoker.native_libraries_list_file, root_build_dir), 462 "--depfile", 463 rebase_path(depfile, root_build_dir), 464 ] 465 } 466 if (defined(invoker.enable_chromium_linker) && 467 invoker.enable_chromium_linker) { 468 args += [ "--enable-chromium-linker" ] 469 } 470 if (defined(invoker.native_lib_32_bit) && invoker.native_lib_32_bit) { 471 args += [ "--native-lib-32-bit" ] 472 } 473 if (defined(invoker.native_lib_64_bit) && invoker.native_lib_64_bit) { 474 args += [ "--native-lib-64-bit" ] 475 } 476 } 477 } 478 } 479 480 # Declare a target for a set of Android resources generated at build 481 # time and stored in a single zip archive. The content of the archive 482 # should match the layout of a regular Android res/ folder (but the 483 # archive should not include a top-level res/ directory). 484 # 485 # Note that there is no associated .srcjar, R.txt or package name 486 # associated with this target. 487 # 488 # Variables: 489 # generated_resources_zip: Generated zip archive path. 490 # generating_target: Name of the target generating 491 # generated_resources_zip. This rule will check that it is part 492 # of its outputs. 493 # deps: Specifies the dependencies of this target. Any Android resources 494 # listed here will be also be included *after* this one when compiling 495 # all resources for a final apk or junit binary. This is useful to 496 # ensure that the resources of the current target override those of the 497 # dependency as well (and would not work if you have these deps to the 498 # generating target's dependencies). 499 # 500 # Example 501 # _zip_archive = "$target_gen_dir/${target_name}.resources_zip" 502 # 503 # action("my_resources__create_zip") { 504 # _depfile = "$target_gen_dir/${target_name}.d" 505 # script = "//chromium/build/path/to/create_my_resources_zip.py" 506 # args = [ 507 # "--depfile", rebase_path(_depfile, root_build_dir), 508 # "--output-zip", rebase_path(_zip_archive, root_build_dir), 509 # ] 510 # inputs = [] 511 # outputs = _zip_archive 512 # depfile = _depfile 513 # } 514 # 515 # android_generated_resources("my_resources") { 516 # generated_resources_zip = _zip_archive 517 # generating_target = ":my_resources__create_zip" 518 # } 519 # 520 template("android_generated_resources") { 521 forward_variables_from(invoker, [ "testonly" ]) 522 _build_config = "$target_gen_dir/${target_name}.build_config.json" 523 _rtxt_out_path = "$target_gen_dir/${target_name}.R.txt" 524 write_build_config("$target_name$build_config_target_suffix") { 525 forward_variables_from(invoker, [ "resource_overlay" ]) 526 527 build_config = _build_config 528 resources_zip = invoker.generated_resources_zip 529 type = "android_resources" 530 if (defined(invoker.deps)) { 531 possible_config_deps = invoker.deps 532 } 533 r_text = _rtxt_out_path 534 } 535 action_with_pydeps(target_name) { 536 forward_variables_from(invoker, [ "visibility" ]) 537 public_deps = [ 538 ":$target_name$build_config_target_suffix", 539 invoker.generating_target, 540 ] 541 inputs = [ invoker.generated_resources_zip ] 542 outputs = [ _rtxt_out_path ] 543 script = "//chromium/build/android/gyp/create_r_txt.py" 544 args = [ 545 "--resources-zip-path", 546 rebase_path(invoker.generated_resources_zip, root_build_dir), 547 "--rtxt-path", 548 rebase_path(_rtxt_out_path, root_build_dir), 549 ] 550 } 551 } 552 553 # Declare a target for processing Android resources as Jinja templates. 554 # 555 # This takes an Android resource directory where each resource is a Jinja 556 # template, processes each template, then packages the results in a zip file 557 # which can be consumed by an android resources, library, or apk target. 558 # 559 # If this target is included in the deps of an android resources/library/apk, 560 # the resources will be included with that target. 561 # 562 # Variables 563 # resources: The list of resources files to process. 564 # res_dir: The resource directory containing the resources. 565 # variables: (Optional) A list of variables to make available to the template 566 # processing environment, e.g. ["name=foo", "color=red"]. 567 # 568 # Example 569 # jinja_template_resources("chrome_public_template_resources") { 570 # res_dir = "res_template" 571 # resources = ["res_template/xml/syncable.xml"] 572 # variables = ["color=red"] 573 # } 574 template("jinja_template_resources") { 575 _resources_zip = "$target_out_dir/${target_name}.resources.zip" 576 _generating_target_name = "${target_name}__template" 577 578 action_with_pydeps(_generating_target_name) { 579 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 580 inputs = invoker.resources 581 script = "//chromium/build/android/gyp/jinja_template.py" 582 583 outputs = [ _resources_zip ] 584 585 _rebased_resources = rebase_path(invoker.resources, root_build_dir) 586 args = [ 587 "--inputs=${_rebased_resources}", 588 "--inputs-base-dir", 589 rebase_path(invoker.res_dir, root_build_dir), 590 "--outputs-zip", 591 rebase_path(_resources_zip, root_build_dir), 592 "--check-includes", 593 ] 594 if (defined(invoker.variables)) { 595 variables = invoker.variables 596 args += [ "--variables=${variables}" ] 597 } 598 } 599 600 android_generated_resources(target_name) { 601 forward_variables_from(invoker, 602 TESTONLY_AND_VISIBILITY + [ 603 "deps", 604 "resource_overlay", 605 ]) 606 generating_target = ":$_generating_target_name" 607 generated_resources_zip = _resources_zip 608 } 609 } 610 611 # Declare a prebuilt android native library. 612 # 613 # This takes a base directory and library name and then looks for the library 614 # in <base dir>/$android_app_abi/<library name>. 615 # 616 # If you depend on this target, the library is stripped and output to the 617 # same locations non-prebuilt libraries are output. 618 # 619 # Variables 620 # base_dir: Directory where all ABIs of the library live. 621 # library_name: Name of the library .so file. 622 # 623 # Example 624 # android_native_prebuilt("elements_native") { 625 # base_dir = "//third_party/elements" 626 # lib_name = "elements.so" 627 # } 628 template("android_native_prebuilt") { 629 action_with_pydeps(target_name) { 630 forward_variables_from(invoker, 631 [ 632 "deps", 633 "testonly", 634 ]) 635 script = "//chromium/build/android/gyp/process_native_prebuilt.py" 636 _lib_path = "${invoker.base_dir}/$android_app_abi/${invoker.lib_name}" 637 _stripped_output_path = "$root_out_dir/${invoker.lib_name}" 638 _unstripped_output_path = 639 "$root_out_dir/lib.unstripped/${invoker.lib_name}" 640 inputs = [ _lib_path ] 641 outputs = [ 642 _stripped_output_path, 643 _unstripped_output_path, 644 ] 645 646 # Add unstripped output to runtime deps for use by bots during stacktrace 647 # symbolization. 648 data = [ _unstripped_output_path ] 649 650 _rebased_lib_path = rebase_path(_lib_path, root_build_dir) 651 _rebased_stripped_ouput_path = 652 rebase_path(_stripped_output_path, root_build_dir) 653 _rebased_unstripped_ouput_path = 654 rebase_path(_unstripped_output_path, root_build_dir) 655 _strip_tool_path = 656 rebase_path("//buildtools/third_party/eu-strip/bin/eu-strip", 657 root_build_dir) 658 659 args = [ 660 "--strip-path=$_strip_tool_path", 661 "--input-path=$_rebased_lib_path", 662 "--stripped-output-path=$_rebased_stripped_ouput_path", 663 "--unstripped-output-path=$_rebased_unstripped_ouput_path", 664 ] 665 } 666 } 667 668 # Declare an Android resources target 669 # 670 # This creates a resources zip file that will be used when building an Android 671 # library or apk and included into a final apk. 672 # 673 # To include these resources in a library/apk, this target should be listed in 674 # the library's deps. A library/apk will also include any resources used by its 675 # own dependencies. 676 # 677 # Variables 678 # sources: List of resource files for this target. 679 # deps: Specifies the dependencies of this target. Any Android resources 680 # listed in deps will be included by libraries/apks that depend on this 681 # target. 682 # alternative_android_sdk_dep: Optional. Alternative Android system 683 # android java target to use. 684 # android_manifest: AndroidManifest.xml for this target (optional). Will be 685 # merged into apks that directly or indirectly depend on this target. 686 # android_manifest_dep: Target that generates AndroidManifest (if applicable) 687 # custom_package: java package for generated .java files. 688 # allow_missing_resources: Do not fail if a resource exists in a directory 689 # but is not listed in sources. 690 # shared_resources: If true make a resource package that can be loaded by a 691 # different application at runtime to access the package's resources. 692 # resource_overlay: Whether the resources in 'sources' should override 693 # resources with the same name. Does not affect the behaviour of any 694 # android_resources() deps of this target. If a target with 695 # resource_overlay=true depends on another target with 696 # resource_overlay=true the target with the dependency overrides the 697 # other. 698 # r_text_file: (optional) path to pre-generated R.txt to be used when 699 # generating R.java instead of resource-based aapt-generated one. 700 # recursive_resource_deps: (optional) whether deps should be walked 701 # recursively to find resource deps. 702 # 703 # Example: 704 # android_resources("foo_resources") { 705 # deps = [":foo_strings_grd"] 706 # sources = [ 707 # "res/drawable/foo1.xml", 708 # "res/drawable/foo2.xml", 709 # ] 710 # custom_package = "org.chromium.foo" 711 # } 712 # 713 # android_resources("foo_resources_overrides") { 714 # deps = [":foo_resources"] 715 # sources = [ 716 # "res_overrides/drawable/foo1.xml", 717 # "res_overrides/drawable/foo2.xml", 718 # ] 719 # } 720 template("android_resources") { 721 forward_variables_from(invoker, [ "testonly" ]) 722 723 _base_path = "$target_gen_dir/$target_name" 724 if (defined(invoker.v14_skip)) { 725 not_needed(invoker, [ "v14_skip" ]) 726 } 727 728 _res_sources_path = "$target_gen_dir/${invoker.target_name}.res.sources" 729 730 _resources_zip = "$target_out_dir/$target_name.resources.zip" 731 _r_text_out_path = _base_path + "_R.txt" 732 _build_config = _base_path + ".build_config.json" 733 _build_config_target_name = "$target_name$build_config_target_suffix" 734 735 _deps = [] 736 if (defined(invoker.deps)) { 737 _deps += invoker.deps 738 } 739 740 if (defined(invoker.alternative_android_sdk_dep)) { 741 _android_sdk_dep = invoker.alternative_android_sdk_dep 742 } else { 743 _android_sdk_dep = default_android_sdk_dep 744 } 745 746 _resource_files = [] 747 if (defined(invoker.sources)) { 748 _resource_files += invoker.sources 749 } 750 751 _rebased_resource_files = rebase_path(_resource_files, root_build_dir) 752 write_file(_res_sources_path, _rebased_resource_files) 753 754 # This is necessary so we only lint chromium resources. 755 if (defined(invoker.chromium_code)) { 756 _chromium_code = invoker.chromium_code 757 } else { 758 # Default based on whether target is in third_party. 759 _chromium_code = 760 filter_exclude([ get_label_info(":$target_name", "dir") ], 761 [ "*\bthird_party\b*" ]) != [] 762 } 763 764 write_build_config(_build_config_target_name) { 765 type = "android_resources" 766 build_config = _build_config 767 resources_zip = _resources_zip 768 res_sources_path = _res_sources_path 769 chromium_code = _chromium_code 770 771 forward_variables_from(invoker, 772 [ 773 "android_manifest", 774 "android_manifest_dep", 775 "custom_package", 776 "mergeable_android_manifests", 777 "resource_overlay", 778 "recursive_resource_deps", 779 ]) 780 781 r_text = _r_text_out_path 782 possible_config_deps = _deps + [ _android_sdk_dep ] 783 784 # Always merge manifests from resources. 785 # * Might want to change this at some point for consistency and clarity, 786 # but keeping for backwards-compatibility. 787 if (!defined(mergeable_android_manifests) && defined(android_manifest)) { 788 mergeable_android_manifests = [ android_manifest ] 789 } 790 } 791 792 prepare_resources(target_name) { 793 forward_variables_from(invoker, 794 [ 795 "allow_missing_resources", 796 "public_deps", 797 "strip_drawables", 798 "visibility", 799 ]) 800 _lib_deps = filter_exclude(filter_include(_deps, java_library_patterns), 801 java_resource_patterns) 802 if (defined(public_deps)) { 803 # Since java library targets depend directly on sub-targets rather than 804 # top-level targets, public_deps are not properly propagated, at least 805 # in terms of the "did you depend on the target that generates your 806 # inputs" GN check. 807 assert(filter_include(public_deps, java_target_patterns) == [], 808 "Java targets should use deps, not public_deps. " + 809 "target=${target_name}, public_deps=${public_deps}") 810 } 811 812 # Depend on non-library deps and on __assetres subtargets of library deps. 813 deps = filter_exclude(_deps, _lib_deps) + [ _android_sdk_dep ] 814 foreach(_lib_dep, _lib_deps) { 815 # Expand //foo/java -> //foo/java:java 816 _lib_dep = get_label_info(_lib_dep, "label_no_toolchain") 817 deps += [ "${_lib_dep}__assetres" ] 818 } 819 820 res_sources_path = _res_sources_path 821 sources = _resource_files 822 823 resources_zip = _resources_zip 824 r_text_out_path = _r_text_out_path 825 826 if (defined(invoker.r_text_file)) { 827 r_text_in_path = invoker.r_text_file 828 } 829 } 830 } 831 832 # Declare an Android assets target. 833 # 834 # Defines a set of files to include as assets in a dependent apk. 835 # 836 # To include these assets in an apk, this target should be listed in 837 # the apk's deps, or in the deps of a library target used by an apk. 838 # 839 # Variables 840 # deps: Specifies the dependencies of this target. Any Android assets 841 # listed in deps will be included by libraries/apks that depend on this 842 # target. 843 # sources: List of files to include as assets. 844 # renaming_sources: List of files to include as assets and be renamed. 845 # renaming_destinations: List of asset paths for files in renaming_sources. 846 # disable_compression: Whether to disable compression for files that are 847 # known to be compressable (default: false). 848 # treat_as_locale_paks: Causes base's BuildConfig.java to consider these 849 # assets to be locale paks. 850 # 851 # Example: 852 # android_assets("content_shell_assets") { 853 # deps = [ 854 # ":generates_foo", 855 # ":other_assets", 856 # ] 857 # sources = [ 858 # "//path/asset1.png", 859 # "//path/asset2.png", 860 # "$target_gen_dir/foo.dat", 861 # ] 862 # } 863 # 864 # android_assets("overriding_content_shell_assets") { 865 # deps = [ ":content_shell_assets" ] 866 # # Override foo.dat from content_shell_assets. 867 # sources = [ "//custom/foo.dat" ] 868 # renaming_sources = [ "//path/asset2.png" ] 869 # renaming_destinations = [ "renamed/asset2.png" ] 870 # } 871 template("android_assets") { 872 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 873 874 _build_config = "$target_gen_dir/$target_name.build_config.json" 875 _build_config_target_name = "$target_name$build_config_target_suffix" 876 877 _sources = [] 878 if (defined(invoker.sources)) { 879 _sources = invoker.sources 880 } 881 _renaming_sources = [] 882 if (defined(invoker.renaming_sources)) { 883 _renaming_sources = invoker.renaming_sources 884 } 885 write_build_config(_build_config_target_name) { 886 type = "android_assets" 887 build_config = _build_config 888 889 forward_variables_from(invoker, 890 [ 891 "disable_compression", 892 "treat_as_locale_paks", 893 ]) 894 895 if (defined(invoker.deps)) { 896 possible_config_deps = invoker.deps 897 } 898 899 if (_sources != []) { 900 asset_sources = _sources 901 } 902 if (_renaming_sources != []) { 903 assert(defined(invoker.renaming_destinations)) 904 _source_count = 0 905 foreach(_, _renaming_sources) { 906 _source_count += 1 907 } 908 _dest_count = 0 909 foreach(_, invoker.renaming_destinations) { 910 _dest_count += 1 911 } 912 assert( 913 _source_count == _dest_count, 914 "android_assets() renaming_sources.length != renaming_destinations.length") 915 asset_renaming_sources = _renaming_sources 916 asset_renaming_destinations = invoker.renaming_destinations 917 } 918 } 919 920 # Use an action in order to mark sources as "inputs" to a GN target so that 921 # GN will fail if the appropriate deps do not exist, and so that "gn refs" 922 # will know about the sources. We do not add these inputs & deps to the 923 # __build_config target because we want building .build_config.json files 924 # to be fast (and because write_build_config.py does not need the files to 925 # exist). 926 _all_sources = _sources + _renaming_sources 927 if (_all_sources != []) { 928 action(target_name) { 929 forward_variables_from(invoker, [ "deps" ]) 930 public_deps = [ ":$_build_config_target_name" ] 931 932 script = "//chromium/build/android/gyp/validate_inputs.py" 933 inputs = _all_sources 934 outputs = [ "$target_gen_dir/$target_name.stamp" ] 935 args = [ 936 "--stamp", 937 rebase_path(outputs[0], root_build_dir), 938 ] + rebase_path(_all_sources, root_build_dir) 939 } 940 } else { 941 group(target_name) { 942 forward_variables_from(invoker, [ "deps" ]) 943 public_deps = [ ":$_build_config_target_name" ] 944 } 945 } 946 } 947 948 # Declare a group() that supports forwarding java dependency information. 949 # 950 # Example 951 # java_group("conditional_deps") { 952 # if (enable_foo) { 953 # deps = [":foo_java"] 954 # } 955 # } 956 template("java_group") { 957 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 958 _build_config_vars = [ 959 "input_jars_paths", 960 "preferred_dep", 961 "mergeable_android_manifests", 962 "proguard_configs", 963 "requires_android", 964 ] 965 _invoker_deps = [] 966 if (defined(invoker.deps)) { 967 _invoker_deps += invoker.deps 968 } 969 if (defined(invoker.public_deps)) { 970 _invoker_deps += invoker.public_deps 971 } 972 write_build_config("$target_name$build_config_target_suffix") { 973 forward_variables_from(invoker, _build_config_vars) 974 type = "group" 975 build_config = "$target_gen_dir/${invoker.target_name}.build_config.json" 976 supports_android = true 977 possible_config_deps = _invoker_deps 978 } 979 980 _assetres_deps = filter_include(_invoker_deps, java_resource_patterns) 981 _invoker_deps_minus_assetres = filter_exclude(_invoker_deps, _assetres_deps) 982 _lib_deps = 983 filter_include(_invoker_deps_minus_assetres, java_library_patterns) 984 _other_deps = _invoker_deps_minus_assetres - _lib_deps 985 986 _expanded_lib_deps = [] 987 foreach(_lib_dep, _lib_deps) { 988 _expanded_lib_deps += [ get_label_info(_lib_dep, "label_no_toolchain") ] 989 } 990 foreach(_group_name, 991 [ 992 "assetres", 993 "header", 994 "host", 995 "validate", 996 ]) { 997 group("${target_name}__$_group_name") { 998 deps = [] 999 foreach(_lib_dep, _expanded_lib_deps) { 1000 deps += [ "${_lib_dep}__${_group_name}" ] 1001 } 1002 if (_group_name == "assetres") { 1003 # _other_deps are necessary when generating mergeable_android_manifests. 1004 deps += _assetres_deps + _other_deps 1005 } else if (_group_name == "header" && defined(invoker.jar_deps)) { 1006 deps += invoker.jar_deps 1007 } 1008 } 1009 } 1010 1011 group(target_name) { 1012 forward_variables_from(invoker, 1013 "*", 1014 _build_config_vars + TESTONLY_AND_VISIBILITY) 1015 if (!defined(deps)) { 1016 deps = [] 1017 } 1018 deps += [ ":$target_name$build_config_target_suffix" ] 1019 if (is_cronet_build) { 1020 _abs_deps = [] 1021 if (defined(invoker.deps)) { 1022 foreach(dep, invoker.deps) { 1023 _abs_deps += [ get_label_info(dep, "label_no_toolchain") ] 1024 } 1025 } 1026 metadata = { 1027 all_deps = _abs_deps 1028 target_type = [ "java_library" ] 1029 } 1030 } 1031 } 1032 } 1033 1034 # Declare a Java executable target 1035 # 1036 # Same as java_library, but also creates a wrapper script within 1037 # $root_out_dir/bin. 1038 # 1039 # Supports all variables of java_library(), plus: 1040 # main_class: When specified, a wrapper script is created within 1041 # $root_build_dir/bin to launch the binary with the given class as the 1042 # entrypoint. 1043 # wrapper_script_name: Filename for the wrapper script (default=target_name) 1044 # wrapper_script_args: List of additional arguments for the wrapper script. 1045 # 1046 # Example 1047 # java_binary("foo") { 1048 # sources = [ "org/chromium/foo/FooMain.java" ] 1049 # deps = [ ":bar_java" ] 1050 # main_class = "org.chromium.foo.FooMain" 1051 # } 1052 # 1053 # java_binary("foo") { 1054 # jar_path = "lib/prebuilt.jar" 1055 # deps = [ ":bar_java" ] 1056 # main_class = "org.chromium.foo.FooMain" 1057 # } 1058 template("java_binary") { 1059 java_library_impl(target_name) { 1060 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1061 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1062 type = "java_binary" 1063 } 1064 } 1065 1066 # Declare a Java Annotation Processor. 1067 # 1068 # Supports all variables of java_library(), plus: 1069 # jar_path: Path to a prebuilt jar. Mutually exclusive with sources & 1070 # srcjar_deps. 1071 # main_class: The fully-quallified class name of the processor's entry 1072 # point. 1073 # 1074 # Example 1075 # java_annotation_processor("foo_processor") { 1076 # sources = [ "org/chromium/foo/FooProcessor.java" ] 1077 # deps = [ ":bar_java" ] 1078 # main_class = "org.chromium.foo.FooProcessor" 1079 # } 1080 # 1081 # java_annotation_processor("foo_processor") { 1082 # jar_path = "lib/prebuilt.jar" 1083 # main_class = "org.chromium.foo.FooMain" 1084 # } 1085 # 1086 # java_library("...") { 1087 # annotation_processor_deps = [":foo_processor"] 1088 # } 1089 # 1090 template("java_annotation_processor") { 1091 java_library_impl(target_name) { 1092 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1093 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1094 type = "java_annotation_processor" 1095 } 1096 } 1097 1098 # Declare a Robolectric host side test binary. 1099 # 1100 # This target creates an executable from java code for running as a 1101 # Robolectric test suite. The executable will be in the output folder's /bin/ 1102 # directory. 1103 # 1104 # Supports all variables of java_binary(). 1105 # 1106 # Example 1107 # robolectric_binary("foo") { 1108 # sources = [ "org/chromium/foo/FooTest.java" ] 1109 # deps = [ ":bar_java" ] 1110 # } 1111 template("robolectric_binary") { 1112 testonly = true 1113 1114 _main_class = "org.chromium.testing.local.JunitTestMain" 1115 _build_config = "$target_gen_dir/$target_name.build_config.json" 1116 _build_config_target_name = "$target_name$build_config_target_suffix" 1117 _java_binary_target_name = "${target_name}__java_binary" 1118 1119 _invoker_deps = [ 1120 "//testing/android/junit:junit_test_support", 1121 "//third_party/android_deps:robolectric_all_java", 1122 "//third_party/junit", 1123 "//third_party/mockito:mockito_jvm_java", 1124 ] 1125 if (defined(invoker.deps)) { 1126 _invoker_deps += invoker.deps 1127 } 1128 _non_java_deps = filter_exclude(_invoker_deps, java_target_patterns) 1129 _java_assetres_deps = [ ":${_java_binary_target_name}__assetres" ] 1130 1131 # A package name or a manifest is required to have resources. This is 1132 # added so that junit tests that do not care about the package name can 1133 # still use resources without having to explicitly set one. 1134 if (defined(invoker.package_name)) { 1135 _package_name = invoker.package_name 1136 } else if (!defined(invoker.android_manifest)) { 1137 _package_name = "no.manifest.configured" 1138 } 1139 1140 _merge_manifest_target_name = "${target_name}__merge_manifests" 1141 _android_manifest = 1142 "$target_gen_dir/$target_name.AndroidManifest.merged.xml" 1143 1144 merge_manifests(_merge_manifest_target_name) { 1145 if (defined(invoker.android_manifest)) { 1146 input_manifest = invoker.android_manifest 1147 } else { 1148 input_manifest = "//chromium/build/android/AndroidManifest.xml" 1149 } 1150 1151 if (defined(_package_name)) { 1152 manifest_package = _package_name 1153 } 1154 output_manifest = _android_manifest 1155 build_config = _build_config 1156 min_sdk_version = default_min_sdk_version 1157 target_sdk_version = default_target_sdk_version 1158 deps = _non_java_deps + _java_assetres_deps + 1159 [ ":$_build_config_target_name" ] 1160 if (defined(invoker.android_manifest_dep)) { 1161 deps += [ invoker.android_manifest_dep ] 1162 } 1163 } 1164 1165 _resource_arsc_output = "${target_out_dir}/${target_name}.ap_" 1166 _compile_resources_target_name = "${target_name}__compile_resources" 1167 compile_resources(_compile_resources_target_name) { 1168 deps = _non_java_deps + _java_assetres_deps + 1169 [ ":$_merge_manifest_target_name" ] 1170 build_config_dep = ":$_build_config_target_name" 1171 build_config = _build_config 1172 if (defined(_package_name)) { 1173 rename_manifest_package = _package_name 1174 } 1175 android_manifest = _android_manifest 1176 arsc_output = _resource_arsc_output 1177 min_sdk_version = default_min_sdk_version 1178 target_sdk_version = default_target_sdk_version 1179 forward_variables_from(invoker, [ "override_target_sdk" ]) 1180 } 1181 1182 # apkbuilder step needed only to add android assets to the .ap_ file. 1183 _apkbuilder_output = "${target_out_dir}/${target_name}.robo.ap_" 1184 _apkbuilder_target_name = "${target_name}__apkbuilder" 1185 package_apk("$_apkbuilder_target_name") { 1186 build_config = _build_config 1187 min_sdk_version = default_min_sdk_version 1188 deps = _java_assetres_deps + [ 1189 ":$_build_config_target_name", 1190 ":$_compile_resources_target_name", 1191 ] 1192 1193 is_robolectric_apk = true 1194 packaged_resources_path = _resource_arsc_output 1195 output_apk_path = _apkbuilder_output 1196 } 1197 1198 # Some may want to disable this to remove dependency on //base 1199 # (JNI generator is in //base). 1200 _generate_final_jni = 1201 !defined(invoker.generate_final_jni) || invoker.generate_final_jni 1202 if (_generate_final_jni) { 1203 _jni_srcjar_deps = [] 1204 if (defined(invoker.shared_libraries)) { 1205 foreach(_dep, invoker.shared_libraries) { 1206 _dep_no_toolchain = get_label_info(_dep, "label_no_toolchain") 1207 _dep_toolchain = get_label_info(_dep, "toolchain") 1208 assert( 1209 _dep_toolchain == robolectric_toolchain, 1210 "$target_name has shared_libraries with incorrect toolchain. " + 1211 "Should contain (\$robolectric_toolchain) suffix: $_dep") 1212 _jni_srcjar_deps += 1213 [ "${_dep_no_toolchain}__jni_registration($default_toolchain)" ] 1214 } 1215 1216 # Write shared library output files of all dependencies to a file. Those 1217 # will be the shared libraries packaged into the APK. 1218 _shared_library_list_file = "$target_gen_dir/$target_name.native_libs" 1219 generated_file("${target_name}__shared_library_list") { 1220 deps = invoker.shared_libraries 1221 outputs = [ _shared_library_list_file ] 1222 data_keys = [ "shared_libraries" ] 1223 walk_keys = [ "shared_libraries_barrier" ] 1224 rebase = root_build_dir 1225 } 1226 } else { 1227 # Needed for generate_jni_registration. Keeping this import guarded so 1228 # that projects who import //build but not //third_party/jni_zero don't 1229 # have issues. 1230 import("//third_party/jni_zero/jni_zero.gni") 1231 _jni_srcjar_target_name = "${target_name}__final_jni" 1232 generate_jni_registration(_jni_srcjar_target_name) { 1233 java_targets = [ ":$_java_binary_target_name" ] 1234 add_stubs_for_missing_jni = true 1235 } 1236 _jni_srcjar_deps = [ ":$_jni_srcjar_target_name" ] 1237 } 1238 _native_libraries_target_name = "${target_name}__native_libraries" 1239 write_native_libraries_java(_native_libraries_target_name) { 1240 enable_chromium_linker = false 1241 use_final_fields = true 1242 if (defined(_shared_library_list_file)) { 1243 native_libraries_list_file = _shared_library_list_file 1244 } 1245 } 1246 } 1247 1248 java_library_impl(_java_binary_target_name) { 1249 forward_variables_from(invoker, 1250 "*", 1251 TESTONLY_AND_VISIBILITY + [ 1252 "deps", 1253 "extra_args", 1254 "shared_libraries", 1255 ]) 1256 type = "robolectric_binary" 1257 main_target_name = invoker.target_name 1258 1259 deps = _invoker_deps 1260 testonly = true 1261 main_class = _main_class 1262 wrapper_script_name = "helper/$main_target_name" 1263 1264 # As of April 2021, adding -XX:TieredStopAtLevel=1 does not affect the 1265 # wall time of a single robolectric shard, but does reduce the CPU time by 1266 # 66%, which makes sharding more effective. 1267 tiered_stop_at_level_one = true 1268 1269 is_robolectric = true 1270 include_android_sdk = true 1271 alternative_android_sdk_dep = 1272 "//third_party/robolectric:robolectric_test_sdk_java" 1273 1274 if (!defined(srcjar_deps)) { 1275 srcjar_deps = [] 1276 } 1277 srcjar_deps += [ 1278 ":$_compile_resources_target_name", 1279 "//chromium/build/android:build_config_for_robolectric_srcjar", 1280 ] 1281 if (_generate_final_jni) { 1282 srcjar_deps += [ ":$_native_libraries_target_name" ] + _jni_srcjar_deps 1283 } 1284 } 1285 1286 test_runner_script(target_name) { 1287 forward_variables_from(invoker, 1288 [ 1289 "assert_no_deps", 1290 "extra_args", 1291 "visibility", 1292 ]) 1293 test_name = invoker.target_name 1294 test_suite = invoker.target_name 1295 test_type = "junit" 1296 ignore_all_data_deps = true 1297 resource_apk = _apkbuilder_output 1298 deps = [ 1299 ":$_apkbuilder_target_name", 1300 ":$_build_config_target_name", 1301 ":${_java_binary_target_name}__host", 1302 ":${_java_binary_target_name}__java_binary_script", 1303 ":${_java_binary_target_name}__validate", 1304 "//third_party/robolectric:robolectric_runtime_jars", 1305 ] 1306 if (defined(invoker.shared_libraries)) { 1307 data_deps = invoker.shared_libraries 1308 } 1309 1310 # Add non-libary deps, since the __host target does not depend on them. 1311 deps += filter_exclude(_invoker_deps, java_library_patterns) 1312 1313 metadata = { 1314 # Allows metadata collection via apk targets that traverse only java deps. 1315 java_walk_keys = [ ":${_java_binary_target_name}__host" ] 1316 } 1317 } 1318 } 1319 1320 # Declare a java library target 1321 # 1322 # Variables 1323 # deps: Specifies the dependencies of this target. Java targets in this list 1324 # will be added to the javac classpath. 1325 # public_deps: Dependencies that this target exposes as part of its public API. 1326 # public_deps do not need to be listed in both the 'deps' and 'public_deps' lists. 1327 # annotation_processor_deps: List of java_annotation_processor targets to 1328 # use when compiling. 1329 # 1330 # jar_path: Path to a prebuilt jar. Mutually exclusive with sources & 1331 # srcjar_deps. 1332 # sources: List of .java files included in this library. 1333 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars 1334 # will be added to sources and be included in this library. 1335 # 1336 # input_jars_paths: A list of paths to the jars that should be included 1337 # in the compile-time classpath. These are in addition to library .jars 1338 # that appear in deps. 1339 # 1340 # chromium_code: If true, extra analysis warning/errors will be enabled. 1341 # enable_errorprone: If true, enables the errorprone compiler. 1342 # skip_build_server: If true, avoids sending tasks to the build server. 1343 # 1344 # jar_excluded_patterns: List of patterns of .class files to exclude. 1345 # jar_included_patterns: List of patterns of .class files to include. 1346 # When omitted, all classes not matched by jar_excluded_patterns are 1347 # included. When specified, all non-matching .class files are stripped. 1348 # 1349 # low_classpath_priority: Indicates that the library should be placed at the 1350 # end of the classpath. The default classpath order has libraries ordered 1351 # before the libraries that they depend on. 'low_classpath_priority' is 1352 # useful when one java_library() overrides another via 1353 # 'jar_excluded_patterns' and the overriding library does not depend on 1354 # the overridee. 1355 # 1356 # output_name: File name for the output .jar (not including extension). 1357 # Defaults to the input .jar file name. 1358 # 1359 # proguard_configs: List of proguard configs to use in final apk step for 1360 # any apk that depends on this library. 1361 # 1362 # supports_android: If true, Android targets (android_library, android_apk) 1363 # may depend on this target. Note: if true, this target must only use the 1364 # subset of Java available on Android. 1365 # bypass_platform_checks: Disables checks about cross-platform (Java/Android) 1366 # dependencies for this target. This will allow depending on an 1367 # android_library target, for example. 1368 # enable_desugar: If false, disables desugaring of lambdas, etc. Use this 1369 # only when you are sure the library does not require desugaring. E.g. 1370 # to hide warnings shown from desugaring. 1371 # 1372 # additional_jar_files: Use to package additional files (Java resources) 1373 # into the output jar. Pass a list of length-2 lists with format: 1374 # [ [ path_to_file, path_to_put_in_jar ] ] 1375 # 1376 # javac_args: Additional arguments to pass to javac. 1377 # errorprone_args: Additional arguments to pass to errorprone. 1378 # 1379 # data_deps, testonly 1380 # 1381 # Example 1382 # java_library("foo_java") { 1383 # sources = [ 1384 # "org/chromium/foo/Foo.java", 1385 # "org/chromium/foo/FooInterface.java", 1386 # "org/chromium/foo/FooService.java", 1387 # ] 1388 # deps = [ 1389 # ":bar_java" 1390 # ] 1391 # srcjar_deps = [ 1392 # ":foo_generated_enum" 1393 # ] 1394 # jar_excluded_patterns = [ 1395 # "*/FooService.class", "org/chromium/FooService\$*.class" 1396 # ] 1397 # } 1398 template("java_library") { 1399 java_library_impl(target_name) { 1400 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1401 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1402 type = "java_library" 1403 } 1404 } 1405 1406 # Declare a java library target for a prebuilt jar 1407 # 1408 # Supports all variables of java_library(). 1409 # 1410 # Example 1411 # java_prebuilt("foo_java") { 1412 # jar_path = "foo.jar" 1413 # deps = [ 1414 # ":foo_resources", 1415 # ":bar_java" 1416 # ] 1417 # } 1418 template("java_prebuilt") { 1419 java_library_impl(target_name) { 1420 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1421 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1422 type = "java_library" 1423 } 1424 } 1425 1426 # Combines all dependent .jar files into a single .jar file. 1427 # 1428 # Variables: 1429 # output: Path to the output jar. 1430 # use_interface_jars: Use all dependent interface .jars rather than 1431 # implementation .jars. 1432 # use_unprocessed_jars: Use unprocessed / undesugared .jars. 1433 # direct_deps_only: Do not recurse on deps. 1434 # jar_excluded_patterns (optional) 1435 # List of globs for paths to exclude. 1436 # renaming_rules: rename java classes inside according to these rules. 1437 # 1438 # Example 1439 # dist_jar("lib_fatjar") { 1440 # deps = [ ":my_java_lib" ] 1441 # output = "$root_build_dir/MyLibrary.jar" 1442 # } 1443 template("dist_jar") { 1444 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1445 1446 # TODO: Remove uses. 1447 not_needed(invoker, [ "use_unprocessed_jars" ]) 1448 _use_interface_jars = 1449 defined(invoker.use_interface_jars) && invoker.use_interface_jars 1450 _supports_android = 1451 !defined(invoker.supports_android) || invoker.supports_android 1452 _requires_android = 1453 defined(invoker.requires_android) && invoker.requires_android 1454 _has_renaming_rules = defined(invoker.renaming_rules) 1455 1456 _is_java_target_name = 1457 filter_exclude([ target_name ], java_target_patterns) == [] 1458 _target_name_without_java_or_junit = 1459 string_replace(string_replace(target_name, "_java", "_J"), 1460 "_junit", 1461 "_U") 1462 _zip_target_name = "${_target_name_without_java_or_junit}_zip" 1463 _zip_jar_path = invoker.output 1464 1465 if (_has_renaming_rules) { 1466 _zip_jar_path = "$target_gen_dir/$target_name.singlejar.jar" 1467 1468 # if we are java-like and have renaming rules, the main target is the 1469 # java_library_impl otherwise its the renaming target. 1470 if (_is_java_target_name) { 1471 _renaming_target_name = "${_target_name_without_java_or_junit}_renamed" 1472 _final_jar_target = _renaming_target_name 1473 } else { 1474 _renaming_target_name = target_name 1475 } 1476 } else { 1477 # If we dont have renaming rules then the main target is either the zip 1478 # target or the java_library_impl if we are java-like. 1479 if (_is_java_target_name) { 1480 _final_jar_target = _zip_target_name 1481 } else { 1482 _zip_target_name = target_name 1483 } 1484 } 1485 1486 _build_config = "$target_gen_dir/$target_name.build_config.json" 1487 _build_config_target_name = "$target_name$build_config_target_suffix" 1488 _build_config_dep = ":$_build_config_target_name" 1489 1490 if (_is_java_target_name) { 1491 # If we have a java-like target name we need to provide the expected 1492 # meta_targets as well as the processing (eg: ijar, bytecode rewriting) 1493 # that is expected of java targets so that other java targets can depend 1494 # on us. 1495 java_library_impl(target_name) { 1496 forward_variables_from(invoker, 1497 [ 1498 "deps", 1499 "direct_deps_only", 1500 "jar_excluded_patterns", 1501 ]) 1502 type = "dist_jar" 1503 if (!defined(deps)) { 1504 deps = [] 1505 } 1506 deps += [ ":$_final_jar_target" ] 1507 1508 supports_android = _supports_android 1509 requires_android = _requires_android 1510 jar_path = invoker.output 1511 enable_bytecode_checks = false 1512 use_interface_jars = _use_interface_jars 1513 } 1514 } else { 1515 write_build_config(_build_config_target_name) { 1516 type = "dist_jar" 1517 forward_variables_from(invoker, [ "direct_deps_only" ]) 1518 supports_android = _supports_android 1519 requires_android = _requires_android 1520 possible_config_deps = invoker.deps 1521 build_config = _build_config 1522 use_interface_jars = _use_interface_jars 1523 } 1524 } 1525 1526 _rebased_build_config = rebase_path(_build_config, root_build_dir) 1527 action_with_pydeps(_zip_target_name) { 1528 forward_variables_from(invoker, [ "data" ]) 1529 script = "//chromium/build/android/gyp/zip.py" 1530 depfile = "$target_gen_dir/$target_name.d" 1531 deps = [ _build_config_dep ] 1532 1533 if (_use_interface_jars) { 1534 _lib_deps = 1535 filter_exclude(filter_include(invoker.deps, java_library_patterns), 1536 java_resource_patterns) 1537 _other_deps = filter_exclude(invoker.deps, _lib_deps) 1538 foreach(_lib_dep, _lib_deps) { 1539 # Expand //foo/java -> //foo/java:java 1540 _lib_dep = get_label_info(_lib_dep, "label_no_toolchain") 1541 deps += [ "${_lib_dep}__header" ] 1542 } 1543 deps += _other_deps 1544 } else { 1545 deps += invoker.deps 1546 } 1547 1548 inputs = [ _build_config ] 1549 1550 outputs = [ _zip_jar_path ] 1551 1552 args = [ 1553 "--depfile", 1554 rebase_path(depfile, root_build_dir), 1555 "--output", 1556 rebase_path(_zip_jar_path, root_build_dir), 1557 "--no-compress", 1558 "--input-zips=@FileArg($_rebased_build_config:dist_jar:jars)", 1559 ] 1560 1561 _excludes = [] 1562 if (defined(invoker.jar_excluded_patterns)) { 1563 _excludes += invoker.jar_excluded_patterns 1564 } 1565 if (_use_interface_jars) { 1566 # Turbine adds files like: META-INF/TRANSITIVE/.../Foo.class 1567 # These confuse proguard: https://crbug.com/1081443 1568 _excludes += [ "META-INF/*" ] 1569 } else { 1570 # Manifest files will never be correct when merging jars. 1571 _excludes += [ "META-INF/*.MF" ] 1572 } 1573 if (_excludes != []) { 1574 args += [ "--input-zips-excluded-globs=$_excludes" ] 1575 } 1576 } 1577 1578 if (_has_renaming_rules) { 1579 rename_jar_classes(_renaming_target_name) { 1580 input = _zip_jar_path 1581 output = invoker.output 1582 deps = [ ":$_zip_target_name" ] 1583 renaming_rules = invoker.renaming_rules 1584 } 1585 } 1586 } 1587 1588 # Combines all dependent .jar files into a single proguarded .dex file. 1589 # 1590 # Variables: 1591 # output: Path to the output .dex or .dex.jar. 1592 # proguard_enabled: Whether to enable R8. 1593 # proguard_configs: List of proguard configs. 1594 # proguard_enable_obfuscation: Whether to enable obfuscation (default=true). 1595 # package_name: Used in the Proguard map ID. 1596 # version_code: Used in the Proguard map ID. 1597 # 1598 # Example 1599 # dist_dex("lib_fatjar") { 1600 # deps = [ ":my_java_lib" ] 1601 # output = "$root_build_dir/MyLibrary.jar" 1602 # } 1603 template("dist_dex") { 1604 _deps = [ default_android_sdk_dep ] 1605 if (defined(invoker.deps)) { 1606 _deps += invoker.deps 1607 } 1608 1609 _build_config = "$target_gen_dir/$target_name.build_config.json" 1610 _build_config_target_name = "$target_name$build_config_target_suffix" 1611 1612 write_build_config(_build_config_target_name) { 1613 type = "dist_jar" 1614 forward_variables_from(invoker, 1615 [ 1616 "proguard_configs", 1617 "proguard_enabled", 1618 ]) 1619 supports_android = true 1620 requires_android = true 1621 possible_config_deps = _deps 1622 build_config = _build_config 1623 } 1624 1625 dex(target_name) { 1626 forward_variables_from(invoker, 1627 TESTONLY_AND_VISIBILITY + [ 1628 "data", 1629 "data_deps", 1630 "package_name", 1631 "proguard_configs", 1632 "proguard_enabled", 1633 "proguard_enable_obfuscation", 1634 "min_sdk_version", 1635 "repackage_classes", 1636 "version_code", 1637 ]) 1638 deps = [ ":$_build_config_target_name" ] + _deps 1639 build_config = _build_config 1640 output = invoker.output 1641 if (defined(proguard_enabled) && proguard_enabled) { 1642 # The individual dependencies would have caught real missing deps in 1643 # their respective dex steps. False positives that were suppressed at 1644 # per-target dex steps are emitted here since this is using jar files 1645 # rather than dex files. 1646 ignore_desugar_missing_deps = true 1647 } else { 1648 _rebased_build_config = rebase_path(_build_config, root_build_dir) 1649 input_dex_filearg = 1650 "@FileArg(${_rebased_build_config}:deps_info:all_dex_files)" 1651 } 1652 } 1653 } 1654 1655 # Creates an Android .aar library. 1656 # 1657 # Currently supports: 1658 # * AndroidManifest.xml 1659 # * classes.jar 1660 # * jni/ 1661 # * res/ 1662 # * R.txt 1663 # * proguard.txt 1664 # Does not yet support: 1665 # * public.txt 1666 # * annotations.zip 1667 # * assets/ 1668 # See: https://developer.android.com/studio/projects/android-library.html#aar-contents 1669 # 1670 # Variables: 1671 # output: Path to the output .aar. 1672 # proguard_configs: List of proguard configs (optional). 1673 # android_manifest: Path to AndroidManifest.xml (optional). 1674 # native_libraries: list of native libraries (optional). 1675 # direct_deps_only: Do not recurse on deps (optional, defaults false). 1676 # jar_excluded_patterns: List of globs for paths to exclude (optional). 1677 # jar_included_patterns: List of globs for paths to include (optional). 1678 # resource_excluded_patterns: Resource path glob list to exclude (optional) 1679 # resource_included_patterns: Resource path glob list to include (optional) 1680 # 1681 # Example 1682 # dist_aar("my_aar") { 1683 # deps = [ ":my_java_lib" ] 1684 # output = "$root_build_dir/MyLibrary.aar" 1685 # } 1686 template("dist_aar") { 1687 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1688 1689 _direct_deps_only = 1690 defined(invoker.direct_deps_only) && invoker.direct_deps_only 1691 1692 _deps = [] 1693 1694 if (defined(invoker.deps)) { 1695 _deps += invoker.deps 1696 } 1697 1698 _build_config = "$target_gen_dir/$target_name.build_config.json" 1699 _build_config_target_name = "$target_name$build_config_target_suffix" 1700 1701 write_build_config(_build_config_target_name) { 1702 type = "dist_aar" 1703 forward_variables_from(invoker, [ "proguard_configs" ]) 1704 possible_config_deps = _deps 1705 supports_android = true 1706 requires_android = true 1707 build_config = _build_config 1708 } 1709 1710 _deps += [ ":$_build_config_target_name" ] 1711 1712 _rebased_build_config = rebase_path(_build_config, root_build_dir) 1713 1714 action_with_pydeps(target_name) { 1715 forward_variables_from(invoker, 1716 [ 1717 "data", 1718 "assert_no_deps", 1719 ]) 1720 depfile = "$target_gen_dir/$target_name.d" 1721 deps = _deps 1722 script = "//chromium/build/android/gyp/dist_aar.py" 1723 1724 inputs = [ _build_config ] 1725 1726 # Although these will be listed as deps in the depfile, they must also 1727 # appear here so that "gn analyze" knows about them. 1728 # https://crbug.com/827197 1729 if (defined(invoker.proguard_configs)) { 1730 inputs += invoker.proguard_configs 1731 } 1732 1733 outputs = [ invoker.output ] 1734 1735 args = [ 1736 "--depfile", 1737 rebase_path(depfile, root_build_dir), 1738 "--output", 1739 rebase_path(invoker.output, root_build_dir), 1740 "--dependencies-res-zips=@FileArg($_rebased_build_config:deps_info:dependency_zips)", 1741 "--r-text-files=@FileArg($_rebased_build_config:deps_info:dependency_r_txt_files)", 1742 "--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)", 1743 ] 1744 if (_direct_deps_only) { 1745 args += [ "--jars=@FileArg($_rebased_build_config:javac:classpath)" ] 1746 } else { 1747 args += [ 1748 "--jars=@FileArg($_rebased_build_config:deps_info:device_classpath)", 1749 ] 1750 } 1751 1752 if (defined(invoker.android_manifest)) { 1753 args += [ 1754 "--android-manifest", 1755 rebase_path(invoker.android_manifest, root_build_dir), 1756 ] 1757 } 1758 if (defined(invoker.native_libraries) && invoker.native_libraries != []) { 1759 inputs += invoker.native_libraries 1760 _rebased_native_libraries = 1761 rebase_path(invoker.native_libraries, root_build_dir) 1762 1763 args += [ 1764 "--native-libraries=$_rebased_native_libraries", 1765 "--abi=$android_app_abi", 1766 ] 1767 } 1768 if (defined(invoker.jar_excluded_patterns)) { 1769 args += [ "--jar-excluded-globs=${invoker.jar_excluded_patterns}" ] 1770 } 1771 if (defined(invoker.jar_included_patterns)) { 1772 args += [ "--jar-included-globs=${invoker.jar_included_patterns}" ] 1773 } 1774 if (defined(invoker.resource_included_patterns)) { 1775 args += [ 1776 "--resource-included-globs=${invoker.resource_included_patterns}", 1777 ] 1778 } 1779 if (defined(invoker.resource_excluded_patterns)) { 1780 args += [ 1781 "--resource-excluded-globs=${invoker.resource_excluded_patterns}", 1782 ] 1783 } 1784 } 1785 } 1786 1787 # Declare an Android library target 1788 # 1789 # This target creates an Android library containing java code and Android 1790 # resources. 1791 # 1792 # Supports all variables of java_library(), plus: 1793 # deps: In addition to defining java deps, this can also include 1794 # android_assets() and android_resources() targets. 1795 # alternative_android_sdk_dep: android_system_java_prebuilt target to use 1796 # in place of the default android.jar. 1797 # 1798 # Example 1799 # android_library("foo_java") { 1800 # sources = [ 1801 # "android/org/chromium/foo/Foo.java", 1802 # "android/org/chromium/foo/FooInterface.java", 1803 # "android/org/chromium/foo/FooService.java", 1804 # ] 1805 # deps = [ 1806 # ":bar_java" 1807 # ] 1808 # srcjar_deps = [ 1809 # ":foo_generated_enum" 1810 # ] 1811 # jar_excluded_patterns = [ 1812 # "*/FooService.class", "org/chromium/FooService\$*.class" 1813 # ] 1814 # } 1815 template("android_library") { 1816 java_library(target_name) { 1817 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1818 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1819 1820 supports_android = true 1821 requires_android = true 1822 1823 if (!defined(jar_excluded_patterns)) { 1824 jar_excluded_patterns = [] 1825 } 1826 jar_excluded_patterns += [ 1827 "*/R.class", 1828 "*/R\$*.class", 1829 "*/Manifest.class", 1830 "*/Manifest\$*.class", 1831 "*/*GEN_JNI.class", 1832 ] 1833 } 1834 } 1835 1836 # Declare an Android robolectric library target 1837 # 1838 # This target creates an Android library containing java code and Android 1839 # resources. 1840 # 1841 # Supports all variables of java_library(), plus: 1842 # deps: In addition to defining java deps, this can also include 1843 # android_assets() and android_resources() targets. 1844 # 1845 # Example 1846 # robolectric_library("foo_junit") { 1847 # sources = [ 1848 # "android/org/chromium/foo/FooTest.java", 1849 # "android/org/chromium/foo/FooTestUtils.java", 1850 # "android/org/chromium/foo/FooMock.java", 1851 # ] 1852 # deps = [ 1853 # "//base:base_junit_test_support" 1854 # ] 1855 # srcjar_deps = [ 1856 # ":foo_generated_enum" 1857 # ] 1858 # jar_excluded_patterns = [ 1859 # "*/FooService.class", "org/chromium/FooService\$*.class" 1860 # ] 1861 # } 1862 template("robolectric_library") { 1863 java_library(target_name) { 1864 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1865 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1866 1867 testonly = true 1868 1869 is_robolectric = true 1870 include_android_sdk = true 1871 alternative_android_sdk_dep = 1872 "//third_party/robolectric:robolectric_test_sdk_java" 1873 1874 if (!defined(jar_excluded_patterns)) { 1875 jar_excluded_patterns = [] 1876 } 1877 jar_excluded_patterns += [ 1878 "*/R.class", 1879 "*/R\$*.class", 1880 "*/Manifest.class", 1881 "*/Manifest\$*.class", 1882 "*/*GEN_JNI.class", 1883 ] 1884 1885 if (!defined(deps)) { 1886 deps = [] 1887 } 1888 deps += [ "//third_party/android_deps:robolectric_all_java" ] 1889 } 1890 } 1891 1892 # Declare an Android library target for a prebuilt jar 1893 # 1894 # This target creates an Android library containing java code and Android 1895 # resources. 1896 # 1897 # Supports all variables of android_library(). 1898 # 1899 # Example 1900 # android_java_prebuilt("foo_java") { 1901 # jar_path = "foo.jar" 1902 # deps = [ 1903 # ":foo_resources", 1904 # ":bar_java" 1905 # ] 1906 # } 1907 template("android_java_prebuilt") { 1908 android_library(target_name) { 1909 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1910 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1911 } 1912 } 1913 1914 template("android_system_java_prebuilt") { 1915 java_library_impl(target_name) { 1916 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 1917 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 1918 supports_android = true 1919 type = "system_java_library" 1920 } 1921 } 1922 1923 # Creates org/chromium/build/BuildConfig.java 1924 template("generate_build_config_srcjar") { 1925 java_cpp_template(target_name) { 1926 forward_variables_from(invoker, 1927 TESTONLY_AND_VISIBILITY + [ 1928 "deps", 1929 "inputs", 1930 ]) 1931 sources = [ "//chromium/build/android/java/templates/BuildConfig.template" ] 1932 defines = [] 1933 1934 if ((defined(invoker.assertions_implicitly_enabled) && 1935 invoker.assertions_implicitly_enabled) || enable_java_asserts) { 1936 defines += [ "_ENABLE_ASSERTS" ] 1937 } 1938 if (use_cfi_diag || is_ubsan_any) { 1939 defines += [ "_IS_UBSAN" ] 1940 } 1941 1942 if (is_chrome_branded) { 1943 defines += [ "_IS_CHROME_BRANDED" ] 1944 } 1945 1946 if (defined(invoker.isolated_splits_enabled) && 1947 invoker.isolated_splits_enabled) { 1948 defines += [ "_ISOLATED_SPLITS_ENABLED" ] 1949 } 1950 1951 if (defined(invoker.is_incremental_install) && 1952 invoker.is_incremental_install) { 1953 defines += [ "_IS_INCREMENTAL_INSTALL" ] 1954 } 1955 1956 if (defined(invoker.min_sdk_version)) { 1957 defines += [ "_MIN_SDK_VERSION=${invoker.min_sdk_version}" ] 1958 } else { 1959 defines += [ "_MIN_SDK_VERSION=$default_min_sdk_version" ] 1960 } 1961 if (defined(invoker.version_code)) { 1962 defines += [ "_VERSION_CODE=${invoker.version_code}" ] 1963 } else { 1964 defines += [ "_VERSION_CODE=$android_default_version_code" ] 1965 } 1966 if (defined(invoker.resources_version_variable)) { 1967 defines += [ 1968 "_RESOURCES_VERSION_VARIABLE=${invoker.resources_version_variable}", 1969 ] 1970 } 1971 if (defined(invoker.apk_assets_suffixed_list)) { 1972 defines += [ 1973 "_APK_ASSETS_SUFFIXED_LIST=${invoker.apk_assets_suffixed_list}", 1974 "_APK_ASSETS_SUFFIX=${invoker.apk_assets_suffix}", 1975 ] 1976 } 1977 1978 _test_only = defined(testonly) && testonly 1979 if (_test_only) { 1980 defines += [ "_IS_FOR_TEST" ] 1981 } 1982 1983 if (!is_java_debug && (!_test_only || is_cronet_build)) { 1984 defines += [ "_DISABLE_DEBUG_LOGS" ] 1985 } 1986 1987 if (is_cronet_build) { 1988 defines += [ "_IS_CRONET_BUILD" ] 1989 defines += [ "_LOGTAG_PREFIX=cn_" ] 1990 } else { 1991 defines += [ "_LOGTAG_PREFIX=cr_" ] 1992 } 1993 if (is_desktop_android) { 1994 defines += [ "_IS_DESKTOP_ANDROID" ] 1995 } 1996 1997 if (defined(invoker.write_clang_profiling_data) && 1998 invoker.write_clang_profiling_data) { 1999 defines += [ "_WRITE_CLANG_PROFILING_DATA" ] 2000 } 2001 2002 if (defined(invoker.disable_strict_mode_context) && 2003 invoker.disable_strict_mode_context) { 2004 defines += [ "_DISABLE_STRICT_MODE_CONTEXT" ] 2005 } 2006 } 2007 } 2008 2009 # Creates ProductConfig.java, a file containing product-specific configuration. 2010 # 2011 # Currently, this includes the list of locales, both in their compressed and 2012 # uncompressed format, as well as library loading 2013 # 2014 # Variables: 2015 # build_config: Path to build_config used for locale lists. 2016 # java_package: Java package for the generated class. 2017 # use_chromium_linker: 2018 template("generate_product_config_srcjar") { 2019 java_cpp_template(target_name) { 2020 defines = [] 2021 _use_final = 2022 defined(invoker.build_config) || 2023 defined(invoker.use_chromium_linker) || defined(invoker.is_bundle) 2024 if (_use_final) { 2025 defines += [ "USE_FINAL" ] 2026 } 2027 2028 sources = [ "//chromium/build/android/java/templates/ProductConfig.template" ] 2029 defines += [ "PACKAGE=${invoker.java_package}" ] 2030 2031 _use_chromium_linker = 2032 defined(invoker.use_chromium_linker) && invoker.use_chromium_linker 2033 defines += [ "USE_CHROMIUM_LINKER_VALUE=$_use_chromium_linker" ] 2034 if (defined(invoker.build_config)) { 2035 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 2036 _rebased_build_config = 2037 rebase_path(invoker.build_config, root_build_dir) 2038 defines += [ "LOCALE_LIST=@FileArg($_rebased_build_config:deps_info:locales_java_list)" ] 2039 } 2040 } 2041 } 2042 2043 # Declare an Android app module target, which is used as the basis for an 2044 # Android APK or an Android app bundle module. 2045 # 2046 # Supports all variables of android_library(), plus: 2047 # android_manifest: Path to AndroidManifest.xml. NOTE: This manifest must 2048 # not contain a <uses-sdk> element. Use [min|target|max]_sdk_version 2049 # instead. 2050 # android_manifest_dep: Target that generates AndroidManifest (if applicable) 2051 # png_to_webp: If true, pngs (with the exception of 9-patch) are 2052 # converted to webp during resource packaging. 2053 # loadable_modules: List of paths to native libraries to include. Different 2054 # from |shared_libraries| in that: 2055 # * dependencies of this .so are not automatically included 2056 # * they are not side-loaded when incremental_install=true. 2057 # * they are not included in NativeLibraries.java 2058 # Use this instead of shared_libraries when you are going to load the library 2059 # conditionally, and only when shared_libraries doesn't work for you. 2060 # secondary_abi_loadable_modules: This is the loadable_modules analog to 2061 # secondary_abi_shared_libraries. 2062 # shared_libraries: List shared_library targets to bundle. If these 2063 # libraries depend on other shared_library targets, those dependencies will 2064 # also be included in the apk (e.g. for is_component_build). 2065 # secondary_abi_shared_libraries: secondary abi shared_library targets to 2066 # bundle. If these libraries depend on other shared_library targets, those 2067 # dependencies will also be included in the apk (e.g. for is_component_build). 2068 # native_lib_placeholders: List of placeholder filenames to add to the apk 2069 # (optional). 2070 # secondary_native_lib_placeholders: List of placeholder filenames to add to 2071 # the apk for the secondary ABI (optional). 2072 # generate_buildconfig_java: If defined and false, skip generating the 2073 # BuildConfig java class describing the build configuration. The default 2074 # is true when building with Chromium for non-test APKs. 2075 # generate_native_libraries_java: If defined, whether NativeLibraries.java is 2076 # generated is solely controlled by this flag. Otherwise, the default behavior 2077 # is NativeLibraries.java will only be generated for the base module/apk when 2078 # its `shared_libraries` is not empty. 2079 # aapt_locale_allowlist: If set, all locales not in this list will be 2080 # stripped from resources.arsc. 2081 # resource_exclusion_regex: Causes all drawable images matching the regex to 2082 # be excluded (mipmaps are still included). 2083 # resource_exclusion_exceptions: A list of globs used when 2084 # resource_exclusion_regex is set. Files that match this list will 2085 # still be included. 2086 # resource_values_filter_rules: List of "source_path:name_regex" used to 2087 # filter out unwanted values/ resources. 2088 # shared_resources: True if this is a runtime shared library APK, like 2089 # the system_webview_apk target. Ensures that its resources can be 2090 # used by the loading application process. 2091 # app_as_shared_lib: True if this is a regular application apk that can 2092 # also serve as a runtime shared library, like the monochrome_public_apk 2093 # target. Ensures that the resources are usable both by the APK running 2094 # as an application, or by another process that loads it at runtime. 2095 # shared_resources_allowlist_target: Optional name of a target specifying 2096 # an input R.txt file that lists the resources that can be exported 2097 # by the APK when shared_resources or app_as_shared_lib is defined. 2098 # uncompress_dex: Store final .dex files uncompressed in the apk. 2099 # omit_dex: If true, do not build or include classes.dex. 2100 # strip_resource_names: True if resource names should be stripped from the 2101 # resources.arsc file in the apk or module. 2102 # strip_unused_resources: True if unused resources should be stripped from 2103 # the apk or module. 2104 # short_resource_paths: True if resource paths should be shortened in the 2105 # apk or module. 2106 # resources_config_paths: List of paths to the aapt2 optimize config files 2107 # that tags resources with acceptable/non-acceptable optimizations. 2108 # expected_android_manifest: Enables verification of expected merged 2109 # manifest based on a golden file. 2110 # resource_ids_provider_dep: If passed, this target will use the resource 2111 # IDs generated by {resource_ids_provider_dep}__compile_res during 2112 # resource compilation. 2113 # enforce_resource_overlays_in_tests: Enables check for testonly targets that 2114 # dependent resource targets which override another target set 2115 # overlay_resources=true. This check is on for non-test targets and 2116 # cannot be disabled. 2117 # static_library_provider: Specifies a single target that this target will 2118 # use as a static library APK. 2119 # min_sdk_version: The minimum Android SDK version this target supports. 2120 # Optional, default $default_min_sdk_version. 2121 # target_sdk_version: The target Android SDK version for this target. 2122 # Optional, default to default_target_sdk_version. 2123 # max_sdk_version: The maximum Android SDK version this target supports. 2124 # Optional, default not set. 2125 # require_native_mocks: Enforce that any native calls using 2126 # org.chromium.base.annotations.NativeMethods must have a mock set 2127 # (optional). 2128 # product_config_java_packages: Optional list of java packages. If given, a 2129 # ProductConfig.java file will be generated for each package. 2130 # enable_proguard_checks: Turns on -checkdiscard directives and missing 2131 # symbols check in the proguard step (default=true). 2132 # annotation_processor_deps: List of java_annotation_processor targets to 2133 # use when compiling the sources given to this target (optional). 2134 # processor_args_javac: List of args to pass to annotation processors when 2135 # compiling sources given to this target (optional). 2136 # bundles_supported: Enable Java code to treat this target as a bundle 2137 # whether (by default determined by the target type). 2138 # expected_libs_and_assets: Verify the list of included native libraries 2139 # and assets is consistent with the given expectation file. 2140 # expected_libs_and_assets_base: Treat expected_libs_and_assets as a diff 2141 # with this file as the base. 2142 # expected_proguard_config: Checks that the merged set of proguard flags 2143 # matches the given config. 2144 # expected_proguard_config_base: Treat expected_proguard_config as a diff 2145 # with this file as the base. 2146 # suffix_apk_assets_used_by: Prefixes android assets used by the given apk 2147 # with $package_name. Adds the list of renamed packages to 2148 # BuildConfig.java. 2149 template("android_apk_or_module") { 2150 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 2151 _template_name = target_name 2152 _base_path = "$target_out_dir/$target_name/$target_name" 2153 _build_config = "$target_gen_dir/$target_name.build_config.json" 2154 _build_config_target = "$target_name$build_config_target_suffix" 2155 _java_target_name = "${_template_name}__java" 2156 2157 _min_sdk_version = default_min_sdk_version 2158 _target_sdk_version = default_target_sdk_version 2159 if (defined(invoker.min_sdk_version)) { 2160 _min_sdk_version = invoker.min_sdk_version 2161 } 2162 if (is_asan && _min_sdk_version < min_supported_sdk_version) { 2163 _min_sdk_version = min_supported_sdk_version 2164 } 2165 if (defined(invoker.target_sdk_version)) { 2166 _target_sdk_version = invoker.target_sdk_version 2167 } 2168 2169 _is_bundle_module = 2170 defined(invoker.is_bundle_module) && invoker.is_bundle_module 2171 _is_base_module = !_is_bundle_module || (defined(invoker.is_base_module) && 2172 invoker.is_base_module) 2173 2174 _omit_dex = defined(invoker.omit_dex) && invoker.omit_dex 2175 2176 if (!_is_bundle_module) { 2177 _final_apk_path = invoker.final_apk_path 2178 _final_rtxt_path = "${_final_apk_path}.R.txt" 2179 } 2180 2181 _res_size_info_path = "$target_out_dir/$target_name.ap_.info" 2182 if (!_is_bundle_module) { 2183 _final_apk_path_no_ext_list = 2184 process_file_template([ _final_apk_path ], 2185 "{{source_dir}}/{{source_name_part}}") 2186 _final_apk_path_no_ext = _final_apk_path_no_ext_list[0] 2187 not_needed([ "_final_apk_path_no_ext" ]) 2188 } 2189 2190 # Non-base bundle modules create only proto resources. 2191 if (_is_base_module) { 2192 _arsc_resources_path = "$target_out_dir/$target_name.ap_" 2193 } 2194 if (_is_bundle_module) { 2195 # Path to the intermediate proto-format resources zip file. 2196 _proto_resources_path = "$target_out_dir/$target_name.proto.ap_" 2197 } else { 2198 # resource_sizes.py needs to be able to find the unpacked resources.arsc 2199 # file based on apk name to compute normatlized size. 2200 _resource_sizes_arsc_path = 2201 "$root_out_dir/arsc/" + 2202 rebase_path(_final_apk_path_no_ext, root_build_dir) + ".ap_" 2203 } 2204 2205 if (defined(invoker.version_code)) { 2206 _version_code = invoker.version_code 2207 } else { 2208 _version_code = android_default_version_code 2209 } 2210 2211 if (android_override_version_code != "") { 2212 _version_code = android_override_version_code 2213 } 2214 2215 if (defined(invoker.version_name)) { 2216 _version_name = invoker.version_name 2217 } else { 2218 _version_name = android_default_version_name 2219 } 2220 2221 if (android_override_version_name != "") { 2222 _version_name = android_override_version_name 2223 } 2224 2225 if (defined(invoker.deps)) { 2226 _invoker_deps = invoker.deps 2227 } else { 2228 _invoker_deps = [] 2229 } 2230 _non_java_deps = filter_exclude(_invoker_deps, java_target_patterns) 2231 _java_assetres_deps = [ ":${_java_target_name}__assetres" ] 2232 2233 _srcjar_deps = [] 2234 if (defined(invoker.srcjar_deps)) { 2235 _srcjar_deps = invoker.srcjar_deps 2236 } 2237 2238 _use_chromium_linker = 2239 defined(invoker.use_chromium_linker) && invoker.use_chromium_linker 2240 2241 not_needed([ "_use_chromium_linker" ]) 2242 2243 # The dependency that makes the chromium linker, if any is needed. 2244 _native_libs_deps = [] 2245 _shared_libraries_is_valid = 2246 defined(invoker.shared_libraries) && invoker.shared_libraries != [] 2247 2248 if (_shared_libraries_is_valid) { 2249 _native_libs_deps += invoker.shared_libraries 2250 2251 # Write shared library output files of all dependencies to a file. Those 2252 # will be the shared libraries packaged into the APK. 2253 _shared_library_list_file = 2254 "$target_gen_dir/${_template_name}.native_libs" 2255 generated_file("${_template_name}__shared_library_list") { 2256 deps = _native_libs_deps 2257 outputs = [ _shared_library_list_file ] 2258 data_keys = [ "shared_libraries" ] 2259 walk_keys = [ "shared_libraries_barrier" ] 2260 rebase = root_build_dir 2261 } 2262 } else { 2263 # Must exist for instrumentation_test_apk() to depend on. 2264 group("${_template_name}__shared_library_list") { 2265 } 2266 } 2267 2268 _secondary_abi_native_libs_deps = [] 2269 2270 if (defined(invoker.secondary_abi_shared_libraries) && 2271 invoker.secondary_abi_shared_libraries != []) { 2272 _secondary_abi_native_libs_deps = invoker.secondary_abi_shared_libraries 2273 2274 # Write shared library output files of all dependencies to a file. Those 2275 # will be the shared libraries packaged into the APK. 2276 _secondary_abi_shared_library_list_file = 2277 "$target_gen_dir/${_template_name}.secondary_abi_native_libs" 2278 generated_file("${_template_name}__secondary_abi_shared_library_list") { 2279 deps = _secondary_abi_native_libs_deps 2280 outputs = [ _secondary_abi_shared_library_list_file ] 2281 data_keys = [ "shared_libraries" ] 2282 walk_keys = [ "shared_libraries_barrier" ] 2283 rebase = root_build_dir 2284 } 2285 } else { 2286 # Must exist for instrumentation_test_apk() to depend on. 2287 group("${_template_name}__secondary_abi_shared_library_list") { 2288 } 2289 } 2290 2291 _rebased_build_config = rebase_path(_build_config, root_build_dir) 2292 assert(_rebased_build_config != "") # Mark as used. 2293 2294 _generate_productconfig_java = 2295 defined(invoker.product_config_java_packages) && !_omit_dex 2296 2297 _proguard_enabled = 2298 defined(invoker.proguard_enabled) && invoker.proguard_enabled 2299 2300 if (!_is_bundle_module && _proguard_enabled) { 2301 _proguard_mapping_path = "$_final_apk_path.mapping" 2302 } 2303 2304 if (defined(invoker.resource_ids_provider_dep)) { 2305 _resource_ids_provider_dep = invoker.resource_ids_provider_dep 2306 } 2307 2308 if (defined(invoker.shared_resources_allowlist_target)) { 2309 _shared_resources_allowlist_target = 2310 invoker.shared_resources_allowlist_target 2311 } 2312 2313 _uses_static_library = defined(invoker.static_library_provider) 2314 2315 # TODO(crbug.com/40585188): Allow incremental installs of bundle modules. 2316 _incremental_apk = 2317 !_is_bundle_module && 2318 !(defined(invoker.never_incremental) && invoker.never_incremental) && 2319 incremental_install && _min_sdk_version >= default_min_sdk_version 2320 if (_incremental_apk) { 2321 _target_dir_name = get_label_info(target_name, "dir") 2322 _incremental_install_json_path = "$root_out_dir/gen.runtime/$_target_dir_name/$target_name.incremental.json" 2323 _incremental_apk_path = "${_final_apk_path_no_ext}_incremental.apk" 2324 } 2325 2326 if (!_incremental_apk && !_omit_dex) { 2327 # Bundle modules don't build the dex here, but need to write this path 2328 # to their .build_config.json file only when proguarding. 2329 if (_proguard_enabled) { 2330 _final_dex_path = "$_base_path.r8dex.jar" 2331 } else if (!_is_bundle_module) { 2332 _final_dex_path = "$_base_path.mergeddex.jar" 2333 } 2334 } 2335 2336 _android_manifest = 2337 "$target_gen_dir/${_template_name}/AndroidManifest.merged.xml" 2338 _merge_manifest_target = "${_template_name}__merge_manifests" 2339 merge_manifests(_merge_manifest_target) { 2340 forward_variables_from(invoker, 2341 [ 2342 "manifest_package", 2343 "max_sdk_version", 2344 ]) 2345 input_manifest = invoker.android_manifest 2346 output_manifest = _android_manifest 2347 build_config = _build_config 2348 min_sdk_version = _min_sdk_version 2349 target_sdk_version = _target_sdk_version 2350 2351 # Depend on android_resources() targets that use generated files 2352 # in mergeable_android_manifests (such as android_aar_prebuilt). 2353 deps = _java_assetres_deps + [ ":$_build_config_target" ] 2354 if (defined(invoker.android_manifest_dep)) { 2355 deps += [ invoker.android_manifest_dep ] 2356 } 2357 } 2358 2359 _final_deps = [ ":$_java_target_name" ] 2360 2361 _generated_proguard_config = "$_base_path.resources.proguard.txt" 2362 2363 if (defined(_shared_resources_allowlist_target)) { 2364 _allowlist_gen_dir = 2365 get_label_info(_shared_resources_allowlist_target, "target_gen_dir") 2366 _allowlist_target_name = 2367 get_label_info(_shared_resources_allowlist_target, "name") 2368 _allowlist_r_txt_path = 2369 "${_allowlist_gen_dir}/${_allowlist_target_name}" + 2370 "__compile_resources_R.txt" 2371 _allowlist_deps = 2372 "${_shared_resources_allowlist_target}__compile_resources" 2373 } 2374 2375 if (_incremental_apk) { 2376 _incremental_android_manifest = 2377 "$target_gen_dir/${_template_name}/AndroidManifest.incremental.xml" 2378 _incremental_manifest_target_name = "${target_name}__incremental_manifest" 2379 action_with_pydeps(_incremental_manifest_target_name) { 2380 deps = [ ":$_merge_manifest_target" ] 2381 script = 2382 "//chromium/build/android/incremental_install/generate_android_manifest.py" 2383 inputs = [ _android_manifest ] 2384 outputs = [ _incremental_android_manifest ] 2385 2386 args = [ 2387 "--disable-isolated-processes", 2388 "--src-manifest", 2389 rebase_path(_android_manifest, root_build_dir), 2390 "--dst-manifest", 2391 rebase_path(_incremental_android_manifest, root_build_dir), 2392 ] 2393 } 2394 } 2395 2396 _compile_resources_target = "${_template_name}__compile_resources" 2397 _compile_resources_rtxt_out = 2398 "${target_gen_dir}/${_compile_resources_target}_R.txt" 2399 _compile_resources_emit_ids_out = 2400 "${target_gen_dir}/${_compile_resources_target}.resource_ids" 2401 compile_resources(_compile_resources_target) { 2402 forward_variables_from( 2403 invoker, 2404 [ 2405 "aapt_locale_allowlist", 2406 "app_as_shared_lib", 2407 "enforce_resource_overlays_in_tests", 2408 "expected_android_manifest", 2409 "expected_android_manifest_base", 2410 "expected_android_manifest_library_version_offset", 2411 "expected_android_manifest_version_code_offset", 2412 "manifest_package", 2413 "max_sdk_version", 2414 "override_target_sdk", 2415 "package_id", 2416 "png_to_webp", 2417 "r_java_root_package_name", 2418 "resource_exclusion_exceptions", 2419 "resource_exclusion_regex", 2420 "resource_values_filter_rules", 2421 "shared_resources", 2422 "shared_resources_allowlist_locales", 2423 "uses_split", 2424 ]) 2425 android_manifest = _android_manifest 2426 android_manifest_dep = ":$_merge_manifest_target" 2427 version_code = _version_code 2428 version_name = _version_name 2429 min_sdk_version = _min_sdk_version 2430 target_sdk_version = _target_sdk_version 2431 2432 if (defined(expected_android_manifest)) { 2433 top_target_name = _template_name 2434 } 2435 2436 if (defined(_resource_ids_provider_dep)) { 2437 resource_ids_provider_dep = _resource_ids_provider_dep 2438 } 2439 2440 if (defined(invoker.module_name)) { 2441 package_name = invoker.module_name 2442 } 2443 2444 if (defined(invoker.post_process_package_resources_script)) { 2445 post_process_script = invoker.post_process_package_resources_script 2446 } 2447 r_text_out_path = _compile_resources_rtxt_out 2448 emit_ids_out_path = _compile_resources_emit_ids_out 2449 size_info_path = _res_size_info_path 2450 proguard_file = _generated_proguard_config 2451 2452 build_config = _build_config 2453 build_config_dep = ":$_build_config_target" 2454 deps = _java_assetres_deps + _non_java_deps 2455 2456 if (_incremental_apk) { 2457 android_manifest = _incremental_android_manifest 2458 android_manifest_dep = ":$_incremental_manifest_target_name" 2459 } 2460 2461 if (defined(invoker.apk_under_test)) { 2462 # Set the arsc package name to match the apk_under_test package name 2463 # So that test resources can references under_test resources via 2464 # @type/name syntax. 2465 r_java_root_package_name = "test" 2466 arsc_package_name = 2467 "@FileArg($_rebased_build_config:deps_info:arsc_package_name)" 2468 2469 # Passing in the --emit-ids mapping will cause aapt2 to assign resources 2470 # IDs that do not conflict with those from apk_under_test. 2471 assert(!defined(resource_ids_provider_dep)) 2472 resource_ids_provider_dep = invoker.apk_under_test 2473 2474 _link_against = invoker.apk_under_test 2475 } 2476 2477 if (_is_bundle_module) { 2478 is_bundle_module = true 2479 proto_output = _proto_resources_path 2480 2481 if (defined(invoker.base_module_target)) { 2482 _link_against = invoker.base_module_target 2483 } 2484 } 2485 2486 if (defined(_link_against)) { 2487 deps += [ "${_link_against}__compile_resources" ] 2488 include_resource = get_label_info(_link_against, "target_out_dir") + 2489 "/" + get_label_info(_link_against, "name") + ".ap_" 2490 } 2491 2492 # Bundle modules have to reference resources from the base module. 2493 if (_is_base_module) { 2494 arsc_output = _arsc_resources_path 2495 } 2496 2497 if (defined(_shared_resources_allowlist_target)) { 2498 # Used to ensure that the WebView resources are properly shared 2499 # (i.e. are non-final and with package ID 0). 2500 shared_resources_allowlist = _allowlist_r_txt_path 2501 deps += [ _allowlist_deps ] 2502 } 2503 } 2504 _srcjar_deps += [ ":$_compile_resources_target" ] 2505 2506 _short_resource_paths = 2507 defined(invoker.short_resource_paths) && invoker.short_resource_paths && 2508 enable_arsc_obfuscation 2509 _strip_resource_names = 2510 defined(invoker.strip_resource_names) && invoker.strip_resource_names && 2511 enable_arsc_obfuscation 2512 _strip_unused_resources = 2513 defined(invoker.strip_unused_resources) && 2514 invoker.strip_unused_resources && enable_unused_resource_stripping 2515 _optimize_resources = _strip_resource_names || _short_resource_paths || 2516 _strip_unused_resources 2517 2518 if (_strip_unused_resources) { 2519 # These need to be kept in sync with the target names + output paths 2520 # in the android_app_bundle template. 2521 _unused_resources_target = "${_template_name}__unused_resources" 2522 _unused_resources_config_path = 2523 "$target_gen_dir/${_template_name}_unused_resources.config" 2524 } 2525 2526 if (_optimize_resources) { 2527 if (_is_bundle_module) { 2528 _optimized_proto_resources_path = 2529 "$target_out_dir/$target_name.optimized.proto.ap_" 2530 } else { 2531 _optimized_arsc_resources_path = 2532 "$target_out_dir/$target_name.optimized.ap_" 2533 } 2534 if (_short_resource_paths) { 2535 _resources_path_map_out_path = 2536 "${target_gen_dir}/${_template_name}_resources_path_map.txt" 2537 } 2538 _optimize_resources_target = "${_template_name}__optimize_resources" 2539 optimize_resources(_optimize_resources_target) { 2540 deps = _non_java_deps + [ ":$_compile_resources_target" ] 2541 short_resource_paths = _short_resource_paths 2542 strip_resource_names = _strip_resource_names 2543 if (_short_resource_paths) { 2544 resources_path_map_out_path = _resources_path_map_out_path 2545 } 2546 r_text_path = _compile_resources_rtxt_out 2547 if (_is_bundle_module) { 2548 proto_input_path = _proto_resources_path 2549 optimized_proto_output = _optimized_proto_resources_path 2550 } else { 2551 arsc_input_path = _arsc_resources_path 2552 optimized_arsc_output = _optimized_arsc_resources_path 2553 } 2554 resources_config_paths = [] 2555 if (_strip_unused_resources) { 2556 resources_config_paths += [ _unused_resources_config_path ] 2557 deps += [ ":$_unused_resources_target" ] 2558 } 2559 if (defined(invoker.resources_config_paths)) { 2560 resources_config_paths += invoker.resources_config_paths 2561 } 2562 } 2563 2564 if (_strip_unused_resources) { 2565 # Copy the unused resources config to the final bundle output dir. 2566 _copy_unused_resources_target = 2567 "${_template_name}__copy_unused_resources" 2568 _final_deps += [ ":$_copy_unused_resources_target" ] 2569 } 2570 2571 # Bundles write their pathmap in a android_app_bundle template. 2572 if (_short_resource_paths && !_is_bundle_module) { 2573 _final_resources_pathmap_path = "${_final_apk_path}.pathmap.txt" 2574 _copy_pathmap_target = "${_template_name}__copy_pathmap" 2575 copy(_copy_pathmap_target) { 2576 deps = [ ":$_optimize_resources_target" ] 2577 sources = [ _resources_path_map_out_path ] 2578 outputs = [ _final_resources_pathmap_path ] 2579 } 2580 _final_deps += [ ":$_copy_pathmap_target" ] 2581 } 2582 } else { 2583 not_needed(invoker, [ "resources_config_paths" ]) 2584 } 2585 2586 if (!_is_bundle_module) { 2587 # Output the R.txt file to a more easily discoverable location for 2588 # archiving. This is necessary when stripping resource names so that we 2589 # have an archive of resource names to ids for shipped apks (for 2590 # debugging purposes). We copy the file rather than change the location 2591 # of the original because other targets rely on the location of the R.txt 2592 # file. 2593 _copy_rtxt_target = "${_template_name}__copy_rtxt" 2594 copy(_copy_rtxt_target) { 2595 deps = [ ":$_compile_resources_target" ] 2596 sources = [ _compile_resources_rtxt_out ] 2597 outputs = [ _final_rtxt_path ] 2598 } 2599 _final_deps += [ ":$_copy_rtxt_target" ] 2600 } 2601 2602 if (defined(_resource_sizes_arsc_path)) { 2603 _copy_arsc_target = "${_template_name}__copy_arsc" 2604 copy(_copy_arsc_target) { 2605 deps = [ ":$_compile_resources_target" ] 2606 2607 # resource_sizes.py doesn't care if it gets the optimized .arsc. 2608 sources = [ _arsc_resources_path ] 2609 outputs = [ _resource_sizes_arsc_path ] 2610 } 2611 _final_deps += [ ":$_copy_arsc_target" ] 2612 } 2613 2614 if (defined(invoker.generate_native_libraries_java)) { 2615 _generate_native_libraries_java = invoker.generate_native_libraries_java 2616 } else { 2617 _generate_native_libraries_java = 2618 _is_base_module && !_omit_dex && !defined(invoker.apk_under_test) 2619 } 2620 if (_generate_native_libraries_java) { 2621 write_native_libraries_java("${_template_name}__native_libraries") { 2622 if (defined(_shared_library_list_file)) { 2623 _use_secondary_abi = false 2624 } else if (defined(_secondary_abi_shared_library_list_file)) { 2625 _use_secondary_abi = true 2626 } 2627 if (_uses_static_library) { 2628 if (defined(_use_secondary_abi)) { 2629 # Use the library list in TrichromeWebView instead of TrichromeLibrary. 2630 _from_static_library = false 2631 } else { 2632 _from_static_library = true 2633 _use_secondary_abi = 2634 defined(invoker.static_library_provider_use_secondary_abi) && 2635 invoker.static_library_provider_use_secondary_abi 2636 } 2637 } else { 2638 _from_static_library = false 2639 } 2640 if (_from_static_library) { 2641 _prefix = get_label_info(invoker.static_library_provider, 2642 "target_gen_dir") + "/" + 2643 get_label_info(invoker.static_library_provider, "name") 2644 if (_use_secondary_abi) { 2645 native_libraries_list_file = "${_prefix}.secondary_abi_native_libs" 2646 } else { 2647 native_libraries_list_file = "${_prefix}.native_libs" 2648 } 2649 } else if (defined(_use_secondary_abi)) { 2650 if (_use_secondary_abi) { 2651 native_libraries_list_file = _secondary_abi_shared_library_list_file 2652 } else { 2653 native_libraries_list_file = _shared_library_list_file 2654 } 2655 } 2656 2657 if (defined(_use_secondary_abi)) { 2658 if (_use_secondary_abi || !android_64bit_target_cpu) { 2659 native_lib_32_bit = true 2660 } else { 2661 native_lib_64_bit = true 2662 } 2663 } 2664 2665 enable_chromium_linker = _use_chromium_linker 2666 use_final_fields = true 2667 2668 # Do not add a dep on the generated_file target in order to avoid having 2669 # to build the native libraries before this target. The dependency is 2670 # instead captured via a depfile. 2671 } 2672 _srcjar_deps += [ ":${_template_name}__native_libraries" ] 2673 } 2674 2675 _loadable_modules = [] 2676 if (defined(invoker.loadable_modules)) { 2677 _loadable_modules = invoker.loadable_modules 2678 } 2679 _sanitizer_loadable_modules = [] 2680 _sanitizer_deps = [] 2681 if (_is_base_module && _native_libs_deps != [] && !_uses_static_library) { 2682 _sanitizer_loadable_modules += _sanitizer_runtimes 2683 } 2684 if ((is_hwasan || is_asan) && _is_base_module && 2685 (_uses_static_library || _native_libs_deps != [])) { 2686 _sanitizer_loadable_modules += 2687 [ "$root_gen_dir/build/android/generate_wrap_sh/wrap.sh" ] 2688 _sanitizer_deps += [ "//chromium/build/android:generate_wrap_sh" ] 2689 } 2690 2691 _assertions_implicitly_enabled = defined(invoker.custom_assertion_handler) 2692 2693 # Many possible paths where we wouldn't use this variable. 2694 not_needed([ "_assertions_implicitly_enabled" ]) 2695 2696 _generate_buildconfig_java = !defined(invoker.apk_under_test) && !_omit_dex 2697 if (defined(invoker.generate_buildconfig_java)) { 2698 _generate_buildconfig_java = invoker.generate_buildconfig_java 2699 } 2700 if (_generate_buildconfig_java) { 2701 generate_build_config_srcjar("${_template_name}__build_config_srcjar") { 2702 forward_variables_from(invoker, 2703 [ 2704 "disable_strict_mode_context", 2705 "isolated_splits_enabled", 2706 ]) 2707 assertions_implicitly_enabled = _assertions_implicitly_enabled 2708 is_incremental_install = _incremental_apk 2709 version_code = _version_code 2710 min_sdk_version = _min_sdk_version 2711 write_clang_profiling_data = 2712 use_clang_coverage && _generate_native_libraries_java 2713 if (defined(invoker.build_config_include_product_version_resource) && 2714 invoker.build_config_include_product_version_resource) { 2715 resources_version_variable = 2716 "org.chromium.base.R.string.product_version" 2717 } 2718 if (defined(invoker.suffix_apk_assets_used_by)) { 2719 deps = [ ":$_build_config_target" ] 2720 inputs = [ _build_config ] 2721 apk_assets_suffixed_list = 2722 "@FileArg(${_rebased_build_config}:apk_assets_suffixed_list)" 2723 apk_assets_suffix = 2724 "@FileArg(${_rebased_build_config}:apk_assets_suffix)" 2725 } 2726 } 2727 _srcjar_deps += [ ":${_template_name}__build_config_srcjar" ] 2728 } 2729 2730 if (_generate_productconfig_java) { 2731 foreach(_package, invoker.product_config_java_packages) { 2732 _locale_target_name = 2733 "${_template_name}_${_package}__product_config_srcjar" 2734 generate_product_config_srcjar("$_locale_target_name") { 2735 build_config = _build_config 2736 java_package = _package 2737 use_chromium_linker = _use_chromium_linker 2738 deps = [ ":$_build_config_target" ] 2739 } 2740 _srcjar_deps += [ ":$_locale_target_name" ] 2741 } 2742 } 2743 2744 if (_is_bundle_module) { 2745 _add_view_trace_events = 2746 defined(invoker.add_view_trace_events) && 2747 invoker.add_view_trace_events && enable_trace_event_bytecode_rewriting 2748 } 2749 2750 # We cannot skip this target when omit_dex = true because it writes the 2751 # build_config.json. 2752 java_library_impl(_java_target_name) { 2753 forward_variables_from(invoker, 2754 [ 2755 "alternative_android_sdk_dep", 2756 "android_manifest", 2757 "android_manifest_dep", 2758 "annotation_processor_deps", 2759 "apk_under_test", 2760 "asset_deps", 2761 "base_module_target", 2762 "chromium_code", 2763 "deps", 2764 "jacoco_never_instrument", 2765 "jar_excluded_patterns", 2766 "javac_args", 2767 "mergeable_android_manifests", 2768 "native_lib_placeholders", 2769 "parent_module_target", 2770 "processor_args_javac", 2771 "secondary_abi_loadable_modules", 2772 "secondary_native_lib_placeholders", 2773 "sources", 2774 "suffix_apk_assets_used_by", 2775 "library_always_compress", 2776 ]) 2777 version_code = _version_code 2778 version_name = _version_name 2779 if (_is_bundle_module) { 2780 type = "android_app_bundle_module" 2781 res_size_info_path = _res_size_info_path 2782 if (defined(invoker.module_name)) { 2783 module_name = invoker.module_name 2784 } else { 2785 module_name = "base" 2786 } 2787 add_view_trace_events = _add_view_trace_events 2788 } else { 2789 type = "android_apk" 2790 } 2791 r_text_path = _compile_resources_rtxt_out 2792 main_target_name = _template_name 2793 supports_android = true 2794 requires_android = true 2795 srcjar_deps = _srcjar_deps 2796 merged_android_manifest = _android_manifest 2797 if (defined(_final_dex_path)) { 2798 final_dex_path = _final_dex_path 2799 } 2800 if (defined(invoker.assert_no_native_deps)) { 2801 assert_no_deps = invoker.assert_no_native_deps 2802 } 2803 2804 if (_is_bundle_module) { 2805 proto_resources_path = _proto_resources_path 2806 if (_optimize_resources) { 2807 proto_resources_path = _optimized_proto_resources_path 2808 if (_short_resource_paths) { 2809 module_pathmap_path = _resources_path_map_out_path 2810 } 2811 } 2812 } else { 2813 apk_path = _final_apk_path 2814 if (_incremental_apk) { 2815 incremental_apk_path = _incremental_apk_path 2816 incremental_install_json_path = _incremental_install_json_path 2817 } 2818 } 2819 2820 proguard_enabled = _proguard_enabled 2821 if (_proguard_enabled) { 2822 proguard_configs = [ _generated_proguard_config ] 2823 if (defined(invoker.proguard_configs)) { 2824 proguard_configs += invoker.proguard_configs 2825 } 2826 if (!_is_bundle_module) { 2827 proguard_mapping_path = _proguard_mapping_path 2828 } 2829 } 2830 2831 # Do not add a dep on the generated_file target in order to avoid having 2832 # to build the native libraries before this target. The dependency is 2833 # instead captured via a depfile. 2834 if (_native_libs_deps != []) { 2835 shared_libraries_runtime_deps_file = _shared_library_list_file 2836 } 2837 if (defined(_secondary_abi_shared_library_list_file)) { 2838 secondary_abi_shared_libraries_runtime_deps_file = 2839 _secondary_abi_shared_library_list_file 2840 } 2841 2842 if (!defined(deps)) { 2843 deps = [] 2844 } 2845 deps += _sanitizer_deps 2846 loadable_modules = _loadable_modules + _sanitizer_loadable_modules 2847 2848 if (defined(_allowlist_r_txt_path) && _is_bundle_module) { 2849 # Used to write the file path to the target's .build_config.json only. 2850 base_allowlist_rtxt_path = _allowlist_r_txt_path 2851 } 2852 } 2853 2854 if (_is_bundle_module || _omit_dex) { 2855 # Dex generation for app bundle modules take place in the 2856 # android_app_bundle template. 2857 not_needed(invoker, [ "custom_assertion_handler" ]) 2858 } else if (_incremental_apk) { 2859 not_needed(invoker, 2860 [ 2861 "enable_proguard_checks", 2862 "custom_assertion_handler", 2863 ]) 2864 } else { 2865 _final_dex_target_name = "${_template_name}__final_dex" 2866 dex(_final_dex_target_name) { 2867 forward_variables_from(invoker, 2868 [ 2869 "enable_proguard_checks", 2870 "custom_assertion_handler", 2871 "proguard_enable_obfuscation", 2872 "repackage_classes", 2873 ]) 2874 min_sdk_version = _min_sdk_version 2875 proguard_enabled = _proguard_enabled 2876 build_config = _build_config 2877 output = _final_dex_path 2878 deps = [ 2879 ":$_build_config_target", 2880 ":$_java_target_name", 2881 ] 2882 if (_proguard_enabled) { 2883 # Generates proguard configs 2884 deps += [ ":$_compile_resources_target" ] 2885 proguard_mapping_path = _proguard_mapping_path 2886 has_apk_under_test = defined(invoker.apk_under_test) 2887 2888 # Must not be set via write_build_config, because that will cause it 2889 # to be picked up by test apks that use apk_under_test. 2890 if (!_assertions_implicitly_enabled && !enable_java_asserts && 2891 (!defined(testonly) || !testonly) && 2892 # Injected JaCoCo code causes -checkdiscards to fail. 2893 !use_jacoco_coverage) { 2894 proguard_configs = [ 2895 "//chromium/build/android/dcheck_is_off.flags", 2896 "//third_party/jni_zero/checkdiscard_proguard.flags", 2897 ] 2898 } 2899 } else { 2900 if (_min_sdk_version >= default_min_sdk_version) { 2901 # Enable dex merging only when min_sdk_version is >= what the library 2902 # .dex files were created with. 2903 input_dex_filearg = 2904 "@FileArg(${_rebased_build_config}:deps_info:all_dex_files)" 2905 2906 # Pure dex-merge. 2907 enable_desugar = false 2908 } else { 2909 input_classes_filearg = 2910 "@FileArg($_rebased_build_config:deps_info:device_classpath)" 2911 } 2912 } 2913 2914 # The individual dependencies would have caught real missing deps in 2915 # their respective dex steps. False positives that were suppressed at 2916 # per-target dex steps are emitted here since this may use jar files 2917 # rather than dex files. 2918 if (!defined(enable_desugar)) { 2919 ignore_desugar_missing_deps = true 2920 } 2921 } 2922 2923 _final_dex_target_dep = ":$_final_dex_target_name" 2924 2925 # Unused resources target for bundles handled in android_app_bundle 2926 # template. 2927 if (_strip_unused_resources && !_is_bundle_module) { 2928 unused_resources(_unused_resources_target) { 2929 deps = [ 2930 ":$_build_config_target", 2931 ":$_compile_resources_target", 2932 ":$_final_dex_target_name", 2933 ] 2934 build_config = _build_config 2935 if (_proguard_enabled) { 2936 proguard_mapping_path = _proguard_mapping_path 2937 } 2938 output_config = _unused_resources_config_path 2939 } 2940 } 2941 } 2942 2943 _all_native_libs_deps = _native_libs_deps + _secondary_abi_native_libs_deps 2944 if (_all_native_libs_deps != []) { 2945 _native_libs_filearg_dep = ":$_build_config_target" 2946 _all_native_libs_deps += [ _native_libs_filearg_dep ] 2947 2948 if (!_is_bundle_module) { 2949 _native_libs_filearg = 2950 "@FileArg($_rebased_build_config:native:libraries)" 2951 } 2952 } 2953 2954 if (_is_bundle_module) { 2955 _final_deps += [ 2956 ":$_build_config_target", 2957 ":$_compile_resources_target", 2958 ":$_merge_manifest_target", 2959 ] + _all_native_libs_deps 2960 if (defined(invoker.asset_deps)) { 2961 _final_deps += invoker.asset_deps 2962 } 2963 if (_optimize_resources) { 2964 _final_deps += [ ":$_optimize_resources_target" ] 2965 } 2966 if (defined(_final_dex_target_dep)) { 2967 not_needed([ "_final_dex_target_dep" ]) 2968 } 2969 } else { 2970 # Generate size-info/*.jar.info files. 2971 if (defined(invoker.name)) { 2972 # Create size info files for targets that care about size 2973 # (have proguard enabled). 2974 _include_size_info = 2975 defined(invoker.include_size_info) && invoker.include_size_info 2976 if (_include_size_info || _proguard_enabled) { 2977 _size_info_target = "${target_name}__size_info" 2978 create_size_info_files(_size_info_target) { 2979 name = "${invoker.name}.apk" 2980 build_config = _build_config 2981 res_size_info_path = _res_size_info_path 2982 deps = [ 2983 ":$_build_config_target", 2984 ":$_compile_resources_target", 2985 ":$_java_target_name", 2986 ] 2987 if (defined(invoker.asset_deps)) { 2988 deps += invoker.asset_deps 2989 } 2990 } 2991 _final_deps += [ ":$_size_info_target" ] 2992 } else { 2993 not_needed(invoker, [ "name" ]) 2994 } 2995 } 2996 2997 _create_apk_target = "${_template_name}__create" 2998 _final_deps += [ ":$_create_apk_target" ] 2999 package_apk("$_create_apk_target") { 3000 forward_variables_from(invoker, 3001 [ 3002 "expected_libs_and_assets", 3003 "expected_libs_and_assets_base", 3004 "keystore_name", 3005 "keystore_path", 3006 "keystore_password", 3007 "native_lib_placeholders", 3008 "secondary_abi_loadable_modules", 3009 "secondary_native_lib_placeholders", 3010 "uncompress_dex", 3011 "library_always_compress", 3012 ]) 3013 3014 if (defined(expected_libs_and_assets)) { 3015 build_config_dep = ":$_build_config_target" 3016 top_target_name = _template_name 3017 } 3018 3019 build_config = _build_config 3020 min_sdk_version = _min_sdk_version 3021 packaged_resources_path = _arsc_resources_path 3022 3023 # Need full deps rather than _non_java_deps, because loadable_modules 3024 # may include .so files extracted by __unpack_aar targets. 3025 deps = _invoker_deps + _sanitizer_deps + [ ":$_build_config_target" ] 3026 if (defined(invoker.asset_deps)) { 3027 deps += invoker.asset_deps 3028 } 3029 3030 if (_incremental_apk) { 3031 _dex_target = "//chromium/build/android/incremental_install:apk_dex" 3032 3033 deps += [ 3034 ":$_compile_resources_target", 3035 _dex_target, 3036 ] 3037 3038 dex_path = get_label_info(_dex_target, "target_out_dir") + "/apk.dex" 3039 3040 # Incremental APKs cannot be installed via `adb install` as such they 3041 # should be clearly named/labeled "incremental". 3042 output_apk_path = _incremental_apk_path 3043 3044 loadable_modules = _sanitizer_loadable_modules 3045 3046 # All native libraries are side-loaded, so use a placeholder to force 3047 # the proper bitness for the app. 3048 _has_native_libs = 3049 defined(_native_libs_filearg) || _loadable_modules != [] || 3050 _sanitizer_loadable_modules != [] 3051 if (_has_native_libs && loadable_modules == [] && 3052 !defined(native_lib_placeholders)) { 3053 native_lib_placeholders = [ "libfix.crbug.384638.so" ] 3054 } 3055 } else { 3056 loadable_modules = _loadable_modules + _sanitizer_loadable_modules 3057 deps += _all_native_libs_deps + [ 3058 ":$_compile_resources_target", 3059 ":$_merge_manifest_target", 3060 ] 3061 3062 if (defined(_final_dex_path)) { 3063 dex_path = _final_dex_path 3064 deps += [ _final_dex_target_dep ] 3065 } 3066 3067 output_apk_path = _final_apk_path 3068 3069 if (_optimize_resources) { 3070 packaged_resources_path = _optimized_arsc_resources_path 3071 deps += [ ":$_optimize_resources_target" ] 3072 } else { 3073 packaged_resources_path = _arsc_resources_path 3074 deps += [ ":$_compile_resources_target" ] 3075 } 3076 3077 if (defined(_native_libs_filearg)) { 3078 native_libs_filearg = _native_libs_filearg 3079 secondary_abi_native_libs_filearg = "@FileArg($_rebased_build_config:native:secondary_abi_libraries)" 3080 } 3081 } 3082 } 3083 } 3084 3085 if (_incremental_apk) { 3086 _write_installer_json_rule_name = "${_template_name}__incremental_json" 3087 action_with_pydeps(_write_installer_json_rule_name) { 3088 script = "//chromium/build/android/incremental_install/write_installer_json.py" 3089 deps = [ ":$_build_config_target" ] + _all_native_libs_deps 3090 3091 data = [ _incremental_install_json_path ] 3092 inputs = [ _build_config ] 3093 outputs = [ _incremental_install_json_path ] 3094 3095 _rebased_incremental_apk_path = 3096 rebase_path(_incremental_apk_path, root_build_dir) 3097 _rebased_incremental_install_json_path = 3098 rebase_path(_incremental_install_json_path, root_build_dir) 3099 args = [ 3100 "--apk-path=$_rebased_incremental_apk_path", 3101 "--output-path=$_rebased_incremental_install_json_path", 3102 "--dex-file=@FileArg($_rebased_build_config:deps_info:all_dex_files)", 3103 ] 3104 if (_proguard_enabled) { 3105 args += [ "--show-proguard-warning" ] 3106 } 3107 if (defined(_native_libs_filearg)) { 3108 args += [ "--native-libs=$_native_libs_filearg" ] 3109 deps += [ _native_libs_filearg_dep ] 3110 } 3111 if (_loadable_modules != []) { 3112 _rebased_loadable_modules = 3113 rebase_path(_loadable_modules, root_build_dir) 3114 args += [ "--native-libs=$_rebased_loadable_modules" ] 3115 } 3116 } 3117 _final_deps += [ ":$_write_installer_json_rule_name" ] 3118 } 3119 3120 # Generate apk operation related script. 3121 if (!_is_bundle_module && 3122 (!defined(invoker.create_apk_script) || invoker.create_apk_script)) { 3123 if (_uses_static_library) { 3124 _install_artifacts_target = "${target_name}__install_artifacts" 3125 _install_artifacts_json = 3126 "${target_gen_dir}/${target_name}.install_artifacts" 3127 generated_file(_install_artifacts_target) { 3128 output_conversion = "json" 3129 deps = [ invoker.static_library_provider ] 3130 outputs = [ _install_artifacts_json ] 3131 data_keys = [ "install_artifacts" ] 3132 rebase = root_build_dir 3133 } 3134 } 3135 _apk_operations_target_name = "${target_name}__apk_operations" 3136 action_with_pydeps(_apk_operations_target_name) { 3137 _generated_script = "$root_build_dir/bin/${invoker.target_name}" 3138 script = "//chromium/build/android/gyp/create_apk_operations_script.py" 3139 outputs = [ _generated_script ] 3140 args = [ 3141 "--script-output-path", 3142 rebase_path(_generated_script, root_build_dir), 3143 "--target-cpu=$target_cpu", 3144 ] 3145 if (defined(invoker.command_line_flags_file)) { 3146 args += [ 3147 "--command-line-flags-file", 3148 invoker.command_line_flags_file, 3149 ] 3150 } 3151 if (_incremental_apk) { 3152 args += [ 3153 "--incremental-install-json-path", 3154 rebase_path(_incremental_install_json_path, root_build_dir), 3155 ] 3156 } else { 3157 args += [ 3158 "--apk-path", 3159 rebase_path(_final_apk_path, root_build_dir), 3160 ] 3161 } 3162 if (_uses_static_library) { 3163 deps = [ ":$_install_artifacts_target" ] 3164 _rebased_install_artifacts_json = 3165 rebase_path(_install_artifacts_json, root_build_dir) 3166 _static_library_apk_path = 3167 "@FileArg($_rebased_install_artifacts_json[])" 3168 args += [ 3169 "--additional-apk", 3170 _static_library_apk_path, 3171 ] 3172 } 3173 data = [] 3174 data_deps = [ 3175 "//chromium/build/android:apk_operations_py", 3176 "//chromium/build/android:stack_tools", 3177 ] 3178 3179 if (_proguard_enabled && !_incremental_apk) { 3180 # Required by logcat command. 3181 data_deps += [ "//chromium/build/android/stacktrace:java_deobfuscate" ] 3182 data += [ "$_final_apk_path.mapping" ] 3183 args += [ 3184 "--proguard-mapping-path", 3185 rebase_path("$_final_apk_path.mapping", root_build_dir), 3186 ] 3187 } 3188 } 3189 _final_deps += [ ":$_apk_operations_target_name" ] 3190 } 3191 3192 _enable_lint = defined(invoker.enable_lint) && invoker.enable_lint && 3193 !disable_android_lint 3194 if (_enable_lint) { 3195 android_lint("${target_name}__lint") { 3196 forward_variables_from(invoker, 3197 [ 3198 "lint_baseline_file", 3199 "lint_gen_dir", 3200 "lint_suppressions_file", 3201 "min_sdk_version", 3202 ]) 3203 build_config = _build_config 3204 build_config_dep = ":$_build_config_target" 3205 3206 # This will use library subtargets under-the-hood 3207 deps = [ ":$_java_target_name" ] 3208 if (defined(invoker.lint_suppressions_dep)) { 3209 deps += [ invoker.lint_suppressions_dep ] 3210 } 3211 if (defined(invoker.asset_deps)) { 3212 deps += invoker.asset_deps 3213 } 3214 if (defined(invoker.lint_min_sdk_version)) { 3215 min_sdk_version = invoker.lint_min_sdk_version 3216 } 3217 } 3218 } else { 3219 not_needed(invoker, 3220 [ 3221 "lint_baseline_file", 3222 "lint_gen_dir", 3223 "lint_jar_path", 3224 "lint_min_sdk_version", 3225 "lint_suppressions_dep", 3226 "lint_suppressions_file", 3227 ]) 3228 } 3229 3230 group(target_name) { 3231 forward_variables_from(invoker, 3232 [ 3233 "assert_no_deps", 3234 "data", 3235 "data_deps", 3236 ]) 3237 metadata = { 3238 if (defined(invoker.metadata)) { 3239 forward_variables_from(invoker.metadata, "*") 3240 } 3241 3242 # Allows metadata collection via apk targets that traverse only java deps. 3243 java_walk_keys = [ ":$_java_target_name" ] 3244 } 3245 3246 # Generate apk related operations at runtime. 3247 public_deps = _final_deps 3248 3249 if (!defined(data_deps)) { 3250 data_deps = [] 3251 } 3252 3253 # Include unstripped native libraries so tests can symbolize stacks. 3254 data_deps += _all_native_libs_deps + [ ":${_java_target_name}__validate" ] 3255 if (_enable_lint) { 3256 data_deps += [ ":${target_name}__lint" ] 3257 } 3258 3259 if (_uses_static_library) { 3260 data_deps += [ invoker.static_library_provider ] 3261 } 3262 } 3263 } 3264 3265 # Declare an Android APK target 3266 # 3267 # This target creates an Android APK containing java code, resources, assets, 3268 # and (possibly) native libraries. 3269 # 3270 # Supports all variables of android_apk_or_module(), plus: 3271 # apk_name: Name for final apk. 3272 # final_apk_path: (Optional) path to output APK. 3273 # 3274 # Example 3275 # android_apk("foo_apk") { 3276 # android_manifest = "AndroidManifest.xml" 3277 # sources = [ 3278 # "android/org/chromium/foo/FooApplication.java", 3279 # "android/org/chromium/foo/FooActivity.java", 3280 # ] 3281 # deps = [ 3282 # ":foo_support_java" 3283 # ":foo_resources" 3284 # ] 3285 # srcjar_deps = [ 3286 # ":foo_generated_enum" 3287 # ] 3288 # shared_libraries = [ 3289 # ":my_shared_lib", 3290 # ] 3291 # } 3292 template("android_apk") { 3293 android_apk_or_module(target_name) { 3294 forward_variables_from( 3295 invoker, 3296 [ 3297 "aapt_locale_allowlist", 3298 "additional_jar_files", 3299 "allow_unused_jni_from_native", 3300 "alternative_android_sdk_dep", 3301 "android_manifest", 3302 "android_manifest_dep", 3303 "annotation_processor_deps", 3304 "apk_under_test", 3305 "app_as_shared_lib", 3306 "assert_no_deps", 3307 "assert_no_native_deps", 3308 "asset_deps", 3309 "build_config_include_product_version_resource", 3310 "bundles_supported", 3311 "chromium_code", 3312 "command_line_flags_file", 3313 "create_apk_script", 3314 "custom_assertion_handler", 3315 "data", 3316 "data_deps", 3317 "deps", 3318 "enable_lint", 3319 "enable_proguard_checks", 3320 "errorprone_args", 3321 "disable_strict_mode_context", 3322 "enforce_resource_overlays_in_tests", 3323 "expected_android_manifest", 3324 "expected_android_manifest_base", 3325 "expected_android_manifest_library_version_offset", 3326 "expected_android_manifest_version_code_offset", 3327 "expected_libs_and_assets", 3328 "expected_libs_and_assets_base", 3329 "generate_buildconfig_java", 3330 "generate_native_libraries_java", 3331 "include_size_info", 3332 "input_jars_paths", 3333 "jacoco_never_instrument", 3334 "javac_args", 3335 "keystore_name", 3336 "keystore_password", 3337 "keystore_path", 3338 "lint_baseline_file", 3339 "lint_gen_dir", 3340 "lint_min_sdk_version", 3341 "lint_suppressions_dep", 3342 "lint_suppressions_file", 3343 "loadable_modules", 3344 "manifest_package", 3345 "max_sdk_version", 3346 "mergeable_android_manifests", 3347 "product_config_java_packages", 3348 "min_sdk_version", 3349 "native_lib_placeholders", 3350 "never_incremental", 3351 "omit_dex", 3352 "png_to_webp", 3353 "post_process_package_resources_script", 3354 "processor_args_javac", 3355 "proguard_configs", 3356 "proguard_enabled", 3357 "proguard_enable_obfuscation", 3358 "r_java_root_package_name", 3359 "repackage_classes", 3360 "resource_exclusion_exceptions", 3361 "resource_exclusion_regex", 3362 "resource_ids_provider_dep", 3363 "resource_values_filter_rules", 3364 "resources_config_paths", 3365 "require_native_mocks", 3366 "secondary_abi_loadable_modules", 3367 "secondary_abi_shared_libraries", 3368 "secondary_native_lib_placeholders", 3369 "shared_libraries", 3370 "shared_resources", 3371 "shared_resources_allowlist_locales", 3372 "shared_resources_allowlist_target", 3373 "short_resource_paths", 3374 "sources", 3375 "srcjar_deps", 3376 "static_library_provider", 3377 "static_library_provider_use_secondary_abi", 3378 "strip_unused_resources", 3379 "strip_resource_names", 3380 "suffix_apk_assets_used_by", 3381 "target_sdk_version", 3382 "testonly", 3383 "uncompress_dex", 3384 "library_always_compress", 3385 "use_chromium_linker", 3386 "version_code", 3387 "version_name", 3388 "visibility", 3389 ]) 3390 is_bundle_module = false 3391 name = invoker.apk_name 3392 if (defined(invoker.final_apk_path)) { 3393 final_apk_path = invoker.final_apk_path 3394 } else { 3395 final_apk_path = "$root_build_dir/apks/${invoker.apk_name}.apk" 3396 } 3397 metadata = { 3398 install_artifacts = [ final_apk_path ] 3399 if (defined(invoker.static_library_provider)) { 3400 install_artifacts_barrier = [] 3401 } 3402 } 3403 3404 # TODO(smaier) - there were some remaining usages of this in angle. Once 3405 # they are removed, remove this line. 3406 not_needed(invoker, [ "generate_final_jni" ]) 3407 } 3408 } 3409 3410 # Declare an Android app bundle module target. 3411 # 3412 # The module can be used for an android_apk_or_module(). 3413 # 3414 # Supports all variables of android_library(), plus: 3415 # module_name: Name of the module. 3416 # is_base_module: If defined and true, indicates that this is the bundle's 3417 # base module (optional). 3418 # base_module_target: Base module target of the bundle this module will be 3419 # added to (optional). Can only be specified for non-base modules. 3420 template("android_app_bundle_module") { 3421 _is_base_module = defined(invoker.is_base_module) && invoker.is_base_module 3422 3423 if (_is_base_module) { 3424 assert(!defined(invoker.base_module_target)) 3425 } else { 3426 assert(!defined(invoker.app_as_shared_lib)) 3427 assert(!defined(invoker.shared_resources)) 3428 assert(!defined(invoker.shared_resources_allowlist_target)) 3429 assert(!defined(invoker.shared_resources_allowlist_locales)) 3430 assert(defined(invoker.base_module_target)) 3431 } 3432 3433 # android_app_bundle's write_build_config expects module targets to be named 3434 # according to java_target_patterns otherwise it ignores them when listed in 3435 # possible_config_deps. See https://crbug.com/1418398. 3436 if (filter_exclude([ target_name ], [ "*_bundle_module" ]) != []) { 3437 assert(false, 3438 "Invalid android_app_bundle_module target name ($target_name), " + 3439 "must end in _bundle_module.") 3440 } 3441 3442 # TODO(tiborg): We have several flags that are necessary for workarounds 3443 # that come from the fact that the resources get compiled in the bundle 3444 # module target, but bundle modules have to have certain flags in 3445 # common or bundle modules have to know information about the base module. 3446 # Those flags include version_code, version_name, and base_module_target. 3447 # It would be better to move the resource compile target into the bundle 3448 # target. Doing so would keep the bundle modules independent from the bundle 3449 # and potentially reuse the same bundle modules for multiple bundles. 3450 android_apk_or_module(target_name) { 3451 forward_variables_from( 3452 invoker, 3453 [ 3454 "add_view_trace_events", 3455 "aapt_locale_allowlist", 3456 "additional_jar_files", 3457 "allow_unused_jni_from_native", 3458 "alternative_android_sdk_dep", 3459 "android_manifest", 3460 "android_manifest_dep", 3461 "annotation_processor_deps", 3462 "app_as_shared_lib", 3463 "assert_no_deps", 3464 "assert_no_native_deps", 3465 "asset_deps", 3466 "base_module_target", 3467 "build_config_include_product_version_resource", 3468 "bundle_target", 3469 "chromium_code", 3470 "custom_assertion_handler", 3471 "data", 3472 "data_deps", 3473 "deps", 3474 "disable_strict_mode_context", 3475 "expected_android_manifest", 3476 "expected_android_manifest_base", 3477 "expected_android_manifest_library_version_offset", 3478 "expected_android_manifest_version_code_offset", 3479 "generate_buildconfig_java", 3480 "generate_native_libraries_java", 3481 "input_jars_paths", 3482 "isolated_splits_enabled", 3483 "is_base_module", 3484 "jacoco_never_instrument", 3485 "jar_excluded_patterns", 3486 "javac_args", 3487 "loadable_modules", 3488 "product_config_java_packages", 3489 "manifest_package", 3490 "max_sdk_version", 3491 "min_sdk_version", 3492 "mergeable_android_manifests", 3493 "override_target_sdk", 3494 "module_name", 3495 "native_lib_placeholders", 3496 "package_id", 3497 "parent_module_target", 3498 "png_to_webp", 3499 "processor_args_javac", 3500 "proguard_configs", 3501 "proguard_enabled", 3502 "proguard_enable_obfuscation", 3503 "repackage_classes", 3504 "resource_exclusion_exceptions", 3505 "resource_exclusion_regex", 3506 "resource_ids_provider_dep", 3507 "resource_values_filter_rules", 3508 "resources_config_paths", 3509 "secondary_abi_loadable_modules", 3510 "secondary_abi_shared_libraries", 3511 "secondary_native_lib_placeholders", 3512 "shared_libraries", 3513 "shared_resources", 3514 "shared_resources_allowlist_locales", 3515 "shared_resources_allowlist_target", 3516 "short_resource_paths", 3517 "srcjar_deps", 3518 "static_library_provider", 3519 "static_library_provider_use_secondary_abi", 3520 "strip_resource_names", 3521 "strip_unused_resources", 3522 "suffix_apk_assets_used_by", 3523 "target_sdk_version", 3524 "testonly", 3525 "library_always_compress", 3526 "use_chromium_linker", 3527 "uses_split", 3528 "version_code", 3529 "version_name", 3530 "visibility", 3531 ]) 3532 is_bundle_module = true 3533 generate_buildconfig_java = _is_base_module 3534 if (defined(uses_split)) { 3535 assert(defined(parent_module_target), 3536 "Must set parent_module_target when uses_split is set") 3537 } 3538 } 3539 } 3540 3541 # Declare an Android instrumentation test runner. 3542 # 3543 # This target creates a wrapper script to run Android instrumentation tests. 3544 # 3545 # Arguments: 3546 # android_test_apk: The target containing the tests. 3547 # 3548 # The following args are optional: 3549 # apk_under_test: The target being tested. 3550 # additional_apks: Additional targets to install on device. 3551 # data: List of runtime data file dependencies. 3552 # data_deps: List of non-linked dependencies. 3553 # deps: List of private dependencies. 3554 # extra_args: Extra arguments set for test runner. 3555 # ignore_all_data_deps: Don't build data_deps and additional_apks. 3556 # modules: Extra dynamic feature modules to install for test target. Can 3557 # only be used if |apk_under_test| is an Android app bundle. 3558 # fake_modules: Similar to |modules| but fake installed instead. 3559 # never_incremental: Disable incremental builds. 3560 # proguard_enabled: Enable proguard 3561 # public_deps: List of public dependencies 3562 # 3563 # Example 3564 # instrumentation_test_runner("foo_test_for_bar") { 3565 # android_test_apk: ":foo" 3566 # apk_under_test: ":bar" 3567 # } 3568 template("instrumentation_test_runner") { 3569 if (use_rts) { 3570 action("${invoker.target_name}__rts_filters") { 3571 script = "//chromium/build/add_rts_filters.py" 3572 rts_file = "${root_build_dir}/gen/rts/${invoker.target_name}.filter" 3573 args = [ rebase_path(rts_file, root_build_dir) ] 3574 outputs = [ rts_file ] 3575 } 3576 } 3577 _incremental_apk = !(defined(invoker.never_incremental) && 3578 invoker.never_incremental) && incremental_install 3579 _apk_operations_target_name = "${target_name}__apk_operations" 3580 _apk_target = invoker.android_test_apk 3581 if (defined(invoker.apk_under_test) && !_incremental_apk) { 3582 # The actual target is defined in the test_runner_script template. 3583 _install_artifacts_json = 3584 "${target_gen_dir}/${target_name}.install_artifacts" 3585 _install_artifacts_target_name = "${target_name}__install_artifacts" 3586 } 3587 3588 action_with_pydeps(_apk_operations_target_name) { 3589 testonly = true 3590 script = "//chromium/build/android/gyp/create_test_apk_wrapper_script.py" 3591 deps = [] 3592 _generated_script = "$root_build_dir/bin/${invoker.target_name}" 3593 outputs = [ _generated_script ] 3594 _apk_build_config = 3595 get_label_info(_apk_target, "target_gen_dir") + "/" + 3596 get_label_info(_apk_target, "name") + ".build_config.json" 3597 _rebased_apk_build_config = rebase_path(_apk_build_config, root_build_dir) 3598 args = [ 3599 "--script-output-path", 3600 rebase_path(_generated_script, root_build_dir), 3601 "--package-name", 3602 "@FileArg($_rebased_apk_build_config:deps_info:package_name)", 3603 ] 3604 deps += [ "${_apk_target}$build_config_target_suffix" ] 3605 if (_incremental_apk) { 3606 args += [ 3607 "--test-apk-incremental-install-json", 3608 "@FileArg($_rebased_apk_build_config:deps_info:incremental_install_json_path)", 3609 ] 3610 } else { 3611 args += [ 3612 "--test-apk", 3613 "@FileArg($_rebased_apk_build_config:deps_info:apk_path)", 3614 ] 3615 } 3616 if (defined(invoker.proguard_mapping_path) && !_incremental_apk) { 3617 args += [ 3618 "--proguard-mapping-path", 3619 rebase_path(invoker.proguard_mapping_path, root_build_dir), 3620 ] 3621 } 3622 if (defined(invoker.apk_under_test)) { 3623 if (_incremental_apk) { 3624 deps += [ "${invoker.apk_under_test}$build_config_target_suffix" ] 3625 _apk_under_test_build_config = 3626 get_label_info(invoker.apk_under_test, "target_gen_dir") + "/" + 3627 get_label_info(invoker.apk_under_test, "name") + 3628 ".build_config.json" 3629 _rebased_apk_under_test_build_config = 3630 rebase_path(_apk_under_test_build_config, root_build_dir) 3631 _apk_under_test = "@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_apk_path)" 3632 } else { 3633 deps += [ ":${_install_artifacts_target_name}" ] 3634 _rebased_install_artifacts_json = 3635 rebase_path(_install_artifacts_json, root_build_dir) 3636 _apk_under_test = "@FileArg($_rebased_install_artifacts_json[])" 3637 } 3638 args += [ 3639 "--additional-apk", 3640 _apk_under_test, 3641 ] 3642 } 3643 if (defined(invoker.additional_apks)) { 3644 foreach(additional_apk, invoker.additional_apks) { 3645 deps += [ "$additional_apk$build_config_target_suffix" ] 3646 _build_config = 3647 get_label_info(additional_apk, "target_gen_dir") + "/" + 3648 get_label_info(additional_apk, "name") + ".build_config.json" 3649 _rebased_build_config = rebase_path(_build_config, root_build_dir) 3650 args += [ 3651 "--additional-apk", 3652 "@FileArg($_rebased_build_config:deps_info:apk_path)", 3653 ] 3654 } 3655 deps += invoker.additional_apks 3656 } 3657 } 3658 test_runner_script(target_name) { 3659 forward_variables_from(invoker, 3660 [ 3661 "additional_apks", 3662 "additional_locales", 3663 "apk_under_test", 3664 "data", 3665 "data_deps", 3666 "deps", 3667 "extra_args", 3668 "fake_modules", 3669 "ignore_all_data_deps", 3670 "is_unit_test", 3671 "modules", 3672 "proguard_mapping_path", 3673 "use_webview_provider", 3674 ]) 3675 test_name = invoker.target_name 3676 test_type = "instrumentation" 3677 apk_target = invoker.android_test_apk 3678 incremental_apk = _incremental_apk 3679 3680 public_deps = [ ":$_apk_operations_target_name" ] 3681 if (use_rts) { 3682 if (!defined(data_deps)) { 3683 data_deps = [] 3684 } 3685 data_deps += [ ":${invoker.target_name}__rts_filters" ] 3686 } 3687 } 3688 } 3689 3690 # Declare an Android instrumentation test apk 3691 # 3692 # This target creates an Android instrumentation test apk. 3693 # 3694 # Supports all variables of android_apk(), plus: 3695 # apk_under_test: The apk being tested (optional). 3696 # 3697 # Example 3698 # android_test_apk("foo_test_apk") { 3699 # android_manifest = "AndroidManifest.xml" 3700 # apk_name = "FooTest" 3701 # apk_under_test = "Foo" 3702 # sources = [ 3703 # "android/org/chromium/foo/FooTestCase.java", 3704 # "android/org/chromium/foo/FooExampleTest.java", 3705 # ] 3706 # deps = [ 3707 # ":foo_test_support_java" 3708 # ] 3709 # } 3710 template("android_test_apk") { 3711 android_apk(target_name) { 3712 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 3713 testonly = true 3714 _use_default_launcher = 3715 !defined(invoker.use_default_launcher) || invoker.use_default_launcher 3716 3717 # The size info enables the test_runner to find the source file location 3718 # of a test after it is ran. 3719 include_size_info = true 3720 data = [ "$root_build_dir/size-info/${invoker.apk_name}.apk.jar.info" ] 3721 if (defined(invoker.data)) { 3722 data += invoker.data 3723 } 3724 3725 if (_use_default_launcher) { 3726 deps = [ "//testing/android/instrumentation:test_runner_java" ] 3727 } else { 3728 deps = [] 3729 } 3730 if (defined(invoker.deps)) { 3731 deps += invoker.deps 3732 } 3733 data_deps = [ 3734 # Ensure unstripped libraries are included in runtime deps so that 3735 # symbolization can be done. 3736 ":${target_name}__secondary_abi_shared_library_list", 3737 ":${target_name}__shared_library_list", 3738 ] 3739 if (defined(invoker.data_deps)) { 3740 data_deps += invoker.data_deps 3741 } 3742 if (defined(invoker.apk_under_test)) { 3743 data_deps += [ invoker.apk_under_test ] 3744 } 3745 3746 if (defined(invoker.apk_under_test)) { 3747 _under_test_label = 3748 get_label_info(invoker.apk_under_test, "label_no_toolchain") 3749 data_deps += [ 3750 "${_under_test_label}__secondary_abi_shared_library_list", 3751 "${_under_test_label}__shared_library_list", 3752 ] 3753 } 3754 3755 if (defined(invoker.additional_apks)) { 3756 data_deps += invoker.additional_apks 3757 } 3758 if (defined(invoker.use_webview_provider)) { 3759 data_deps += [ invoker.use_webview_provider ] 3760 } 3761 3762 if (defined(invoker.proguard_enabled) && invoker.proguard_enabled && 3763 !incremental_install) { 3764 # When ProGuard is on, we use ProGuard to combine the under test java 3765 # code and the test java code. This is to allow us to apply all ProGuard 3766 # optimizations that we ship with, but not have them break tests. The 3767 # apk under test will still have the same resources, assets, and 3768 # manifest, all of which are the ones used in the tests. 3769 proguard_configs = [ 3770 "//testing/android/proguard_for_test.flags", 3771 "//third_party/jni_zero/proguard_for_test.flags", 3772 ] 3773 if (defined(invoker.proguard_configs)) { 3774 proguard_configs += invoker.proguard_configs 3775 } 3776 enable_proguard_checks = false 3777 if (defined(invoker.final_apk_path)) { 3778 _final_apk_path = invoker.final_apk_path 3779 } else { 3780 _final_apk_path = "$root_build_dir/apks/${invoker.apk_name}.apk" 3781 } 3782 data += [ "$_final_apk_path.mapping" ] 3783 } 3784 3785 create_apk_script = false 3786 3787 forward_variables_from(invoker, 3788 "*", 3789 TESTONLY_AND_VISIBILITY + [ 3790 "data", 3791 "data_deps", 3792 "deps", 3793 "extra_args", 3794 "is_unit_test", 3795 "proguard_configs", 3796 ]) 3797 } 3798 } 3799 3800 # Declare an Android instrumentation test apk with wrapper script. 3801 # 3802 # This target creates an Android instrumentation test apk with wrapper script 3803 # to run the test. 3804 # 3805 # Supports all variables of android_test_apk. 3806 template("instrumentation_test_apk") { 3807 assert(defined(invoker.apk_name)) 3808 _apk_target_name = "${target_name}__test_apk" 3809 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 3810 android_test_apk(_apk_target_name) { 3811 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 3812 } 3813 instrumentation_test_runner(target_name) { 3814 forward_variables_from(invoker, 3815 [ 3816 "additional_apks", 3817 "apk_under_test", 3818 "data", 3819 "data_deps", 3820 "deps", 3821 "extra_args", 3822 "ignore_all_data_deps", 3823 "is_unit_test", 3824 "modules", 3825 "never_incremental", 3826 "public_deps", 3827 "use_webview_provider", 3828 ]) 3829 android_test_apk = ":${_apk_target_name}" 3830 if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) { 3831 proguard_mapping_path = 3832 "$root_build_dir/apks/${invoker.apk_name}.apk.mapping" 3833 } 3834 } 3835 } 3836 3837 # Declare an Android gtest apk 3838 # 3839 # This target creates an Android apk for running gtest-based unittests. 3840 # 3841 # Variables 3842 # deps: Specifies the dependencies of this target. These will be passed to 3843 # the underlying android_apk invocation and should include the java and 3844 # resource dependencies of the apk. 3845 # shared_library: shared_library target that contains the unit tests. 3846 # apk_name: The name of the produced apk. If unspecified, it uses the name 3847 # of the shared_library target suffixed with "_apk". 3848 # use_default_launcher: Whether the default activity (NativeUnitTestActivity) 3849 # should be used for launching tests. 3850 # allow_cleartext_traffic: (Optional) Whether to allow cleartext network 3851 # requests during the test. 3852 # use_native_activity: Test implements ANativeActivity_onCreate(). 3853 # 3854 # Example 3855 # unittest_apk("foo_unittests_apk") { 3856 # deps = [ ":foo_java", ":foo_resources" ] 3857 # shared_library = ":foo_unittests" 3858 # } 3859 template("unittest_apk") { 3860 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 3861 _use_native_activity = 3862 defined(invoker.use_native_activity) && invoker.use_native_activity 3863 _android_manifest = "$target_gen_dir/$target_name/AndroidManifest.xml" 3864 assert(invoker.shared_library != "") 3865 3866 # This trivial assert is needed in case android_manifest is defined, 3867 # as otherwise _use_native_activity and _android_manifest would not be used. 3868 assert(_use_native_activity != "" && _android_manifest != "") 3869 3870 if (!defined(invoker.android_manifest)) { 3871 _allow_cleartext_traffic = defined(invoker.allow_cleartext_traffic) && 3872 invoker.allow_cleartext_traffic 3873 jinja_template("${target_name}_manifest") { 3874 _native_library_name = get_label_info(invoker.shared_library, "name") 3875 if (defined(invoker.android_manifest_template)) { 3876 input = invoker.android_manifest_template 3877 } else { 3878 input = 3879 "//testing/android/native_test/java/AndroidManifest.xml.jinja2" 3880 } 3881 output = _android_manifest 3882 variables = [ 3883 "is_component_build=${is_component_build}", 3884 "native_library_name=${_native_library_name}", 3885 "use_native_activity=${_use_native_activity}", 3886 "allow_cleartext_traffic=${_allow_cleartext_traffic}", 3887 ] 3888 } 3889 } 3890 3891 android_test_apk(target_name) { 3892 data_deps = [] 3893 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 3894 create_apk_script = false 3895 3896 if (!defined(apk_name)) { 3897 apk_name = get_label_info(invoker.shared_library, "name") 3898 } 3899 3900 if (!defined(android_manifest)) { 3901 android_manifest_dep = ":${target_name}_manifest" 3902 android_manifest = _android_manifest 3903 } 3904 3905 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk" 3906 3907 if (!defined(use_default_launcher) || use_default_launcher) { 3908 deps += [ 3909 "//chromium/build/android/gtest_apk:native_test_instrumentation_test_runner_java", 3910 "//testing/android/native_test:native_test_java", 3911 ] 3912 } 3913 shared_libraries = [ invoker.shared_library ] 3914 deps += [ 3915 ":${target_name}__secondary_abi_shared_library_list", 3916 ":${target_name}__shared_library_list", 3917 ] 3918 } 3919 } 3920 3921 # Generate .java files from .aidl files. 3922 # 3923 # This target will store the .java files in a srcjar and should be included in 3924 # an android_library or android_apk's srcjar_deps. 3925 # 3926 # Variables 3927 # sources: Paths to .aidl files to compile. 3928 # import_include: Path to directory containing .java files imported by the 3929 # .aidl files. 3930 # interface_file: Preprocessed aidl file to import. 3931 # 3932 # Example 3933 # android_aidl("foo_aidl") { 3934 # import_include = "java/src" 3935 # sources = [ 3936 # "java/src/com/foo/bar/FooBarService.aidl", 3937 # "java/src/com/foo/bar/FooBarServiceCallback.aidl", 3938 # ] 3939 # } 3940 template("android_aidl") { 3941 action_with_pydeps(target_name) { 3942 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 3943 3944 script = "//chromium/build/android/gyp/aidl.py" 3945 depfile = "$target_gen_dir/$target_name.d" 3946 sources = invoker.sources 3947 3948 _srcjar_path = "${target_gen_dir}/${target_name}.srcjar" 3949 _aidl_path = "${android_sdk_build_tools}/aidl" 3950 _framework_aidl = "$android_sdk/framework.aidl" 3951 _imports = [ _framework_aidl ] 3952 if (defined(invoker.interface_file)) { 3953 assert(invoker.interface_file != "") 3954 _imports += [ invoker.interface_file ] 3955 } 3956 3957 inputs = [ _aidl_path ] + _imports 3958 3959 outputs = [ _srcjar_path ] 3960 _rebased_imports = rebase_path(_imports, root_build_dir) 3961 args = [ 3962 "--aidl-path", 3963 rebase_path(_aidl_path, root_build_dir), 3964 "--imports=$_rebased_imports", 3965 "--srcjar", 3966 rebase_path(_srcjar_path, root_build_dir), 3967 "--depfile", 3968 rebase_path(depfile, root_build_dir), 3969 ] 3970 if (defined(invoker.import_include) && invoker.import_include != []) { 3971 _rebased_import_paths = [] 3972 foreach(_import_path, invoker.import_include) { 3973 _rebased_import_path = [] 3974 _rebased_import_path = [ rebase_path(_import_path, root_build_dir) ] 3975 _rebased_import_paths += _rebased_import_path 3976 } 3977 args += [ "--includes=$_rebased_import_paths" ] 3978 } 3979 args += rebase_path(sources, root_build_dir) 3980 } 3981 } 3982 3983 # Compile a protocol buffer to java. 3984 # 3985 # This generates java files from protocol buffers and creates an Android library 3986 # containing the classes. 3987 # 3988 # Variables 3989 # sources (required) 3990 # Paths to .proto files to compile. 3991 # 3992 # proto_path (required) 3993 # Root directory of .proto files. 3994 # 3995 # deps (optional) 3996 # Additional dependencies. Passed through to both the action and the 3997 # android_library targets. 3998 # 3999 # import_dirs (optional) 4000 # A list of extra import directories to be passed to protoc compiler. 4001 # WARNING: This circumvents proto checkdeps, and should only be used 4002 # when needed, typically when proto files cannot cleanly import through 4003 # absolute paths, such as for third_party or generated .proto files. 4004 # http://crbug.com/691451 tracks fixing this. 4005 # 4006 # generator_plugin_label (optional) 4007 # GN label for plugin executable which generates custom cc stubs. 4008 # Don't specify a toolchain, host toolchain is assumed. 4009 # 4010 # Example: 4011 # proto_java_library("foo_proto_java") { 4012 # proto_path = "src/foo" 4013 # sources = [ "$proto_path/foo.proto" ] 4014 # } 4015 template("proto_java_library") { 4016 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4017 4018 _template_name = target_name 4019 4020 action_with_pydeps("${_template_name}__protoc_java") { 4021 # The suffix "__protoc_java.srcjar" is used by SuperSize to identify 4022 # protobuf symbols. 4023 _srcjar_path = "$target_gen_dir/$target_name.srcjar" 4024 script = "//chromium/build/protoc_java.py" 4025 4026 if (defined(invoker.deps)) { 4027 # Need to care only about targets that might generate .proto files. 4028 # No need to depend on java_library or android_resource targets. 4029 deps = filter_exclude(invoker.deps, java_target_patterns) 4030 } 4031 4032 sources = invoker.sources 4033 depfile = "$target_gen_dir/$target_name.d" 4034 outputs = [ _srcjar_path ] 4035 inputs = [ android_protoc_bin ] 4036 args = [ 4037 "--depfile", 4038 rebase_path(depfile, root_build_dir), 4039 "--protoc", 4040 rebase_path(android_protoc_bin, root_build_dir), 4041 "--proto-path", 4042 rebase_path(invoker.proto_path, root_build_dir), 4043 "--srcjar", 4044 rebase_path(_srcjar_path, root_build_dir), 4045 ] 4046 4047 if (defined(invoker.generator_plugin_label)) { 4048 if (host_os == "win") { 4049 _host_executable_suffix = ".exe" 4050 } else { 4051 _host_executable_suffix = "" 4052 } 4053 4054 _plugin_host_label = 4055 invoker.generator_plugin_label + "($host_toolchain)" 4056 _plugin_path = 4057 get_label_info(_plugin_host_label, "root_out_dir") + "/" + 4058 get_label_info(_plugin_host_label, "name") + _host_executable_suffix 4059 args += [ 4060 "--plugin", 4061 rebase_path(_plugin_path, root_build_dir), 4062 ] 4063 deps += [ _plugin_host_label ] 4064 inputs += [ _plugin_path ] 4065 } 4066 4067 args += rebase_path(sources, root_build_dir) 4068 4069 if (defined(invoker.import_dirs)) { 4070 foreach(_import_dir, invoker.import_dirs) { 4071 args += [ 4072 "--import-dir", 4073 rebase_path(_import_dir, root_build_dir), 4074 ] 4075 } 4076 } 4077 } 4078 4079 android_library(target_name) { 4080 chromium_code = false 4081 sources = [] 4082 srcjar_deps = [ ":${_template_name}__protoc_java" ] 4083 deps = [ "//third_party/android_deps:protobuf_lite_runtime_java" ] 4084 if (defined(invoker.deps)) { 4085 deps += invoker.deps 4086 } 4087 } 4088 } 4089 4090 # Compile a flatbuffer to java. 4091 # 4092 # This generates java files from flat buffers and creates an Android library 4093 # containing the classes. 4094 # 4095 # Variables 4096 # sources (required) 4097 # Paths to .fbs files to compile. 4098 # 4099 # root_dir (required) 4100 # Root directory of .fbs files. 4101 # 4102 # deps (optional) 4103 # Additional dependencies. Passed through to both the action and the 4104 # android_library targets. 4105 # 4106 # flatc_include_dirs (optional) 4107 # A list of extra import directories to be passed to flatc compiler. 4108 # 4109 # 4110 # Example: 4111 # flatbuffer_java_library("foo_flatbuffer_java") { 4112 # root_dir = "src/foo" 4113 # sources = [ "$proto_path/foo.fbs" ] 4114 # } 4115 template("flatbuffer_java_library") { 4116 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4117 4118 _template_name = target_name 4119 _flatc_dep = "//third_party/flatbuffers:flatc($host_toolchain)" 4120 _flatc_out_dir = get_label_info(_flatc_dep, "root_out_dir") 4121 _flatc_bin = "$_flatc_out_dir/flatc" 4122 4123 action_with_pydeps("${_template_name}__flatc_java") { 4124 _srcjar_path = "$target_gen_dir/$target_name.srcjar" 4125 script = "//chromium/build/android/gyp/flatc_java.py" 4126 4127 deps = [ _flatc_dep ] 4128 if (defined(invoker.deps)) { 4129 deps += invoker.deps 4130 } 4131 inputs = [ _flatc_bin ] 4132 4133 sources = invoker.sources 4134 outputs = [ _srcjar_path ] 4135 args = [ 4136 "--flatc", 4137 rebase_path(_flatc_bin, root_build_dir), 4138 "--import-dir", 4139 rebase_path(invoker.root_dir, root_build_dir), 4140 "--srcjar", 4141 rebase_path(_srcjar_path, root_build_dir), 4142 ] + rebase_path(sources, root_build_dir) 4143 4144 if (defined(invoker.flatc_include_dirs)) { 4145 foreach(_include_dir, invoker.flatc_include_dirs) { 4146 args += [ 4147 "--import-dir", 4148 rebase_path(_include_dir, root_build_dir), 4149 ] 4150 } 4151 } 4152 } 4153 4154 android_library(target_name) { 4155 chromium_code = false 4156 sources = [] 4157 srcjar_deps = [ ":${_template_name}__flatc_java" ] 4158 deps = [ "//third_party/flatbuffers:flatbuffers_java" ] 4159 if (defined(invoker.deps)) { 4160 deps += invoker.deps 4161 } 4162 } 4163 } 4164 4165 # Declare an Android library target for a prebuilt AAR. 4166 # 4167 # This target creates an Android library containing java code and Android 4168 # resources. For libraries without resources, it will not generate 4169 # corresponding android_resources targets. 4170 # 4171 # To avoid slowing down "gn gen", an associated .info file must be committed 4172 # along with the .aar file. In order to create this file, define the target 4173 # and then run once with the gn arg "update_android_aar_prebuilts = true". 4174 # 4175 # Variables 4176 # aar_path: Path to the AAR. 4177 # info_path: Path to the .aar.info file (generated via 4178 # update_android_aar_prebuilts GN arg). 4179 # proguard_configs: List of proguard configs to use in final apk step for 4180 # any apk that depends on this library. 4181 # ignore_aidl: Whether to ignore .aidl files found with the .aar. 4182 # ignore_assets: Whether to ignore assets found in the .aar. 4183 # ignore_manifest: Whether to ignore creating manifest. 4184 # ignore_native_libraries: Whether to ignore .so files found in the .aar. 4185 # See also extract_native_libraries. 4186 # ignore_proguard_configs: Whether to ignore proguard configs. 4187 # strip_resources: Whether to ignore android resources found in the .aar. 4188 # custom_package: Java package for generated R.java files. 4189 # extract_native_libraries: Whether to extract .so files found in the .aar. 4190 # If the file contains .so, either extract_native_libraries or 4191 # ignore_native_libraries must be set. 4192 # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed. 4193 # requires_android: Whether this target can only be used for compiling 4194 # Android related targets. 4195 # 4196 # Example 4197 # android_aar_prebuilt("foo_java") { 4198 # aar_path = "foo.aar" 4199 # } 4200 template("android_aar_prebuilt") { 4201 _info_path = "$target_name.info" 4202 if (defined(invoker.info_path)) { 4203 _info_path = invoker.info_path 4204 } 4205 _output_path = "${target_out_dir}/${target_name}" 4206 4207 # Some targets only differ by _java with other targets so _java and _junit 4208 # need to be replaced by non-empty strings to avoid duplicate targets. (e.g. 4209 # androidx_window_window_java vs androidx_window_window_java_java). 4210 _target_name_without_java_or_junit = 4211 string_replace(string_replace(target_name, "_java", "_J"), 4212 "_junit", 4213 "_U") 4214 4215 # This unpack target is a python action, not a valid java target. Since the 4216 # java targets below depend on it, its name must not match the java patterns 4217 # in internal_rules.gni. 4218 _unpack_target_name = "${_target_name_without_java_or_junit}__unpack_aar" 4219 _ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl 4220 _ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets 4221 _ignore_manifest = 4222 defined(invoker.ignore_manifest) && invoker.ignore_manifest 4223 _ignore_native_libraries = defined(invoker.ignore_native_libraries) && 4224 invoker.ignore_native_libraries 4225 _ignore_proguard_configs = defined(invoker.ignore_proguard_configs) && 4226 invoker.ignore_proguard_configs 4227 _extract_native_libraries = defined(invoker.extract_native_libraries) && 4228 invoker.extract_native_libraries 4229 _strip_resources = 4230 defined(invoker.strip_resources) && invoker.strip_resources 4231 4232 # Allow 'resource_overlay' parameter even if there are no resources in order 4233 # to keep the logic for generated 'android_aar_prebuilt' rules simple. 4234 not_needed(invoker, [ "resource_overlay" ]) 4235 4236 _aar_common_args = [ rebase_path(invoker.aar_path, root_build_dir) ] 4237 if (_strip_resources) { 4238 _aar_common_args += [ "--ignore-resources" ] 4239 } 4240 if (defined(invoker.resource_exclusion_globs)) { 4241 _aar_common_args += 4242 [ "--resource-exclusion-globs=${invoker.resource_exclusion_globs}" ] 4243 } 4244 4245 # Scan the AAR file and determine the resources and jar files. 4246 # Some libraries might not have resources; others might have two jars. 4247 if (update_android_aar_prebuilts) { 4248 print("Writing " + rebase_path(_info_path, "//")) 4249 exec_script("//chromium/build/android/gyp/aar.py", 4250 [ 4251 "list", 4252 "--output", 4253 rebase_path(_info_path, root_build_dir), 4254 ] + _aar_common_args) 4255 } 4256 4257 # If "gn gen" is failing on the following line, you need to generate an 4258 # .info file for your new target by running: 4259 # gn gen --args='target_os="android" update_android_aar_prebuilts=true' out/tmp 4260 # rm -r out/tmp 4261 _scanned_files = read_file(_info_path, "scope") 4262 4263 _use_scanned_assets = !_ignore_assets && _scanned_files.assets != [] 4264 _has_resources = _scanned_files.resources != [] 4265 _common_deps = [ ":$_unpack_target_name" ] 4266 if (defined(invoker.deps)) { 4267 _common_deps += invoker.deps 4268 } 4269 if (defined(invoker.public_deps)) { 4270 _common_deps += invoker.public_deps 4271 } 4272 4273 assert(_ignore_aidl || _scanned_files.aidl == [], 4274 "android_aar_prebuilt() aidl not yet supported." + 4275 " Implement or use ignore_aidl = true." + 4276 " http://crbug.com/644439") 4277 assert( 4278 !_scanned_files.has_native_libraries || 4279 (_ignore_native_libraries || _extract_native_libraries), 4280 "android_aar_prebuilt(" + target_name + ") contains .so files." + 4281 " Please set ignore_native_libraries or extract_native_libraries.") 4282 assert( 4283 !(_ignore_native_libraries && _extract_native_libraries), 4284 "ignore_native_libraries and extract_native_libraries cannot both be set.") 4285 assert(!_scanned_files.has_native_libraries || 4286 _scanned_files.native_libraries != []) 4287 assert(_scanned_files.has_classes_jar || _scanned_files.subjars == []) 4288 4289 if (_extract_native_libraries && defined(_scanned_files.prefab_headers)) { 4290 _output_headers_paths = get_path_info( 4291 rebase_path(_scanned_files.prefab_headers, "", _output_path), 4292 "abspath") 4293 } 4294 4295 action_with_pydeps(_unpack_target_name) { 4296 script = "//chromium/build/android/gyp/aar.py" # Unzips the AAR 4297 args = [ 4298 "extract", 4299 "--output-dir", 4300 rebase_path(_output_path, root_build_dir), 4301 "--assert-info-file", 4302 rebase_path(_info_path, root_build_dir), 4303 ] + _aar_common_args 4304 inputs = [ invoker.aar_path ] 4305 outputs = [ "${_output_path}/AndroidManifest.xml" ] 4306 outputs += 4307 get_path_info(rebase_path(_scanned_files.resources, "", _output_path), 4308 "abspath") 4309 if (_scanned_files.has_r_text_file) { 4310 # Certain packages, in particular Play Services have no R.txt even 4311 # though its presence is mandated by AAR spec. Such packages cause 4312 # spurious rebuilds if this output is specified unconditionally. 4313 outputs += [ "${_output_path}/R.txt" ] 4314 } 4315 4316 if (_scanned_files.has_classes_jar) { 4317 outputs += [ "${_output_path}/classes.jar" ] 4318 } 4319 outputs += 4320 get_path_info(rebase_path(_scanned_files.subjars, "", _output_path), 4321 "abspath") 4322 if (!_ignore_proguard_configs) { 4323 if (_scanned_files.has_proguard_flags) { 4324 outputs += [ "${_output_path}/proguard.txt" ] 4325 } 4326 } 4327 4328 if (_extract_native_libraries && _scanned_files.has_native_libraries) { 4329 outputs += get_path_info( 4330 rebase_path(_scanned_files.native_libraries, "", _output_path), 4331 "abspath") 4332 } 4333 if (defined(_output_headers_paths)) { 4334 outputs += _output_headers_paths 4335 } 4336 if (_use_scanned_assets) { 4337 outputs += 4338 get_path_info(rebase_path(_scanned_files.assets, "", _output_path), 4339 "abspath") 4340 } 4341 } 4342 4343 _should_process_manifest = 4344 !_ignore_manifest && !_scanned_files.is_manifest_empty 4345 4346 # Create the android_resources target for resources. 4347 if (_has_resources || _should_process_manifest) { 4348 _res_target_name = "${target_name}__resources" 4349 android_resources(_res_target_name) { 4350 forward_variables_from(invoker, 4351 [ 4352 "custom_package", 4353 "resource_overlay", 4354 "testonly", 4355 "strip_drawables", 4356 ]) 4357 deps = _common_deps 4358 if (_should_process_manifest) { 4359 android_manifest_dep = ":$_unpack_target_name" 4360 android_manifest = "${_output_path}/AndroidManifest.xml" 4361 } else if (defined(_scanned_files.manifest_package) && 4362 !defined(custom_package)) { 4363 custom_package = _scanned_files.manifest_package 4364 } 4365 4366 sources = rebase_path(_scanned_files.resources, "", _output_path) 4367 if (_scanned_files.has_r_text_file) { 4368 r_text_file = "${_output_path}/R.txt" 4369 } 4370 } 4371 } else if (defined(invoker.strip_drawables)) { 4372 not_needed(invoker, [ "strip_drawables" ]) 4373 } 4374 4375 if (_ignore_manifest) { 4376 # Having this available can be useful for DFMs that depend on AARs. It 4377 # provides a way to have manifest entries go into the base split while 4378 # the code goes into a DFM. 4379 java_group("${target_name}__ignored_manifest") { 4380 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4381 deps = [ ":$_unpack_target_name" ] 4382 mergeable_android_manifests = [ "${_output_path}/AndroidManifest.xml" ] 4383 } 4384 } 4385 4386 # Create the android_assets target for assets 4387 if (_use_scanned_assets) { 4388 _assets_target_name = "${target_name}__assets" 4389 android_assets(_assets_target_name) { 4390 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4391 deps = [ ":$_unpack_target_name" ] 4392 renaming_sources = [] 4393 renaming_destinations = [] 4394 foreach(_asset_file, _scanned_files.assets) { 4395 _original_path = 4396 get_path_info(rebase_path(_asset_file, "", _output_path), 4397 "abspath") 4398 _updated_path = string_replace(_asset_file, "assets/", "", 1) 4399 renaming_sources += [ _original_path ] 4400 renaming_destinations += [ _updated_path ] 4401 } 4402 } 4403 } 4404 4405 _target_label = get_label_info(":$target_name", "label_no_toolchain") 4406 4407 # Create android_java_prebuilt target for classes.jar. 4408 if (_scanned_files.has_classes_jar) { 4409 _java_library_vars = [ 4410 "alternative_android_sdk_dep", 4411 "bytecode_rewriter_target", 4412 "enable_bytecode_checks", 4413 "jar_excluded_patterns", 4414 "jar_included_patterns", 4415 "missing_classes_allowlist", 4416 "requires_android", 4417 "testonly", 4418 ] 4419 4420 # Create android_java_prebuilt target for extra jars within jars/. 4421 _subjar_targets = [] 4422 foreach(_tuple, _scanned_files.subjar_tuples) { 4423 _current_target = "${target_name}__subjar_${_tuple[0]}" 4424 _subjar_targets += [ ":$_current_target" ] 4425 java_prebuilt(_current_target) { 4426 forward_variables_from(invoker, _java_library_vars) 4427 deps = _common_deps 4428 if (!defined(requires_android)) { 4429 requires_android = true 4430 } 4431 supports_android = true 4432 jar_path = "$_output_path/${_tuple[1]}" 4433 _base_output_name = get_path_info(jar_path, "name") 4434 output_name = "${invoker.target_name}-$_base_output_name" 4435 public_target_label = _target_label 4436 } 4437 } 4438 4439 _jar_target_name = "${target_name}__classes" 4440 java_prebuilt(_jar_target_name) { 4441 forward_variables_from(invoker, _java_library_vars) 4442 forward_variables_from(invoker, 4443 [ 4444 "input_jars_paths", 4445 "mergeable_android_manifests", 4446 "proguard_configs", 4447 ]) 4448 deps = _common_deps + _subjar_targets 4449 if (defined(_res_target_name)) { 4450 deps += [ ":$_res_target_name" ] 4451 } 4452 if (!defined(requires_android)) { 4453 requires_android = true 4454 } 4455 include_java_resources = !defined(invoker.include_java_resources) || 4456 invoker.include_java_resources 4457 supports_android = true 4458 jar_path = "$_output_path/classes.jar" 4459 aar_path = invoker.aar_path 4460 output_name = invoker.target_name 4461 4462 if (!_ignore_proguard_configs) { 4463 if (!defined(proguard_configs)) { 4464 proguard_configs = [] 4465 } 4466 if (_scanned_files.has_proguard_flags) { 4467 proguard_configs += [ "$_output_path/proguard.txt" ] 4468 } 4469 } 4470 public_target_label = _target_label 4471 } 4472 } 4473 4474 if (defined(_output_headers_paths)) { 4475 _config_name = "${target_name}__include_dirs_config" 4476 config(_config_name) { 4477 include_dirs = 4478 get_path_info(rebase_path(_scanned_files.prefab_include_dirs, 4479 "", 4480 _output_path), 4481 "abspath") 4482 } 4483 source_set("${target_name}_headers") { 4484 sources = _output_headers_paths 4485 public_configs = [ ":$_config_name" ] 4486 deps = [ ":$_unpack_target_name" ] 4487 } 4488 } 4489 4490 java_group(target_name) { 4491 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 4492 public_deps = [ ":$_unpack_target_name" ] 4493 if (defined(invoker.public_deps)) { 4494 public_deps += invoker.public_deps 4495 } 4496 deps = [] 4497 if (defined(_jar_target_name)) { 4498 deps += [ ":$_jar_target_name" ] 4499 4500 # Although subjars are meant to be private, we add them as deps here 4501 # because in practice they seem to contain classes required to be in the 4502 # classpath. 4503 deps += _subjar_targets 4504 } 4505 if (defined(_res_target_name)) { 4506 deps += [ ":$_res_target_name" ] 4507 } 4508 if (defined(_assets_target_name)) { 4509 deps += [ ":$_assets_target_name" ] 4510 } 4511 } 4512 } 4513 4514 # Create an Android application bundle from one base android_apk target, 4515 # and zero or more associated android_apk. 4516 # 4517 # Variables: 4518 # base_module_target: Name of the android_app_bundle_module target 4519 # corresponding to the base module for this application bundle. The 4520 # bundle file will include the same content in its base module, though in 4521 # a slightly different format. 4522 # 4523 # bundle_base_path: Optional. If set, the bundle will be output to this 4524 # directory. Defaults to "$root_build_dir/apks". 4525 # 4526 # bundle_name: Optional. If set, the bundle will be output to the 4527 # filename "${bundle_name}.aab". 4528 # 4529 # extra_modules: Optional list of scopes, one per extra module used by 4530 # this bundle. Each scope must have a 'name' field that specifies the 4531 # module name (which cannot be 'base', since this is reserved for the 4532 # base module), and an 'apk_target' field that specified the 4533 # corresponding android_apk target name the module is modeled on. 4534 # 4535 # enable_language_splits: Optional. If true, enable APK splits based 4536 # on languages. 4537 # 4538 # keystore_path: optional keystore path, used only when generating APKs. 4539 # keystore_name: optional keystore name, used only when generating APKs. 4540 # keystore_password: optional keystore password, used only when 4541 # generating APKs. 4542 # rotation_config: optional .textproto to enable key rotation. 4543 # 4544 # command_line_flags_file: Optional. If provided, named of the on-device 4545 # file that will be used to store command-line arguments. The default 4546 # is 'command_line_flags_file', but this is typically redefined to 4547 # something more specific for certain bundles (e.g. the Chromium based 4548 # APKs use 'chrome-command-line', the WebView one uses 4549 # 'webview-command-line'). 4550 # 4551 # proguard_enabled: Optional. True if proguarding is enabled for this 4552 # bundle. Default is to enable this only for release builds. Note that 4553 # this will always perform synchronized proguarding. 4554 # 4555 # proguard_enable_obfuscation: Whether to enable obfuscation (default=true) 4556 # 4557 # proguard_android_sdk_dep: Optional. android_system_java_prebuilt() target 4558 # used as a library jar for synchronized proguarding. 4559 # 4560 # system_image_locale_allowlist: List of locales that should be included 4561 # on system APKs generated from this bundle. 4562 # 4563 # static_library_provider: Specifies a single target that this target will 4564 # use as a static library APK. 4565 # 4566 # expected_libs_and_assets: Verify the list of included native libraries 4567 # and assets is consistent with the given expectation file. 4568 # expected_libs_and_assets_base: Treat expected_libs_and_assets as a diff 4569 # with this file as the base. 4570 # expected_proguard_config: Checks that the merged set of proguard flags 4571 # matches the given config. 4572 # expected_proguard_config_base: Treat expected_proguard_config as a diff 4573 # with this file as the base. 4574 # 4575 # version_code: Optional. Version code of the target. 4576 # 4577 # is_multi_abi: If true will add a library placeholder for the missing ABI 4578 # if either the primary or the secondary ABI has no native libraries set. 4579 # 4580 # default_modules_for_testing: (optional): A list of DFM that the wrapper 4581 # script should install. This is for local testing only, and does not 4582 # affect the actual DFM in production. 4583 # 4584 # add_view_trace_events: (optional): If true will add an additional step to 4585 # add trace events to all Android views contained in the bundle. It also 4586 # requires build argument enable_trace_event_bytecode_rewriting = true. 4587 # 4588 # Example: 4589 # android_app_bundle("chrome_public_bundle") { 4590 # base_module_target = "//chrome/android:chrome_public_apk" 4591 # extra_modules = [ 4592 # { # NOTE: Scopes require one field per line, and no comma separators. 4593 # name = "my_module" 4594 # module_target = ":my_module" 4595 # }, 4596 # ] 4597 # } 4598 # 4599 template("android_app_bundle") { 4600 _target_name = target_name 4601 _uses_static_library = defined(invoker.static_library_provider) 4602 _proguard_enabled = 4603 defined(invoker.proguard_enabled) && invoker.proguard_enabled 4604 4605 _min_sdk_version = default_min_sdk_version 4606 if (defined(invoker.min_sdk_version)) { 4607 _min_sdk_version = invoker.min_sdk_version 4608 } 4609 if (is_asan && _min_sdk_version < min_supported_sdk_version) { 4610 _min_sdk_version = min_supported_sdk_version 4611 } 4612 4613 _bundle_base_path = "$root_build_dir/apks" 4614 if (defined(invoker.bundle_base_path)) { 4615 _bundle_base_path = invoker.bundle_base_path 4616 } 4617 4618 _bundle_name = _target_name 4619 if (defined(invoker.bundle_name)) { 4620 _bundle_name = invoker.bundle_name 4621 } 4622 _bundle_path = "$_bundle_base_path/${_bundle_name}.aab" 4623 _rebased_bundle_path = rebase_path(_bundle_path, root_build_dir) 4624 4625 _base_target_name = get_label_info(invoker.base_module_target, "name") 4626 _base_target_gen_dir = 4627 get_label_info(invoker.base_module_target, "target_gen_dir") 4628 _base_module_build_config = 4629 "$_base_target_gen_dir/${_base_target_name}.build_config.json" 4630 _base_module_build_config_target = 4631 "${invoker.base_module_target}$build_config_target_suffix" 4632 _rebased_base_module_build_config = 4633 rebase_path(_base_module_build_config, root_build_dir) 4634 4635 _modules = [ 4636 { 4637 name = "base" 4638 module_target = invoker.base_module_target 4639 build_config = _base_module_build_config 4640 build_config_target = _base_module_build_config_target 4641 if (_uses_static_library) { 4642 parent = "lib" 4643 } 4644 }, 4645 ] 4646 4647 if (_proguard_enabled) { 4648 _dex_target = "${_target_name}__dex" 4649 _proguard_mapping_path = "${_bundle_path}.mapping" 4650 } 4651 4652 if (defined(invoker.extra_modules)) { 4653 _module_count = 0 4654 not_needed([ "_module_count" ]) 4655 4656 foreach(_module, invoker.extra_modules) { 4657 _module_count += 1 4658 assert(defined(_module.name), 4659 "Missing 'name' field for extra module #${_module_count}.") 4660 assert(_module.name != "base", 4661 "Module name 'base' is reserved for the main bundle module") 4662 assert( 4663 defined(_module.module_target), 4664 "Missing 'module_target' field for extra module ${_module.name}.") 4665 _module_target = _module.module_target 4666 _module_target_name = get_label_info(_module_target, "name") 4667 _module_target_gen_dir = 4668 get_label_info(_module_target, "target_gen_dir") 4669 _module.build_config = 4670 "$_module_target_gen_dir/${_module_target_name}.build_config.json" 4671 _module.build_config_target = 4672 "$_module_target$build_config_target_suffix" 4673 _module.parent = "base" 4674 _modules += [ _module ] 4675 } 4676 } 4677 4678 # Make build config, which is required for synchronized proguarding. 4679 _module_java_targets = [] 4680 _module_build_configs = [] 4681 _module_targets = [] 4682 foreach(_module, _modules) { 4683 _module_targets += [ _module.module_target ] 4684 _module_java_targets += [ "${_module.module_target}__java" ] 4685 _module_build_configs += [ _module.build_config ] 4686 } 4687 4688 # Used to expose the module Java targets of the bundle. 4689 group("${_target_name}__java") { 4690 deps = _module_java_targets 4691 } 4692 group("${_target_name}__compile_resources") { 4693 deps = [ "${invoker.base_module_target}__compile_resources" ] 4694 } 4695 4696 _build_config = "$target_gen_dir/${_target_name}.build_config.json" 4697 _rebased_build_config = rebase_path(_build_config, root_build_dir) 4698 if (defined(invoker.proguard_android_sdk_dep)) { 4699 _android_sdk_dep = invoker.proguard_android_sdk_dep 4700 } else { 4701 _android_sdk_dep = default_android_sdk_dep 4702 } 4703 4704 if (_proguard_enabled) { 4705 _proguard_mapping_path = "${_bundle_path}.mapping" 4706 _add_view_trace_events = 4707 defined(invoker.add_view_trace_events) && 4708 invoker.add_view_trace_events && enable_trace_event_bytecode_rewriting 4709 } else { 4710 not_needed(invoker, [ "add_view_trace_events" ]) 4711 } 4712 4713 _build_config_target_name = "$_target_name$build_config_target_suffix" 4714 _build_config_target = ":$_build_config_target_name" 4715 write_build_config(_build_config_target_name) { 4716 type = "android_app_bundle" 4717 possible_config_deps = _module_targets + [ _android_sdk_dep ] 4718 build_config = _build_config 4719 proguard_enabled = _proguard_enabled 4720 module_build_configs = _module_build_configs 4721 modules = _modules 4722 4723 if (_proguard_enabled) { 4724 add_view_trace_events = _add_view_trace_events 4725 proguard_mapping_path = _proguard_mapping_path 4726 } 4727 } 4728 4729 if (_proguard_enabled) { 4730 if (_add_view_trace_events) { 4731 _trace_event_rewriter_target = 4732 "//chromium/build/android/bytecode:trace_event_adder" 4733 _rewritten_jar_target_name = "${target_name}__trace_event_rewritten" 4734 _rewriter_path = root_build_dir + "/bin/helper/trace_event_adder" 4735 _stamp = "${target_out_dir}/${target_name}.trace_event_rewrite.stamp" 4736 action_with_pydeps(_rewritten_jar_target_name) { 4737 script = "//chromium/build/android/gyp/trace_event_bytecode_rewriter.py" 4738 inputs = java_paths_for_inputs + [ 4739 _rewriter_path, 4740 _build_config, 4741 ] 4742 outputs = [ _stamp ] 4743 depfile = "$target_gen_dir/$_rewritten_jar_target_name.d" 4744 args = [ 4745 "--stamp", 4746 rebase_path(_stamp, root_build_dir), 4747 "--depfile", 4748 rebase_path(depfile, root_build_dir), 4749 "--script", 4750 rebase_path(_rewriter_path, root_build_dir), 4751 "--classpath", 4752 "@FileArg($_rebased_build_config:android:sdk_jars)", 4753 "--input-jars", 4754 "@FileArg($_rebased_build_config:deps_info:device_classpath)", 4755 "--output-jars", 4756 "@FileArg($_rebased_build_config:deps_info:trace_event_rewritten_device_classpath)", 4757 ] 4758 deps = [ 4759 _build_config_target, 4760 _trace_event_rewriter_target, 4761 ] + _module_java_targets 4762 } 4763 } 4764 4765 dex(_dex_target) { 4766 forward_variables_from(invoker, 4767 [ 4768 "custom_assertion_handler", 4769 "expected_proguard_config", 4770 "expected_proguard_config_base", 4771 "proguard_enable_obfuscation", 4772 "repackage_classes", 4773 ]) 4774 if (defined(expected_proguard_config)) { 4775 top_target_name = _target_name 4776 } 4777 min_sdk_version = _min_sdk_version 4778 add_view_trace_events = _add_view_trace_events 4779 proguard_enabled = true 4780 proguard_mapping_path = _proguard_mapping_path 4781 build_config = _build_config 4782 4783 deps = _module_java_targets + [ _build_config_target ] 4784 if (_add_view_trace_events) { 4785 deps += [ ":${_rewritten_jar_target_name}" ] 4786 } 4787 modules = _modules 4788 4789 # Must not be set via write_build_config, because that will cause it 4790 # to be picked up by test apks that use apk_under_test. 4791 _assertions_implicitly_enabled = 4792 defined(invoker.custom_assertion_handler) 4793 if (!_assertions_implicitly_enabled && !enable_java_asserts && 4794 (!defined(testonly) || !testonly) && 4795 # Injected JaCoCo code causes -checkdiscards to fail. 4796 !use_jacoco_coverage) { 4797 proguard_configs = [ 4798 "//chromium/build/android/dcheck_is_off.flags", 4799 "//third_party/jni_zero/checkdiscard_proguard.flags", 4800 ] 4801 } 4802 } 4803 } 4804 4805 _all_create_module_targets = [] 4806 _all_module_zip_paths = [] 4807 _all_module_build_configs = [] 4808 _all_module_unused_resources_deps = [] 4809 foreach(_module, _modules) { 4810 _module_target = _module.module_target 4811 _module_build_config = _module.build_config 4812 _module_build_config_target = _module.build_config_target 4813 4814 if (!_proguard_enabled) { 4815 _module_target_name = get_label_info(_module_target, "name") 4816 _dex_target = "${_module_target_name}__final_dex" 4817 _dex_path = "$target_out_dir/$_module_target_name/$_module_target_name.mergeddex.jar" 4818 dex(_dex_target) { 4819 forward_variables_from(invoker, [ "custom_assertion_handler" ]) 4820 min_sdk_version = _min_sdk_version 4821 output = _dex_path 4822 build_config = _build_config 4823 4824 # This will be a pure dex-merge. 4825 input_dex_filearg = "@FileArg($_rebased_build_config:modules:${_module.name}:all_dex_files)" 4826 enable_desugar = false 4827 4828 deps = [ 4829 ":${_module_target_name}__java", 4830 _build_config_target, 4831 ] 4832 } 4833 } 4834 _dex_target_for_module = ":$_dex_target" 4835 4836 # Generate one module .zip file per bundle module. 4837 # 4838 # Important: the bundle tool uses the module's zip filename as 4839 # the internal module name inside the final bundle, in other words, 4840 # this file *must* be named ${_module.name}.zip 4841 _create_module_target = "${_target_name}__${_module.name}__create" 4842 _module_zip_path = "$target_out_dir/$target_name/${_module.name}.zip" 4843 create_android_app_bundle_module(_create_module_target) { 4844 forward_variables_from(invoker, 4845 [ 4846 "is_multi_abi", 4847 "uncompress_dex", 4848 ]) 4849 module_name = _module.name 4850 min_sdk_version = _min_sdk_version 4851 build_config = _module_build_config 4852 app_bundle_build_config = _build_config 4853 module_zip_path = _module_zip_path 4854 if (!_proguard_enabled) { 4855 dex_path = _dex_path 4856 # dex_path is read from the build_config in the proguard case. 4857 } 4858 4859 if (module_name == "base" && 4860 defined(invoker.expected_libs_and_assets)) { 4861 forward_variables_from(invoker, 4862 [ 4863 "expected_libs_and_assets", 4864 "expected_libs_and_assets_base", 4865 ]) 4866 top_target_name = _target_name 4867 build_config_target = _module_build_config_target 4868 app_bundle_build_config_target = _build_config_target 4869 } 4870 4871 deps = [ 4872 _build_config_target, 4873 _dex_target_for_module, 4874 _module_build_config_target, 4875 _module_target, 4876 ] 4877 } 4878 4879 _all_create_module_targets += [ 4880 ":$_create_module_target", 4881 _module_build_config_target, 4882 "${_module_target}__compile_resources", 4883 ] 4884 _all_module_zip_paths += [ _module_zip_path ] 4885 _all_module_build_configs += [ _module_build_config ] 4886 _all_module_unused_resources_deps += [ 4887 "${_module_target}__compile_resources", 4888 _dex_target_for_module, 4889 _module_build_config_target, 4890 ] 4891 } 4892 _strip_unused_resources = defined(invoker.strip_unused_resources) && 4893 invoker.strip_unused_resources 4894 if (_strip_unused_resources) { 4895 # Resources only live in the base module so we define the unused resources 4896 # target only on the base module target. 4897 _unused_resources_target = "${_base_target_name}__unused_resources" 4898 _unused_resources_config = 4899 "${_base_target_gen_dir}/${_base_target_name}_unused_resources.config" 4900 _unused_resources_r_txt_out = 4901 "${_base_target_gen_dir}/${_base_target_name}_unused_resources.R.txt" 4902 unused_resources(_unused_resources_target) { 4903 deps = _all_module_unused_resources_deps 4904 all_module_build_configs = _all_module_build_configs 4905 build_config = _base_module_build_config 4906 if (_proguard_enabled) { 4907 proguard_mapping_path = _proguard_mapping_path 4908 } 4909 output_config = _unused_resources_config 4910 output_r_txt = _unused_resources_r_txt_out 4911 } 4912 _unused_resources_final_path = "${_bundle_path}.unused_resources" 4913 _copy_unused_resources_target = 4914 "${_base_target_name}__copy_unused_resources" 4915 copy(_copy_unused_resources_target) { 4916 deps = [ ":$_unused_resources_target" ] 4917 sources = [ _unused_resources_config ] 4918 outputs = [ _unused_resources_final_path ] 4919 } 4920 } 4921 4922 _all_rebased_module_zip_paths = 4923 rebase_path(_all_module_zip_paths, root_build_dir) 4924 4925 _enable_language_splits = defined(invoker.enable_language_splits) && 4926 invoker.enable_language_splits 4927 4928 _split_dimensions = [] 4929 if (_enable_language_splits) { 4930 _split_dimensions += [ "language" ] 4931 } 4932 4933 _keystore_path = android_keystore_path 4934 _keystore_password = android_keystore_password 4935 _keystore_name = android_keystore_name 4936 4937 if (defined(invoker.keystore_path)) { 4938 _keystore_path = invoker.keystore_path 4939 _keystore_password = invoker.keystore_password 4940 _keystore_name = invoker.keystore_name 4941 } 4942 4943 _rebased_keystore_path = rebase_path(_keystore_path, root_build_dir) 4944 4945 _bundle_target_name = "${_target_name}__bundle" 4946 action_with_pydeps(_bundle_target_name) { 4947 script = "//chromium/build/android/gyp/create_app_bundle.py" 4948 inputs = _all_module_zip_paths + _all_module_build_configs + 4949 [ _BUNDLETOOL_JAR_PATH ] + java_paths_for_inputs 4950 outputs = [ _bundle_path ] 4951 deps = _all_create_module_targets + [ _build_config_target ] 4952 args = [ 4953 "--out-bundle=$_rebased_bundle_path", 4954 "--rtxt-out-path=$_rebased_bundle_path.R.txt", 4955 "--pathmap-out-path=$_rebased_bundle_path.pathmap.txt", 4956 "--module-zips=$_all_rebased_module_zip_paths", 4957 ] 4958 if (_split_dimensions != []) { 4959 args += [ "--split-dimensions=$_split_dimensions" ] 4960 } 4961 4962 # Android P+ support loading from stored dex. 4963 if (_min_sdk_version < 27) { 4964 args += [ "--compress-dex" ] 4965 } 4966 4967 if (defined(invoker.rotation_config)) { 4968 args += [ 4969 "--rotation-config", 4970 rebase_path(invoker.rotation_config, root_build_dir), 4971 ] 4972 } 4973 4974 if (treat_warnings_as_errors) { 4975 args += [ "--warnings-as-errors" ] 4976 } 4977 4978 if (_enable_language_splits) { 4979 args += [ "--base-allowlist-rtxt-path=@FileArg($_rebased_base_module_build_config:deps_info:base_allowlist_rtxt_path)" ] 4980 if (_strip_unused_resources) { 4981 # Use the stripped out rtxt file to set resources that are pinned to 4982 # the default language split. 4983 _rebased_unused_resources_r_txt_out = 4984 rebase_path(_unused_resources_r_txt_out, root_build_dir) 4985 inputs += [ _unused_resources_r_txt_out ] 4986 deps += [ ":$_unused_resources_target" ] 4987 args += 4988 [ "--base-module-rtxt-path=$_rebased_unused_resources_r_txt_out" ] 4989 } else { 4990 args += [ "--base-module-rtxt-path=@FileArg($_rebased_base_module_build_config:deps_info:r_text_path)" ] 4991 } 4992 } 4993 if (defined(invoker.validate_services) && invoker.validate_services) { 4994 args += [ "--validate-services" ] 4995 } 4996 4997 foreach(_module, _modules) { 4998 _rebased_build_config = 4999 rebase_path(_module.build_config, root_build_dir) 5000 args += [ 5001 "--uncompressed-assets=@FileArg(" + 5002 "$_rebased_build_config:deps_info:uncompressed_assets)", 5003 "--rtxt-in-paths=@FileArg(" + 5004 "$_rebased_build_config:deps_info:r_text_path)", 5005 "--pathmap-in-paths=@FileArg(" + 5006 "$_rebased_build_config:deps_info:module_pathmap_path)", 5007 "--module-name=" + _module.name, 5008 ] 5009 } 5010 5011 # http://crbug.com/725224. Fix for bots running out of memory. 5012 if (defined(java_cmd_pool_size)) { 5013 pool = "//chromium/build/config/android:java_cmd_pool($default_toolchain)" 5014 } else { 5015 pool = "//chromium/build/toolchain:link_pool($default_toolchain)" 5016 } 5017 } 5018 5019 # Create size info files for targets that care about size 5020 # (have proguard enabled). 5021 if (_proguard_enabled) { 5022 _size_info_target = "${_target_name}__size_info" 5023 create_size_info_files(_size_info_target) { 5024 name = "$_bundle_name.aab" 5025 deps = _module_targets + [ _build_config_target ] 5026 modules = _modules 5027 build_config = _build_config 5028 } 5029 } 5030 5031 if (_uses_static_library) { 5032 _install_artifacts_target = "${target_name}__install_artifacts" 5033 _install_artifacts_json = 5034 "${target_gen_dir}/${target_name}.install_artifacts" 5035 generated_file(_install_artifacts_target) { 5036 output_conversion = "json" 5037 deps = [ invoker.static_library_provider ] 5038 outputs = [ _install_artifacts_json ] 5039 data_keys = [ "install_artifacts" ] 5040 rebase = root_build_dir 5041 } 5042 } 5043 5044 # Generate a wrapper script for the bundle. 5045 _android_aapt2_path = android_sdk_tools_bundle_aapt2 5046 5047 _bundle_apks_path = "$_bundle_base_path/$_bundle_name.apks" 5048 _bundle_wrapper_script_dir = "$root_build_dir/bin" 5049 _bundle_wrapper_script_path = "$_bundle_wrapper_script_dir/$_target_name" 5050 5051 action_with_pydeps("${_target_name}__wrapper_script") { 5052 script = "//chromium/build/android/gyp/create_bundle_wrapper_script.py" 5053 inputs = [ _base_module_build_config ] 5054 outputs = [ _bundle_wrapper_script_path ] 5055 5056 # Telemetry for bundles uses the wrapper script for installation. 5057 data = [ 5058 _bundle_wrapper_script_path, 5059 _android_aapt2_path, 5060 _keystore_path, 5061 _bundle_path, 5062 ] 5063 data_deps = [ 5064 "//chromium/build/android:apk_operations_py", 5065 "//chromium/build/android:stack_tools", 5066 ] 5067 5068 deps = [ _base_module_build_config_target ] 5069 args = [ 5070 "--script-output-path", 5071 rebase_path(_bundle_wrapper_script_path, root_build_dir), 5072 "--package-name=@FileArg($_rebased_base_module_build_config:deps_info:package_name)", 5073 "--aapt2", 5074 rebase_path(_android_aapt2_path, root_build_dir), 5075 "--bundle-path", 5076 _rebased_bundle_path, 5077 "--bundle-apks-path", 5078 rebase_path(_bundle_apks_path, root_build_dir), 5079 "--target-cpu=$target_cpu", 5080 "--keystore-path", 5081 _rebased_keystore_path, 5082 "--keystore-password", 5083 _keystore_password, 5084 "--key-name", 5085 _keystore_name, 5086 ] 5087 if (defined(invoker.default_modules_for_testing)) { 5088 args += [ "--default-modules" ] + invoker.default_modules_for_testing 5089 } 5090 if (defined(invoker.system_image_locale_allowlist)) { 5091 args += [ 5092 "--system-image-locales=${invoker.system_image_locale_allowlist}", 5093 ] 5094 } 5095 if (defined(invoker.command_line_flags_file)) { 5096 args += [ 5097 "--command-line-flags-file", 5098 invoker.command_line_flags_file, 5099 ] 5100 } 5101 if (_uses_static_library) { 5102 deps += [ ":$_install_artifacts_target" ] 5103 _rebased_install_artifacts_json = 5104 rebase_path(_install_artifacts_json, root_build_dir) 5105 _static_library_apk_path = 5106 "@FileArg($_rebased_install_artifacts_json[])" 5107 args += [ 5108 "--additional-apk", 5109 _static_library_apk_path, 5110 ] 5111 } 5112 5113 if (_proguard_enabled) { 5114 args += [ 5115 "--proguard-mapping-path", 5116 rebase_path(_proguard_mapping_path, root_build_dir), 5117 ] 5118 5119 # Required by logcat command. 5120 data_deps += [ "//chromium/build/android/stacktrace:java_deobfuscate" ] 5121 data += [ _proguard_mapping_path ] 5122 } 5123 if (is_official_build) { 5124 args += [ "--is-official-build" ] 5125 } 5126 } 5127 5128 _enable_lint = defined(invoker.enable_lint) && invoker.enable_lint && 5129 !disable_android_lint 5130 if (_enable_lint) { 5131 android_lint("${target_name}__lint") { 5132 forward_variables_from(invoker, 5133 [ 5134 "lint_baseline_file", 5135 "lint_gen_dir", 5136 "lint_jar_path", 5137 "lint_suppressions_file", 5138 ]) 5139 build_config = _build_config 5140 build_config_dep = _build_config_target 5141 deps = _module_java_targets 5142 if (defined(invoker.lint_suppressions_dep)) { 5143 deps += [ invoker.lint_suppressions_dep ] 5144 } 5145 if (defined(invoker.lint_min_sdk_version)) { 5146 min_sdk_version = invoker.lint_min_sdk_version 5147 } else { 5148 min_sdk_version = _min_sdk_version 5149 } 5150 } 5151 } else { 5152 not_needed(invoker, 5153 [ 5154 "lint_baseline_file", 5155 "lint_gen_dir", 5156 "lint_jar_path", 5157 "lint_min_sdk_version", 5158 "lint_suppressions_dep", 5159 "lint_suppressions_file", 5160 ]) 5161 } 5162 5163 group(_target_name) { 5164 public_deps = [ 5165 ":$_bundle_target_name", 5166 ":${_target_name}__wrapper_script", 5167 ] 5168 if (defined(_size_info_target)) { 5169 public_deps += [ ":$_size_info_target" ] 5170 } 5171 if (_enable_lint) { 5172 if (!defined(data_deps)) { 5173 data_deps = [] 5174 } 5175 data_deps += [ ":${target_name}__lint" ] 5176 } 5177 } 5178 5179 _apks_path = "$root_build_dir/apks/$_bundle_name.apks" 5180 action_with_pydeps("${_target_name}_apks") { 5181 script = "//chromium/build/android/gyp/create_app_bundle_apks.py" 5182 inputs = java_paths_for_inputs + [ 5183 _bundle_path, 5184 _BUNDLETOOL_JAR_PATH, 5185 ] 5186 outputs = [ _apks_path ] 5187 data = [ _apks_path ] 5188 args = [ 5189 "--bundle", 5190 _rebased_bundle_path, 5191 "--output", 5192 rebase_path(_apks_path, root_build_dir), 5193 "--aapt2-path", 5194 rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir), 5195 "--keystore-path", 5196 rebase_path(android_keystore_path, root_build_dir), 5197 "--keystore-name", 5198 android_keystore_name, 5199 "--keystore-password", 5200 android_keystore_password, 5201 ] 5202 if (debuggable_apks) { 5203 args += [ "--local-testing" ] 5204 } 5205 deps = [ ":$_bundle_target_name" ] 5206 metadata = { 5207 install_artifacts = [ _apks_path ] 5208 if (defined(invoker.static_library_provider)) { 5209 install_artifacts_barrier = [] 5210 } 5211 } 5212 5213 # http://crbug.com/725224. Fix for bots running out of memory. 5214 if (defined(java_cmd_pool_size)) { 5215 pool = "//chromium/build/config/android:java_cmd_pool($default_toolchain)" 5216 } else { 5217 pool = "//chromium/build/toolchain:link_pool($default_toolchain)" 5218 } 5219 } 5220 } 5221 5222 # Create an .apks file from an .aab file. The .apks file will contain the 5223 # minimal set of .apk files needed for tracking binary size. 5224 # The file will be created at "$bundle_path_without_extension.minimal.apks". 5225 # 5226 # Variables: 5227 # bundle_path: Path to the input .aab file. 5228 # 5229 # Example: 5230 # create_app_bundle_minimal_apks("minimal_apks") { 5231 # deps = [ 5232 # ":bundle_target", 5233 # ] 5234 # bundle_path = "$root_build_dir/apks/Bundle.aab" 5235 # } 5236 template("create_app_bundle_minimal_apks") { 5237 action_with_pydeps(target_name) { 5238 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ]) 5239 script = "//chromium/build/android/gyp/create_app_bundle_apks.py" 5240 _dir = get_path_info(invoker.bundle_path, "dir") 5241 _name = get_path_info(invoker.bundle_path, "name") 5242 _output_path = "$_dir/$_name.minimal.apks" 5243 outputs = [ _output_path ] 5244 inputs = [ invoker.bundle_path ] + java_paths_for_inputs 5245 args = [ 5246 "--bundle", 5247 rebase_path(invoker.bundle_path, root_build_dir), 5248 "--output", 5249 rebase_path(_output_path, root_build_dir), 5250 "--aapt2-path", 5251 rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir), 5252 "--keystore-path", 5253 rebase_path(android_keystore_path, root_build_dir), 5254 "--keystore-name", 5255 android_keystore_name, 5256 "--keystore-password", 5257 android_keystore_password, 5258 "--minimal", 5259 ] 5260 } 5261 } 5262 5263 template("alias_with_wrapper_script") { 5264 copy(target_name) { 5265 _aliased_wrapper_script_name = 5266 get_label_info(invoker.alias_target, "name") 5267 _aliased_wrapper_script = 5268 "$root_build_dir/bin/$_aliased_wrapper_script_name" 5269 sources = [ _aliased_wrapper_script ] 5270 deps = [ invoker.alias_target ] 5271 5272 _output_path = "$root_build_dir/bin/$target_name" 5273 outputs = [ _output_path ] 5274 } 5275 } 5276 5277 # Generate an Android resources target that contains localized strings 5278 # describing the current locale used by the Android framework to display 5279 # UI strings. These are used by 5280 # org.chromium.chrome.browser.ChromeLocalizationUtils. 5281 # 5282 # Variables: 5283 # ui_locales: List of Chromium locale names to generate resources for. 5284 # 5285 template("generate_ui_locale_resources") { 5286 _generating_target_name = "${target_name}__generate" 5287 _rebased_output_zip_path = rebase_path(target_gen_dir, root_gen_dir) 5288 _output_zip = "${root_out_dir}/resource_zips/${_rebased_output_zip_path}/" + 5289 "${target_name}.zip" 5290 5291 action_with_pydeps(_generating_target_name) { 5292 script = "//chromium/build/android/gyp/create_ui_locale_resources.py" 5293 outputs = [ _output_zip ] 5294 args = [ 5295 "--locale-list=${invoker.ui_locales}", 5296 "--output-zip", 5297 rebase_path(_output_zip, root_build_dir), 5298 ] 5299 } 5300 5301 android_generated_resources(target_name) { 5302 generating_target = ":$_generating_target_name" 5303 generated_resources_zip = _output_zip 5304 } 5305 } 5306 }