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")
9 rebased_android_sdk = rebase_path(android_sdk, root_build_dir)
10 rebased_android_sdk_root = rebase_path(android_sdk_root, root_build_dir)
11 rebased_android_sdk_build_tools =
12 rebase_path(android_sdk_build_tools, root_build_dir)
14 android_sdk_jar = "$android_sdk/android.jar"
15 rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir)
16 android_aapt_path = "$rebased_android_sdk_build_tools/aapt"
18 template("android_lint") {
19 set_sources_assignment_filter([])
21 jar_path = invoker.jar_path
22 android_manifest = invoker.android_manifest
23 java_files = invoker.java_files
24 base_path = "$target_gen_dir/$target_name"
27 forward_variables_from(invoker,
34 script = "//build/android/gyp/lint.py"
35 result_path = base_path + "/result.xml"
36 config_path = base_path + "/config.xml"
37 suppressions_file = "//build/android/lint/suppressions.xml"
49 rebased_java_files = rebase_path(java_files, root_build_dir)
52 "--lint-path=$rebased_android_sdk_root/tools/lint",
54 rebase_path(suppressions_file, root_build_dir),
56 rebase_path(android_manifest, root_build_dir),
59 rebase_path(jar_path, root_build_dir),
60 "--processed-config-path",
61 rebase_path(config_path, root_build_dir),
63 rebase_path(result_path, root_build_dir),
64 "--java-files=$rebased_java_files",
70 template("findbugs") {
71 jar_path = invoker.jar_path
73 build_config = invoker.build_config
76 forward_variables_from(invoker,
81 script = "//build/android/findbugs_diff.py"
82 depfile = "$target_gen_dir/$target_name.d"
83 result_path = "$target_gen_dir/$target_name/result.xml"
84 exclusions_file = "//build/android/findbugs_filter/findbugs_exclude.xml"
86 rebased_build_config = rebase_path(build_config, root_build_dir)
89 "//build/android/pylib/utils/findbugs.py",
101 rebase_path(depfile, root_build_dir),
103 rebase_path(exclusions_file, root_build_dir),
104 "--auxclasspath-gyp",
105 "@FileArg($rebased_build_config:javac:classpath)",
107 rebase_path(result_path, root_build_dir),
108 rebase_path(jar_path, root_build_dir),
111 if (findbugs_verbose) {
118 set_sources_assignment_filter([])
120 assert(defined(invoker.output))
121 action(target_name) {
122 forward_variables_from(invoker,
129 script = "//build/android/gyp/dex.py"
130 depfile = "$target_gen_dir/$target_name.d"
136 rebased_output = rebase_path(invoker.output, root_build_dir)
140 rebase_path(depfile, root_build_dir),
141 "--android-sdk-tools",
142 rebased_android_sdk_build_tools,
147 if (defined(invoker.no_locals) && invoker.no_locals) {
148 args += [ "--no-locals=1" ]
151 if (defined(invoker.args)) {
155 if (defined(invoker.sources)) {
156 args += rebase_path(invoker.sources, root_build_dir)
161 # Creates a zip archive of the inputs.
162 # If base_dir is provided, the archive paths will be relative to it.
164 set_sources_assignment_filter([])
165 assert(defined(invoker.inputs))
166 assert(defined(invoker.output))
168 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
169 rebase_output = rebase_path(invoker.output, root_build_dir)
170 action(target_name) {
171 forward_variables_from(invoker,
180 script = "//build/android/gn/zip.py"
181 depfile = "$target_gen_dir/$target_name.d"
188 rebase_path(depfile, root_build_dir),
189 "--inputs=$rebase_inputs",
190 "--output=$rebase_output",
192 if (defined(invoker.base_dir)) {
195 rebase_path(invoker.base_dir, root_build_dir),
201 # Write the target's .build_config file. This is a json file that contains a
202 # dictionary of information about how to build this target (things that
203 # require knowledge about this target's dependencies and cannot be calculated
204 # at gn-time). There is a special syntax to add a value in that dictionary to
205 # an action/action_foreachs args:
206 # --python-arg=@FileArg($rebased_build_config_path:key0:key1)
207 # At runtime, such an arg will be replaced by the value in the build_config.
208 # See build/android/gyp/write_build_config.py and
209 # build/android/gyp/util/build_utils.py:ExpandFileArgs
210 template("write_build_config") {
211 set_sources_assignment_filter([])
213 assert(defined(invoker.type))
214 assert(defined(invoker.build_config))
217 build_config = invoker.build_config
219 assert(type == "android_apk" || type == "java_library" ||
220 type == "android_resources" || type == "deps_dex")
222 action(target_name) {
224 forward_variables_from(invoker,
231 script = "//build/android/gyp/write_build_config.py"
232 depfile = "$target_gen_dir/$target_name.d"
235 possible_deps_configs = []
237 dep_gen_dir = get_label_info(d, "target_gen_dir")
238 dep_name = get_label_info(d, "name")
239 possible_deps_configs += [ "$dep_gen_dir/$dep_name.build_config" ]
241 rebase_possible_deps_configs =
242 rebase_path(possible_deps_configs, root_build_dir)
253 rebase_path(depfile, root_build_dir),
254 "--possible-deps-configs=$rebase_possible_deps_configs",
256 rebase_path(build_config, root_build_dir),
259 is_java_library = type == "java_library"
260 is_apk = type == "android_apk"
261 is_android_resources = type == "android_resources"
262 is_deps_dex = type == "deps_dex"
264 supports_android = is_apk || is_android_resources || is_deps_dex ||
265 (is_java_library && defined(invoker.supports_android) &&
266 invoker.supports_android)
267 requires_android = is_apk || is_android_resources || is_deps_dex ||
268 (is_java_library && defined(invoker.requires_android) &&
269 invoker.requires_android)
271 assert(!requires_android || supports_android,
272 "requires_android requires" + " supports_android")
274 # Mark these variables as used.
275 assert(is_java_library || true)
276 assert(is_apk || true)
277 assert(is_android_resources || true)
278 assert(is_deps_dex || true)
280 if (is_java_library || is_apk) {
283 rebase_path(invoker.jar_path, root_build_dir),
287 if (is_apk || is_deps_dex || (is_java_library && supports_android)) {
290 rebase_path(invoker.dex_path, root_build_dir),
293 if (supports_android) {
294 args += [ "--supports-android" ]
296 if (requires_android) {
297 args += [ "--requires-android" ]
299 if (defined(invoker.bypass_platform_checks) &&
300 invoker.bypass_platform_checks) {
301 args += [ "--bypass-platform-checks" ]
304 if (defined(invoker.apk_under_test)) {
305 deps += [ invoker.apk_under_test ]
306 apk_under_test_gen_dir =
307 get_label_info(invoker.apk_under_test, "target_gen_dir")
308 apk_under_test_name = get_label_info(invoker.apk_under_test, "name")
309 apk_under_test_config =
310 "$apk_under_test_gen_dir/$apk_under_test_name.build_config"
312 "--tested-apk-config",
313 rebase_path(apk_under_test_config, root_build_dir),
317 if (is_android_resources || is_apk) {
318 assert(defined(invoker.resources_zip))
321 rebase_path(invoker.resources_zip, root_build_dir),
323 if (defined(invoker.android_manifest)) {
324 inputs += [ invoker.android_manifest ]
326 "--android-manifest",
327 rebase_path(invoker.android_manifest, root_build_dir),
330 assert(!is_apk, "apk build configs require an android_manifest")
332 if (defined(invoker.custom_package)) {
335 invoker.custom_package,
338 if (defined(invoker.r_text)) {
341 rebase_path(invoker.r_text, root_build_dir),
347 if (defined(invoker.native_libs)) {
348 inputs += invoker.native_libs
349 rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir)
350 rebased_android_readelf = rebase_path(android_readelf, root_build_dir)
352 "--native-libs=$rebased_native_libs",
353 "--readelf-path=$rebased_android_readelf",
358 if (defined(invoker.srcjar)) {
361 rebase_path(invoker.srcjar, root_build_dir),
367 template("process_java_prebuilt") {
368 set_sources_assignment_filter([])
369 forward_variables_from(invoker, [ "testonly" ])
371 _input_jar_path = invoker.input_jar_path
372 _output_jar_path = invoker.output_jar_path
373 _jar_toc_path = _output_jar_path + ".TOC"
375 assert(invoker.build_config != "")
377 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
378 _proguard_jar_path = "$android_sdk_root/tools/proguard/lib/proguard.jar"
379 _proguard_config_path = invoker.proguard_config
380 _build_config = invoker.build_config
381 _rebased_build_config = rebase_path(_build_config, root_build_dir)
382 _output_jar_target = "${target_name}__proguard_process"
383 action(_output_jar_target) {
384 forward_variables_from(invoker,
390 script = "//build/android/gyp/proguard.py"
396 _proguard_config_path,
398 depfile = "${target_gen_dir}/${target_name}.d"
405 rebase_path(depfile, root_build_dir),
407 rebase_path(_proguard_jar_path, root_build_dir),
409 rebase_path(_input_jar_path, root_build_dir),
411 rebase_path(_output_jar_path, root_build_dir),
413 rebase_path(_proguard_config_path, root_build_dir),
415 rebased_android_sdk_jar,
416 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
420 _output_jar_target = "${target_name}__copy_jar"
421 copy(_output_jar_target) {
422 forward_variables_from(invoker,
437 action("${target_name}__jar_toc") {
438 script = "//build/android/gyp/jar_toc.py"
439 depfile = "$target_gen_dir/$target_name.d"
443 _jar_toc_path + ".md5.stamp",
450 rebase_path(depfile, root_build_dir),
452 rebase_path(_output_jar_path, root_build_dir),
454 rebase_path(_jar_toc_path, root_build_dir),
457 ":$_output_jar_target",
462 forward_variables_from(invoker, [ "visibility" ])
464 ":${target_name}__jar_toc",
465 ":$_output_jar_target",
470 template("finalize_apk") {
471 action(target_name) {
472 forward_variables_from(invoker,
479 script = "//build/android/gyp/finalize_apk.py"
480 depfile = "$target_gen_dir/$target_name.d"
483 invoker.input_apk_path,
486 invoker.keystore_path,
490 invoker.output_apk_path,
495 rebase_path(depfile, root_build_dir),
497 rebase_path(zipalign_path, root_build_dir),
498 "--unsigned-apk-path",
499 rebase_path(invoker.input_apk_path, root_build_dir),
501 rebase_path(invoker.output_apk_path, root_build_dir),
503 rebase_path(invoker.keystore_path, root_build_dir),
505 invoker.keystore_name,
507 invoker.keystore_password,
509 if (defined(invoker.rezip_apk) && invoker.rezip_apk) {
510 _rezip_jar_path = "$root_build_dir/lib.java/rezip_apk.jar"
511 inputs += [ _rezip_jar_path ]
513 "--load-library-from-zip=1",
514 "--rezip-apk-jar-path",
515 rebase_path(_rezip_jar_path, root_build_dir),
521 # Packages resources, assets, dex, and native libraries into an apk. Signs and
523 template("create_apk") {
524 set_sources_assignment_filter([])
525 forward_variables_from(invoker, [ "testonly" ])
527 _android_manifest = invoker.android_manifest
528 _base_path = invoker.base_path
529 _final_apk_path = invoker.apk_path
531 if (defined(invoker.resources_zip)) {
532 _resources_zip = invoker.resources_zip
534 if (defined(invoker.dex_path)) {
535 _dex_path = invoker.dex_path
537 _load_library_from_apk = invoker.load_library_from_apk
540 if (defined(invoker.deps)) {
541 _package_deps = invoker.deps
544 _native_libs_dir = "//build/android/empty/res"
545 if (defined(invoker.native_libs_dir)) {
546 _native_libs_dir = invoker.native_libs_dir
549 if (defined(invoker.asset_location)) {
550 _asset_location = invoker.asset_location
553 _version_code = invoker.version_code
554 _version_name = invoker.version_name
556 _base_apk_path = _base_path + ".apk_intermediates"
558 _resource_packaged_apk_path = _base_apk_path + ".ap_"
559 _packaged_apk_path = _base_apk_path + ".unfinished.apk"
561 defined(invoker.shared_resources) && invoker.shared_resources
563 _configuration_name = "Release"
565 _configuration_name = "Debug"
568 _keystore_path = invoker.keystore_path
569 _keystore_name = invoker.keystore_name
570 _keystore_password = invoker.keystore_password
572 _split_densities = []
573 if (defined(invoker.create_density_splits) && invoker.create_density_splits) {
583 _split_languages = []
584 if (defined(invoker.language_splits)) {
585 _split_languages = invoker.language_splits
588 _package_resources_target_name = "${target_name}__package_resources"
589 action(_package_resources_target_name) {
592 script = "//build/android/gyp/package_resources.py"
593 depfile = "${target_gen_dir}/${target_name}.d"
597 if (defined(_resources_zip)) {
598 inputs += [ _resources_zip ]
602 _resource_packaged_apk_path,
607 rebase_path(depfile, root_build_dir),
612 "--configuration-name=$_configuration_name",
613 "--android-manifest",
614 rebase_path(_android_manifest, root_build_dir),
620 rebase_path(_resource_packaged_apk_path, root_build_dir),
623 if (defined(_asset_location)) {
626 rebase_path(_asset_location, root_build_dir),
629 if (defined(_resources_zip)) {
632 rebase_path(_resources_zip, root_build_dir),
635 if (_shared_resources) {
636 args += [ "--shared-resources" ]
638 if (_split_densities != []) {
639 args += [ "--create-density-splits" ]
640 foreach(_density, _split_densities) {
641 outputs += [ "${_resource_packaged_apk_path}_${_density}" ]
644 if (_split_languages != []) {
645 args += [ "--language-splits=$_split_languages" ]
646 foreach(_language, _split_languages) {
647 outputs += [ "${_resource_packaged_apk_path}_${_language}" ]
650 if (defined(invoker.extensions_to_not_compress)) {
653 invoker.extensions_to_not_compress,
658 package_target = "${target_name}__package"
659 action(package_target) {
660 script = "//build/android/gyp/ant.py"
661 _ant_script = "//build/android/ant/apk-package.xml"
664 ":${_package_resources_target_name}",
666 if (defined(invoker.deps)) {
669 depfile = "$target_gen_dir/$target_name.d"
672 _resource_packaged_apk_path,
675 if (defined(_dex_path)) {
676 inputs += [ _dex_path ]
684 _rebased_emma_jar = ""
685 _rebased_resource_packaged_apk_path =
686 rebase_path(_resource_packaged_apk_path, root_build_dir)
687 _rebased_packaged_apk_path = rebase_path(_packaged_apk_path, root_build_dir)
688 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
691 rebase_path(depfile, root_build_dir),
694 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root",
695 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools",
696 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path",
697 "-DCONFIGURATION_NAME=$_configuration_name",
698 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir",
700 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path",
701 "-DEMMA_INSTRUMENT=0",
702 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar",
705 rebase_path(_ant_script, root_build_dir),
707 if (defined(_dex_path)) {
708 _rebased_dex_path = rebase_path(_dex_path, root_build_dir)
710 "-DDEX_FILE_PATH=$_rebased_dex_path",
714 args += [ "-DHAS_CODE=false" ]
718 _finalize_apk_rule_name = "${target_name}__finalize"
719 finalize_apk(_finalize_apk_rule_name) {
720 input_apk_path = _packaged_apk_path
721 output_apk_path = _final_apk_path
722 keystore_path = _keystore_path
723 keystore_name = _keystore_name
724 keystore_password = _keystore_password
725 rezip_apk = _load_library_from_apk
728 # Generator of the _packaged_apk_path this target takes as input.
733 _final_deps = [ ":${_finalize_apk_rule_name}" ]
735 template("finalize_split") {
736 finalize_apk(target_name) {
737 _config = invoker.split_config
738 _type = invoker.split_type
739 input_apk_path = "${_resource_packaged_apk_path}_${_config}"
740 _output_paths = process_file_template(
742 "{{source_dir}}/{{source_name_part}}-${_type}-${_config}.apk")
743 output_apk_path = _output_paths[0]
744 keystore_path = _keystore_path
745 keystore_name = _keystore_name
746 keystore_password = _keystore_password
748 ":${_package_resources_target_name}",
753 foreach(_split, _split_densities) {
754 _split_rule = "${target_name}__finalize_${_split}_split"
755 finalize_split(_split_rule) {
756 split_type = "density"
757 split_config = _split
759 _final_deps += [ ":$_split_rule" ]
761 foreach(_split, _split_languages) {
762 _split_rule = "${target_name}__finalize_${_split}_split"
763 finalize_split(_split_rule) {
765 split_config = _split
767 _final_deps += [ ":$_split_rule" ]
771 public_deps = _final_deps
775 template("java_prebuilt_impl") {
776 set_sources_assignment_filter([])
777 forward_variables_from(invoker, [ "testonly" ])
779 defined(invoker.supports_android) && invoker.supports_android
781 assert(defined(invoker.jar_path))
782 _base_path = "${target_gen_dir}/$target_name"
783 _jar_path = _base_path + ".jar"
784 _build_config = _base_path + ".build_config"
786 if (_supports_android) {
787 _dex_path = _base_path + ".dex.jar"
790 if (defined(invoker.deps)) {
794 if (defined(invoker.jar_dep)) {
795 _jar_deps = [ invoker.jar_dep ]
798 _template_name = target_name
800 build_config_target_name = "${_template_name}__build_config"
801 process_jar_target_name = "${_template_name}__process_jar"
802 if (_supports_android) {
803 dex_target_name = "${_template_name}__dex"
806 write_build_config(build_config_target_name) {
807 type = "java_library"
808 supports_android = _supports_android
810 defined(invoker.requires_android) && invoker.requires_android
813 build_config = _build_config
815 if (_supports_android) {
820 process_java_prebuilt(process_jar_target_name) {
821 visibility = [ ":$_template_name" ]
822 if (_supports_android) {
823 visibility += [ ":$dex_target_name" ]
826 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
827 proguard_preprocess = true
828 proguard_config = invoker.proguard_config
831 build_config = _build_config
832 input_jar_path = invoker.jar_path
833 output_jar_path = _jar_path
835 deps = [ ":$build_config_target_name" ] + _deps + _jar_deps
838 if (_supports_android) {
839 dex(dex_target_name) {
844 deps = [ ":$process_jar_target_name" ] + _deps + _jar_deps
849 forward_variables_from(invoker, [ "data_deps" ])
851 ":$process_jar_target_name",
853 if (_supports_android) {
854 deps += [ ":$dex_target_name" ]
859 # Compiles and jars a set of java files.
866 # java_files: List of .java files to compile.
867 # java_deps: List of java dependencies. These should all have a .jar output
868 # at "${target_gen_dir}/${target_name}.jar.
869 # chromium_code: If true, enable extra warnings.
870 # srcjar_deps: List of srcjar dependencies. The .java files contained in the
871 # dependencies srcjar outputs will be compiled and added to the output jar.
872 # jar_path: Use this to explicitly set the output jar path. Defaults to
873 # "${target_gen_dir}/${target_name}.jar.
874 template("compile_java") {
875 set_sources_assignment_filter([])
876 forward_variables_from(invoker, [ "testonly" ])
878 assert(defined(invoker.java_files))
879 assert(defined(invoker.build_config))
880 assert(defined(invoker.jar_path))
882 _java_files = invoker.java_files
883 _final_jar_path = invoker.jar_path
884 _intermediate_jar_path = "$target_gen_dir/$target_name.initial.jar"
886 _build_config = invoker.build_config
888 _jar_excluded_patterns = []
889 if (defined(invoker.jar_excluded_patterns)) {
890 _jar_excluded_patterns += invoker.jar_excluded_patterns
893 _chromium_code = false
894 if (defined(invoker.chromium_code)) {
895 _chromium_code = invoker.chromium_code
898 _supports_android = true
899 if (defined(invoker.supports_android)) {
900 _supports_android = invoker.supports_android
903 _enable_errorprone = use_errorprone_java_compiler
904 if (defined(invoker.enable_errorprone)) {
905 _enable_errorprone = invoker.enable_errorprone
908 _manifest_entries = []
909 if (defined(invoker.manifest_entries)) {
910 _manifest_entries = invoker.manifest_entries
914 if (defined(invoker.srcjar_deps)) {
915 _srcjar_deps += invoker.srcjar_deps
919 if (defined(invoker.srcjars)) {
920 _java_srcjars = invoker.srcjars
922 foreach(dep, _srcjar_deps) {
923 _dep_gen_dir = get_label_info(dep, "target_gen_dir")
924 _dep_name = get_label_info(dep, "name")
925 _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
928 # Mark srcjar_deps as used.
929 assert(_srcjar_deps == [] || true)
932 if (defined(invoker.android) && invoker.android) {
933 _system_jars += [ android_sdk_jar ]
936 _rebased_build_config = rebase_path(_build_config, root_build_dir)
937 _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir)
939 javac_target_name = "${target_name}__javac"
940 finish_target_name = "${target_name}__finish"
941 final_target_name = target_name
943 action(javac_target_name) {
944 script = "//build/android/gyp/javac.py"
945 depfile = "$target_gen_dir/$target_name.d"
947 if (defined(invoker.deps)) {
953 _intermediate_jar_path,
954 _intermediate_jar_path + ".md5.stamp",
956 sources = _java_files + _java_srcjars
957 inputs = _system_jars + [ _build_config ]
959 _rebased_system_jars = rebase_path(_system_jars, root_build_dir)
960 _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
961 _rebased_depfile = rebase_path(depfile, root_build_dir)
963 "--depfile=$_rebased_depfile",
964 "--classpath=$_rebased_system_jars",
965 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
966 "--jar-path=$_rebased_jar_path",
967 "--java-srcjars=$_rebased_java_srcjars",
968 "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)",
969 "--jar-excluded-classes=$_jar_excluded_patterns",
971 if (_supports_android) {
972 _rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir)
973 args += [ "--bootclasspath=$_rebased_android_sdk_jar" ]
975 foreach(e, _manifest_entries) {
976 args += [ "--manifest-entry=" + e ]
978 if (_chromium_code) {
979 args += [ "--chromium-code=1" ]
981 if (_enable_errorprone) {
982 deps += [ "//third_party/errorprone:chromium_errorprone" ]
984 "--use-errorprone-path",
985 "bin/chromium_errorprone",
988 args += rebase_path(_java_files, root_build_dir)
991 process_java_prebuilt(finish_target_name) {
992 visibility = [ ":$final_target_name" ]
994 build_config = _build_config
995 input_jar_path = _intermediate_jar_path
996 output_jar_path = _final_jar_path
997 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
998 proguard_preprocess = invoker.proguard_preprocess
999 proguard_config = invoker.proguard_config
1002 ":$javac_target_name",
1006 group(final_target_name) {
1007 forward_variables_from(invoker, [ "visibility" ])
1009 ":$finish_target_name",
1014 template("java_library_impl") {
1015 set_sources_assignment_filter([])
1016 forward_variables_from(invoker, [ "testonly" ])
1019 defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir) ||
1020 defined(invoker.srcjars) || defined(invoker.srcjar_deps))
1021 _base_path = "$target_gen_dir/$target_name"
1022 _jar_path = _base_path + ".jar"
1023 if (defined(invoker.jar_path)) {
1024 _jar_path = invoker.jar_path
1026 _template_name = target_name
1029 _final_datadeps = []
1030 if (defined(invoker.datadeps)) {
1031 _final_datadeps = invoker.datadeps
1035 defined(invoker.supports_android) && invoker.supports_android
1037 defined(invoker.requires_android) && invoker.requires_android
1039 if (_supports_android) {
1040 _dex_path = _base_path + ".dex.jar"
1041 if (defined(invoker.dex_path)) {
1042 _dex_path = invoker.dex_path
1046 # Define build_config_deps which will be a list of targets required to
1047 # build the _build_config.
1048 if (defined(invoker.override_build_config)) {
1049 _build_config = invoker.override_build_config
1051 # When a custom build config file is specified, we need to use the deps
1052 # supplied by the invoker any time we reference the build config file.
1053 assert(defined(invoker.deps),
1054 "If you specify a build config file for " +
1055 "java_library_impl($target_name), you should " +
1056 "also specify the target that made it in the deps")
1057 build_config_deps = invoker.deps
1059 _build_config = _base_path + ".build_config"
1060 build_config_target_name = "${_template_name}__build_config"
1061 build_config_deps = [ ":$build_config_target_name" ]
1063 write_build_config(build_config_target_name) {
1064 forward_variables_from(invoker, [ "deps" ])
1065 type = "java_library"
1066 supports_android = _supports_android
1067 requires_android = _requires_android
1068 bypass_platform_checks = defined(invoker.bypass_platform_checks) &&
1069 invoker.bypass_platform_checks
1071 build_config = _build_config
1072 jar_path = _jar_path
1073 if (_supports_android) {
1074 dex_path = _dex_path
1079 _chromium_code = true
1080 if (defined(invoker.chromium_code)) {
1081 _chromium_code = invoker.chromium_code
1085 if (defined(invoker.srcjar_deps)) {
1086 _srcjar_deps = invoker.srcjar_deps
1090 if (defined(invoker.srcjars)) {
1091 _srcjars = invoker.srcjars
1095 if (defined(invoker.java_files)) {
1096 _java_files = invoker.java_files
1097 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1098 _src_dir = invoker.DEPRECATED_java_in_dir + "/src"
1099 _src_dir_exists = exec_script("//build/dir_exists.py",
1100 [ rebase_path(_src_dir, root_build_dir) ],
1102 assert(_src_dir_exists == "False",
1103 "In GN, java_in_dir should be the fully specified java directory " +
1104 "(i.e. including the trailing \"/src\")")
1106 _java_files_build_rel = exec_script(
1107 "//build/android/gyp/find.py",
1111 rebase_path(invoker.DEPRECATED_java_in_dir, root_build_dir),
1114 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1116 assert(_java_files != [] || _srcjar_deps != [] || _srcjars != [])
1118 _compile_java_target = "${_template_name}__compile_java"
1119 _final_deps += [ ":$_compile_java_target" ]
1120 compile_java(_compile_java_target) {
1121 forward_variables_from(invoker,
1124 "enable_errorprone",
1125 "jar_excluded_patterns",
1128 "proguard_preprocess",
1130 jar_path = _jar_path
1131 build_config = _build_config
1132 java_files = _java_files
1133 srcjar_deps = _srcjar_deps
1135 chromium_code = _chromium_code
1136 android = _requires_android
1138 supports_android = _supports_android
1139 deps = build_config_deps
1142 if (defined(invoker.main_class)) {
1143 _final_deps += [ ":${_template_name}__binary_script" ]
1144 action("${_template_name}__binary_script") {
1145 script = "//build/android/gyp/create_java_binary_script.py"
1146 depfile = "$target_gen_dir/$target_name.d"
1147 java_script = "$root_build_dir/bin/$_template_name"
1155 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1158 rebase_path(depfile, root_build_dir),
1160 rebase_path(java_script, root_build_dir),
1161 "--classpath=@FileArg($_rebased_build_config:java:full_classpath)",
1163 rebase_path(_jar_path, root_build_dir),
1168 deps = build_config_deps
1172 if (_supports_android) {
1173 if (defined(invoker.chromium_code) && invoker.chromium_code) {
1174 _android_manifest = "//build/android/AndroidManifest.xml"
1175 if (defined(invoker.android_manifest)) {
1176 _android_manifest = invoker.android_manifest
1179 _final_datadeps += [ ":${_template_name}__lint" ]
1180 android_lint("${_template_name}__lint") {
1181 android_manifest = _android_manifest
1182 jar_path = _jar_path
1183 java_files = _java_files
1185 ":$_compile_java_target",
1187 if (defined(invoker.deps)) {
1188 deps += invoker.deps
1192 if (defined(invoker.run_findbugs)) {
1193 run_findbugs = invoker.run_findbugs
1196 _final_datadeps += [ ":${_template_name}__findbugs" ]
1197 findbugs("${_template_name}__findbugs") {
1198 build_config = _build_config
1199 jar_path = _jar_path
1201 ":$_compile_java_target",
1207 _final_deps += [ ":${_template_name}__dex" ]
1208 dex("${_template_name}__dex") {
1214 ":$_compile_java_target",
1219 group(target_name) {
1220 forward_variables_from(invoker, [ "visibility" ])
1221 public_deps = _final_deps
1222 data_deps = _final_datadeps
1226 # Runs process_resources.py
1227 template("process_resources") {
1228 set_sources_assignment_filter([])
1229 forward_variables_from(invoker, [ "testonly" ])
1231 zip_path = invoker.zip_path
1232 srcjar_path = invoker.srcjar_path
1233 r_text_path = invoker.r_text_path
1234 build_config = invoker.build_config
1235 resource_dirs = invoker.resource_dirs
1236 android_manifest = invoker.android_manifest
1238 non_constant_id = true
1239 if (defined(invoker.generate_constant_ids) && invoker.generate_constant_ids) {
1240 non_constant_id = false
1243 action(target_name) {
1244 forward_variables_from(invoker,
1249 script = "//build/android/gyp/process_resources.py"
1251 depfile = "$target_gen_dir/$target_name.d"
1259 sources_build_rel = exec_script("//build/android/gyp/find.py",
1260 rebase_path(resource_dirs, root_build_dir),
1262 sources = rebase_path(sources_build_rel, ".", root_build_dir)
1269 rebase_resource_dirs = rebase_path(resource_dirs, root_build_dir)
1270 rebase_build_config = rebase_path(build_config, root_build_dir)
1273 rebase_path(depfile, root_build_dir),
1275 rebase_path(android_sdk, root_build_dir),
1278 "--android-manifest",
1279 rebase_path(android_manifest, root_build_dir),
1280 "--resource-dirs=$rebase_resource_dirs",
1282 rebase_path(srcjar_path, root_build_dir),
1283 "--resource-zip-out",
1284 rebase_path(zip_path, root_build_dir),
1286 rebase_path(r_text_path, root_build_dir),
1287 "--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)",
1288 "--extra-res-packages=@FileArg($rebase_build_config:resources:extra_package_names)",
1289 "--extra-r-text-files=@FileArg($rebase_build_config:resources:extra_r_text_files)",
1292 if (non_constant_id) {
1293 args += [ "--non-constant-id" ]
1296 if (defined(invoker.custom_package)) {
1299 invoker.custom_package,
1303 if (defined(invoker.v14_skip) && invoker.v14_skip) {
1304 args += [ "--v14-skip" ]
1307 if (defined(invoker.shared_resources) && invoker.shared_resources) {
1308 args += [ "--shared-resources" ]
1311 if (defined(invoker.include_all_resources) &&
1312 invoker.include_all_resources) {
1313 args += [ "--include-all-resources" ]
1316 if (defined(invoker.all_resources_zip_path)) {
1317 all_resources_zip = invoker.all_resources_zip_path
1318 outputs += [ all_resources_zip ]
1320 "--all-resources-zip-out",
1321 rebase_path(all_resources_zip, root_build_dir),
1325 if (defined(invoker.args)) {
1326 args += invoker.args
1331 template("copy_ex") {
1332 set_sources_assignment_filter([])
1333 action(target_name) {
1336 forward_variables_from(invoker,
1344 script = "//build/android/gyp/copy_ex.py"
1346 depfile = "$target_gen_dir/$target_name.d"
1353 rebase_path(depfile, root_build_dir),
1355 rebase_path(invoker.dest, root_build_dir),
1357 rebased_sources = rebase_path(sources, root_build_dir)
1358 args += [ "--files=$rebased_sources" ]
1360 if (defined(invoker.clear_dir) && invoker.clear_dir) {
1361 args += [ "--clear" ]
1364 if (defined(invoker.args)) {
1365 args += invoker.args
1370 # Produces a single .dex.jar out of a set of Java dependencies.
1371 template("deps_dex") {
1372 set_sources_assignment_filter([])
1373 build_config = "$target_gen_dir/${target_name}.build_config"
1374 build_config_target_name = "${target_name}__build_config"
1376 write_build_config(build_config_target_name) {
1377 forward_variables_from(invoker,
1383 build_config = build_config
1386 rebased_build_config = rebase_path(build_config, root_build_dir)
1391 output = invoker.dex_path
1392 dex_arg_key = "${rebased_build_config}:final_dex:dependency_dex_files"
1393 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1394 if (defined(invoker.excluded_jars)) {
1395 excluded_jars = rebase_path(invoker.excluded_jars, root_build_dir)
1396 args += [ "--excluded-paths=${excluded_jars}" ]
1399 ":$build_config_target_name",
1404 # Creates an AndroidManifest.xml for an APK split.
1405 template("generate_split_manifest") {
1406 assert(defined(invoker.main_manifest))
1407 assert(defined(invoker.out_manifest))
1408 assert(defined(invoker.split_name))
1410 action(target_name) {
1411 forward_variables_from(invoker,
1416 depfile = "$target_gen_dir/$target_name.d"
1419 rebase_path(invoker.main_manifest, root_build_dir),
1421 rebase_path(invoker.out_manifest, root_build_dir),
1425 if (defined(invoker.version_code)) {
1428 invoker.version_code,
1431 if (defined(invoker.version_name)) {
1434 invoker.version_name,
1437 if (defined(invoker.has_code)) {
1445 rebase_path(depfile, root_build_dir),
1448 script = "//build/android/gyp/generate_split_manifest.py"
1451 invoker.out_manifest,
1454 invoker.main_manifest,
1459 # Generates a script in the output bin directory which runs the test
1460 # target using the test runner script in build/android/test_runner.py.
1461 template("test_runner_script") {
1463 _test_name = invoker.test_name
1464 _test_type = invoker.test_type
1466 action(target_name) {
1467 script = "//build/android/gyp/create_test_runner_script.py"
1468 depfile = "$target_gen_dir/$target_name.d"
1470 test_runner_args = [
1472 "--output-directory",
1473 rebase_path(root_build_dir, root_build_dir),
1475 if (_test_type == "gtest") {
1476 assert(defined(invoker.test_suite))
1477 test_runner_args += [
1481 } else if (_test_type == "instrumentation") {
1482 assert(defined(invoker.test_apk))
1483 test_runner_args += [
1488 assert(false, "Invalid test type: $_test_type.")
1491 if (defined(invoker.isolate_file)) {
1492 test_runner_args += [
1493 "--isolate-file-path",
1494 rebase_path(invoker.isolate_file, root_build_dir),
1498 generated_script = "$root_build_dir/bin/run_${_test_name}"
1505 rebase_path(depfile, root_build_dir),
1506 "--script-output-path",
1507 rebase_path(generated_script, root_build_dir),
1509 args += test_runner_args