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([])
20 if (defined(invoker.testonly)) {
21 testonly = invoker.testonly
24 jar_path = invoker.jar_path
25 android_manifest = invoker.android_manifest
26 java_files = invoker.java_files
27 base_path = "$target_gen_dir/$target_name"
30 script = "//build/android/gyp/lint.py"
31 result_path = base_path + "/result.xml"
32 config_path = base_path + "/config.xml"
33 suppressions_file = "//build/android/lint/suppressions.xml"
45 rebased_java_files = rebase_path(java_files, root_build_dir)
48 "--lint-path=$rebased_android_sdk_root/tools/lint",
50 rebase_path(suppressions_file, root_build_dir),
52 rebase_path(android_manifest, root_build_dir),
55 rebase_path(jar_path, root_build_dir),
56 "--processed-config-path",
57 rebase_path(config_path, root_build_dir),
59 rebase_path(result_path, root_build_dir),
60 "--java-files=$rebased_java_files",
64 if (defined(invoker.deps)) {
67 if (defined(invoker.public_deps)) {
68 public_deps = invoker.public_deps
70 if (defined(invoker.data_deps)) {
71 data_deps = invoker.data_deps
76 template("findbugs") {
77 jar_path = invoker.jar_path
79 build_config = invoker.build_config
82 script = "//build/android/findbugs_diff.py"
83 depfile = "$target_gen_dir/$target_name.d"
84 result_path = "$target_gen_dir/$target_name/result.xml"
85 exclusions_file = "//build/android/findbugs_filter/findbugs_exclude.xml"
87 rebased_build_config = rebase_path(build_config, root_build_dir)
89 if (defined(invoker.deps)) {
93 if (defined(invoker.testonly)) {
94 testonly = invoker.testonly
98 "//build/android/pylib/utils/findbugs.py",
110 rebase_path(depfile, root_build_dir),
112 rebase_path(exclusions_file, root_build_dir),
113 "--auxclasspath-gyp",
114 "@FileArg($rebased_build_config:javac:classpath)",
116 rebase_path(result_path, root_build_dir),
117 rebase_path(jar_path, root_build_dir),
123 set_sources_assignment_filter([])
124 if (defined(invoker.testonly)) {
125 testonly = invoker.testonly
128 assert(defined(invoker.output))
129 action(target_name) {
130 script = "//build/android/gyp/dex.py"
131 depfile = "$target_gen_dir/$target_name.d"
132 if (defined(invoker.sources)) {
133 sources = invoker.sources
139 if (defined(invoker.inputs)) {
140 inputs = invoker.inputs
143 if (defined(invoker.deps)) {
147 rebased_output = rebase_path(invoker.output, root_build_dir)
151 rebase_path(depfile, root_build_dir),
152 "--android-sdk-tools",
153 rebased_android_sdk_build_tools,
158 if (defined(invoker.no_locals) && invoker.no_locals) {
159 args += [ "--no-locals=1" ]
162 if (defined(invoker.args)) {
166 if (defined(invoker.sources)) {
167 args += rebase_path(invoker.sources, root_build_dir)
172 # Creates a zip archive of the inputs.
173 # If base_dir is provided, the archive paths will be relative to it.
175 set_sources_assignment_filter([])
176 if (defined(invoker.testonly)) {
177 testonly = invoker.testonly
180 assert(defined(invoker.inputs))
181 assert(defined(invoker.output))
183 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
184 rebase_output = rebase_path(invoker.output, root_build_dir)
185 action(target_name) {
186 script = "//build/android/gn/zip.py"
187 depfile = "$target_gen_dir/$target_name.d"
188 inputs = invoker.inputs
195 rebase_path(depfile, root_build_dir),
196 "--inputs=$rebase_inputs",
197 "--output=$rebase_output",
199 if (defined(invoker.base_dir)) {
202 rebase_path(invoker.base_dir, root_build_dir),
206 if (defined(invoker.deps)) {
209 if (defined(invoker.public_deps)) {
210 public_deps = invoker.public_deps
212 if (defined(invoker.data_deps)) {
213 data_deps = invoker.data_deps
216 if (defined(invoker.visibility)) {
217 visibility = invoker.visibility
222 # Write the target's .build_config file. This is a json file that contains a
223 # dictionary of information about how to build this target (things that
224 # require knowledge about this target's dependencies and cannot be calculated
225 # at gn-time). There is a special syntax to add a value in that dictionary to
226 # an action/action_foreachs args:
227 # --python-arg=@FileArg($rebased_build_config_path:key0:key1)
228 # At runtime, such an arg will be replaced by the value in the build_config.
229 # See build/android/gyp/write_build_config.py and
230 # build/android/gyp/util/build_utils.py:ExpandFileArgs
231 template("write_build_config") {
232 set_sources_assignment_filter([])
233 if (defined(invoker.testonly)) {
234 testonly = invoker.testonly
237 assert(defined(invoker.type))
238 assert(defined(invoker.build_config))
241 build_config = invoker.build_config
243 assert(type == "android_apk" || type == "java_library" ||
244 type == "android_resources" || type == "deps_dex")
246 action(target_name) {
247 if (defined(invoker.visibility)) {
248 visibility = invoker.visibility
251 script = "//build/android/gyp/write_build_config.py"
252 depfile = "$target_gen_dir/$target_name.d"
256 if (defined(invoker.deps)) {
260 possible_deps_configs = []
262 dep_gen_dir = get_label_info(d, "target_gen_dir")
263 dep_name = get_label_info(d, "name")
264 possible_deps_configs += [ "$dep_gen_dir/$dep_name.build_config" ]
266 rebase_possible_deps_configs =
267 rebase_path(possible_deps_configs, root_build_dir)
278 rebase_path(depfile, root_build_dir),
279 "--possible-deps-configs=$rebase_possible_deps_configs",
281 rebase_path(build_config, root_build_dir),
284 is_java_library = type == "java_library"
285 is_apk = type == "android_apk"
286 is_android_resources = type == "android_resources"
287 is_deps_dex = type == "deps_dex"
289 supports_android = is_apk || is_android_resources || is_deps_dex ||
290 (is_java_library && defined(invoker.supports_android) &&
291 invoker.supports_android)
292 requires_android = is_apk || is_android_resources || is_deps_dex ||
293 (is_java_library && defined(invoker.requires_android) &&
294 invoker.requires_android)
296 assert(!requires_android || supports_android,
297 "requires_android requires" + " supports_android")
299 # Mark these variables as used.
300 assert(is_java_library || true)
301 assert(is_apk || true)
302 assert(is_android_resources || true)
303 assert(is_deps_dex || true)
305 if (is_java_library || is_apk) {
308 rebase_path(invoker.jar_path, root_build_dir),
312 if (is_apk || is_deps_dex || (is_java_library && supports_android)) {
315 rebase_path(invoker.dex_path, root_build_dir),
318 if (supports_android) {
319 args += [ "--supports-android" ]
321 if (requires_android) {
322 args += [ "--requires-android" ]
324 if (defined(invoker.bypass_platform_checks) &&
325 invoker.bypass_platform_checks) {
326 args += [ "--bypass-platform-checks" ]
329 if (defined(invoker.apk_under_test)) {
330 deps += [ invoker.apk_under_test ]
331 apk_under_test_gen_dir =
332 get_label_info(invoker.apk_under_test, "target_gen_dir")
333 apk_under_test_name = get_label_info(invoker.apk_under_test, "name")
334 apk_under_test_config =
335 "$apk_under_test_gen_dir/$apk_under_test_name.build_config"
337 "--tested-apk-config",
338 rebase_path(apk_under_test_config, root_build_dir),
342 if (is_android_resources || is_apk) {
343 assert(defined(invoker.resources_zip))
346 rebase_path(invoker.resources_zip, root_build_dir),
348 if (defined(invoker.android_manifest)) {
349 inputs += [ invoker.android_manifest ]
351 "--android-manifest",
352 rebase_path(invoker.android_manifest, root_build_dir),
355 assert(!is_apk, "apk build configs require an android_manifest")
357 if (defined(invoker.custom_package)) {
360 invoker.custom_package,
363 if (defined(invoker.r_text)) {
366 rebase_path(invoker.r_text, root_build_dir),
372 if (defined(invoker.native_libs)) {
373 inputs += invoker.native_libs
374 rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir)
375 rebased_android_readelf = rebase_path(android_readelf, root_build_dir)
377 "--native-libs=$rebased_native_libs",
378 "--readelf-path=$rebased_android_readelf",
383 if (defined(invoker.srcjar)) {
386 rebase_path(invoker.srcjar, root_build_dir),
392 template("process_java_prebuilt") {
393 set_sources_assignment_filter([])
394 if (defined(invoker.testonly)) {
395 testonly = invoker.testonly
398 _input_jar_path = invoker.input_jar_path
399 _output_jar_path = invoker.output_jar_path
400 _jar_toc_path = _output_jar_path + ".TOC"
402 assert(invoker.build_config != "")
404 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
405 _proguard_jar_path = "$android_sdk_root/tools/proguard/lib/proguard.jar"
406 _proguard_config_path = invoker.proguard_config
407 _build_config = invoker.build_config
408 _rebased_build_config = rebase_path(_build_config, root_build_dir)
409 _output_jar_target = "${target_name}__proguard_process"
410 action(_output_jar_target) {
411 script = "//build/android/gyp/proguard.py"
417 _proguard_config_path,
419 depfile = "${target_gen_dir}/${target_name}.d"
426 rebase_path(depfile, root_build_dir),
428 rebase_path(_proguard_jar_path, root_build_dir),
430 rebase_path(_input_jar_path, root_build_dir),
432 rebase_path(_output_jar_path, root_build_dir),
434 rebase_path(_proguard_config_path, root_build_dir),
436 rebased_android_sdk_jar,
437 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
440 if (defined(invoker.deps)) {
443 if (defined(invoker.public_deps)) {
444 public_deps = invoker.public_deps
446 if (defined(invoker.data_deps)) {
447 data_deps = invoker.data_deps
451 _output_jar_target = "${target_name}__copy_jar"
452 copy(_output_jar_target) {
460 if (defined(invoker.deps)) {
463 if (defined(invoker.public_deps)) {
464 public_deps = invoker.public_deps
466 if (defined(invoker.data_deps)) {
467 data_deps = invoker.data_deps
472 action("${target_name}__jar_toc") {
473 script = "//build/android/gyp/jar_toc.py"
474 depfile = "$target_gen_dir/$target_name.d"
478 _jar_toc_path + ".md5.stamp",
485 rebase_path(depfile, root_build_dir),
487 rebase_path(_output_jar_path, root_build_dir),
489 rebase_path(_jar_toc_path, root_build_dir),
492 ":$_output_jar_target",
497 if (defined(invoker.visibility)) {
498 visibility = invoker.visibility
501 ":${target_name}__jar_toc",
502 ":$_output_jar_target",
507 template("finalize_apk") {
508 action(target_name) {
509 script = "//build/android/gyp/finalize_apk.py"
510 depfile = "$target_gen_dir/$target_name.d"
512 if (defined(invoker.testonly)) {
513 testonly = invoker.testonly
517 invoker.input_apk_path,
520 invoker.keystore_path,
524 invoker.output_apk_path,
529 rebase_path(depfile, root_build_dir),
531 rebase_path(zipalign_path, root_build_dir),
532 "--unsigned-apk-path",
533 rebase_path(invoker.input_apk_path, root_build_dir),
535 rebase_path(invoker.output_apk_path, root_build_dir),
537 rebase_path(invoker.keystore_path, root_build_dir),
539 invoker.keystore_name,
541 invoker.keystore_password,
543 if (defined(invoker.rezip_apk) && invoker.rezip_apk) {
544 _rezip_jar_path = "$root_build_dir/lib.java/rezip_apk.jar"
545 inputs += [ _rezip_jar_path ]
547 "--load-library-from-zip=1",
548 "--rezip-apk-jar-path",
549 rebase_path(_rezip_jar_path, root_build_dir),
553 if (defined(invoker.deps)) {
556 if (defined(invoker.public_deps)) {
557 public_deps = invoker.public_deps
559 if (defined(invoker.data_deps)) {
560 data_deps = invoker.data_deps
565 # Packages resources, assets, dex, and native libraries into an apk. Signs and
567 template("create_apk") {
568 set_sources_assignment_filter([])
569 if (defined(invoker.testonly)) {
570 testonly = invoker.testonly
573 _android_manifest = invoker.android_manifest
574 _base_path = invoker.base_path
575 _final_apk_path = invoker.apk_path
577 if (defined(invoker.resources_zip)) {
578 _resources_zip = invoker.resources_zip
580 if (defined(invoker.dex_path)) {
581 _dex_path = invoker.dex_path
583 _load_library_from_apk = invoker.load_library_from_apk
586 if (defined(invoker.deps)) {
587 _package_deps = invoker.deps
590 _native_libs_dir = "//build/android/empty/res"
591 if (defined(invoker.native_libs_dir)) {
592 _native_libs_dir = invoker.native_libs_dir
595 if (defined(invoker.asset_location)) {
596 _asset_location = invoker.asset_location
599 _version_code = invoker.version_code
600 _version_name = invoker.version_name
602 _base_apk_path = _base_path + ".apk_intermediates"
604 _resource_packaged_apk_path = _base_apk_path + ".ap_"
605 _packaged_apk_path = _base_apk_path + ".unfinished.apk"
607 defined(invoker.shared_resources) && invoker.shared_resources
609 _configuration_name = "Release"
611 _configuration_name = "Debug"
614 _keystore_path = invoker.keystore_path
615 _keystore_name = invoker.keystore_name
616 _keystore_password = invoker.keystore_password
618 _split_densities = []
619 if (defined(invoker.create_density_splits) && invoker.create_density_splits) {
629 _split_languages = []
630 if (defined(invoker.language_splits)) {
631 _split_languages = invoker.language_splits
634 _package_resources_target_name = "${target_name}__package_resources"
635 action(_package_resources_target_name) {
638 script = "//build/android/gyp/package_resources.py"
639 depfile = "${target_gen_dir}/${target_name}.d"
643 if (defined(_resources_zip)) {
644 inputs += [ _resources_zip ]
648 _resource_packaged_apk_path,
653 rebase_path(depfile, root_build_dir),
658 "--configuration-name=$_configuration_name",
659 "--android-manifest",
660 rebase_path(_android_manifest, root_build_dir),
666 rebase_path(_resource_packaged_apk_path, root_build_dir),
669 if (defined(_asset_location)) {
672 rebase_path(_asset_location, root_build_dir),
675 if (defined(_resources_zip)) {
678 rebase_path(_resources_zip, root_build_dir),
681 if (_shared_resources) {
682 args += [ "--shared-resources" ]
684 if (_split_densities != []) {
685 args += [ "--create-density-splits" ]
686 foreach(_density, _split_densities) {
687 outputs += [ "${_resource_packaged_apk_path}_${_density}" ]
690 if (_split_languages != []) {
691 args += [ "--language-splits=$_split_languages" ]
692 foreach(_language, _split_languages) {
693 outputs += [ "${_resource_packaged_apk_path}_${_language}" ]
696 if (defined(invoker.extensions_to_not_compress)) {
699 invoker.extensions_to_not_compress,
704 package_target = "${target_name}__package"
705 action(package_target) {
706 script = "//build/android/gyp/ant.py"
707 _ant_script = "//build/android/ant/apk-package.xml"
710 ":${_package_resources_target_name}",
712 if (defined(invoker.deps)) {
715 depfile = "$target_gen_dir/$target_name.d"
718 _resource_packaged_apk_path,
721 if (defined(_dex_path)) {
722 inputs += [ _dex_path ]
730 _rebased_emma_jar = ""
731 _rebased_resource_packaged_apk_path =
732 rebase_path(_resource_packaged_apk_path, root_build_dir)
733 _rebased_packaged_apk_path = rebase_path(_packaged_apk_path, root_build_dir)
734 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
737 rebase_path(depfile, root_build_dir),
740 "-DANDROID_SDK_ROOT=$rebased_android_sdk_root",
741 "-DANDROID_SDK_TOOLS=$rebased_android_sdk_build_tools",
742 "-DRESOURCE_PACKAGED_APK_NAME=$_rebased_resource_packaged_apk_path",
743 "-DCONFIGURATION_NAME=$_configuration_name",
744 "-DNATIVE_LIBS_DIR=$_rebased_native_libs_dir",
746 "-DUNSIGNED_APK_PATH=$_rebased_packaged_apk_path",
747 "-DEMMA_INSTRUMENT=0",
748 "-DEMMA_DEVICE_JAR=$_rebased_emma_jar",
751 rebase_path(_ant_script, root_build_dir),
753 if (defined(_dex_path)) {
754 _rebased_dex_path = rebase_path(_dex_path, root_build_dir)
756 "-DDEX_FILE_PATH=$_rebased_dex_path",
760 args += [ "-DHAS_CODE=false" ]
764 _finalize_apk_rule_name = "${target_name}__finalize"
765 finalize_apk(_finalize_apk_rule_name) {
766 input_apk_path = _packaged_apk_path
767 output_apk_path = _final_apk_path
768 keystore_path = _keystore_path
769 keystore_name = _keystore_name
770 keystore_password = _keystore_password
771 rezip_apk = _load_library_from_apk
774 # Generator of the _packaged_apk_path this target takes as input.
779 _final_deps = [ ":${_finalize_apk_rule_name}" ]
781 template("finalize_split") {
782 finalize_apk(target_name) {
783 _config = invoker.split_config
784 _type = invoker.split_type
785 input_apk_path = "${_resource_packaged_apk_path}_${_config}"
786 _output_paths = process_file_template(
788 "{{source_dir}}/{{source_name_part}}-${_type}-${_config}.apk")
789 output_apk_path = _output_paths[0]
790 keystore_path = _keystore_path
791 keystore_name = _keystore_name
792 keystore_password = _keystore_password
794 ":${_package_resources_target_name}",
799 foreach(_split, _split_densities) {
800 _split_rule = "${target_name}__finalize_${_split}_split"
801 finalize_split(_split_rule) {
802 split_type = "density"
803 split_config = _split
805 _final_deps += [ ":$_split_rule" ]
807 foreach(_split, _split_languages) {
808 _split_rule = "${target_name}__finalize_${_split}_split"
809 finalize_split(_split_rule) {
811 split_config = _split
813 _final_deps += [ ":$_split_rule" ]
817 public_deps = _final_deps
821 template("java_prebuilt_impl") {
822 set_sources_assignment_filter([])
823 if (defined(invoker.testonly)) {
824 testonly = invoker.testonly
827 defined(invoker.supports_android) && invoker.supports_android
829 assert(defined(invoker.jar_path))
830 _base_path = "${target_gen_dir}/$target_name"
831 _jar_path = _base_path + ".jar"
832 _build_config = _base_path + ".build_config"
834 if (_supports_android) {
835 _dex_path = _base_path + ".dex.jar"
838 if (defined(invoker.deps)) {
842 if (defined(invoker.jar_dep)) {
843 _jar_deps = [ invoker.jar_dep ]
846 _template_name = target_name
848 build_config_target_name = "${_template_name}__build_config"
849 process_jar_target_name = "${_template_name}__process_jar"
850 if (_supports_android) {
851 dex_target_name = "${_template_name}__dex"
854 write_build_config(build_config_target_name) {
855 type = "java_library"
856 supports_android = _supports_android
858 defined(invoker.requires_android) && invoker.requires_android
861 build_config = _build_config
863 if (_supports_android) {
868 process_java_prebuilt(process_jar_target_name) {
869 visibility = [ ":$_template_name" ]
870 if (_supports_android) {
871 visibility += [ ":$dex_target_name" ]
874 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
875 proguard_preprocess = true
876 proguard_config = invoker.proguard_config
879 build_config = _build_config
880 input_jar_path = invoker.jar_path
881 output_jar_path = _jar_path
883 deps = [ ":$build_config_target_name" ] + _deps + _jar_deps
886 if (_supports_android) {
887 dex(dex_target_name) {
892 deps = [ ":$process_jar_target_name" ] + _deps + _jar_deps
898 ":$process_jar_target_name",
900 if (defined(invoker.data_deps)) {
901 data_deps = invoker.data_deps
903 if (_supports_android) {
904 deps += [ ":$dex_target_name" ]
909 # Compiles and jars a set of java files.
916 # java_files: List of .java files to compile.
917 # java_deps: List of java dependencies. These should all have a .jar output
918 # at "${target_gen_dir}/${target_name}.jar.
919 # chromium_code: If true, enable extra warnings.
920 # srcjar_deps: List of srcjar dependencies. The .java files contained in the
921 # dependencies srcjar outputs will be compiled and added to the output jar.
922 # jar_path: Use this to explicitly set the output jar path. Defaults to
923 # "${target_gen_dir}/${target_name}.jar.
924 template("compile_java") {
925 set_sources_assignment_filter([])
926 if (defined(invoker.testonly)) {
927 testonly = invoker.testonly
930 assert(defined(invoker.java_files))
931 assert(defined(invoker.build_config))
932 assert(defined(invoker.jar_path))
934 _java_files = invoker.java_files
935 _final_jar_path = invoker.jar_path
936 _intermediate_jar_path = "$target_gen_dir/$target_name.initial.jar"
938 _build_config = invoker.build_config
940 _jar_excluded_patterns = []
941 if (defined(invoker.jar_excluded_patterns)) {
942 _jar_excluded_patterns += invoker.jar_excluded_patterns
945 _chromium_code = false
946 if (defined(invoker.chromium_code)) {
947 _chromium_code = invoker.chromium_code
950 _supports_android = true
951 if (defined(invoker.supports_android)) {
952 _supports_android = invoker.supports_android
955 _enable_errorprone = use_errorprone_java_compiler
956 if (defined(invoker.enable_errorprone)) {
957 _enable_errorprone = invoker.enable_errorprone
960 _manifest_entries = []
961 if (defined(invoker.manifest_entries)) {
962 _manifest_entries = invoker.manifest_entries
966 if (defined(invoker.srcjar_deps)) {
967 _srcjar_deps += invoker.srcjar_deps
971 if (defined(invoker.srcjars)) {
972 _java_srcjars = invoker.srcjars
974 foreach(dep, _srcjar_deps) {
975 _dep_gen_dir = get_label_info(dep, "target_gen_dir")
976 _dep_name = get_label_info(dep, "name")
977 _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ]
980 # Mark srcjar_deps as used.
981 assert(_srcjar_deps == [] || true)
984 if (defined(invoker.android) && invoker.android) {
985 _system_jars += [ android_sdk_jar ]
988 _rebased_build_config = rebase_path(_build_config, root_build_dir)
989 _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir)
991 javac_target_name = "${target_name}__javac"
992 finish_target_name = "${target_name}__finish"
993 final_target_name = target_name
995 action(javac_target_name) {
996 script = "//build/android/gyp/javac.py"
997 depfile = "$target_gen_dir/$target_name.d"
999 if (defined(invoker.deps)) {
1000 deps += invoker.deps
1005 _intermediate_jar_path,
1006 _intermediate_jar_path + ".md5.stamp",
1008 sources = _java_files + _java_srcjars
1009 inputs = _system_jars + [ _build_config ]
1011 _rebased_system_jars = rebase_path(_system_jars, root_build_dir)
1012 _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
1013 _rebased_depfile = rebase_path(depfile, root_build_dir)
1015 "--depfile=$_rebased_depfile",
1016 "--classpath=$_rebased_system_jars",
1017 "--classpath=@FileArg($_rebased_build_config:javac:classpath)",
1018 "--jar-path=$_rebased_jar_path",
1019 "--java-srcjars=$_rebased_java_srcjars",
1020 "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)",
1021 "--jar-excluded-classes=$_jar_excluded_patterns",
1023 if (_supports_android) {
1024 _rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir)
1025 args += [ "--bootclasspath=$_rebased_android_sdk_jar" ]
1027 foreach(e, _manifest_entries) {
1028 args += [ "--manifest-entry=" + e ]
1030 if (_chromium_code) {
1031 args += [ "--chromium-code=1" ]
1033 if (_enable_errorprone) {
1034 deps += [ "//third_party/errorprone:chromium_errorprone" ]
1036 "--use-errorprone-path",
1037 "bin/chromium_errorprone",
1040 args += rebase_path(_java_files, root_build_dir)
1043 process_java_prebuilt(finish_target_name) {
1044 visibility = [ ":$final_target_name" ]
1046 build_config = _build_config
1047 input_jar_path = _intermediate_jar_path
1048 output_jar_path = _final_jar_path
1049 if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) {
1050 proguard_preprocess = invoker.proguard_preprocess
1051 proguard_config = invoker.proguard_config
1054 ":$javac_target_name",
1058 group(final_target_name) {
1059 if (defined(invoker.visibility)) {
1060 visibility = invoker.visibility
1063 ":$finish_target_name",
1068 template("java_library_impl") {
1069 set_sources_assignment_filter([])
1070 if (defined(invoker.testonly)) {
1071 testonly = invoker.testonly
1075 defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir) ||
1076 defined(invoker.srcjars) || defined(invoker.srcjar_deps))
1077 _base_path = "$target_gen_dir/$target_name"
1078 _jar_path = _base_path + ".jar"
1079 if (defined(invoker.jar_path)) {
1080 _jar_path = invoker.jar_path
1082 _template_name = target_name
1085 _final_datadeps = []
1086 if (defined(invoker.datadeps)) {
1087 _final_datadeps = invoker.datadeps
1091 defined(invoker.supports_android) && invoker.supports_android
1093 defined(invoker.requires_android) && invoker.requires_android
1095 if (_supports_android) {
1096 _dex_path = _base_path + ".dex.jar"
1097 if (defined(invoker.dex_path)) {
1098 _dex_path = invoker.dex_path
1102 # Define build_config_deps which will be a list of targets required to
1103 # build the _build_config.
1104 if (defined(invoker.override_build_config)) {
1105 _build_config = invoker.override_build_config
1107 # When a custom build config file is specified, we need to use the deps
1108 # supplied by the invoker any time we reference the build config file.
1109 assert(defined(invoker.deps),
1110 "If you specify a build config file for " +
1111 "java_library_impl($target_name), you should " +
1112 "also specify the target that made it in the deps")
1113 build_config_deps = invoker.deps
1115 _build_config = _base_path + ".build_config"
1116 build_config_target_name = "${_template_name}__build_config"
1117 build_config_deps = [ ":$build_config_target_name" ]
1119 write_build_config(build_config_target_name) {
1120 type = "java_library"
1121 supports_android = _supports_android
1122 requires_android = _requires_android
1123 bypass_platform_checks = defined(invoker.bypass_platform_checks) &&
1124 invoker.bypass_platform_checks
1127 if (defined(invoker.deps)) {
1128 deps += invoker.deps
1131 build_config = _build_config
1132 jar_path = _jar_path
1133 if (_supports_android) {
1134 dex_path = _dex_path
1139 _chromium_code = true
1140 if (defined(invoker.chromium_code)) {
1141 _chromium_code = invoker.chromium_code
1145 if (defined(invoker.srcjar_deps)) {
1146 _srcjar_deps = invoker.srcjar_deps
1150 if (defined(invoker.srcjars)) {
1151 _srcjars = invoker.srcjars
1155 if (defined(invoker.java_files)) {
1156 _java_files = invoker.java_files
1157 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1158 _src_dir = invoker.DEPRECATED_java_in_dir + "/src"
1159 _src_dir_exists = exec_script("//build/dir_exists.py",
1160 [ rebase_path(_src_dir, root_build_dir) ],
1162 assert(_src_dir_exists == "False",
1163 "In GN, java_in_dir should be the fully specified java directory " +
1164 "(i.e. including the trailing \"/src\")")
1166 _java_files_build_rel = exec_script(
1167 "//build/android/gyp/find.py",
1171 rebase_path(invoker.DEPRECATED_java_in_dir, root_build_dir),
1174 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1176 assert(_java_files != [] || _srcjar_deps != [] || _srcjars != [])
1178 _compile_java_target = "${_template_name}__compile_java"
1179 _final_deps += [ ":$_compile_java_target" ]
1180 compile_java(_compile_java_target) {
1181 jar_path = _jar_path
1182 build_config = _build_config
1183 java_files = _java_files
1184 srcjar_deps = _srcjar_deps
1186 chromium_code = _chromium_code
1187 android = _requires_android
1189 if (defined(invoker.enable_errorprone)) {
1190 enable_errorprone = invoker.enable_errorprone
1192 if (defined(invoker.jar_excluded_patterns)) {
1193 jar_excluded_patterns = invoker.jar_excluded_patterns
1195 if (defined(invoker.proguard_preprocess)) {
1196 proguard_preprocess = invoker.proguard_preprocess
1198 if (defined(invoker.proguard_config)) {
1199 proguard_config = invoker.proguard_config
1201 if (defined(invoker.dist_jar_path)) {
1202 dist_jar_path = invoker.dist_jar_path
1204 if (defined(invoker.manifest_entries)) {
1205 manifest_entries = invoker.manifest_entries
1208 supports_android = _supports_android
1209 deps = build_config_deps
1212 if (defined(invoker.main_class)) {
1213 _final_deps += [ ":${_template_name}__binary_script" ]
1214 action("${_template_name}__binary_script") {
1215 script = "//build/android/gyp/create_java_binary_script.py"
1216 depfile = "$target_gen_dir/$target_name.d"
1217 java_script = "$root_build_dir/bin/$_template_name"
1225 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1228 rebase_path(depfile, root_build_dir),
1230 rebase_path(java_script, root_build_dir),
1231 "--classpath=@FileArg($_rebased_build_config:java:full_classpath)",
1233 rebase_path(_jar_path, root_build_dir),
1238 deps = build_config_deps
1242 if (_supports_android) {
1243 if (defined(invoker.chromium_code) && invoker.chromium_code) {
1244 _android_manifest = "//build/android/AndroidManifest.xml"
1245 if (defined(invoker.android_manifest)) {
1246 _android_manifest = invoker.android_manifest
1249 _final_datadeps += [ ":${_template_name}__lint" ]
1250 android_lint("${_template_name}__lint") {
1251 android_manifest = _android_manifest
1252 jar_path = _jar_path
1253 java_files = _java_files
1255 ":$_compile_java_target",
1257 if (defined(invoker.deps)) {
1258 deps += invoker.deps
1263 _final_datadeps += [ ":${_template_name}__findbugs" ]
1264 findbugs("${_template_name}__findbugs") {
1265 build_config = _build_config
1266 jar_path = _jar_path
1267 deps = build_config_deps
1272 _final_deps += [ ":${_template_name}__dex" ]
1273 dex("${_template_name}__dex") {
1279 ":$_compile_java_target",
1284 group(target_name) {
1285 if (defined(invoker.visibility)) {
1286 visibility = invoker.visibility
1288 public_deps = _final_deps
1289 data_deps = _final_datadeps
1293 # Runs process_resources.py
1294 template("process_resources") {
1295 set_sources_assignment_filter([])
1296 if (defined(invoker.testonly)) {
1297 testonly = invoker.testonly
1300 zip_path = invoker.zip_path
1301 srcjar_path = invoker.srcjar_path
1302 r_text_path = invoker.r_text_path
1303 build_config = invoker.build_config
1304 resource_dirs = invoker.resource_dirs
1305 android_manifest = invoker.android_manifest
1307 non_constant_id = true
1308 if (defined(invoker.generate_constant_ids) && invoker.generate_constant_ids) {
1309 non_constant_id = false
1312 action(target_name) {
1313 if (defined(invoker.visibility)) {
1314 visibility = invoker.visibility
1317 script = "//build/android/gyp/process_resources.py"
1319 depfile = "$target_gen_dir/$target_name.d"
1327 sources_build_rel = exec_script("//build/android/gyp/find.py",
1328 rebase_path(resource_dirs, root_build_dir),
1330 sources = rebase_path(sources_build_rel, ".", root_build_dir)
1337 rebase_resource_dirs = rebase_path(resource_dirs, root_build_dir)
1338 rebase_build_config = rebase_path(build_config, root_build_dir)
1341 rebase_path(depfile, root_build_dir),
1343 rebase_path(android_sdk, root_build_dir),
1346 "--android-manifest",
1347 rebase_path(android_manifest, root_build_dir),
1348 "--resource-dirs=$rebase_resource_dirs",
1350 rebase_path(srcjar_path, root_build_dir),
1351 "--resource-zip-out",
1352 rebase_path(zip_path, root_build_dir),
1354 rebase_path(r_text_path, root_build_dir),
1355 "--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)",
1356 "--extra-res-packages=@FileArg($rebase_build_config:resources:extra_package_names)",
1357 "--extra-r-text-files=@FileArg($rebase_build_config:resources:extra_r_text_files)",
1360 if (non_constant_id) {
1361 args += [ "--non-constant-id" ]
1364 if (defined(invoker.custom_package)) {
1367 invoker.custom_package,
1371 if (defined(invoker.v14_skip) && invoker.v14_skip) {
1372 args += [ "--v14-skip" ]
1375 if (defined(invoker.shared_resources) && invoker.shared_resources) {
1376 args += [ "--shared-resources" ]
1379 if (defined(invoker.include_all_resources) &&
1380 invoker.include_all_resources) {
1381 args += [ "--include-all-resources" ]
1384 if (defined(invoker.all_resources_zip_path)) {
1385 all_resources_zip = invoker.all_resources_zip_path
1386 outputs += [ all_resources_zip ]
1388 "--all-resources-zip-out",
1389 rebase_path(all_resources_zip, root_build_dir),
1393 if (defined(invoker.args)) {
1394 args += invoker.args
1396 if (defined(invoker.deps)) {
1402 template("copy_ex") {
1403 set_sources_assignment_filter([])
1404 if (defined(invoker.testonly)) {
1405 testonly = invoker.testonly
1408 action(target_name) {
1409 if (defined(invoker.visibility)) {
1410 visibility = invoker.visibility
1413 script = "//build/android/gyp/copy_ex.py"
1415 if (defined(invoker.deps)) {
1420 if (defined(invoker.sources)) {
1421 sources += invoker.sources
1425 if (defined(invoker.inputs)) {
1426 inputs += invoker.inputs
1429 depfile = "$target_gen_dir/$target_name.d"
1436 rebase_path(depfile, root_build_dir),
1438 rebase_path(invoker.dest, root_build_dir),
1440 rebased_sources = rebase_path(sources, root_build_dir)
1441 args += [ "--files=$rebased_sources" ]
1443 if (defined(invoker.clear_dir) && invoker.clear_dir) {
1444 args += [ "--clear" ]
1447 if (defined(invoker.args)) {
1448 args += invoker.args
1453 # Produces a single .dex.jar out of a set of Java dependencies.
1454 template("deps_dex") {
1455 set_sources_assignment_filter([])
1456 build_config = "$target_gen_dir/${target_name}.build_config"
1457 build_config_target_name = "${target_name}__build_config"
1459 write_build_config(build_config_target_name) {
1463 build_config = build_config
1464 dex_path = invoker.dex_path
1467 rebased_build_config = rebase_path(build_config, root_build_dir)
1472 output = invoker.dex_path
1473 dex_arg_key = "${rebased_build_config}:final_dex:dependency_dex_files"
1474 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1475 if (defined(invoker.excluded_jars)) {
1476 excluded_jars = rebase_path(invoker.excluded_jars, root_build_dir)
1477 args += [ "--excluded-paths=${excluded_jars}" ]
1480 ":$build_config_target_name",
1485 # Creates an AndroidManifest.xml for an APK split.
1486 template("generate_split_manifest") {
1487 assert(defined(invoker.main_manifest))
1488 assert(defined(invoker.out_manifest))
1489 assert(defined(invoker.split_name))
1491 action(target_name) {
1492 depfile = "$target_gen_dir/$target_name.d"
1493 if (defined(invoker.deps)) {
1498 rebase_path(invoker.main_manifest, root_build_dir),
1500 rebase_path(invoker.out_manifest, root_build_dir),
1504 if (defined(invoker.version_code)) {
1507 invoker.version_code,
1510 if (defined(invoker.version_name)) {
1513 invoker.version_name,
1516 if (defined(invoker.has_code)) {
1524 rebase_path(depfile, root_build_dir),
1527 script = "//build/android/gyp/generate_split_manifest.py"
1530 invoker.out_manifest,
1533 invoker.main_manifest,
1538 # Generates a script in the output bin directory which runs the test
1539 # target using the test runner script in build/android/test_runner.py.
1540 template("test_runner_script") {
1542 _test_name = invoker.test_name
1543 _test_type = invoker.test_type
1545 action(target_name) {
1546 script = "//build/android/gyp/create_test_runner_script.py"
1547 depfile = "$target_gen_dir/$target_name.d"
1549 test_runner_args = [
1551 "--output-directory",
1552 rebase_path(root_build_dir, root_build_dir),
1554 if (_test_type == "gtest") {
1555 assert(defined(invoker.test_suite))
1556 test_runner_args += [
1560 } else if (_test_type == "instrumentation") {
1561 assert(defined(invoker.test_apk))
1562 test_runner_args += [
1567 assert(false, "Invalid test type: $_test_type.")
1570 if (defined(invoker.isolate_file)) {
1571 test_runner_args += [
1572 "--isolate-file-path",
1573 rebase_path(invoker.isolate_file, root_build_dir),
1577 generated_script = "$root_build_dir/bin/run_${_test_name}"
1584 rebase_path(depfile, root_build_dir),
1585 "--script-output-path",
1586 rebase_path(generated_script, root_build_dir),
1588 args += test_runner_args