1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/config/android/config.gni")
6 import("//third_party/ijar/ijar.gni")
10 rebased_android_sdk = rebase_path(android_sdk, root_build_dir)
11 rebased_android_sdk_root = rebase_path(android_sdk_root, root_build_dir)
12 rebased_android_sdk_build_tools =
13 rebase_path(android_sdk_build_tools, root_build_dir)
15 android_sdk_jar = "$android_sdk/android.jar"
16 rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir)
17 android_aapt_path = "$rebased_android_sdk_build_tools/aapt"
19 android_configuration_name = "Release"
21 android_configuration_name = "Debug"
24 template("android_lint") {
25 set_sources_assignment_filter([])
27 jar_path = invoker.jar_path
28 android_manifest = invoker.android_manifest
29 java_files = invoker.java_files
30 base_path = "$target_gen_dir/$target_name"
33 forward_variables_from(invoker,
40 script = "//build/android/gyp/lint.py"
41 result_path = base_path + "/result.xml"
42 config_path = base_path + "/config.xml"
43 suppressions_file = "//build/android/lint/suppressions.xml"
55 rebased_java_files = rebase_path(java_files, root_build_dir)
58 "--lint-path=$rebased_android_sdk_root/tools/lint",
60 rebase_path(suppressions_file, root_build_dir),
62 rebase_path(android_manifest, root_build_dir),
65 rebase_path(jar_path, root_build_dir),
66 "--processed-config-path",
67 rebase_path(config_path, root_build_dir),
69 rebase_path(result_path, root_build_dir),
70 "--java-files=$rebased_java_files",
76 template("findbugs") {
77 jar_path = invoker.jar_path
79 build_config = invoker.build_config
82 forward_variables_from(invoker,
87 script = "//build/android/findbugs_diff.py"
88 depfile = "$target_gen_dir/$target_name.d"
89 result_path = "$target_gen_dir/$target_name/result.xml"
90 exclusions_file = "//build/android/findbugs_filter/findbugs_exclude.xml"
92 rebased_build_config = rebase_path(build_config, root_build_dir)
95 "//build/android/pylib/utils/findbugs.py",
107 rebase_path(depfile, root_build_dir),
109 rebase_path(exclusions_file, root_build_dir),
110 "--auxclasspath-gyp",
111 "@FileArg($rebased_build_config:javac:classpath)",
113 rebase_path(result_path, root_build_dir),
114 rebase_path(jar_path, root_build_dir),
117 if (findbugs_verbose) {
123 # Generates a script in the output bin.java directory to run a java binary.
126 # main_class: The class containing the progam entry point.
127 # jar_path: The path to the jar to run.
128 # script_name: Name of the script to generate.
129 # build_config: Path to .build_config for the jar (contains classpath).
130 # wrapper_script_args: List of extra arguments to pass to the executable.
132 template("java_binary_script") {
133 set_sources_assignment_filter([])
134 forward_variables_from(invoker, [ "testonly" ])
136 _main_class = invoker.main_class
137 _build_config = invoker.build_config
138 _jar_path = invoker.jar_path
139 _script_name = invoker.script_name
141 action(target_name) {
142 script = "//build/android/gyp/create_java_binary_script.py"
143 depfile = "$target_gen_dir/$_script_name.d"
144 java_script = "$root_build_dir/bin/$_script_name"
152 forward_variables_from(invoker, [ "deps" ])
153 _rebased_build_config = rebase_path(_build_config, root_build_dir)
156 rebase_path(depfile, root_build_dir),
158 rebase_path(java_script, root_build_dir),
159 "--classpath=@FileArg($_rebased_build_config:java:full_classpath)",
161 rebase_path(_jar_path, root_build_dir),
165 if (defined(invoker.wrapper_script_args)) {
166 args += [ "--" ] + invoker.wrapper_script_args
172 set_sources_assignment_filter([])
174 assert(defined(invoker.output))
175 action(target_name) {
176 forward_variables_from(invoker,
183 script = "//build/android/gyp/dex.py"
184 depfile = "$target_gen_dir/$target_name.d"
190 rebased_output = rebase_path(invoker.output, root_build_dir)
194 rebase_path(depfile, root_build_dir),
195 "--android-sdk-tools",
196 rebased_android_sdk_build_tools,
201 if (defined(invoker.no_locals) && invoker.no_locals) {
202 args += [ "--no-locals=1" ]
205 if (defined(invoker.args)) {
209 if (defined(invoker.sources)) {
210 args += rebase_path(invoker.sources, root_build_dir)
215 # Creates a zip archive of the inputs.
216 # If base_dir is provided, the archive paths will be relative to it.
218 set_sources_assignment_filter([])
219 assert(defined(invoker.inputs))
220 assert(defined(invoker.output))
222 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
223 rebase_output = rebase_path(invoker.output, root_build_dir)
224 action(target_name) {
225 forward_variables_from(invoker,
234 script = "//build/android/gn/zip.py"
235 depfile = "$target_gen_dir/$target_name.d"
242 rebase_path(depfile, root_build_dir),
243 "--inputs=$rebase_inputs",
244 "--output=$rebase_output",
246 if (defined(invoker.base_dir)) {
249 rebase_path(invoker.base_dir, root_build_dir),
255 # Write the target's .build_config file. This is a json file that contains a
256 # dictionary of information about how to build this target (things that
257 # require knowledge about this target's dependencies and cannot be calculated
258 # at gn-time). There is a special syntax to add a value in that dictionary to
259 # an action/action_foreachs args:
260 # --python-arg=@FileArg($rebased_build_config_path:key0:key1)
261 # At runtime, such an arg will be replaced by the value in the build_config.
262 # See build/android/gyp/write_build_config.py and
263 # build/android/gyp/util/build_utils.py:ExpandFileArgs
264 template("write_build_config") {
265 set_sources_assignment_filter([])
267 assert(defined(invoker.type))
268 assert(defined(invoker.build_config))
271 build_config = invoker.build_config
273 assert(type == "android_apk" || type == "java_library" ||
274 type == "android_resources" || type == "deps_dex")
276 action(target_name) {
278 forward_variables_from(invoker,
285 script = "//build/android/gyp/write_build_config.py"
286 depfile = "$target_gen_dir/$target_name.d"
289 possible_deps_configs = []
291 dep_gen_dir = get_label_info(d, "target_gen_dir")
292 dep_name = get_label_info(d, "name")
293 possible_deps_configs += [ "$dep_gen_dir/$dep_name.build_config" ]
295 rebase_possible_deps_configs =
296 rebase_path(possible_deps_configs, root_build_dir)
307 rebase_path(depfile, root_build_dir),
308 "--possible-deps-configs=$rebase_possible_deps_configs",
310 rebase_path(build_config, root_build_dir),
313 is_java_library = type == "java_library"
314 is_apk = type == "android_apk"
315 is_android_resources = type == "android_resources"
316 is_deps_dex = type == "deps_dex"
318 supports_android = is_apk || is_android_resources || is_deps_dex ||
319 (is_java_library && defined(invoker.supports_android) &&
320 invoker.supports_android)
321 requires_android = is_apk || is_android_resources || is_deps_dex ||
322 (is_java_library && defined(invoker.requires_android) &&
323 invoker.requires_android)
325 assert(!requires_android || supports_android,
326 "requires_android requires" + " supports_android")
328 # Mark these variables as used.
329 assert(is_java_library || true)
330 assert(is_apk || true)
331 assert(is_android_resources || true)
332 assert(is_deps_dex || true)
334 if (is_java_library || is_apk) {
337 rebase_path(invoker.jar_path, root_build_dir),
341 if (is_apk || is_deps_dex || (is_java_library && supports_android)) {
344 rebase_path(invoker.dex_path, root_build_dir),
347 if (supports_android) {
348 args += [ "--supports-android" ]
350 if (requires_android) {
351 args += [ "--requires-android" ]
353 if (defined(invoker.bypass_platform_checks) &&
354 invoker.bypass_platform_checks) {
355 args += [ "--bypass-platform-checks" ]
358 if (defined(invoker.apk_under_test)) {
359 deps += [ invoker.apk_under_test ]
360 apk_under_test_gen_dir =
361 get_label_info(invoker.apk_under_test, "target_gen_dir")
362 apk_under_test_name = get_label_info(invoker.apk_under_test, "name")
363 apk_under_test_config =
364 "$apk_under_test_gen_dir/$apk_under_test_name.build_config"
366 "--tested-apk-config",
367 rebase_path(apk_under_test_config, root_build_dir),
371 if (is_android_resources || is_apk) {
372 assert(defined(invoker.resources_zip))
375 rebase_path(invoker.resources_zip, root_build_dir),
377 if (defined(invoker.android_manifest)) {
378 inputs += [ invoker.android_manifest ]
380 "--android-manifest",
381 rebase_path(invoker.android_manifest, root_build_dir),
384 assert(!is_apk, "apk build configs require an android_manifest")
386 if (defined(invoker.custom_package)) {
389 invoker.custom_package,
392 if (defined(invoker.r_text)) {
395 rebase_path(invoker.r_text, root_build_dir),
401 if (defined(invoker.native_libs)) {
402 inputs += invoker.native_libs
403 rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir)
404 rebased_android_readelf = rebase_path(android_readelf, root_build_dir)
406 "--native-libs=$rebased_native_libs",
407 "--readelf-path=$rebased_android_readelf",
412 if (defined(invoker.srcjar)) {
415 rebase_path(invoker.srcjar, root_build_dir),
421 template("process_java_prebuilt") {
422 set_sources_assignment_filter([])
423 forward_variables_from(invoker, [ "testonly" ])
425 _input_jar_path = invoker.input_jar_path
426 _output_jar_path = invoker.output_jar_path
427 _output_ijar_path = get_path_info(_output_jar_path, "dir") + "/" +
428 get_path_info(_output_jar_path, "name") + ".interface.jar"
430 assert(invoker.build_config != "")
432 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
433 _proguard_jar_path = "//third_party/proguard/lib/proguard.jar"
434 _proguard_config_path = invoker.proguard_config
435 _build_config = invoker.build_config
436 _rebased_build_config = rebase_path(_build_config, root_build_dir)
437 _output_jar_target = "${target_name}__proguard_process"
438 action(_output_jar_target) {
439 forward_variables_from(invoker,
445 script = "//build/android/gyp/proguard.py"
451 _proguard_config_path,
453 depfile = "${target_gen_dir}/${target_name}.d"
460 rebase_path(depfile, root_build_dir),
462 rebase_path(_proguard_jar_path, root_build_dir),
464 rebase_path(_input_jar_path, root_build_dir),
466 rebase_path(_output_jar_path, root_build_dir),
468 rebase_path(_proguard_config_path, root_build_dir),
470 rebased_android_sdk_jar,
471 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
475 _output_jar_target = "${target_name}__copy_jar"
476 copy(_output_jar_target) {
477 forward_variables_from(invoker,
492 generate_interface_jar("${target_name}__ijar") {
493 input_jar = _output_jar_path
494 output_jar = _output_ijar_path
496 ":$_output_jar_target",
501 forward_variables_from(invoker, [ "visibility" ])
503 ":${target_name}__ijar",
504 ":$_output_jar_target",
509 # Creates an unsigned .apk.
512 # deps: Specifies the dependencies of this target.
513 # dex_path: Path to classes.dex file to include (optional).
514 # resource_packaged_apk_path: Path to .ap_ to use.
515 # output_apk_path: Output path for the generated .apk.
516 # native_libs_dir: Directory containing native libraries.
517 template("package_apk") {
518 action(target_name) {
519 forward_variables_from(invoker,
526 script = "//build/android/gyp/ant.py"
527 _ant_script = "//build/android/ant/apk-package.xml"
529 depfile = "$target_gen_dir/$target_name.d"
532 invoker.resource_packaged_apk_path,
535 if (defined(invoker.dex_path)) {
536 inputs += [ invoker.dex_path ]
541 invoker.output_apk_path,
544 _rebased_emma_jar = ""
545 _rebased_resource_packaged_apk_path =
546 rebase_path(invoker.resource_packaged_apk_path, root_build_dir)
547 _rebased_packaged_apk_path =
548 rebase_path(invoker.output_apk_path, root_build_dir)
549 _rebased_native_libs_dir =
550 rebase_path(invoker.native_libs_dir, root_build_dir)
553 rebase_path(depfile, root_build_dir),
556 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root",
557 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools",
558 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path",
559 "-DCONFIGURATION_NAME=$android_configuration_name",
560 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir",
562 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path",
563 "-DEMMA_INSTRUMENT=0",
564 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar",
567 rebase_path(_ant_script, root_build_dir),
569 if (defined(invoker.dex_path)) {
570 _rebased_dex_path = rebase_path(invoker.dex_path, root_build_dir)
572 "-DDEX_FILE_PATH=$_rebased_dex_path",
576 args += [ "-DHAS_CODE=false" ]
581 # Signs & zipaligns an apk.
584 # input_apk_path: Path of the .apk to be finalized.
585 # output_apk_path: Output path for the generated .apk.
586 # keystore_path: Path to keystore to use for signing.
587 # keystore_name: Key alias to use.
588 # keystore_password: Keystore password.
589 # rezip_apk: Whether to add crazy-linker alignment.
590 template("finalize_apk") {
591 action(target_name) {
592 script = "//build/android/gyp/finalize_apk.py"
593 depfile = "$target_gen_dir/$target_name.d"
594 forward_variables_from(invoker,
603 invoker.input_apk_path,
606 invoker.keystore_path,
610 invoker.output_apk_path,
615 rebase_path(depfile, root_build_dir),
617 rebase_path(zipalign_path, root_build_dir),
618 "--unsigned-apk-path",
619 rebase_path(invoker.input_apk_path, root_build_dir),
621 rebase_path(invoker.output_apk_path, root_build_dir),
623 rebase_path(invoker.keystore_path, root_build_dir),
625 invoker.keystore_name,
627 invoker.keystore_password,
629 if (defined(invoker.rezip_apk) && invoker.rezip_apk) {
630 _rezip_jar_path = "$root_build_dir/lib.java/rezip_apk.jar"
631 inputs += [ _rezip_jar_path ]
633 "--load-library-from-zip=1",
634 "--rezip-apk-jar-path",
635 rebase_path(_rezip_jar_path, root_build_dir),
641 # Packages resources, assets, dex, and native libraries into an apk. Signs and
643 template("create_apk") {
644 set_sources_assignment_filter([])
645 forward_variables_from(invoker, [ "testonly" ])
647 _android_manifest = invoker.android_manifest
648 _base_path = invoker.base_path
649 _final_apk_path = invoker.apk_path
650 _incremental_final_apk_path_helper =
651 process_file_template(
653 "{{source_dir}}/{{source_name_part}}_incremental.apk")
654 _incremental_final_apk_path = _incremental_final_apk_path_helper[0]
656 if (defined(invoker.resources_zip)) {
657 _resources_zip = invoker.resources_zip
659 if (defined(invoker.dex_path)) {
660 _dex_path = invoker.dex_path
662 _load_library_from_apk = invoker.load_library_from_apk
665 if (defined(invoker.deps)) {
666 _package_deps = invoker.deps
669 _native_libs_dir = "//build/android/empty/res"
670 if (defined(invoker.native_libs_dir)) {
671 _native_libs_dir = invoker.native_libs_dir
674 if (defined(invoker.asset_location)) {
675 _asset_location = invoker.asset_location
678 _version_code = invoker.version_code
679 _version_name = invoker.version_name
681 _base_apk_path = _base_path + ".apk_intermediates"
683 _resource_packaged_apk_path = _base_apk_path + ".ap_"
684 _packaged_apk_path = _base_apk_path + ".unfinished.apk"
685 _incremental_packaged_apk_path =
686 _base_apk_path + "_incremental.unfinished.apk"
688 defined(invoker.shared_resources) && invoker.shared_resources
690 _keystore_path = invoker.keystore_path
691 _keystore_name = invoker.keystore_name
692 _keystore_password = invoker.keystore_password
694 _split_densities = []
695 if (defined(invoker.create_density_splits) && invoker.create_density_splits) {
705 _split_languages = []
706 if (defined(invoker.language_splits)) {
707 _split_languages = invoker.language_splits
710 _package_resources_target_name = "${target_name}__package_resources"
711 action(_package_resources_target_name) {
714 script = "//build/android/gyp/package_resources.py"
715 depfile = "${target_gen_dir}/${target_name}.d"
719 if (defined(_resources_zip)) {
720 inputs += [ _resources_zip ]
724 _resource_packaged_apk_path,
729 rebase_path(depfile, root_build_dir),
734 "--configuration-name=$android_configuration_name",
735 "--android-manifest",
736 rebase_path(_android_manifest, root_build_dir),
742 rebase_path(_resource_packaged_apk_path, root_build_dir),
745 if (defined(_asset_location)) {
748 rebase_path(_asset_location, root_build_dir),
751 if (defined(_resources_zip)) {
754 rebase_path(_resources_zip, root_build_dir),
757 if (_shared_resources) {
758 args += [ "--shared-resources" ]
760 if (_split_densities != []) {
761 args += [ "--create-density-splits" ]
762 foreach(_density, _split_densities) {
763 outputs += [ "${_resource_packaged_apk_path}_${_density}" ]
766 if (_split_languages != []) {
767 args += [ "--language-splits=$_split_languages" ]
768 foreach(_language, _split_languages) {
769 outputs += [ "${_resource_packaged_apk_path}_${_language}" ]
772 if (defined(invoker.extensions_to_not_compress)) {
775 invoker.extensions_to_not_compress,
780 package_target = "${target_name}__package"
781 package_apk(package_target) {
783 forward_variables_from(invoker, [ "deps" ])
784 deps += [ ":${_package_resources_target_name}" ]
786 data_deps = [ "//tools/android/md5sum" ] # Used when deploying APKs
788 if (defined(_dex_path)) {
791 native_libs_dir = _native_libs_dir
792 output_apk_path = _packaged_apk_path
793 resource_packaged_apk_path = _resource_packaged_apk_path
796 _incremental_package_target = "${target_name}_incremental__package"
797 package_apk(_incremental_package_target) {
799 forward_variables_from(invoker, [ "deps" ])
800 deps += [ ":${_package_resources_target_name}" ]
802 # TODO(agrieve): Multidex
803 if (defined(_dex_path)) {
807 # TODO(agrieve): Add a placeholder .so for http://crbug.com/384638
808 native_libs_dir = "//build/android/empty/res"
809 output_apk_path = _incremental_packaged_apk_path
810 resource_packaged_apk_path = _resource_packaged_apk_path
813 _finalize_apk_rule_name = "${target_name}__finalize"
814 finalize_apk(_finalize_apk_rule_name) {
815 input_apk_path = _packaged_apk_path
816 output_apk_path = _final_apk_path
817 keystore_path = _keystore_path
818 keystore_name = _keystore_name
819 keystore_password = _keystore_password
820 rezip_apk = _load_library_from_apk
823 # Generator of the _packaged_apk_path this target takes as input.
828 _incremental_finalize_apk_rule_name = "${target_name}_incremental__finalize"
829 finalize_apk(_incremental_finalize_apk_rule_name) {
830 input_apk_path = _incremental_packaged_apk_path
831 output_apk_path = _incremental_final_apk_path
832 keystore_path = _keystore_path
833 keystore_name = _keystore_name
834 keystore_password = _keystore_password
837 ":$_incremental_package_target",
843 template("finalize_split") {
844 finalize_apk(target_name) {
845 _config = invoker.split_config
846 _type = invoker.split_type
847 input_apk_path = "${_resource_packaged_apk_path}_${_config}"
848 _output_paths = process_file_template(
850 "{{source_dir}}/{{source_name_part}}-${_type}-${_config}.apk")
851 output_apk_path = _output_paths[0]
852 keystore_path = _keystore_path
853 keystore_name = _keystore_name
854 keystore_password = _keystore_password
856 ":${_package_resources_target_name}",
861 foreach(_split, _split_densities) {
862 _split_rule = "${target_name}__finalize_${_split}_split"
863 finalize_split(_split_rule) {
864 split_type = "density"
865 split_config = _split
867 _split_deps += [ ":$_split_rule" ]
869 foreach(_split, _split_languages) {
870 _split_rule = "${target_name}__finalize_${_split}_split"
871 finalize_split(_split_rule) {
873 split_config = _split
875 _split_deps += [ ":$_split_rule" ]
879 public_deps = [ ":${_finalize_apk_rule_name}" ] + _split_deps
881 group("${target_name}_incremental") {
882 public_deps = [ ":${_incremental_finalize_apk_rule_name}" ] + _split_deps
886 template("java_prebuilt_impl") {
887 set_sources_assignment_filter([])
888 forward_variables_from(invoker, [ "testonly" ])
890 defined(invoker.supports_android) && invoker.supports_android
892 assert(defined(invoker.jar_path))
893 _base_path = "${target_gen_dir}/$target_name"
895 # Jar files can be needed at runtime (by Robolectric tests or java binaries),
896 # so do not put them under gen/.
897 target_dir_name = get_label_info(":$target_name", "dir")
898 _jar_path = "$root_out_dir/lib.java$target_dir_name/$target_name.jar"
899 _build_config = _base_path + ".build_config"
901 if (_supports_android) {
902 _dex_path = _base_path + ".dex.jar"
905 if (defined(invoker.deps)) {
909 if (defined(invoker.jar_dep)) {
910 _jar_deps = [ invoker.jar_dep ]
913 _template_name = target_name
915 build_config_target_name = "${_template_name}__build_config"
916 process_jar_target_name = "${_template_name}__process_jar"
917 if (_supports_android) {
918 dex_target_name = "${_template_name}__dex"
921 write_build_config(build_config_target_name) {
922 type = "java_library"
923 supports_android = _supports_android
925 defined(invoker.requires_android) && invoker.requires_android
928 build_config = _build_config
930 if (_supports_android) {
935 process_java_prebuilt(process_jar_target_name) {
936 visibility = [ ":$_template_name" ]
937 if (_supports_android) {
938 visibility += [ ":$dex_target_name" ]
941 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
942 proguard_preprocess = true
943 proguard_config = invoker.proguard_config
946 build_config = _build_config
947 input_jar_path = invoker.jar_path
948 output_jar_path = _jar_path
950 deps = [ ":$build_config_target_name" ] + _deps + _jar_deps
953 if (_supports_android) {
954 dex(dex_target_name) {
959 deps = [ ":$process_jar_target_name" ] + _deps + _jar_deps
963 if (defined(invoker.main_class)) {
964 binary_script_target_name = "${_template_name}__java_binary_script"
965 java_binary_script(binary_script_target_name) {
966 build_config = _build_config
968 main_class = invoker.main_class
969 script_name = _template_name
971 ":$build_config_target_name",
977 forward_variables_from(invoker, [ "data_deps" ])
979 ":$process_jar_target_name",
981 if (_supports_android) {
982 deps += [ ":$dex_target_name" ]
985 if (defined(invoker.data_deps)) {
986 data_deps += invoker.data_deps
988 if (defined(invoker.main_class)) {
989 data_deps += [ ":$binary_script_target_name" ]
994 # Compiles and jars a set of java files.
998 # $jar_path.interface.jar
1001 # java_files: List of .java files to compile.
1002 # java_deps: List of java dependencies. These should all have a .jar output
1003 # at "${target_gen_dir}/${target_name}.jar.
1004 # chromium_code: If true, enable extra warnings.
1005 # srcjar_deps: List of srcjar dependencies. The .java files contained in the
1006 # dependencies srcjar outputs will be compiled and added to the output jar.
1007 # jar_path: Use this to explicitly set the output jar path. Defaults to
1008 # "${target_gen_dir}/${target_name}.jar.
1009 template("compile_java") {
1010 set_sources_assignment_filter([])
1011 forward_variables_from(invoker, [ "testonly" ])
1013 assert(defined(invoker.java_files))
1014 assert(defined(invoker.build_config))
1015 assert(defined(invoker.jar_path))
1017 _java_files = invoker.java_files
1018 _final_jar_path = invoker.jar_path
1019 _intermediate_jar_path = "$target_gen_dir/$target_name.initial.jar"
1021 _build_config = invoker.build_config
1023 _jar_excluded_patterns = []
1024 if (defined(invoker.jar_excluded_patterns)) {
1025 _jar_excluded_patterns += invoker.jar_excluded_patterns
1028 _chromium_code = false
1029 if (defined(invoker.chromium_code)) {
1030 _chromium_code = invoker.chromium_code
1033 _supports_android = true
1034 if (defined(invoker.supports_android)) {
1035 _supports_android = invoker.supports_android
1038 _enable_errorprone = use_errorprone_java_compiler
1039 if (!_chromium_code) {
1040 _enable_errorprone = false
1041 } else if (defined(invoker.enable_errorprone)) {
1042 _enable_errorprone = invoker.enable_errorprone
1045 _manifest_entries = []
1046 if (defined(invoker.manifest_entries)) {
1047 _manifest_entries = invoker.manifest_entries
1051 if (defined(invoker.srcjar_deps)) {
1052 _srcjar_deps += invoker.srcjar_deps
1056 if (defined(invoker.srcjars)) {
1057 _java_srcjars = invoker.srcjars
1059 foreach(dep, _srcjar_deps) {
1060 _dep_gen_dir = get_label_info(dep, "target_gen_dir")
1061 _dep_name = get_label_info(dep, "name")
1062 _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
1065 # Mark srcjar_deps as used.
1066 assert(_srcjar_deps == [] || true)
1068 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1069 _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir)
1071 javac_target_name = "${target_name}__javac"
1072 finish_target_name = "${target_name}__finish"
1073 final_target_name = target_name
1075 action(javac_target_name) {
1076 script = "//build/android/gyp/javac.py"
1077 depfile = "$target_gen_dir/$target_name.d"
1079 if (defined(invoker.deps)) {
1080 deps += invoker.deps
1085 _intermediate_jar_path,
1086 _intermediate_jar_path + ".md5.stamp",
1088 sources = _java_files + _java_srcjars
1093 _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
1094 _rebased_depfile = rebase_path(depfile, root_build_dir)
1096 "--depfile=$_rebased_depfile",
1098 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
1099 "--jar-path=$_rebased_jar_path",
1100 "--java-srcjars=$_rebased_java_srcjars",
1101 "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)",
1102 "--jar-excluded-classes=$_jar_excluded_patterns",
1104 if (_supports_android) {
1105 deps += [ "//build/android:android_ijar" ]
1106 _android_sdk_ijar = "$root_out_dir/lib.java/android.interface.jar"
1107 inputs += [ _android_sdk_ijar ]
1108 _rebased_android_sdk_ijar = rebase_path(_android_sdk_ijar, root_build_dir)
1109 args += [ "--bootclasspath=$_rebased_android_sdk_ijar" ]
1111 foreach(e, _manifest_entries) {
1112 args += [ "--manifest-entry=" + e ]
1114 if (_chromium_code) {
1115 args += [ "--chromium-code=1" ]
1117 if (_enable_errorprone) {
1118 deps += [ "//third_party/errorprone:chromium_errorprone" ]
1120 "--use-errorprone-path",
1121 "bin/chromium_errorprone",
1124 args += rebase_path(_java_files, root_build_dir)
1127 process_java_prebuilt(finish_target_name) {
1128 visibility = [ ":$final_target_name" ]
1130 build_config = _build_config
1131 input_jar_path = _intermediate_jar_path
1132 output_jar_path = _final_jar_path
1133 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
1134 proguard_preprocess = invoker.proguard_preprocess
1135 proguard_config = invoker.proguard_config
1138 ":$javac_target_name",
1142 group(final_target_name) {
1143 forward_variables_from(invoker, [ "visibility" ])
1145 ":$finish_target_name",
1150 template("java_library_impl") {
1151 set_sources_assignment_filter([])
1152 forward_variables_from(invoker, [ "testonly" ])
1155 defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir) ||
1156 defined(invoker.srcjars) || defined(invoker.srcjar_deps))
1157 _base_path = "$target_gen_dir/$target_name"
1159 # Jar files can be needed at runtime (by Robolectric tests or java binaries),
1160 # so do not put them under gen/.
1161 target_dir_name = get_label_info(":$target_name", "dir")
1162 _jar_path = "$root_out_dir/lib.java$target_dir_name/$target_name.jar"
1163 if (defined(invoker.jar_path)) {
1164 _jar_path = invoker.jar_path
1166 _template_name = target_name
1169 _final_datadeps = []
1170 if (defined(invoker.datadeps)) {
1171 _final_datadeps = invoker.datadeps
1175 defined(invoker.supports_android) && invoker.supports_android
1177 defined(invoker.requires_android) && invoker.requires_android
1178 assert(_requires_android || true) # Mark as used.
1180 if (_supports_android) {
1181 _dex_path = _base_path + ".dex.jar"
1182 if (defined(invoker.dex_path)) {
1183 _dex_path = invoker.dex_path
1187 # Define build_config_deps which will be a list of targets required to
1188 # build the _build_config.
1189 if (defined(invoker.override_build_config)) {
1190 _build_config = invoker.override_build_config
1192 # When a custom build config file is specified, we need to use the deps
1193 # supplied by the invoker any time we reference the build config file.
1194 assert(defined(invoker.deps),
1195 "If you specify a build config file for " +
1196 "java_library_impl($target_name), you should " +
1197 "also specify the target that made it in the deps")
1198 build_config_deps = invoker.deps
1200 _build_config = _base_path + ".build_config"
1201 build_config_target_name = "${_template_name}__build_config"
1202 build_config_deps = [ ":$build_config_target_name" ]
1204 write_build_config(build_config_target_name) {
1205 forward_variables_from(invoker, [ "deps" ])
1206 type = "java_library"
1207 supports_android = _supports_android
1208 requires_android = _requires_android
1209 bypass_platform_checks = defined(invoker.bypass_platform_checks) &&
1210 invoker.bypass_platform_checks
1212 build_config = _build_config
1213 jar_path = _jar_path
1214 if (_supports_android) {
1215 dex_path = _dex_path
1220 _chromium_code = true
1221 if (defined(invoker.chromium_code)) {
1222 _chromium_code = invoker.chromium_code
1226 if (defined(invoker.srcjar_deps)) {
1227 _srcjar_deps = invoker.srcjar_deps
1231 if (defined(invoker.srcjars)) {
1232 _srcjars = invoker.srcjars
1236 if (defined(invoker.DEPRECATED_java_in_dir)) {
1237 _src_dir = invoker.DEPRECATED_java_in_dir + "/src"
1238 _src_dir_exists = exec_script("//build/dir_exists.py",
1239 [ rebase_path(_src_dir, root_build_dir) ],
1241 assert(_src_dir_exists == "False",
1242 "In GN, java_in_dir should be the fully specified java directory " +
1243 "(i.e. including the trailing \"/src\")")
1245 _java_files_build_rel =
1246 exec_script("//build/android/gyp/find.py",
1250 rebase_path(invoker.DEPRECATED_java_in_dir,
1254 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1256 if (defined(invoker.java_files)) {
1257 _java_files += invoker.java_files
1259 assert(_java_files != [] || _srcjar_deps != [] || _srcjars != [])
1261 _compile_java_target = "${_template_name}__compile_java"
1262 _final_deps += [ ":$_compile_java_target" ]
1263 compile_java(_compile_java_target) {
1264 forward_variables_from(invoker,
1267 "enable_errorprone",
1268 "jar_excluded_patterns",
1271 "proguard_preprocess",
1273 jar_path = _jar_path
1274 build_config = _build_config
1275 java_files = _java_files
1276 srcjar_deps = _srcjar_deps
1278 chromium_code = _chromium_code
1279 supports_android = _supports_android
1280 deps = build_config_deps
1283 if (defined(invoker.main_class)) {
1284 _final_datadeps += [ ":${_template_name}__java_binary_script" ]
1285 java_binary_script("${_template_name}__java_binary_script") {
1286 forward_variables_from(invoker,
1289 "wrapper_script_args",
1291 build_config = _build_config
1292 jar_path = _jar_path
1293 script_name = _template_name
1294 deps = build_config_deps
1298 if (_supports_android) {
1299 if (defined(invoker.chromium_code) && invoker.chromium_code) {
1300 _android_manifest = "//build/android/AndroidManifest.xml"
1301 if (defined(invoker.android_manifest)) {
1302 _android_manifest = invoker.android_manifest
1305 _final_datadeps += [ ":${_template_name}__lint" ]
1306 android_lint("${_template_name}__lint") {
1307 android_manifest = _android_manifest
1308 jar_path = _jar_path
1309 java_files = _java_files
1311 ":$_compile_java_target",
1313 if (defined(invoker.deps)) {
1314 deps += invoker.deps
1318 if (defined(invoker.run_findbugs)) {
1319 run_findbugs = invoker.run_findbugs
1322 _final_datadeps += [ ":${_template_name}__findbugs" ]
1323 findbugs("${_template_name}__findbugs") {
1324 build_config = _build_config
1325 jar_path = _jar_path
1327 ":$_compile_java_target",
1333 _final_deps += [ ":${_template_name}__dex" ]
1334 dex("${_template_name}__dex") {
1340 ":$_compile_java_target",
1345 group(target_name) {
1346 forward_variables_from(invoker, [ "visibility" ])
1347 public_deps = _final_deps
1348 data_deps = _final_datadeps
1352 # Runs process_resources.py
1353 template("process_resources") {
1354 set_sources_assignment_filter([])
1355 forward_variables_from(invoker, [ "testonly" ])
1357 zip_path = invoker.zip_path
1358 srcjar_path = invoker.srcjar_path
1359 r_text_path = invoker.r_text_path
1360 build_config = invoker.build_config
1361 resource_dirs = invoker.resource_dirs
1362 android_manifest = invoker.android_manifest
1364 non_constant_id = true
1365 if (defined(invoker.generate_constant_ids) && invoker.generate_constant_ids) {
1366 non_constant_id = false
1369 action(target_name) {
1370 forward_variables_from(invoker,
1375 script = "//build/android/gyp/process_resources.py"
1377 depfile = "$target_gen_dir/$target_name.d"
1385 sources_build_rel = exec_script("//build/android/gyp/find.py",
1386 rebase_path(resource_dirs, root_build_dir),
1388 sources = rebase_path(sources_build_rel, ".", root_build_dir)
1395 rebase_resource_dirs = rebase_path(resource_dirs, root_build_dir)
1396 rebase_build_config = rebase_path(build_config, root_build_dir)
1399 rebase_path(depfile, root_build_dir),
1401 rebase_path(android_sdk, root_build_dir),
1404 "--android-manifest",
1405 rebase_path(android_manifest, root_build_dir),
1406 "--resource-dirs=$rebase_resource_dirs",
1408 rebase_path(srcjar_path, root_build_dir),
1409 "--resource-zip-out",
1410 rebase_path(zip_path, root_build_dir),
1412 rebase_path(r_text_path, root_build_dir),
1413 "--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)",
1414 "--extra-res-packages=@FileArg($rebase_build_config:resources:extra_package_names)",
1415 "--extra-r-text-files=@FileArg($rebase_build_config:resources:extra_r_text_files)",
1418 if (non_constant_id) {
1419 args += [ "--non-constant-id" ]
1422 if (defined(invoker.custom_package)) {
1425 invoker.custom_package,
1429 if (defined(invoker.v14_skip) && invoker.v14_skip) {
1430 args += [ "--v14-skip" ]
1433 if (defined(invoker.shared_resources) && invoker.shared_resources) {
1434 args += [ "--shared-resources" ]
1437 if (defined(invoker.include_all_resources) &&
1438 invoker.include_all_resources) {
1439 args += [ "--include-all-resources" ]
1442 if (defined(invoker.all_resources_zip_path)) {
1443 all_resources_zip = invoker.all_resources_zip_path
1444 outputs += [ all_resources_zip ]
1446 "--all-resources-zip-out",
1447 rebase_path(all_resources_zip, root_build_dir),
1451 if (defined(invoker.args)) {
1452 args += invoker.args
1457 template("copy_ex") {
1458 set_sources_assignment_filter([])
1459 action(target_name) {
1462 forward_variables_from(invoker,
1470 script = "//build/android/gyp/copy_ex.py"
1472 depfile = "$target_gen_dir/$target_name.d"
1479 rebase_path(depfile, root_build_dir),
1481 rebase_path(invoker.dest, root_build_dir),
1483 rebased_sources = rebase_path(sources, root_build_dir)
1484 args += [ "--files=$rebased_sources" ]
1486 if (defined(invoker.clear_dir) && invoker.clear_dir) {
1487 args += [ "--clear" ]
1490 if (defined(invoker.args)) {
1491 args += invoker.args
1496 # Produces a single .dex.jar out of a set of Java dependencies.
1497 template("deps_dex") {
1498 set_sources_assignment_filter([])
1499 build_config = "$target_gen_dir/${target_name}.build_config"
1500 build_config_target_name = "${target_name}__build_config"
1502 write_build_config(build_config_target_name) {
1503 forward_variables_from(invoker,
1509 build_config = build_config
1512 rebased_build_config = rebase_path(build_config, root_build_dir)
1517 output = invoker.dex_path
1518 dex_arg_key = "${rebased_build_config}:final_dex:dependency_dex_files"
1519 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1520 if (defined(invoker.excluded_jars)) {
1521 excluded_jars = rebase_path(invoker.excluded_jars, root_build_dir)
1522 args += [ "--excluded-paths=${excluded_jars}" ]
1525 ":$build_config_target_name",
1530 # Creates an AndroidManifest.xml for an APK split.
1531 template("generate_split_manifest") {
1532 assert(defined(invoker.main_manifest))
1533 assert(defined(invoker.out_manifest))
1534 assert(defined(invoker.split_name))
1536 action(target_name) {
1537 forward_variables_from(invoker,
1542 depfile = "$target_gen_dir/$target_name.d"
1545 rebase_path(invoker.main_manifest, root_build_dir),
1547 rebase_path(invoker.out_manifest, root_build_dir),
1551 if (defined(invoker.version_code)) {
1554 invoker.version_code,
1557 if (defined(invoker.version_name)) {
1560 invoker.version_name,
1563 if (defined(invoker.has_code)) {
1571 rebase_path(depfile, root_build_dir),
1574 script = "//build/android/gyp/generate_split_manifest.py"
1577 invoker.out_manifest,
1580 invoker.main_manifest,
1585 # Generates a script in the output bin directory which runs the test
1586 # target using the test runner script in build/android/test_runner.py.
1587 template("test_runner_script") {
1589 _test_name = invoker.test_name
1590 _test_type = invoker.test_type
1592 action(target_name) {
1593 script = "//build/android/gyp/create_test_runner_script.py"
1594 depfile = "$target_gen_dir/$target_name.d"
1596 test_runner_args = [
1598 "--output-directory",
1599 rebase_path(root_build_dir, root_build_dir),
1601 if (_test_type == "gtest") {
1602 assert(defined(invoker.test_suite))
1603 test_runner_args += [
1607 } else if (_test_type == "instrumentation") {
1608 assert(defined(invoker.test_apk))
1609 test_runner_args += [
1614 assert(false, "Invalid test type: $_test_type.")
1617 if (defined(invoker.isolate_file)) {
1618 test_runner_args += [
1619 "--isolate-file-path",
1620 rebase_path(invoker.isolate_file, root_build_dir),
1624 generated_script = "$root_build_dir/bin/run_${_test_name}"
1631 rebase_path(depfile, root_build_dir),
1632 "--script-output-path",
1633 rebase_path(generated_script, root_build_dir),
1635 args += test_runner_args