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.
865 # data_deps, testonly
868 # java_binary("foo") {
869 # java_files = [ "org/chromium/foo/FooMain.java" ]
870 # deps = [ ":bar_java" ]
871 # main_class = "org.chromium.foo.FooMain"
873 template("java_binary") {
874 set_sources_assignment_filter([])
876 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
877 # dependents shouldn't get the jar in their classpath, etc.).
878 java_library_impl(target_name) {
879 if (defined(invoker.DEPRECATED_java_in_dir)) {
880 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
882 if (defined(invoker.chromium_code)) {
883 chromium_code = invoker.chromium_code
885 if (defined(invoker.data_deps)) {
886 deps = invoker.data_deps
888 if (defined(invoker.deps)) {
891 if (defined(invoker.java_files)) {
892 java_files = invoker.java_files
894 if (defined(invoker.srcjar_deps)) {
895 srcjar_deps = invoker.srcjar_deps
897 if (defined(invoker.srcjars)) {
898 srcjars = invoker.srcjars
900 if (defined(invoker.bypass_platform_checks)) {
901 bypass_platform_checks = invoker.bypass_platform_checks
903 if (defined(invoker.testonly)) {
904 testonly = invoker.testonly
907 main_class = invoker.main_class
911 # Declare a Junit executable target
913 # This target creates an executable from java code for running as a junit test
914 # suite. The executable will be in the output folder's /bin/ directory.
917 # deps: Specifies the dependencies of this target. Java targets in this list
918 # will be included in the executable (and the javac classpath).
920 # java_files: List of .java files included in this library.
921 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
922 # will be added to java_files and be included in this library.
923 # srcjars: List of srcjars to be included in this library, together with the
924 # ones obtained from srcjar_deps.
926 # chromium_code: If true, extra analysis warning/errors will be enabled.
929 # junit_binary("foo") {
930 # java_files = [ "org/chromium/foo/FooTest.java" ]
931 # deps = [ ":bar_java" ]
933 template("junit_binary") {
934 set_sources_assignment_filter([])
936 java_binary(target_name) {
937 bypass_platform_checks = true
938 main_class = "org.chromium.testing.local.JunitTestMain"
941 if (defined(invoker.DEPRECATED_java_in_dir)) {
942 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
944 if (defined(invoker.chromium_code)) {
945 chromium_code = invoker.chromium_code
948 "//testing/android/junit:junit_test_support",
949 "//third_party/junit",
950 "//third_party/mockito:mockito_java",
951 "//third_party/robolectric:robolectric_java",
952 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
954 if (defined(invoker.deps)) {
957 if (defined(invoker.java_files)) {
958 java_files = invoker.java_files
960 if (defined(invoker.srcjar_deps)) {
961 srcjar_deps = invoker.srcjar_deps
963 if (defined(invoker.srcjars)) {
964 srcjars = invoker.srcjars
969 # Declare a java library target
972 # deps: Specifies the dependencies of this target. Java targets in this list
973 # will be added to the javac classpath.
975 # java_files: List of .java files included in this library.
976 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
977 # will be added to java_files and be included in this library.
978 # srcjars: List of srcjars to be included in this library, together with the
979 # ones obtained from srcjar_deps.
980 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
981 # this directory will be included in the library. This is only supported to
982 # ease the gyp->gn conversion and will be removed in the future.
984 # chromium_code: If true, extra analysis warning/errors will be enabled.
985 # jar_excluded_patterns: List of patterns of .class files to exclude from the
988 # proguard_preprocess: If true, proguard preprocessing will be run. This can
989 # be used to remove unwanted parts of the library.
990 # proguard_config: Path to the proguard config for preprocessing.
992 # supports_android: If true, Android targets (android_library, android_apk)
993 # may depend on this target. Note: if true, this target must only use the
994 # subset of Java available on Android.
995 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
996 # dependencies for this target. This will allow depending on an
997 # android_library target, for example.
999 # data_deps, testonly
1002 # java_library("foo_java") {
1004 # "org/chromium/foo/Foo.java",
1005 # "org/chromium/foo/FooInterface.java",
1006 # "org/chromium/foo/FooService.java",
1012 # ":foo_generated_enum"
1014 # jar_excluded_patterns = [
1015 # "*/FooService.class", "*/FooService##*.class"
1018 template("java_library") {
1019 set_sources_assignment_filter([])
1020 java_library_impl(target_name) {
1021 if (defined(invoker.DEPRECATED_java_in_dir)) {
1022 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1024 if (defined(invoker.chromium_code)) {
1025 chromium_code = invoker.chromium_code
1027 if (defined(invoker.data_deps)) {
1028 deps = invoker.data_deps
1030 if (defined(invoker.deps)) {
1033 if (defined(invoker.jar_excluded_patterns)) {
1034 jar_excluded_patterns = invoker.jar_excluded_patterns
1036 if (defined(invoker.java_files)) {
1037 java_files = invoker.java_files
1039 if (defined(invoker.proguard_config)) {
1040 proguard_config = invoker.proguard_config
1042 if (defined(invoker.proguard_preprocess)) {
1043 proguard_preprocess = invoker.proguard_preprocess
1045 if (defined(invoker.srcjar_deps)) {
1046 srcjar_deps = invoker.srcjar_deps
1048 if (defined(invoker.srcjars)) {
1049 srcjars = invoker.srcjars
1051 if (defined(invoker.bypass_platform_checks)) {
1052 bypass_platform_checks = invoker.bypass_platform_checks
1054 if (defined(invoker.testonly)) {
1055 testonly = invoker.testonly
1057 if (defined(invoker.jar_path)) {
1058 jar_path = invoker.jar_path
1061 if (defined(invoker.supports_android) && invoker.supports_android) {
1062 supports_android = true
1067 # Declare a java library target for a prebuilt jar
1070 # deps: Specifies the dependencies of this target. Java targets in this list
1071 # will be added to the javac classpath.
1072 # jar_path: Path to the prebuilt jar.
1073 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1074 # be used to remove unwanted parts of the library.
1075 # proguard_config: Path to the proguard config for preprocessing.
1078 # java_prebuilt("foo_java") {
1079 # jar_path = "foo.jar"
1085 template("java_prebuilt") {
1086 set_sources_assignment_filter([])
1087 java_prebuilt_impl(target_name) {
1088 jar_path = invoker.jar_path
1089 if (defined(invoker.testonly)) {
1090 testonly = invoker.testonly
1092 if (defined(invoker.deps)) {
1095 if (defined(invoker.proguard_config)) {
1096 proguard_config = invoker.proguard_config
1098 if (defined(invoker.proguard_preprocess)) {
1099 proguard_preprocess = invoker.proguard_preprocess
1104 # Declare an Android library target
1106 # This target creates an Android library containing java code and Android
1110 # deps: Specifies the dependencies of this target. Java targets in this list
1111 # will be added to the javac classpath. Android resources in dependencies
1112 # will be used when building this library.
1114 # java_files: List of .java files included in this library.
1115 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1116 # will be added to java_files and be included in this library.
1117 # srcjars: List of srcjars to be included in this library, together with the
1118 # ones obtained from srcjar_deps.
1119 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1120 # this directory will be included in the library. This is only supported to
1121 # ease the gyp->gn conversion and will be removed in the future.
1123 # chromium_code: If true, extra analysis warning/errors will be enabled.
1124 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1127 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1128 # be used to remove unwanted parts of the library.
1129 # proguard_config: Path to the proguard config for preprocessing.
1131 # dex_path: If set, the resulting .dex.jar file will be placed under this
1136 # android_library("foo_java") {
1138 # "android/org/chromium/foo/Foo.java",
1139 # "android/org/chromium/foo/FooInterface.java",
1140 # "android/org/chromium/foo/FooService.java",
1146 # ":foo_generated_enum"
1148 # jar_excluded_patterns = [
1149 # "*/FooService.class", "*/FooService##*.class"
1152 template("android_library") {
1153 set_sources_assignment_filter([])
1154 assert(!defined(invoker.jar_path),
1155 "android_library does not support a custom jar path")
1156 java_library_impl(target_name) {
1157 if (defined(invoker.DEPRECATED_java_in_dir)) {
1158 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1160 if (defined(invoker.chromium_code)) {
1161 chromium_code = invoker.chromium_code
1163 if (defined(invoker.data_deps)) {
1164 deps = invoker.data_deps
1166 if (defined(invoker.deps)) {
1169 if (defined(invoker.jar_excluded_patterns)) {
1170 jar_excluded_patterns = invoker.jar_excluded_patterns
1172 if (defined(invoker.java_files)) {
1173 java_files = invoker.java_files
1175 if (defined(invoker.proguard_config)) {
1176 proguard_config = invoker.proguard_config
1178 if (defined(invoker.proguard_preprocess)) {
1179 proguard_preprocess = invoker.proguard_preprocess
1181 if (defined(invoker.srcjar_deps)) {
1182 srcjar_deps = invoker.srcjar_deps
1184 if (defined(invoker.srcjars)) {
1185 srcjars = invoker.srcjars
1187 if (defined(invoker.testonly)) {
1188 testonly = invoker.testonly
1190 if (defined(invoker.visibility)) {
1191 visibility = invoker.visibility
1193 if (defined(invoker.dex_path)) {
1194 dex_path = invoker.dex_path
1196 if (defined(invoker.manifest_entries)) {
1197 manifest_entries = invoker.manifest_entries
1200 supports_android = true
1201 requires_android = true
1203 if (!defined(jar_excluded_patterns)) {
1204 jar_excluded_patterns = []
1206 jar_excluded_patterns += [
1210 "*/Manifest##*.class",
1215 # Declare a target that packages a set of Java dependencies into a standalone
1219 # deps: specifies the dependencies of this target. Android libraries in deps
1220 # will be packaged into the resulting .dex.jar file.
1221 # dex_path: location at which the output file will be put
1222 template("android_standalone_library") {
1223 set_sources_assignment_filter([])
1224 deps_dex(target_name) {
1226 dex_path = invoker.dex_path
1227 if (defined(invoker.excluded_jars)) {
1228 excluded_jars = invoker.excluded_jars
1233 # Declare an Android library target for a prebuilt jar
1235 # This target creates an Android library containing java code and Android
1239 # deps: Specifies the dependencies of this target. Java targets in this list
1240 # will be added to the javac classpath. Android resources in dependencies
1241 # will be used when building this library.
1242 # jar_path: Path to the prebuilt jar.
1243 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1244 # be used to remove unwanted parts of the library.
1245 # proguard_config: Path to the proguard config for preprocessing.
1248 # android_java_prebuilt("foo_java") {
1249 # jar_path = "foo.jar"
1255 template("android_java_prebuilt") {
1256 set_sources_assignment_filter([])
1257 java_prebuilt_impl(target_name) {
1258 jar_path = invoker.jar_path
1259 supports_android = true
1260 requires_android = true
1261 if (defined(invoker.testonly)) {
1262 testonly = invoker.testonly
1264 if (defined(invoker.deps)) {
1267 if (defined(invoker.proguard_config)) {
1268 proguard_config = invoker.proguard_config
1270 if (defined(invoker.proguard_preprocess)) {
1271 proguard_preprocess = invoker.proguard_preprocess
1276 # Declare an Android apk target
1278 # This target creates an Android APK containing java code, resources, assets,
1279 # and (possibly) native libraries.
1282 # android_manifest: Path to AndroidManifest.xml.
1283 # data_deps: List of dependencies needed at runtime. These will be built but
1284 # won't change the generated .apk in any way (in fact they may be built
1285 # after the .apk is).
1286 # deps: List of dependencies. All Android java resources and libraries in the
1287 # "transitive closure" of these dependencies will be included in the apk.
1288 # Note: this "transitive closure" actually only includes such targets if
1289 # they are depended on through android_library or android_resources targets
1290 # (and so not through builtin targets like 'action', 'group', etc).
1291 # java_files: List of .java files to include in the apk.
1292 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1293 # will be added to java_files and be included in this apk.
1294 # apk_name: Name for final apk.
1295 # final_apk_path: Path to final built apk. Default is
1296 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1297 # native_libs: List paths of native libraries to include in this apk. If these
1298 # libraries depend on other shared_library targets, those dependencies will
1299 # also be included in the apk.
1300 # apk_under_test: For an instrumentation test apk, this is the target of the
1302 # include_all_resources - If true include all resource IDs in all generated
1304 # testonly: Marks this target as "test-only".
1306 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1307 # this directory will be included in the library. This is only supported to
1308 # ease the gyp->gn conversion and will be removed in the future.
1311 # android_apk("foo_apk") {
1312 # android_manifest = "AndroidManifest.xml"
1314 # "android/org/chromium/foo/FooApplication.java",
1315 # "android/org/chromium/foo/FooActivity.java",
1318 # ":foo_support_java"
1322 # ":foo_generated_enum"
1328 template("android_apk") {
1329 set_sources_assignment_filter([])
1330 if (defined(invoker.testonly)) {
1331 testonly = invoker.testonly
1334 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1335 assert(defined(invoker.android_manifest))
1336 gen_dir = "$target_gen_dir/$target_name"
1337 base_path = "$gen_dir/$target_name"
1338 _build_config = "$target_gen_dir/$target_name.build_config"
1339 resources_zip_path = "$base_path.resources.zip"
1340 _all_resources_zip_path = "$base_path.resources.all.zip"
1341 jar_path = "$base_path.jar"
1342 _template_name = target_name
1344 final_dex_path = "$gen_dir/classes.dex"
1345 final_dex_target_name = "${_template_name}__final_dex"
1347 _final_apk_path = ""
1348 if (defined(invoker.final_apk_path)) {
1349 _final_apk_path = invoker.final_apk_path
1350 } else if (defined(invoker.apk_name)) {
1351 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1353 _dist_jar_path_list =
1354 process_file_template(
1355 [ _final_apk_path ],
1356 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1357 _dist_jar_path = _dist_jar_path_list[0]
1362 if (defined(invoker.version_code)) {
1363 _version_code = invoker.version_code
1366 _version_name = "Developer Build"
1367 if (defined(invoker.version_name)) {
1368 _version_name = invoker.version_name
1370 _keystore_path = android_default_keystore_path
1371 _keystore_name = android_default_keystore_name
1372 _keystore_password = android_default_keystore_password
1374 if (defined(invoker.keystore_path)) {
1375 _keystore_path = invoker.keystore_path
1376 _keystore_name = invoker.keystore_name
1377 _keystore_password = invoker.keystore_password
1381 if (defined(invoker.srcjar_deps)) {
1382 _srcjar_deps += invoker.srcjar_deps
1385 _load_library_from_apk = false
1387 # The dependency that makes the chromium linker, if any is needed.
1388 _chromium_linker_dep = []
1390 if (defined(invoker.native_libs)) {
1391 _use_chromium_linker = false
1392 if (defined(invoker.use_chromium_linker)) {
1393 _use_chromium_linker =
1394 invoker.use_chromium_linker && chromium_linker_supported
1395 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1398 if (defined(invoker.load_library_from_apk) &&
1399 invoker.load_library_from_apk) {
1400 _load_library_from_apk = true
1401 assert(_use_chromium_linker,
1402 "Loading library from the apk requires use" +
1403 " of the Chromium linker.")
1406 _enable_relocation_packing = false
1407 if (defined(invoker.enable_relocation_packing) &&
1408 invoker.enable_relocation_packing) {
1409 _enable_relocation_packing = relocation_packing_supported
1410 assert(_use_chromium_linker,
1411 "Relocation packing requires use of the" + " Chromium linker.")
1414 _native_libs = process_file_template(
1415 invoker.native_libs,
1416 "$root_build_dir/lib.stripped/{{source_file_part}}")
1418 _native_libs_dir = base_path + "/libs"
1420 if (_use_chromium_linker) {
1422 [ "$root_build_dir/lib.stripped/libchromium_android_linker.so" ]
1425 _enable_relocation_packing = false
1426 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1427 invoker.enable_relocation_packing) {
1428 _enable_relocation_packing = true
1431 _native_lib_version_name = ""
1432 if (defined(invoker.native_lib_version_name)) {
1433 _native_lib_version_name = invoker.native_lib_version_name
1437 _android_manifest = invoker.android_manifest
1438 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1440 defined(invoker.create_abi_split) && invoker.create_abi_split
1441 _create_density_splits =
1442 defined(invoker.create_density_splits) && invoker.create_density_splits
1444 # Help GN understand that _create_abi_split is not unused (bug in GN).
1445 assert(_create_abi_split || true)
1447 build_config_target = "${_template_name}__build_config"
1448 write_build_config(build_config_target) {
1449 type = "android_apk"
1450 dex_path = final_dex_path
1451 resources_zip = resources_zip_path
1452 build_config = _build_config
1453 android_manifest = _android_manifest
1455 deps = _chromium_linker_dep
1456 if (defined(invoker.deps)) {
1457 deps += invoker.deps
1460 if (defined(invoker.apk_under_test)) {
1461 apk_under_test = invoker.apk_under_test
1464 native_libs = _native_libs
1469 process_resources_target = "${_template_name}__process_resources"
1470 final_deps += [ ":$process_resources_target" ]
1471 process_resources(process_resources_target) {
1472 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1473 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1474 android_manifest = _android_manifest
1475 resource_dirs = [ "//build/android/ant/empty/res" ]
1476 zip_path = resources_zip_path
1477 all_resources_zip_path = _all_resources_zip_path
1478 generate_constant_ids = true
1480 if (defined(invoker.include_all_resources)) {
1481 include_all_resources = invoker.include_all_resources
1484 build_config = _build_config
1486 ":$build_config_target",
1488 if (defined(invoker.deps)) {
1489 deps += invoker.deps
1492 _srcjar_deps += [ ":$process_resources_target" ]
1494 if (_native_libs != []) {
1495 _enable_chromium_linker_tests = false
1496 if (defined(invoker.enable_chromium_linker_tests)) {
1497 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1500 java_cpp_template("${_template_name}__native_libraries_java") {
1501 package_name = "org/chromium/base/library_loader"
1503 "//base/android/java/templates/NativeLibraries.template",
1509 ":$build_config_target",
1513 "NATIVE_LIBRARIES_LIST=" +
1514 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1515 "NATIVE_LIBRARIES_VERSION_NUMBER=\"$_native_lib_version_name\"",
1517 if (_use_chromium_linker) {
1518 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1520 if (_load_library_from_apk) {
1521 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1523 if (_enable_chromium_linker_tests) {
1524 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1527 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1530 java_target = "${_template_name}__java"
1531 final_deps += [ ":$java_target" ]
1532 java_library_impl(java_target) {
1533 supports_android = true
1534 requires_android = true
1535 override_build_config = _build_config
1537 ":$build_config_target",
1540 android_manifest = _android_manifest
1541 chromium_code = true
1542 if (defined(invoker.java_files)) {
1543 java_files = invoker.java_files
1544 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1545 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1549 srcjar_deps = _srcjar_deps
1550 dex_path = base_path + ".dex.jar"
1552 if (defined(invoker.deps)) {
1553 deps += invoker.deps
1557 if (_dist_jar_path != "") {
1558 create_dist_target = "${_template_name}__create_dist_jar"
1559 final_deps += [ ":$create_dist_target" ]
1561 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1562 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1563 # able to just do that calculation at build time instead.
1564 action(create_dist_target) {
1565 script = "//build/android/gyp/create_dist_jar.py"
1566 depfile = "$target_gen_dir/$target_name.d"
1576 rebase_path(depfile, root_build_dir),
1578 rebase_path(_dist_jar_path, root_build_dir),
1579 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1581 inputs += [ jar_path ]
1582 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1583 args += [ "--inputs=$_rebased_jar_path" ]
1585 ":$build_config_target", # Generates the build config file.
1586 ":$java_target", # Generates the jar file.
1591 final_deps += [ ":$final_dex_target_name" ]
1592 dex("$final_dex_target_name") {
1594 ":$build_config_target",
1603 output = final_dex_path
1604 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1605 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1608 if (_native_libs != []) {
1609 action("${_template_name}__prepare_native") {
1610 script = "//build/android/gyp/pack_arm_relocations.py"
1611 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1612 depfile = "$target_gen_dir/$target_name.d"
1617 inputs = _native_libs
1618 deps = _chromium_linker_dep
1620 inputs += [ _build_config ]
1621 deps += [ ":$build_config_target" ]
1623 skip_packing_list = [
1625 "libchromium_android_linker.so",
1628 enable_packing_arg = 0
1629 if (_enable_relocation_packing) {
1630 enable_packing_arg = 1
1631 deps += [ relocation_packer_target ]
1636 rebase_path(depfile, root_build_dir),
1637 "--enable-packing=$enable_packing_arg",
1638 "--exclude-packing-list=$skip_packing_list",
1639 "--android-pack-relocations",
1640 rebase_path(relocation_packer_exe, root_build_dir),
1641 "--stripped-libraries-dir",
1642 rebase_path(root_build_dir, root_build_dir),
1643 "--packed-libraries-dir",
1644 rebase_path(packed_libraries_dir, root_build_dir),
1645 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1649 if (defined(invoker.deps)) {
1650 deps += invoker.deps
1652 if (defined(invoker.public_deps)) {
1653 public_deps = invoker.public_deps
1655 if (defined(invoker.data_deps)) {
1656 data_deps = invoker.data_deps
1660 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1661 inputs += [ android_gdbserver ]
1662 args += [ "--libraries=$rebased_gdbserver" ]
1667 final_deps += [ ":${_template_name}__create" ]
1668 create_apk("${_template_name}__create") {
1669 apk_path = _final_apk_path
1670 android_manifest = _android_manifest
1671 resources_zip = _all_resources_zip_path
1672 dex_path = final_dex_path
1673 load_library_from_apk = _load_library_from_apk
1674 create_density_splits = _create_density_splits
1675 if (defined(invoker.extensions_to_not_compress)) {
1676 extensions_to_not_compress = invoker.extensions_to_not_compress
1678 # Allow icu data and v8 snapshots to be loaded directly from the .apk.
1679 extensions_to_not_compress = "dat,bin"
1682 version_code = _version_code
1683 version_name = _version_name
1685 keystore_name = _keystore_name
1686 keystore_path = _keystore_path
1687 keystore_password = _keystore_password
1689 # This target generates the input file _all_resources_zip_path.
1691 ":$process_resources_target",
1692 ":$final_dex_target_name",
1694 if (defined(invoker.deps)) {
1695 deps += invoker.deps
1698 if (defined(invoker.asset_location)) {
1699 asset_location = invoker.asset_location
1701 # We don't know the exact dependencies that create the assets in
1702 # |asset_location|; we depend on all caller deps until a better solution
1703 # is figured out (http://crbug.com/433330).
1704 if (defined(invoker.deps)) {
1705 deps += invoker.deps
1709 if (_native_libs != [] && !_create_abi_split) {
1710 native_libs_dir = _native_libs_dir
1711 deps += [ ":${_template_name}__prepare_native" ]
1715 if (_native_libs != [] && _create_abi_split) {
1716 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1717 generate_split_manifest(_manifest_rule) {
1718 main_manifest = _android_manifest
1720 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1721 split_name = "abi_${android_app_abi}"
1724 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1725 final_deps += [ ":$_apk_rule" ]
1726 create_apk(_apk_rule) {
1727 _split_paths = process_file_template(
1728 [ _final_apk_path ],
1729 "{{source_dir}}/{{source_name_part}}-abi-${android_app_abi}.apk")
1730 apk_path = _split_paths[0]
1731 base_path = "$gen_dir/$_apk_rule"
1733 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1734 android_manifest = manifest_outputs[1]
1735 load_library_from_apk = _load_library_from_apk
1737 version_code = _version_code
1738 version_name = _version_name
1740 keystore_name = _keystore_name
1741 keystore_path = _keystore_path
1742 keystore_password = _keystore_password
1744 native_libs_dir = _native_libs_dir
1746 ":${_template_name}__prepare_native",
1751 group(target_name) {
1753 if (defined(invoker.data_deps)) {
1754 data_deps = invoker.data_deps
1759 # Declare an Android instrumentation test apk
1761 # This target creates an Android instrumentation test apk.
1764 # android_manifest: Path to AndroidManifest.xml.
1765 # data_deps: List of dependencies needed at runtime. These will be built but
1766 # won't change the generated .apk in any way (in fact they may be built
1767 # after the .apk is).
1768 # deps: List of dependencies. All Android java resources and libraries in the
1769 # "transitive closure" of these dependencies will be included in the apk.
1770 # Note: this "transitive closure" actually only includes such targets if
1771 # they are depended on through android_library or android_resources targets
1772 # (and so not through builtin targets like 'action', 'group', etc).
1773 # java_files: List of .java files to include in the apk.
1774 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1775 # will be added to java_files and be included in this apk.
1776 # apk_name: Name for final apk.
1777 # final_apk_path: Path to final built apk. Default is
1778 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1779 # native_libs: List paths of native libraries to include in this apk. If these
1780 # libraries depend on other shared_library targets, those dependencies will
1781 # also be included in the apk.
1782 # apk_under_test: The apk being tested.
1783 # isolate_file: Isolate file containing the list of test data dependencies.
1785 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1786 # this directory will be included in the library. This is only supported to
1787 # ease the gyp->gn conversion and will be removed in the future.
1790 # instrumentation_test_apk("foo_test_apk") {
1791 # android_manifest = "AndroidManifest.xml"
1792 # apk_name = "FooTest"
1793 # apk_under_test = "Foo"
1795 # "android/org/chromium/foo/FooTestCase.java",
1796 # "android/org/chromium/foo/FooExampleTest.java",
1799 # ":foo_test_support_java"
1802 template("instrumentation_test_apk") {
1803 set_sources_assignment_filter([])
1805 _template_name = target_name
1807 if (defined(invoker.apk_name)) {
1808 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1809 test_runner_script("${_template_name}__test_runner_script") {
1810 test_name = invoker.target_name
1811 test_type = "instrumentation"
1812 test_apk = invoker.apk_name
1813 if (defined(invoker.isolate_file)) {
1814 isolate_file = invoker.isolate_file
1819 android_apk(target_name) {
1820 if (defined(invoker.android_manifest)) {
1821 android_manifest = invoker.android_manifest
1824 "//testing/android/driver:driver_apk",
1825 "//tools/android/forwarder2",
1826 "//tools/android/md5sum",
1828 if (defined(test_runner_data_dep)) {
1829 data_deps += test_runner_data_dep
1831 if (defined(invoker.data_deps)) {
1832 data_deps += invoker.data_deps
1835 "//testing/android/broker:broker_java",
1837 if (defined(invoker.deps)) {
1838 deps += invoker.deps
1840 if (defined(invoker.java_files)) {
1841 java_files = invoker.java_files
1843 if (defined(invoker.srcjar_deps)) {
1844 srcjar_deps = invoker.srcjar_deps
1846 if (defined(invoker.apk_name)) {
1847 apk_name = invoker.apk_name
1849 if (defined(invoker.final_apk_path)) {
1850 final_apk_path = invoker.final_apk_path
1852 if (defined(invoker.native_libs)) {
1853 native_libs = invoker.native_libs
1855 if (defined(invoker.apk_under_test)) {
1856 apk_under_test = invoker.apk_under_test
1858 if (defined(invoker.DEPRECATED_java_in_dir)) {
1859 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1864 # Declare an Android gtest apk
1866 # This target creates an Android apk for running gtest-based unittests.
1869 # deps: Specifies the dependencies of this target. These will be passed to
1870 # the underlying android_apk invocation and should include the java and
1871 # resource dependencies of the apk.
1872 # unittests_dep: This should be the label of the gtest native target. This
1873 # target must be defined previously in the same file.
1874 # unittests_binary: The basename of the library produced by the unittests_dep
1875 # target. If unspecified, it assumes the name of the unittests_dep target
1876 # (which will be correct unless that target specifies an "output_name".
1877 # TODO(brettw) make this automatic by allowing get_target_outputs to
1878 # support executables.
1879 # apk_name: The name of the produced apk. If unspecified, it uses the name
1880 # of the unittests_dep target postfixed with "_apk"
1883 # unittest_apk("foo_unittests_apk") {
1884 # deps = [ ":foo_java", ":foo_resources" ]
1885 # unittests_dep = ":foo_unittests"
1887 template("unittest_apk") {
1888 set_sources_assignment_filter([])
1891 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1893 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1895 # This trivial assert is needed in case both unittests_binary and apk_name
1896 # are defined, as otherwise test_suite_name would not be used.
1897 assert(test_suite_name != "")
1899 if (defined(invoker.unittests_binary)) {
1900 unittests_binary = invoker.unittests_binary
1902 unittests_binary = "lib" + test_suite_name + ".so"
1905 if (defined(invoker.apk_name)) {
1906 apk_name = invoker.apk_name
1908 apk_name = test_suite_name
1911 android_apk(target_name) {
1912 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1914 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
1915 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
1916 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
1917 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
1919 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1920 native_libs = [ unittests_binary ]
1921 if (defined(invoker.asset_location)) {
1922 asset_location = invoker.asset_location
1926 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1927 "//testing/android/appurify_support:appurify_support_java",
1928 "//testing/android/reporter:reporter_java",
1930 if (defined(invoker.deps)) {
1931 deps += invoker.deps
1933 data_deps = [ "//tools/android/md5sum" ]
1934 if (host_os == "linux") {
1935 data_deps += [ "//tools/android/forwarder2" ]
1937 if (defined(invoker.data_deps)) {
1938 data_deps += invoker.data_deps
1943 # Generate .java files from .aidl files.
1945 # This target will store the .java files in a srcjar and should be included in
1946 # an android_library or android_apk's srcjar_deps.
1949 # sources: Paths to .aidl files to compile.
1950 # import_include: Path to directory containing .java files imported by the
1952 # interface_file: Preprocessed aidl file to import.
1955 # android_aidl("foo_aidl") {
1956 # import_include = "java/src"
1958 # "java/src/com/foo/bar/FooBarService.aidl",
1959 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1962 template("android_aidl") {
1963 set_sources_assignment_filter([])
1964 if (defined(invoker.testonly)) {
1965 testonly = invoker.testonly
1968 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1969 aidl_path = "${android_sdk_build_tools}/aidl"
1970 framework_aidl = "$android_sdk/framework.aidl"
1972 action(target_name) {
1973 script = "//build/android/gyp/aidl.py"
1974 sources = invoker.sources
1976 imports = [ framework_aidl ]
1977 if (defined(invoker.interface_file)) {
1978 assert(invoker.interface_file != "")
1979 imports += [ invoker.interface_file ]
1982 inputs = [ aidl_path ] + imports
1984 depfile = "${target_gen_dir}/${target_name}.d"
1989 rebased_imports = rebase_path(imports, root_build_dir)
1992 rebase_path(depfile, root_build_dir),
1994 rebase_path(aidl_path, root_build_dir),
1995 "--imports=$rebased_imports",
1997 rebase_path(srcjar_path, root_build_dir),
1999 if (defined(invoker.import_include) && invoker.import_include != "") {
2000 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
2001 # switch to constructing a depfile for the overall action from that
2002 # instead of having all the .java files in the include paths as inputs.
2003 rebased_import_includes =
2004 rebase_path([ invoker.import_include ], root_build_dir)
2005 args += [ "--includes=$rebased_import_includes" ]
2007 _java_files_build_rel =
2008 exec_script("//build/android/gyp/find.py",
2009 rebase_path([ invoker.import_include ], root_build_dir),
2011 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
2012 inputs += _java_files
2014 args += rebase_path(sources, root_build_dir)
2018 # Creates a dist directory for a native executable.
2020 # Running a native executable on a device requires all the shared library
2021 # dependencies of that executable. To make it easier to install and run such an
2022 # executable, this will create a directory containing the native exe and all
2023 # it's library dependencies.
2025 # Note: It's usually better to package things as an APK than as a native
2029 # dist_dir: Directory for the exe and libraries. Everything in this directory
2030 # will be deleted before copying in the exe and libraries.
2031 # binary: Path to (stripped) executable.
2034 # create_native_executable_dist("foo_dist") {
2035 # dist_dir = "$root_build_dir/foo_dist"
2036 # binary = "$root_build_dir/exe.stripped/foo"
2037 # deps = [ ":the_thing_that_makes_foo" ]
2039 template("create_native_executable_dist") {
2040 set_sources_assignment_filter([])
2041 if (defined(invoker.testonly)) {
2042 testonly = invoker.testonly
2045 dist_dir = invoker.dist_dir
2046 binary = invoker.binary
2047 template_name = target_name
2050 "${target_gen_dir}/${template_name}_library_dependencies.list"
2054 #'<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
2057 find_deps_target_name = "${template_name}__find_library_dependencies"
2058 copy_target_name = "${template_name}__copy_libraries_and_exe"
2060 stripped_libraries_dir = "$root_build_dir/lib.stripped"
2061 action(find_deps_target_name) {
2062 visibility = [ ":$copy_target_name" ]
2064 script = "//build/android/gyp/write_ordered_libraries.py"
2065 depfile = "$target_gen_dir/$target_name.d"
2074 rebased_binaries = rebase_path([ binary ], root_build_dir)
2077 rebase_path(depfile, root_build_dir),
2078 "--input-libraries=$rebased_binaries",
2080 rebase_path(stripped_libraries_dir, root_build_dir),
2082 rebase_path(libraries_list, root_build_dir),
2084 rebase_path(android_readelf, root_build_dir),
2086 if (defined(invoker.deps)) {
2091 copy_ex(copy_target_name) {
2092 visibility = [ ":$template_name" ]
2100 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
2101 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
2103 "--files=$rebased_binaries_list",
2104 "--files=@FileArg($rebased_libraries_list:libraries)",
2108 ":$find_deps_target_name",
2110 if (defined(invoker.deps)) {
2111 deps += invoker.deps
2115 group(template_name) {
2116 if (defined(invoker.visibility)) {
2117 visibility = invoker.visibility
2120 ":$copy_target_name",
2125 # Compile a protocol buffer to java.
2127 # This generates java files from protocol buffers and creates an Android library
2128 # containing the classes.
2131 # sources: Paths to .proto files to compile.
2132 # proto_path: Root directory of .proto files.
2135 # proto_java_library("foo_proto_java") {
2136 # proto_path = [ "src/foo" ]
2137 # sources = [ "$proto_path/foo.proto" ]
2139 template("proto_java_library") {
2140 set_sources_assignment_filter([])
2141 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
2142 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
2143 _protoc_bin = "$_protoc_out_dir/android_protoc"
2144 _proto_path = invoker.proto_path
2146 _template_name = target_name
2148 action("${_template_name}__protoc_java") {
2149 srcjar_path = "$target_gen_dir/$target_name.srcjar"
2150 script = "//build/protoc_java.py"
2154 sources = invoker.sources
2155 depfile = "$target_gen_dir/$target_name.d"
2162 rebase_path(depfile, root_build_dir),
2164 rebase_path(_protoc_bin, root_build_dir),
2166 rebase_path(_proto_path, root_build_dir),
2168 rebase_path(srcjar_path, root_build_dir),
2169 ] + rebase_path(sources, root_build_dir)
2172 android_library(target_name) {
2174 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2176 "//third_party/android_protobuf:protobuf_nano_javalib",
2181 # TODO(GYP): implement this.
2182 template("uiautomator_test") {
2183 set_sources_assignment_filter([])
2184 if (defined(invoker.testonly)) {
2185 testonly = invoker.testonly
2187 assert(target_name != "")
2188 assert(invoker.deps != [] || true)
2189 group(target_name) {