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("//base/android/linker/config.gni")
6 import("//build/config/android/config.gni")
7 import("//build/config/android/internal_rules.gni")
8 import("//third_party/android_platform/config.gni")
9 import("//tools/grit/grit_rule.gni")
13 # Declare a jni target
15 # This target generates the native jni bindings for a set of .java files.
17 # See base/android/jni_generator/jni_generator.py for more info about the
18 # format of generating JNI bindings.
21 # sources: list of .java files to generate jni for
22 # jni_package: subdirectory path for generated bindings
25 # generate_jni("foo_jni") {
27 # "android/java/src/org/chromium/foo/Foo.java",
28 # "android/java/src/org/chromium/foo/FooUtil.java",
32 template("generate_jni") {
33 set_sources_assignment_filter([])
34 if (defined(invoker.testonly)) {
35 testonly = invoker.testonly
38 assert(defined(invoker.sources))
39 assert(defined(invoker.jni_package))
40 jni_package = invoker.jni_package
41 base_output_dir = "${target_gen_dir}/${target_name}"
42 package_output_dir = "${base_output_dir}/${jni_package}"
43 jni_output_dir = "${package_output_dir}/jni"
45 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
47 foreach_target_name = "${target_name}__jni_gen"
48 action_foreach(foreach_target_name) {
49 script = "//base/android/jni_generator/jni_generator.py"
50 depfile = "$target_gen_dir/$target_name.{{source_name_part}}.d"
51 sources = invoker.sources
54 "${jni_output_dir}/{{source_name_part}}_jni.h",
59 rebase_path(depfile, root_build_dir),
60 "--input_file={{source}}",
61 "--optimize_generation=1",
64 rebase_path(jni_output_dir, root_build_dir),
66 rebase_path(jni_generator_include, jni_output_dir),
67 "--native_exports_optional",
69 if (defined(invoker.jni_generator_jarjar_file)) {
72 rebase_path(jni_generator_jarjar_file, root_build_dir),
77 config("jni_includes_${target_name}") {
78 # TODO(cjhopman): #includes should probably all be relative to
79 # base_output_dir. Remove that from this config once the includes are
89 ":$foreach_target_name",
91 public_configs = [ ":jni_includes_${target_name}" ]
93 if (defined(invoker.deps)) {
96 if (defined(invoker.public_deps)) {
97 public_deps = invoker.public_deps
100 if (defined(invoker.visibility)) {
101 visibility = invoker.visibility
106 # Declare a jni target for a prebuilt jar
108 # This target generates the native jni bindings for a set of classes in a .jar.
110 # See base/android/jni_generator/jni_generator.py for more info about the
111 # format of generating JNI bindings.
114 # classes: list of .class files in the jar to generate jni for. These should
115 # include the full path to the .class file.
116 # jni_package: subdirectory path for generated bindings
117 # jar_file: the path to the .jar. If not provided, will default to the sdk's
120 # deps, public_deps: As normal
123 # generate_jar_jni("foo_jni") {
125 # "android/view/Foo.class",
127 # jni_package = "foo"
129 template("generate_jar_jni") {
130 set_sources_assignment_filter([])
131 if (defined(invoker.testonly)) {
132 testonly = invoker.testonly
135 assert(defined(invoker.classes))
136 assert(defined(invoker.jni_package))
138 if (defined(invoker.jar_file)) {
139 jar_file = invoker.jar_file
141 jar_file = android_sdk_jar
144 jni_package = invoker.jni_package
145 base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}"
146 jni_output_dir = "${base_output_dir}/jni"
148 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
150 # TODO(cjhopman): make jni_generator.py support generating jni for multiple
151 # .class files from a .jar.
153 foreach(class, invoker.classes) {
155 _classname_list = process_file_template([ class ], "{{source_name_part}}")
156 classname = _classname_list[0]
157 jni_target_name = "${target_name}__jni_${classname}"
158 jni_actions += [ ":$jni_target_name" ]
159 action(jni_target_name) {
160 # The sources aren't compiled so don't check their dependencies.
161 check_includes = false
162 depfile = "$target_gen_dir/$target_name.d"
163 script = "//base/android/jni_generator/jni_generator.py"
169 "${jni_output_dir}/${classname}_jni.h",
174 rebase_path(depfile, root_build_dir),
176 rebase_path(jar_file, root_build_dir),
179 "--optimize_generation=1",
182 rebase_path(jni_output_dir, root_build_dir),
184 rebase_path(jni_generator_include, jni_output_dir),
185 "--native_exports_optional",
190 config("jni_includes_${target_name}") {
191 include_dirs = [ base_output_dir ]
196 if (defined(invoker.deps)) {
199 if (defined(invoker.public_deps)) {
200 public_deps = invoker.public_deps
202 public_configs = [ ":jni_includes_${target_name}" ]
206 # Declare a target for c-preprocessor-generated java files
208 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
211 # This target generates java files using the host C pre-processor. Each file in
212 # sources will be compiled using the C pre-processor. If include_path is
213 # specified, it will be passed (with --I) to the pre-processor.
215 # This target will create a single .srcjar. Adding this target to an
216 # android_library target's srcjar_deps will make the generated java files be
217 # included in that library's final outputs.
220 # sources: list of files to be processed by the C pre-processor. For each
221 # file in sources, there will be one .java file in the final .srcjar. For a
222 # file named FooBar.template, a java file will be created with name
224 # inputs: additional compile-time dependencies. Any files
225 # `#include`-ed in the templates should be listed here.
226 # package_name: this will be the subdirectory for each .java file in the
230 # java_cpp_template("foo_generated_enum") {
232 # "android/java/templates/Foo.template",
235 # "android/java/templates/native_foo_header.h",
238 # package_name = "org/chromium/base/library_loader"
239 # include_path = "android/java/templates"
241 template("java_cpp_template") {
242 set_sources_assignment_filter([])
243 if (defined(invoker.testonly)) {
244 testonly = invoker.testonly
247 assert(defined(invoker.sources))
248 package_name = invoker.package_name + ""
250 if (defined(invoker.include_path)) {
251 include_path = invoker.include_path + ""
256 apply_gcc_target_name = "${target_name}__apply_gcc"
257 zip_srcjar_target_name = "${target_name}__zip_srcjar"
258 final_target_name = target_name
260 action_foreach(apply_gcc_target_name) {
261 visibility = [ ":$zip_srcjar_target_name" ]
262 script = "//build/android/gyp/gcc_preprocess.py"
263 if (defined(invoker.inputs)) {
264 inputs = invoker.inputs + []
266 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
268 sources = invoker.sources
270 if (defined(invoker.deps)) {
273 if (defined(invoker.public_deps)) {
274 public_deps = invoker.public_deps
276 if (defined(invoker.data_deps)) {
277 data_deps = invoker.data_deps
281 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
282 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
286 gcc_template_output_pattern,
291 rebase_path(depfile, root_build_dir),
293 rebase_path(include_path, root_build_dir),
295 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
296 "--template={{source}}",
299 if (defined(invoker.defines)) {
300 foreach(def, invoker.defines) {
309 apply_gcc_outputs = get_target_outputs(":$apply_gcc_target_name")
310 base_gen_dir = get_label_info(":$apply_gcc_target_name", "target_gen_dir")
312 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
313 zip(zip_srcjar_target_name) {
314 visibility = [ ":$final_target_name" ]
315 inputs = apply_gcc_outputs
317 base_dir = base_gen_dir
319 ":$apply_gcc_target_name",
323 group(final_target_name) {
324 if (defined(invoker.visibility)) {
325 visibility = invoker.visibility
328 ":$zip_srcjar_target_name",
333 # Declare a target for generating Java classes from C++ enums.
335 # This target generates Java files from C++ enums using a script.
337 # This target will create a single .srcjar. Adding this target to an
338 # android_library target's srcjar_deps will make the generated java files be
339 # included in that library's final outputs.
342 # sources: list of files to be processed by the script. For each annotated
343 # enum contained in the sources files the script will generate a .java
344 # file with the same name as the name of the enum.
346 # outputs: list of outputs, relative to the output_dir. These paths are
347 # verified at build time by the script. To get the list programatically run:
348 # python build/android/gyp/java_cpp_enum.py \
349 # --print_output_only . path/to/header/file.h
352 # java_cpp_enum("foo_generated_enum") {
354 # "src/native_foo_header.h",
357 # "org/chromium/FooEnum.java",
360 template("java_cpp_enum") {
361 set_sources_assignment_filter([])
362 if (defined(invoker.testonly)) {
363 testonly = invoker.testonly
366 assert(defined(invoker.sources))
367 assert(defined(invoker.outputs))
369 generate_enum_target_name = "${target_name}__generate_enum"
370 zip_srcjar_target_name = "${target_name}__zip_srcjar"
371 final_target_name = target_name
373 action(generate_enum_target_name) {
374 visibility = [ ":$zip_srcjar_target_name" ]
376 # The sources aren't compiled so don't check their dependencies.
377 check_includes = false
379 sources = invoker.sources
380 script = "//build/android/gyp/java_cpp_enum.py"
381 gen_dir = "${target_gen_dir}/${target_name}/enums"
383 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
386 foreach(output, rebase_path(outputs, root_build_dir)) {
392 args += [ rebase_path(gen_dir, root_build_dir) ]
393 args += rebase_path(invoker.sources, root_build_dir)
396 generate_enum_outputs = get_target_outputs(":$generate_enum_target_name")
397 base_gen_dir = get_label_info(":$generate_enum_target_name", "target_gen_dir")
399 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
400 zip(zip_srcjar_target_name) {
401 visibility = [ ":$final_target_name" ]
402 inputs = generate_enum_outputs
404 base_dir = base_gen_dir
406 ":$generate_enum_target_name",
410 group(final_target_name) {
411 if (defined(invoker.visibility)) {
412 visibility = invoker.visibility
415 ":$zip_srcjar_target_name",
420 # Declare a target for processing a Jinja template.
423 # input: The template file to be processed.
424 # output: Where to save the result.
425 # variables: (Optional) A list of variables to make available to the template
426 # processing environment, e.g. ["name=foo", "color=red"].
429 # jinja_template("chrome_shell_manifest") {
430 # input = "shell/java/AndroidManifest.xml"
431 # output = "$target_gen_dir/AndroidManifest.xml"
433 template("jinja_template") {
434 set_sources_assignment_filter([])
435 if (defined(invoker.testonly)) {
436 testonly = invoker.testonly
439 assert(defined(invoker.input))
440 assert(defined(invoker.output))
442 action(target_name) {
443 if (defined(invoker.visibility)) {
444 visibility = invoker.visibility
450 script = "//build/android/gyp/jinja_template.py"
451 depfile = "$target_gen_dir/$target_name.d"
460 rebase_path(invoker.input, root_build_dir),
462 rebase_path(invoker.output, root_build_dir),
464 rebase_path(depfile, root_build_dir),
466 if (defined(invoker.variables)) {
467 variables = invoker.variables
468 args += [ "--variables=${variables}" ]
473 # Declare a target for processing Android resources as Jinja templates.
475 # This takes an Android resource directory where each resource is a Jinja
476 # template, processes each template, then packages the results in a zip file
477 # which can be consumed by an android resources, library, or apk target.
479 # If this target is included in the deps of an android resources/library/apk,
480 # the resources will be included with that target.
483 # resources: The list of resources files to process.
484 # res_dir: The resource directory containing the resources.
485 # variables: (Optional) A list of variables to make available to the template
486 # processing environment, e.g. ["name=foo", "color=red"].
489 # jinja_template_resources("chrome_shell_template_resources") {
490 # res_dir = "shell/res_template"
491 # resources = ["shell/res_template/xml/syncable.xml"]
492 # variables = ["color=red"]
494 template("jinja_template_resources") {
495 set_sources_assignment_filter([])
496 if (defined(invoker.testonly)) {
497 testonly = invoker.testonly
500 assert(defined(invoker.resources))
501 assert(defined(invoker.res_dir))
503 _base_path = "$target_gen_dir/$target_name"
504 _resources_zip = _base_path + ".resources.zip"
505 _build_config = _base_path + ".build_config"
507 write_build_config("${target_name}__build_config") {
508 build_config = _build_config
509 resources_zip = _resources_zip
510 type = "android_resources"
513 action("${target_name}__template") {
514 sources = invoker.resources
515 script = "//build/android/gyp/jinja_template.py"
516 depfile = "$target_gen_dir/$target_name.d"
523 rebased_resources = rebase_path(invoker.resources, root_build_dir)
525 "--inputs=${rebased_resources}",
527 rebase_path(invoker.res_dir, root_build_dir),
529 rebase_path(_resources_zip, root_build_dir),
531 rebase_path(depfile, root_build_dir),
533 if (defined(invoker.variables)) {
534 variables = invoker.variables
535 args += [ "--variables=${variables}" ]
541 ":${target_name}__build_config",
542 ":${target_name}__template",
547 # Creates a resources.zip with locale.pak files placed into appropriate
548 # resource configs (e.g. en-GB.pak -> res/raw-en/en_gb.pak). Also generates
549 # a locale_paks TypedArray so that resource files can be enumerated at runtime.
551 # If this target is included in the deps of an android resources/library/apk,
552 # the resources will be included with that target.
555 # sources: List of .pak files. Names must be of the form "en.pak" or
557 # deps: (optional) List of dependencies that might be needed to generate
561 # locale_pak_resources("locale_paks") {
562 # sources = [ "path/en-US.pak", "path/fr.pak", ... ]
564 template("locale_pak_resources") {
565 set_sources_assignment_filter([])
566 assert(defined(invoker.sources))
568 _base_path = "$target_gen_dir/$target_name"
569 _resources_zip = _base_path + ".resources.zip"
570 _build_config = _base_path + ".build_config"
572 write_build_config("${target_name}__build_config") {
573 build_config = _build_config
574 resources_zip = _resources_zip
575 type = "android_resources"
578 action("${target_name}__create_resources_zip") {
579 sources = invoker.sources
580 script = "//build/android/gyp/locale_pak_resources.py"
581 depfile = "$target_gen_dir/$target_name.d"
588 _rebased_sources = rebase_path(invoker.sources, root_build_dir)
590 "--locale-paks=${_rebased_sources}",
592 rebase_path(_resources_zip, root_build_dir),
594 rebase_path(depfile, root_build_dir),
597 if (defined(invoker.deps)) {
604 ":${target_name}__build_config",
605 ":${target_name}__create_resources_zip",
610 # Declare an Android resources target
612 # This creates a resources zip file that will be used when building an Android
613 # library or apk and included into a final apk.
615 # To include these resources in a library/apk, this target should be listed in
616 # the library's deps. A library/apk will also include any resources used by its
620 # deps: Specifies the dependencies of this target. Any Android resources
621 # listed in deps will be included by libraries/apks that depend on this
623 # resource_dirs: List of directories containing resources for this target.
624 # android_manifest: AndroidManifest.xml for this target. Defaults to
625 # //build/android/AndroidManifest.xml.
626 # custom_package: java package for generated .java files.
627 # v14_skip: If true, don't run v14 resource generator on this. Defaults to
628 # false. (see build/android/gyp/generate_v14_compatible_resources.py)
630 # shared_resources: If true make a resource package that can be loaded by a
631 # different application at runtime to access the package's resources.
635 # android_resources("foo_resources") {
636 # deps = [":foo_strings_grd"]
637 # resource_dirs = ["res"]
638 # custom_package = "org.chromium.foo"
640 template("android_resources") {
641 set_sources_assignment_filter([])
642 if (defined(invoker.testonly)) {
643 testonly = invoker.testonly
646 assert(defined(invoker.resource_dirs))
647 assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
649 base_path = "$target_gen_dir/$target_name"
650 zip_path = base_path + ".resources.zip"
651 srcjar_path = base_path + ".srcjar"
652 r_text_path = base_path + "_R.txt"
653 build_config = base_path + ".build_config"
655 build_config_target_name = "${target_name}__build_config"
656 process_resources_target_name = "${target_name}__process_resources"
657 final_target_name = target_name
659 write_build_config(build_config_target_name) {
660 visibility = [ ":$process_resources_target_name" ]
662 type = "android_resources"
663 resources_zip = zip_path
666 if (defined(invoker.deps)) {
669 if (defined(invoker.android_manifest)) {
670 android_manifest = invoker.android_manifest
672 if (defined(invoker.custom_package)) {
673 custom_package = invoker.custom_package
677 android_manifest = "//build/android/AndroidManifest.xml"
678 if (defined(invoker.android_manifest)) {
679 android_manifest = invoker.android_manifest
682 process_resources(process_resources_target_name) {
683 visibility = [ ":$final_target_name" ]
685 resource_dirs = invoker.resource_dirs
686 if (defined(invoker.custom_package)) {
687 custom_package = invoker.custom_package
690 if (defined(invoker.v14_skip)) {
691 v14_skip = invoker.v14_skip
694 if (defined(invoker.shared_resources)) {
695 shared_resources = invoker.shared_resources
699 ":$build_config_target_name",
701 if (defined(invoker.deps)) {
702 # Invoker may have added deps that generate the input resources.
707 group(final_target_name) {
708 if (defined(invoker.visibility)) {
709 visibility = invoker.visibility
712 ":${target_name}__process_resources",
717 # Declare a target that generates localized strings.xml from a .grd file.
719 # If this target is included in the deps of an android resources/library/apk,
720 # the strings.xml will be included with that target.
723 # deps: Specifies the dependencies of this target.
724 # grd_file: Path to the .grd file to generate strings.xml from.
725 # outputs: Expected grit outputs (see grit rule).
728 # java_strings_grd("foo_strings_grd") {
729 # grd_file = "foo_strings.grd"
731 template("java_strings_grd") {
732 set_sources_assignment_filter([])
733 if (defined(invoker.testonly)) {
734 testonly = invoker.testonly
737 base_path = "$target_gen_dir/$target_name"
738 resources_zip = base_path + ".resources.zip"
739 build_config = base_path + ".build_config"
741 write_build_config("${target_name}__build_config") {
742 type = "android_resources"
743 if (defined(invoker.deps)) {
748 # Put grit files into this subdirectory of target_gen_dir.
749 extra_output_path = target_name + "_grit_output"
751 grit_target_name = "${target_name}__grit"
752 grit_output_dir = "$target_gen_dir/$extra_output_path"
753 grit(grit_target_name) {
756 "ANDROID_JAVA_TAGGED_ONLY=false",
758 output_dir = grit_output_dir
760 source = invoker.grd_file
761 outputs = invoker.outputs
764 # This needs to get outputs from grit's internal target, not the final
766 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
768 zip("${target_name}__zip") {
769 base_dir = grit_output_dir
770 inputs = generate_strings_outputs
771 output = resources_zip
773 ":$grit_target_name",
779 ":${target_name}__build_config",
780 ":${target_name}__zip",
785 # Declare a target that packages strings.xml generated from a grd file.
787 # If this target is included in the deps of an android resources/library/apk,
788 # the strings.xml will be included with that target.
791 # grit_output_dir: directory containing grit-generated files.
792 # generated_files: list of android resource files to package.
795 # java_strings_grd_prebuilt("foo_strings_grd") {
796 # grit_output_dir = "$root_gen_dir/foo/grit"
797 # generated_files = [
798 # "values/strings.xml"
801 template("java_strings_grd_prebuilt") {
802 set_sources_assignment_filter([])
803 if (defined(invoker.testonly)) {
804 testonly = invoker.testonly
807 base_path = "$target_gen_dir/$target_name"
808 resources_zip = base_path + ".resources.zip"
809 build_config = base_path + ".build_config"
811 build_config_target_name = "${target_name}__build_config"
812 zip_target_name = "${target_name}__zip"
813 final_target_name = target_name
815 write_build_config(build_config_target_name) {
816 visibility = [ ":$zip_target_name" ]
817 type = "android_resources"
820 zip(zip_target_name) {
821 visibility = [ ":$final_target_name" ]
823 base_dir = invoker.grit_output_dir
824 inputs = rebase_path(invoker.generated_files, ".", base_dir)
825 output = resources_zip
827 ":$build_config_target_name",
829 if (defined(invoker.deps)) {
834 group(final_target_name) {
835 if (defined(invoker.visibility)) {
836 visibility = invoker.visibility
844 # Declare a Java executable target
846 # This target creates an executable from java code and libraries. The executable
847 # will be in the output folder's /bin/ directory.
850 # deps: Specifies the dependencies of this target. Java targets in this list
851 # will be included in the executable (and the javac classpath).
853 # java_files: List of .java files included in this library.
854 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
855 # will be added to java_files and be included in this library.
856 # srcjars: List of srcjars to be included in this library, together with the
857 # ones obtained from srcjar_deps.
859 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
860 # dependencies for this target. This will allow depending on an
861 # android_library target, for example.
863 # chromium_code: If true, extra analysis warning/errors will be enabled.
864 # enable_errorprone: If true, enables the errorprone compiler.
866 # data_deps, testonly
869 # java_binary("foo") {
870 # java_files = [ "org/chromium/foo/FooMain.java" ]
871 # deps = [ ":bar_java" ]
872 # main_class = "org.chromium.foo.FooMain"
874 template("java_binary") {
875 set_sources_assignment_filter([])
877 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
878 # dependents shouldn't get the jar in their classpath, etc.).
879 java_library_impl(target_name) {
880 if (defined(invoker.DEPRECATED_java_in_dir)) {
881 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
883 if (defined(invoker.chromium_code)) {
884 chromium_code = invoker.chromium_code
886 if (defined(invoker.data_deps)) {
887 deps = invoker.data_deps
889 if (defined(invoker.deps)) {
892 if (defined(invoker.enable_errorprone)) {
893 enable_errorprone = invoker.enable_errorprone
895 if (defined(invoker.java_files)) {
896 java_files = invoker.java_files
898 if (defined(invoker.srcjar_deps)) {
899 srcjar_deps = invoker.srcjar_deps
901 if (defined(invoker.srcjars)) {
902 srcjars = invoker.srcjars
904 if (defined(invoker.bypass_platform_checks)) {
905 bypass_platform_checks = invoker.bypass_platform_checks
907 if (defined(invoker.testonly)) {
908 testonly = invoker.testonly
911 supports_android = false
912 main_class = invoker.main_class
916 # Declare a Junit executable target
918 # This target creates an executable from java code for running as a junit test
919 # suite. The executable will be in the output folder's /bin/ directory.
922 # deps: Specifies the dependencies of this target. Java targets in this list
923 # will be included in the executable (and the javac classpath).
925 # java_files: List of .java files included in this library.
926 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
927 # will be added to java_files and be included in this library.
928 # srcjars: List of srcjars to be included in this library, together with the
929 # ones obtained from srcjar_deps.
931 # chromium_code: If true, extra analysis warning/errors will be enabled.
934 # junit_binary("foo") {
935 # java_files = [ "org/chromium/foo/FooTest.java" ]
936 # deps = [ ":bar_java" ]
938 template("junit_binary") {
939 set_sources_assignment_filter([])
941 java_binary(target_name) {
942 bypass_platform_checks = true
943 main_class = "org.chromium.testing.local.JunitTestMain"
946 if (defined(invoker.DEPRECATED_java_in_dir)) {
947 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
949 if (defined(invoker.chromium_code)) {
950 chromium_code = invoker.chromium_code
953 "//testing/android/junit:junit_test_support",
954 "//third_party/junit",
955 "//third_party/mockito:mockito_java",
956 "//third_party/robolectric:robolectric_java",
957 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
959 if (defined(invoker.deps)) {
962 if (defined(invoker.java_files)) {
963 java_files = invoker.java_files
965 if (defined(invoker.srcjar_deps)) {
966 srcjar_deps = invoker.srcjar_deps
968 if (defined(invoker.srcjars)) {
969 srcjars = invoker.srcjars
974 # Declare a java library target
977 # deps: Specifies the dependencies of this target. Java targets in this list
978 # will be added to the javac classpath.
980 # java_files: List of .java files included in this library.
981 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
982 # will be added to java_files and be included in this library.
983 # srcjars: List of srcjars to be included in this library, together with the
984 # ones obtained from srcjar_deps.
985 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
986 # this directory will be included in the library. This is only supported to
987 # ease the gyp->gn conversion and will be removed in the future.
989 # chromium_code: If true, extra analysis warning/errors will be enabled.
990 # enable_errorprone: If true, enables the errorprone compiler.
992 # jar_excluded_patterns: List of patterns of .class files to exclude from the
995 # proguard_preprocess: If true, proguard preprocessing will be run. This can
996 # be used to remove unwanted parts of the library.
997 # proguard_config: Path to the proguard config for preprocessing.
999 # supports_android: If true, Android targets (android_library, android_apk)
1000 # may depend on this target. Note: if true, this target must only use the
1001 # subset of Java available on Android.
1002 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
1003 # dependencies for this target. This will allow depending on an
1004 # android_library target, for example.
1006 # data_deps, testonly
1009 # java_library("foo_java") {
1011 # "org/chromium/foo/Foo.java",
1012 # "org/chromium/foo/FooInterface.java",
1013 # "org/chromium/foo/FooService.java",
1019 # ":foo_generated_enum"
1021 # jar_excluded_patterns = [
1022 # "*/FooService.class", "*/FooService##*.class"
1025 template("java_library") {
1026 set_sources_assignment_filter([])
1027 java_library_impl(target_name) {
1028 if (defined(invoker.DEPRECATED_java_in_dir)) {
1029 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1031 if (defined(invoker.chromium_code)) {
1032 chromium_code = invoker.chromium_code
1034 if (defined(invoker.data_deps)) {
1035 deps = invoker.data_deps
1037 if (defined(invoker.deps)) {
1040 if (defined(invoker.enable_errorprone)) {
1041 enable_errorprone = invoker.enable_errorprone
1043 if (defined(invoker.jar_excluded_patterns)) {
1044 jar_excluded_patterns = invoker.jar_excluded_patterns
1046 if (defined(invoker.java_files)) {
1047 java_files = invoker.java_files
1049 if (defined(invoker.proguard_config)) {
1050 proguard_config = invoker.proguard_config
1052 if (defined(invoker.proguard_preprocess)) {
1053 proguard_preprocess = invoker.proguard_preprocess
1055 if (defined(invoker.srcjar_deps)) {
1056 srcjar_deps = invoker.srcjar_deps
1058 if (defined(invoker.srcjars)) {
1059 srcjars = invoker.srcjars
1061 if (defined(invoker.bypass_platform_checks)) {
1062 bypass_platform_checks = invoker.bypass_platform_checks
1064 if (defined(invoker.testonly)) {
1065 testonly = invoker.testonly
1067 if (defined(invoker.jar_path)) {
1068 jar_path = invoker.jar_path
1071 if (defined(invoker.supports_android) && invoker.supports_android) {
1072 supports_android = true
1077 # Declare a java library target for a prebuilt jar
1080 # deps: Specifies the dependencies of this target. Java targets in this list
1081 # will be added to the javac classpath.
1082 # jar_path: Path to the prebuilt jar.
1083 # jar_dep: Target that builds jar_path (optional).
1084 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1085 # be used to remove unwanted parts of the library.
1086 # proguard_config: Path to the proguard config for preprocessing.
1089 # java_prebuilt("foo_java") {
1090 # jar_path = "foo.jar"
1096 template("java_prebuilt") {
1097 set_sources_assignment_filter([])
1098 java_prebuilt_impl(target_name) {
1099 jar_path = invoker.jar_path
1100 if (defined(invoker.jar_dep)) {
1101 jar_dep = invoker.jar_dep
1103 if (defined(invoker.testonly)) {
1104 testonly = invoker.testonly
1106 if (defined(invoker.deps)) {
1109 if (defined(invoker.data_deps)) {
1110 data_deps = invoker.data_deps
1112 if (defined(invoker.proguard_config)) {
1113 proguard_config = invoker.proguard_config
1115 if (defined(invoker.proguard_preprocess)) {
1116 proguard_preprocess = invoker.proguard_preprocess
1121 # Declare an Android library target
1123 # This target creates an Android library containing java code and Android
1127 # deps: Specifies the dependencies of this target. Java targets in this list
1128 # will be added to the javac classpath. Android resources in dependencies
1129 # will be used when building this library.
1131 # java_files: List of .java files included in this library.
1132 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1133 # will be added to java_files and be included in this library.
1134 # srcjars: List of srcjars to be included in this library, together with the
1135 # ones obtained from srcjar_deps.
1136 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1137 # this directory will be included in the library. This is only supported to
1138 # ease the gyp->gn conversion and will be removed in the future.
1140 # chromium_code: If true, extra analysis warning/errors will be enabled.
1141 # enable_errorprone: If true, enables the errorprone compiler.
1143 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1146 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1147 # be used to remove unwanted parts of the library.
1148 # proguard_config: Path to the proguard config for preprocessing.
1150 # dex_path: If set, the resulting .dex.jar file will be placed under this
1155 # android_library("foo_java") {
1157 # "android/org/chromium/foo/Foo.java",
1158 # "android/org/chromium/foo/FooInterface.java",
1159 # "android/org/chromium/foo/FooService.java",
1165 # ":foo_generated_enum"
1167 # jar_excluded_patterns = [
1168 # "*/FooService.class", "*/FooService##*.class"
1171 template("android_library") {
1172 set_sources_assignment_filter([])
1173 assert(!defined(invoker.jar_path),
1174 "android_library does not support a custom jar path")
1175 java_library_impl(target_name) {
1176 if (defined(invoker.DEPRECATED_java_in_dir)) {
1177 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1179 if (defined(invoker.chromium_code)) {
1180 chromium_code = invoker.chromium_code
1182 if (defined(invoker.data_deps)) {
1183 deps = invoker.data_deps
1185 if (defined(invoker.deps)) {
1188 if (defined(invoker.enable_errorprone)) {
1189 enable_errorprone = invoker.enable_errorprone
1191 if (defined(invoker.jar_excluded_patterns)) {
1192 jar_excluded_patterns = invoker.jar_excluded_patterns
1194 if (defined(invoker.java_files)) {
1195 java_files = invoker.java_files
1197 if (defined(invoker.proguard_config)) {
1198 proguard_config = invoker.proguard_config
1200 if (defined(invoker.proguard_preprocess)) {
1201 proguard_preprocess = invoker.proguard_preprocess
1203 if (defined(invoker.srcjar_deps)) {
1204 srcjar_deps = invoker.srcjar_deps
1206 if (defined(invoker.srcjars)) {
1207 srcjars = invoker.srcjars
1209 if (defined(invoker.testonly)) {
1210 testonly = invoker.testonly
1212 if (defined(invoker.visibility)) {
1213 visibility = invoker.visibility
1215 if (defined(invoker.dex_path)) {
1216 dex_path = invoker.dex_path
1218 if (defined(invoker.manifest_entries)) {
1219 manifest_entries = invoker.manifest_entries
1222 supports_android = true
1223 requires_android = true
1225 if (!defined(jar_excluded_patterns)) {
1226 jar_excluded_patterns = []
1228 jar_excluded_patterns += [
1232 "*/Manifest##*.class",
1237 # Declare a target that packages a set of Java dependencies into a standalone
1241 # deps: specifies the dependencies of this target. Android libraries in deps
1242 # will be packaged into the resulting .dex.jar file.
1243 # dex_path: location at which the output file will be put
1244 template("android_standalone_library") {
1245 set_sources_assignment_filter([])
1246 deps_dex(target_name) {
1248 dex_path = invoker.dex_path
1249 if (defined(invoker.excluded_jars)) {
1250 excluded_jars = invoker.excluded_jars
1255 # Declare an Android library target for a prebuilt jar
1257 # This target creates an Android library containing java code and Android
1261 # deps: Specifies the dependencies of this target. Java targets in this list
1262 # will be added to the javac classpath. Android resources in dependencies
1263 # will be used when building this library.
1264 # jar_path: Path to the prebuilt jar.
1265 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1266 # be used to remove unwanted parts of the library.
1267 # proguard_config: Path to the proguard config for preprocessing.
1270 # android_java_prebuilt("foo_java") {
1271 # jar_path = "foo.jar"
1277 template("android_java_prebuilt") {
1278 set_sources_assignment_filter([])
1279 java_prebuilt_impl(target_name) {
1280 jar_path = invoker.jar_path
1281 supports_android = true
1282 requires_android = true
1283 if (defined(invoker.testonly)) {
1284 testonly = invoker.testonly
1286 if (defined(invoker.deps)) {
1289 if (defined(invoker.data_deps)) {
1290 data_deps = invoker.data_deps
1292 if (defined(invoker.proguard_config)) {
1293 proguard_config = invoker.proguard_config
1295 if (defined(invoker.proguard_preprocess)) {
1296 proguard_preprocess = invoker.proguard_preprocess
1301 # Declare an Android apk target
1303 # This target creates an Android APK containing java code, resources, assets,
1304 # and (possibly) native libraries.
1307 # android_manifest: Path to AndroidManifest.xml.
1308 # android_manifest_dep: Target that generates AndroidManifest (if applicable)
1309 # data_deps: List of dependencies needed at runtime. These will be built but
1310 # won't change the generated .apk in any way (in fact they may be built
1311 # after the .apk is).
1312 # deps: List of dependencies. All Android java resources and libraries in the
1313 # "transitive closure" of these dependencies will be included in the apk.
1314 # Note: this "transitive closure" actually only includes such targets if
1315 # they are depended on through android_library or android_resources targets
1316 # (and so not through builtin targets like 'action', 'group', etc).
1317 # java_files: List of .java files to include in the apk.
1318 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1319 # will be added to java_files and be included in this apk.
1320 # apk_name: Name for final apk.
1321 # final_apk_path: Path to final built apk. Default is
1322 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1323 # native_libs: List paths of native libraries to include in this apk. If these
1324 # libraries depend on other shared_library targets, those dependencies will
1325 # also be included in the apk.
1326 # apk_under_test: For an instrumentation test apk, this is the target of the
1328 # include_all_resources - If true include all resource IDs in all generated
1330 # testonly: Marks this target as "test-only".
1332 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1333 # this directory will be included in the library. This is only supported to
1334 # ease the gyp->gn conversion and will be removed in the future.
1337 # android_apk("foo_apk") {
1338 # android_manifest = "AndroidManifest.xml"
1340 # "android/org/chromium/foo/FooApplication.java",
1341 # "android/org/chromium/foo/FooActivity.java",
1344 # ":foo_support_java"
1348 # ":foo_generated_enum"
1354 template("android_apk") {
1355 set_sources_assignment_filter([])
1356 if (defined(invoker.testonly)) {
1357 testonly = invoker.testonly
1360 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1361 assert(defined(invoker.android_manifest))
1362 gen_dir = "$target_gen_dir/$target_name"
1363 base_path = "$gen_dir/$target_name"
1364 _build_config = "$target_gen_dir/$target_name.build_config"
1365 resources_zip_path = "$base_path.resources.zip"
1366 _all_resources_zip_path = "$base_path.resources.all.zip"
1367 jar_path = "$base_path.jar"
1368 _template_name = target_name
1370 final_dex_path = "$gen_dir/classes.dex"
1371 final_dex_target_name = "${_template_name}__final_dex"
1373 _final_apk_path = ""
1374 if (defined(invoker.final_apk_path)) {
1375 _final_apk_path = invoker.final_apk_path
1376 } else if (defined(invoker.apk_name)) {
1377 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1379 _dist_jar_path_list =
1380 process_file_template(
1381 [ _final_apk_path ],
1382 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1383 _dist_jar_path = _dist_jar_path_list[0]
1388 if (defined(invoker.version_code)) {
1389 _version_code = invoker.version_code
1392 _version_name = "Developer Build"
1393 if (defined(invoker.version_name)) {
1394 _version_name = invoker.version_name
1396 _keystore_path = android_default_keystore_path
1397 _keystore_name = android_default_keystore_name
1398 _keystore_password = android_default_keystore_password
1400 if (defined(invoker.keystore_path)) {
1401 _keystore_path = invoker.keystore_path
1402 _keystore_name = invoker.keystore_name
1403 _keystore_password = invoker.keystore_password
1407 if (defined(invoker.srcjar_deps)) {
1408 _srcjar_deps += invoker.srcjar_deps
1411 _load_library_from_apk = false
1413 # The dependency that makes the chromium linker, if any is needed.
1414 _chromium_linker_dep = []
1416 if (defined(invoker.native_libs)) {
1417 _use_chromium_linker = false
1418 if (defined(invoker.use_chromium_linker)) {
1419 _use_chromium_linker =
1420 invoker.use_chromium_linker && chromium_linker_supported
1421 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1424 if (defined(invoker.load_library_from_apk) &&
1425 invoker.load_library_from_apk) {
1426 _load_library_from_apk = true
1427 assert(_use_chromium_linker,
1428 "Loading library from the apk requires use" +
1429 " of the Chromium linker.")
1432 _enable_relocation_packing = false
1433 if (defined(invoker.enable_relocation_packing) &&
1434 invoker.enable_relocation_packing) {
1435 _enable_relocation_packing = relocation_packing_supported
1436 assert(_use_chromium_linker,
1437 "Relocation packing requires use of the" + " Chromium linker.")
1440 if (is_component_build) {
1441 _native_libs += [ "$root_out_dir/lib.stripped/libc++_shared.so" ]
1442 _chromium_linker_dep += [ "//build/android:cpplib_stripped" ]
1445 # Allow native_libs to be in the form "foo.so" or "foo.cr.so"
1446 _first_ext_removed =
1447 process_file_template(invoker.native_libs, "{{source_name_part}}")
1448 _native_libs += process_file_template(
1450 "$root_build_dir/lib.stripped/{{source_name_part}}$android_product_extension")
1452 _native_libs_dir = base_path + "/libs"
1454 if (_use_chromium_linker) {
1455 _native_libs += [ "$root_build_dir/lib.stripped/libchromium_android_linker$android_product_extension" ]
1458 _enable_relocation_packing = false
1459 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1460 invoker.enable_relocation_packing) {
1461 _enable_relocation_packing = true
1464 _native_lib_version_rule = ""
1465 if (defined(invoker.native_lib_version_rule)) {
1466 _native_lib_version_rule = invoker.native_lib_version_rule
1468 _native_lib_version_arg = "\"\""
1469 if (defined(invoker.native_lib_version_arg)) {
1470 _native_lib_version_arg = invoker.native_lib_version_arg
1474 _android_manifest_deps = []
1475 if (defined(invoker.android_manifest_dep)) {
1476 _android_manifest_deps = [ invoker.android_manifest_dep ]
1478 _android_manifest = invoker.android_manifest
1480 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1482 defined(invoker.create_abi_split) && invoker.create_abi_split
1483 _create_density_splits =
1484 defined(invoker.create_density_splits) && invoker.create_density_splits
1486 # Help GN understand that _create_abi_split is not unused (bug in GN).
1487 assert(_create_abi_split || true)
1489 build_config_target = "${_template_name}__build_config"
1490 write_build_config(build_config_target) {
1491 type = "android_apk"
1492 dex_path = final_dex_path
1493 resources_zip = resources_zip_path
1494 build_config = _build_config
1495 android_manifest = _android_manifest
1497 deps = _chromium_linker_dep + _android_manifest_deps
1498 if (defined(invoker.deps)) {
1499 deps += invoker.deps
1502 if (defined(invoker.apk_under_test)) {
1503 apk_under_test = invoker.apk_under_test
1506 native_libs = _native_libs
1511 process_resources_target = "${_template_name}__process_resources"
1512 final_deps += [ ":$process_resources_target" ]
1513 process_resources(process_resources_target) {
1514 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1515 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1516 android_manifest = _android_manifest
1517 resource_dirs = [ "//build/android/ant/empty/res" ]
1518 zip_path = resources_zip_path
1519 all_resources_zip_path = _all_resources_zip_path
1520 generate_constant_ids = true
1522 if (defined(invoker.include_all_resources)) {
1523 include_all_resources = invoker.include_all_resources
1526 build_config = _build_config
1527 deps = _android_manifest_deps + [ ":$build_config_target" ]
1528 if (defined(invoker.deps)) {
1529 deps += invoker.deps
1532 _srcjar_deps += [ ":$process_resources_target" ]
1534 if (_native_libs != []) {
1535 _enable_chromium_linker_tests = false
1536 if (defined(invoker.enable_chromium_linker_tests)) {
1537 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1540 java_cpp_template("${_template_name}__native_libraries_java") {
1541 package_name = "org/chromium/base/library_loader"
1543 "//base/android/java/templates/NativeLibraries.template",
1549 ":$build_config_target",
1551 if (_native_lib_version_rule != "") {
1552 deps += [ _native_lib_version_rule ]
1556 "NATIVE_LIBRARIES_LIST=" +
1557 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1558 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
1560 if (_use_chromium_linker) {
1561 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1563 if (_load_library_from_apk) {
1564 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1566 if (_enable_chromium_linker_tests) {
1567 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1570 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1573 java_target = "${_template_name}__java"
1574 final_deps += [ ":$java_target" ]
1575 java_library_impl(java_target) {
1576 supports_android = true
1577 requires_android = true
1578 override_build_config = _build_config
1579 deps = _android_manifest_deps + [ ":$build_config_target" ]
1581 android_manifest = _android_manifest
1582 chromium_code = true
1583 if (defined(invoker.java_files)) {
1584 java_files = invoker.java_files
1585 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1586 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1590 srcjar_deps = _srcjar_deps
1591 dex_path = base_path + ".dex.jar"
1593 if (defined(invoker.deps)) {
1594 deps += invoker.deps
1598 if (_dist_jar_path != "") {
1599 create_dist_target = "${_template_name}__create_dist_jar"
1600 final_deps += [ ":$create_dist_target" ]
1602 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1603 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1604 # able to just do that calculation at build time instead.
1605 action(create_dist_target) {
1606 script = "//build/android/gyp/create_dist_jar.py"
1607 depfile = "$target_gen_dir/$target_name.d"
1617 rebase_path(depfile, root_build_dir),
1619 rebase_path(_dist_jar_path, root_build_dir),
1620 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1622 inputs += [ jar_path ]
1623 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1624 args += [ "--inputs=$_rebased_jar_path" ]
1626 ":$build_config_target", # Generates the build config file.
1627 ":$java_target", # Generates the jar file.
1632 final_deps += [ ":$final_dex_target_name" ]
1633 dex("$final_dex_target_name") {
1635 ":$build_config_target",
1644 output = final_dex_path
1645 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1646 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1649 if (_native_libs != []) {
1650 action("${_template_name}__prepare_native") {
1651 script = "//build/android/gyp/pack_relocations.py"
1652 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1653 depfile = "$target_gen_dir/$target_name.d"
1658 inputs = _native_libs
1659 deps = _chromium_linker_dep
1661 inputs += [ _build_config ]
1662 deps += [ ":$build_config_target" ]
1664 skip_packing_list = [
1666 "libchromium_android_linker$android_product_extension",
1669 enable_packing_arg = 0
1670 if (_enable_relocation_packing) {
1671 enable_packing_arg = 1
1672 deps += [ relocation_packer_target ]
1677 rebase_path(depfile, root_build_dir),
1678 "--enable-packing=$enable_packing_arg",
1679 "--exclude-packing-list=$skip_packing_list",
1680 "--android-pack-relocations",
1681 rebase_path(relocation_packer_exe, root_build_dir),
1682 "--stripped-libraries-dir",
1683 rebase_path(root_build_dir, root_build_dir),
1684 "--packed-libraries-dir",
1685 rebase_path(packed_libraries_dir, root_build_dir),
1686 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1690 if (defined(invoker.deps)) {
1691 deps += invoker.deps
1693 if (defined(invoker.public_deps)) {
1694 public_deps = invoker.public_deps
1696 if (defined(invoker.data_deps)) {
1697 data_deps = invoker.data_deps
1701 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1702 inputs += [ android_gdbserver ]
1703 args += [ "--libraries=$rebased_gdbserver" ]
1708 final_deps += [ ":${_template_name}__create" ]
1709 create_apk("${_template_name}__create") {
1710 apk_path = _final_apk_path
1711 android_manifest = _android_manifest
1712 resources_zip = _all_resources_zip_path
1713 dex_path = final_dex_path
1714 load_library_from_apk = _load_library_from_apk
1715 create_density_splits = _create_density_splits
1716 if (defined(invoker.language_splits)) {
1717 language_splits = invoker.language_splits
1719 if (defined(invoker.extensions_to_not_compress)) {
1720 extensions_to_not_compress = invoker.extensions_to_not_compress
1722 # Allow icu data, v8 snapshots, and pak files to be loaded directly from
1724 # Note: These are actually suffix matches, not necessarily extensions.
1725 extensions_to_not_compress = ".dat,.bin,.pak"
1728 version_code = _version_code
1729 version_name = _version_name
1731 keystore_name = _keystore_name
1732 keystore_path = _keystore_path
1733 keystore_password = _keystore_password
1735 # This target generates the input file _all_resources_zip_path.
1736 deps = _android_manifest_deps + [
1737 ":$process_resources_target",
1738 ":$final_dex_target_name",
1740 if (defined(invoker.deps)) {
1741 deps += invoker.deps
1744 if (defined(invoker.asset_location)) {
1745 asset_location = invoker.asset_location
1747 # We don't know the exact dependencies that create the assets in
1748 # |asset_location|; we depend on all caller deps until a better solution
1749 # is figured out (http://crbug.com/433330).
1750 if (defined(invoker.deps)) {
1751 deps += invoker.deps
1755 if (_native_libs != [] && !_create_abi_split) {
1756 native_libs_dir = _native_libs_dir
1757 deps += [ ":${_template_name}__prepare_native" ]
1761 if (_native_libs != [] && _create_abi_split) {
1762 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1763 generate_split_manifest(_manifest_rule) {
1764 main_manifest = _android_manifest
1766 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1767 split_name = "abi_${android_app_abi}"
1768 deps = _android_manifest_deps
1771 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1772 final_deps += [ ":$_apk_rule" ]
1773 create_apk(_apk_rule) {
1774 _split_paths = process_file_template(
1775 [ _final_apk_path ],
1776 "{{source_dir}}/{{source_name_part}}-abi-${android_app_abi}.apk")
1777 apk_path = _split_paths[0]
1778 base_path = "$gen_dir/$_apk_rule"
1780 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1781 android_manifest = manifest_outputs[1]
1782 load_library_from_apk = _load_library_from_apk
1784 version_code = _version_code
1785 version_name = _version_name
1787 keystore_name = _keystore_name
1788 keystore_path = _keystore_path
1789 keystore_password = _keystore_password
1791 native_libs_dir = _native_libs_dir
1793 ":${_template_name}__prepare_native",
1794 ":${_manifest_rule}",
1799 group(target_name) {
1801 if (defined(invoker.data_deps)) {
1802 data_deps = invoker.data_deps
1807 # Declare an Android instrumentation test apk
1809 # This target creates an Android instrumentation test apk.
1812 # android_manifest: Path to AndroidManifest.xml.
1813 # data_deps: List of dependencies needed at runtime. These will be built but
1814 # won't change the generated .apk in any way (in fact they may be built
1815 # after the .apk is).
1816 # deps: List of dependencies. All Android java resources and libraries in the
1817 # "transitive closure" of these dependencies will be included in the apk.
1818 # Note: this "transitive closure" actually only includes such targets if
1819 # they are depended on through android_library or android_resources targets
1820 # (and so not through builtin targets like 'action', 'group', etc).
1821 # java_files: List of .java files to include in the apk.
1822 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1823 # will be added to java_files and be included in this apk.
1824 # apk_name: Name for final apk.
1825 # final_apk_path: Path to final built apk. Default is
1826 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1827 # native_libs: List paths of native libraries to include in this apk. If these
1828 # libraries depend on other shared_library targets, those dependencies will
1829 # also be included in the apk.
1830 # apk_under_test: The apk being tested.
1831 # isolate_file: Isolate file containing the list of test data dependencies.
1833 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1834 # this directory will be included in the library. This is only supported to
1835 # ease the gyp->gn conversion and will be removed in the future.
1838 # instrumentation_test_apk("foo_test_apk") {
1839 # android_manifest = "AndroidManifest.xml"
1840 # apk_name = "FooTest"
1841 # apk_under_test = "Foo"
1843 # "android/org/chromium/foo/FooTestCase.java",
1844 # "android/org/chromium/foo/FooExampleTest.java",
1847 # ":foo_test_support_java"
1850 template("instrumentation_test_apk") {
1851 set_sources_assignment_filter([])
1853 _template_name = target_name
1855 if (defined(invoker.apk_name)) {
1856 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1857 test_runner_script("${_template_name}__test_runner_script") {
1858 test_name = invoker.target_name
1859 test_type = "instrumentation"
1860 test_apk = invoker.apk_name
1861 if (defined(invoker.isolate_file)) {
1862 isolate_file = invoker.isolate_file
1867 android_apk(target_name) {
1868 if (defined(invoker.android_manifest)) {
1869 android_manifest = invoker.android_manifest
1872 "//testing/android/driver:driver_apk",
1873 "//tools/android/forwarder2",
1874 "//tools/android/md5sum",
1876 if (defined(test_runner_data_dep)) {
1877 data_deps += test_runner_data_dep
1879 if (defined(invoker.data_deps)) {
1880 data_deps += invoker.data_deps
1883 "//testing/android/broker:broker_java",
1885 if (defined(invoker.deps)) {
1886 deps += invoker.deps
1888 if (defined(invoker.java_files)) {
1889 java_files = invoker.java_files
1891 if (defined(invoker.srcjar_deps)) {
1892 srcjar_deps = invoker.srcjar_deps
1894 if (defined(invoker.apk_name)) {
1895 apk_name = invoker.apk_name
1897 if (defined(invoker.final_apk_path)) {
1898 final_apk_path = invoker.final_apk_path
1900 if (defined(invoker.native_libs)) {
1901 native_libs = invoker.native_libs
1903 if (defined(invoker.apk_under_test)) {
1904 apk_under_test = invoker.apk_under_test
1906 if (defined(invoker.DEPRECATED_java_in_dir)) {
1907 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1912 # Declare an Android gtest apk
1914 # This target creates an Android apk for running gtest-based unittests.
1917 # deps: Specifies the dependencies of this target. These will be passed to
1918 # the underlying android_apk invocation and should include the java and
1919 # resource dependencies of the apk.
1920 # unittests_dep: This should be the label of the gtest native target. This
1921 # target must be defined previously in the same file.
1922 # unittests_binary: The basename of the library produced by the unittests_dep
1923 # target. If unspecified, it assumes the name of the unittests_dep target
1924 # (which will be correct unless that target specifies an "output_name".
1925 # TODO(brettw) make this automatic by allowing get_target_outputs to
1926 # support executables.
1927 # apk_name: The name of the produced apk. If unspecified, it uses the name
1928 # of the unittests_dep target postfixed with "_apk"
1931 # unittest_apk("foo_unittests_apk") {
1932 # deps = [ ":foo_java", ":foo_resources" ]
1933 # unittests_dep = ":foo_unittests"
1935 template("unittest_apk") {
1936 set_sources_assignment_filter([])
1939 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1941 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1943 # This trivial assert is needed in case both unittests_binary and apk_name
1944 # are defined, as otherwise test_suite_name would not be used.
1945 assert(test_suite_name != "")
1947 if (defined(invoker.unittests_binary)) {
1948 unittests_binary = invoker.unittests_binary
1950 unittests_binary = "lib${test_suite_name}${android_product_extension}"
1953 if (defined(invoker.apk_name)) {
1954 apk_name = invoker.apk_name
1956 apk_name = test_suite_name
1959 android_apk(target_name) {
1960 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1962 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
1963 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
1964 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
1965 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
1967 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1968 native_libs = [ unittests_binary ]
1969 if (defined(invoker.asset_location)) {
1970 asset_location = invoker.asset_location
1974 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1975 "//testing/android/appurify_support:appurify_support_java",
1976 "//testing/android/reporter:reporter_java",
1978 if (defined(invoker.deps)) {
1979 deps += invoker.deps
1981 data_deps = [ "//tools/android/md5sum" ]
1982 if (host_os == "linux") {
1983 data_deps += [ "//tools/android/forwarder2" ]
1985 if (defined(invoker.data_deps)) {
1986 data_deps += invoker.data_deps
1991 # Generate .java files from .aidl files.
1993 # This target will store the .java files in a srcjar and should be included in
1994 # an android_library or android_apk's srcjar_deps.
1997 # sources: Paths to .aidl files to compile.
1998 # import_include: Path to directory containing .java files imported by the
2000 # interface_file: Preprocessed aidl file to import.
2003 # android_aidl("foo_aidl") {
2004 # import_include = "java/src"
2006 # "java/src/com/foo/bar/FooBarService.aidl",
2007 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
2010 template("android_aidl") {
2011 set_sources_assignment_filter([])
2012 if (defined(invoker.testonly)) {
2013 testonly = invoker.testonly
2016 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
2017 aidl_path = "${android_sdk_build_tools}/aidl"
2018 framework_aidl = "$android_sdk/framework.aidl"
2020 action(target_name) {
2021 script = "//build/android/gyp/aidl.py"
2022 sources = invoker.sources
2024 imports = [ framework_aidl ]
2025 if (defined(invoker.interface_file)) {
2026 assert(invoker.interface_file != "")
2027 imports += [ invoker.interface_file ]
2030 inputs = [ aidl_path ] + imports
2032 depfile = "${target_gen_dir}/${target_name}.d"
2037 rebased_imports = rebase_path(imports, root_build_dir)
2040 rebase_path(depfile, root_build_dir),
2042 rebase_path(aidl_path, root_build_dir),
2043 "--imports=$rebased_imports",
2045 rebase_path(srcjar_path, root_build_dir),
2047 if (defined(invoker.import_include) && invoker.import_include != "") {
2048 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
2049 # switch to constructing a depfile for the overall action from that
2050 # instead of having all the .java files in the include paths as inputs.
2051 rebased_import_includes =
2052 rebase_path([ invoker.import_include ], root_build_dir)
2053 args += [ "--includes=$rebased_import_includes" ]
2055 _java_files_build_rel =
2056 exec_script("//build/android/gyp/find.py",
2057 rebase_path([ invoker.import_include ], root_build_dir),
2059 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
2060 inputs += _java_files
2062 args += rebase_path(sources, root_build_dir)
2066 # Creates a dist directory for a native executable.
2068 # Running a native executable on a device requires all the shared library
2069 # dependencies of that executable. To make it easier to install and run such an
2070 # executable, this will create a directory containing the native exe and all
2071 # it's library dependencies.
2073 # Note: It's usually better to package things as an APK than as a native
2077 # dist_dir: Directory for the exe and libraries. Everything in this directory
2078 # will be deleted before copying in the exe and libraries.
2079 # binary: Path to (stripped) executable.
2082 # create_native_executable_dist("foo_dist") {
2083 # dist_dir = "$root_build_dir/foo_dist"
2084 # binary = "$root_build_dir/exe.stripped/foo"
2085 # deps = [ ":the_thing_that_makes_foo" ]
2087 template("create_native_executable_dist") {
2088 set_sources_assignment_filter([])
2089 if (defined(invoker.testonly)) {
2090 testonly = invoker.testonly
2093 dist_dir = invoker.dist_dir
2094 binary = invoker.binary
2095 template_name = target_name
2098 "${target_gen_dir}/${template_name}_library_dependencies.list"
2100 find_deps_target_name = "${template_name}__find_library_dependencies"
2101 copy_target_name = "${template_name}__copy_libraries_and_exe"
2103 stripped_libraries_dir = "$root_build_dir/lib.stripped"
2104 action(find_deps_target_name) {
2105 visibility = [ ":$copy_target_name" ]
2107 script = "//build/android/gyp/write_ordered_libraries.py"
2108 depfile = "$target_gen_dir/$target_name.d"
2117 rebased_binaries = rebase_path([ binary ], root_build_dir)
2120 rebase_path(depfile, root_build_dir),
2121 "--input-libraries=$rebased_binaries",
2123 rebase_path(stripped_libraries_dir, root_build_dir),
2125 rebase_path(libraries_list, root_build_dir),
2127 rebase_path(android_readelf, root_build_dir),
2129 if (defined(invoker.deps)) {
2134 copy_ex(copy_target_name) {
2135 visibility = [ ":$template_name" ]
2143 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
2144 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
2146 "--files=$rebased_binaries_list",
2147 "--files=@FileArg($rebased_libraries_list:lib_paths)",
2151 ":$find_deps_target_name",
2153 if (defined(invoker.deps)) {
2154 deps += invoker.deps
2158 group(template_name) {
2159 if (defined(invoker.visibility)) {
2160 visibility = invoker.visibility
2163 ":$copy_target_name",
2168 # Compile a protocol buffer to java.
2170 # This generates java files from protocol buffers and creates an Android library
2171 # containing the classes.
2174 # sources: Paths to .proto files to compile.
2175 # proto_path: Root directory of .proto files.
2178 # proto_java_library("foo_proto_java") {
2179 # proto_path = [ "src/foo" ]
2180 # sources = [ "$proto_path/foo.proto" ]
2182 template("proto_java_library") {
2183 set_sources_assignment_filter([])
2184 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
2185 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
2186 _protoc_bin = "$_protoc_out_dir/android_protoc"
2187 _proto_path = invoker.proto_path
2189 _template_name = target_name
2191 action("${_template_name}__protoc_java") {
2192 srcjar_path = "$target_gen_dir/$target_name.srcjar"
2193 script = "//build/protoc_java.py"
2197 sources = invoker.sources
2198 depfile = "$target_gen_dir/$target_name.d"
2205 rebase_path(depfile, root_build_dir),
2207 rebase_path(_protoc_bin, root_build_dir),
2209 rebase_path(_proto_path, root_build_dir),
2211 rebase_path(srcjar_path, root_build_dir),
2212 ] + rebase_path(sources, root_build_dir)
2215 android_library(target_name) {
2217 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2219 "//third_party/android_protobuf:protobuf_nano_javalib",
2224 # TODO(GYP): implement this.
2225 template("uiautomator_test") {
2226 set_sources_assignment_filter([])
2227 if (defined(invoker.testonly)) {
2228 testonly = invoker.testonly
2230 assert(target_name != "")
2231 assert(invoker.deps != [] || true)
2232 group(target_name) {