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("//build/toolchain/toolchain.gni")
9 import("//third_party/android_platform/config.gni")
10 import("//tools/grit/grit_rule.gni")
14 # Declare a jni target
16 # This target generates the native jni bindings for a set of .java files.
18 # See base/android/jni_generator/jni_generator.py for more info about the
19 # format of generating JNI bindings.
22 # sources: list of .java files to generate jni for
23 # jni_package: subdirectory path for generated bindings
26 # generate_jni("foo_jni") {
28 # "android/java/src/org/chromium/foo/Foo.java",
29 # "android/java/src/org/chromium/foo/FooUtil.java",
33 template("generate_jni") {
34 set_sources_assignment_filter([])
35 if (defined(invoker.testonly)) {
36 testonly = invoker.testonly
39 assert(defined(invoker.sources))
40 assert(defined(invoker.jni_package))
41 jni_package = invoker.jni_package
42 base_output_dir = "${target_gen_dir}/${target_name}"
43 package_output_dir = "${base_output_dir}/${jni_package}"
44 jni_output_dir = "${package_output_dir}/jni"
46 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
48 foreach_target_name = "${target_name}__jni_gen"
49 action_foreach(foreach_target_name) {
50 script = "//base/android/jni_generator/jni_generator.py"
51 depfile = "$target_gen_dir/$target_name.{{source_name_part}}.d"
52 sources = invoker.sources
55 "${jni_output_dir}/{{source_name_part}}_jni.h",
60 rebase_path(depfile, root_build_dir),
61 "--input_file={{source}}",
62 "--optimize_generation=1",
65 rebase_path(jni_output_dir, root_build_dir),
67 rebase_path(jni_generator_include, jni_output_dir),
68 "--native_exports_optional",
70 if (defined(invoker.jni_generator_jarjar_file)) {
73 rebase_path(jni_generator_jarjar_file, root_build_dir),
78 config("jni_includes_${target_name}") {
79 # TODO(cjhopman): #includes should probably all be relative to
80 # base_output_dir. Remove that from this config once the includes are
90 ":$foreach_target_name",
92 public_configs = [ ":jni_includes_${target_name}" ]
94 if (defined(invoker.deps)) {
97 if (defined(invoker.public_deps)) {
98 public_deps = invoker.public_deps
101 if (defined(invoker.visibility)) {
102 visibility = invoker.visibility
107 # Declare a jni target for a prebuilt jar
109 # This target generates the native jni bindings for a set of classes in a .jar.
111 # See base/android/jni_generator/jni_generator.py for more info about the
112 # format of generating JNI bindings.
115 # classes: list of .class files in the jar to generate jni for. These should
116 # include the full path to the .class file.
117 # jni_package: subdirectory path for generated bindings
118 # jar_file: the path to the .jar. If not provided, will default to the sdk's
121 # deps, public_deps: As normal
124 # generate_jar_jni("foo_jni") {
126 # "android/view/Foo.class",
128 # jni_package = "foo"
130 template("generate_jar_jni") {
131 set_sources_assignment_filter([])
132 if (defined(invoker.testonly)) {
133 testonly = invoker.testonly
136 assert(defined(invoker.classes))
137 assert(defined(invoker.jni_package))
139 if (defined(invoker.jar_file)) {
140 jar_file = invoker.jar_file
142 jar_file = android_sdk_jar
145 jni_package = invoker.jni_package
146 base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}"
147 jni_output_dir = "${base_output_dir}/jni"
149 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
151 # TODO(cjhopman): make jni_generator.py support generating jni for multiple
152 # .class files from a .jar.
154 foreach(class, invoker.classes) {
156 _classname_list = process_file_template([ class ], "{{source_name_part}}")
157 classname = _classname_list[0]
158 jni_target_name = "${target_name}__jni_${classname}"
159 jni_actions += [ ":$jni_target_name" ]
160 action(jni_target_name) {
161 # The sources aren't compiled so don't check their dependencies.
162 check_includes = false
163 depfile = "$target_gen_dir/$target_name.d"
164 script = "//base/android/jni_generator/jni_generator.py"
170 "${jni_output_dir}/${classname}_jni.h",
175 rebase_path(depfile, root_build_dir),
177 rebase_path(jar_file, root_build_dir),
180 "--optimize_generation=1",
183 rebase_path(jni_output_dir, root_build_dir),
185 rebase_path(jni_generator_include, jni_output_dir),
186 "--native_exports_optional",
191 config("jni_includes_${target_name}") {
192 include_dirs = [ base_output_dir ]
197 if (defined(invoker.deps)) {
200 if (defined(invoker.public_deps)) {
201 public_deps = invoker.public_deps
203 public_configs = [ ":jni_includes_${target_name}" ]
207 # Declare a target for c-preprocessor-generated java files
209 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
212 # This target generates java files using the host C pre-processor. Each file in
213 # sources will be compiled using the C pre-processor. If include_path is
214 # specified, it will be passed (with --I) to the pre-processor.
216 # This target will create a single .srcjar. Adding this target to an
217 # android_library target's srcjar_deps will make the generated java files be
218 # included in that library's final outputs.
221 # sources: list of files to be processed by the C pre-processor. For each
222 # file in sources, there will be one .java file in the final .srcjar. For a
223 # file named FooBar.template, a java file will be created with name
225 # inputs: additional compile-time dependencies. Any files
226 # `#include`-ed in the templates should be listed here.
227 # package_name: this will be the subdirectory for each .java file in the
231 # java_cpp_template("foo_generated_enum") {
233 # "android/java/templates/Foo.template",
236 # "android/java/templates/native_foo_header.h",
239 # package_name = "org/chromium/base/library_loader"
240 # include_path = "android/java/templates"
242 template("java_cpp_template") {
243 set_sources_assignment_filter([])
244 if (defined(invoker.testonly)) {
245 testonly = invoker.testonly
248 assert(defined(invoker.sources))
249 package_name = invoker.package_name + ""
251 if (defined(invoker.include_path)) {
252 include_path = invoker.include_path + ""
257 apply_gcc_target_name = "${target_name}__apply_gcc"
258 zip_srcjar_target_name = "${target_name}__zip_srcjar"
259 final_target_name = target_name
261 action_foreach(apply_gcc_target_name) {
262 visibility = [ ":$zip_srcjar_target_name" ]
263 script = "//build/android/gyp/gcc_preprocess.py"
264 if (defined(invoker.inputs)) {
265 inputs = invoker.inputs + []
267 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
269 sources = invoker.sources
271 if (defined(invoker.deps)) {
274 if (defined(invoker.public_deps)) {
275 public_deps = invoker.public_deps
277 if (defined(invoker.data_deps)) {
278 data_deps = invoker.data_deps
282 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
283 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
287 gcc_template_output_pattern,
292 rebase_path(depfile, root_build_dir),
294 rebase_path(include_path, root_build_dir),
296 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
297 "--template={{source}}",
300 if (defined(invoker.defines)) {
301 foreach(def, invoker.defines) {
310 apply_gcc_outputs = get_target_outputs(":$apply_gcc_target_name")
311 base_gen_dir = get_label_info(":$apply_gcc_target_name", "target_gen_dir")
313 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
314 zip(zip_srcjar_target_name) {
315 visibility = [ ":$final_target_name" ]
316 inputs = apply_gcc_outputs
318 base_dir = base_gen_dir
320 ":$apply_gcc_target_name",
324 group(final_target_name) {
325 if (defined(invoker.visibility)) {
326 visibility = invoker.visibility
329 ":$zip_srcjar_target_name",
334 # Declare a target for generating Java classes from C++ enums.
336 # This target generates Java files from C++ enums using a script.
338 # This target will create a single .srcjar. Adding this target to an
339 # android_library target's srcjar_deps will make the generated java files be
340 # included in that library's final outputs.
343 # sources: list of files to be processed by the script. For each annotated
344 # enum contained in the sources files the script will generate a .java
345 # file with the same name as the name of the enum.
347 # outputs: list of outputs, relative to the output_dir. These paths are
348 # verified at build time by the script. To get the list programatically run:
349 # python build/android/gyp/java_cpp_enum.py \
350 # --print_output_only . path/to/header/file.h
353 # java_cpp_enum("foo_generated_enum") {
355 # "src/native_foo_header.h",
358 # "org/chromium/FooEnum.java",
361 template("java_cpp_enum") {
362 set_sources_assignment_filter([])
363 if (defined(invoker.testonly)) {
364 testonly = invoker.testonly
367 assert(defined(invoker.sources))
368 assert(defined(invoker.outputs))
370 generate_enum_target_name = "${target_name}__generate_enum"
371 zip_srcjar_target_name = "${target_name}__zip_srcjar"
372 final_target_name = target_name
374 action(generate_enum_target_name) {
375 visibility = [ ":$zip_srcjar_target_name" ]
377 # The sources aren't compiled so don't check their dependencies.
378 check_includes = false
380 sources = invoker.sources
381 script = "//build/android/gyp/java_cpp_enum.py"
382 gen_dir = "${target_gen_dir}/${target_name}/enums"
384 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
387 foreach(output, rebase_path(outputs, root_build_dir)) {
393 args += [ rebase_path(gen_dir, root_build_dir) ]
394 args += rebase_path(invoker.sources, root_build_dir)
397 generate_enum_outputs = get_target_outputs(":$generate_enum_target_name")
398 base_gen_dir = get_label_info(":$generate_enum_target_name", "target_gen_dir")
400 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
401 zip(zip_srcjar_target_name) {
402 visibility = [ ":$final_target_name" ]
403 inputs = generate_enum_outputs
405 base_dir = base_gen_dir
407 ":$generate_enum_target_name",
411 group(final_target_name) {
412 if (defined(invoker.visibility)) {
413 visibility = invoker.visibility
416 ":$zip_srcjar_target_name",
421 # Declare a target for processing a Jinja template.
424 # input: The template file to be processed.
425 # output: Where to save the result.
426 # variables: (Optional) A list of variables to make available to the template
427 # processing environment, e.g. ["name=foo", "color=red"].
430 # jinja_template("chrome_shell_manifest") {
431 # input = "shell/java/AndroidManifest.xml"
432 # output = "$target_gen_dir/AndroidManifest.xml"
434 template("jinja_template") {
435 set_sources_assignment_filter([])
436 if (defined(invoker.testonly)) {
437 testonly = invoker.testonly
440 assert(defined(invoker.input))
441 assert(defined(invoker.output))
443 action(target_name) {
444 if (defined(invoker.visibility)) {
445 visibility = invoker.visibility
451 script = "//build/android/gyp/jinja_template.py"
452 depfile = "$target_gen_dir/$target_name.d"
461 rebase_path(invoker.input, root_build_dir),
463 rebase_path(invoker.output, root_build_dir),
465 rebase_path(depfile, root_build_dir),
467 if (defined(invoker.variables)) {
468 variables = invoker.variables
469 args += [ "--variables=${variables}" ]
474 # Declare a target for processing Android resources as Jinja templates.
476 # This takes an Android resource directory where each resource is a Jinja
477 # template, processes each template, then packages the results in a zip file
478 # which can be consumed by an android resources, library, or apk target.
480 # If this target is included in the deps of an android resources/library/apk,
481 # the resources will be included with that target.
484 # resources: The list of resources files to process.
485 # res_dir: The resource directory containing the resources.
486 # variables: (Optional) A list of variables to make available to the template
487 # processing environment, e.g. ["name=foo", "color=red"].
490 # jinja_template_resources("chrome_shell_template_resources") {
491 # res_dir = "shell/res_template"
492 # resources = ["shell/res_template/xml/syncable.xml"]
493 # variables = ["color=red"]
495 template("jinja_template_resources") {
496 set_sources_assignment_filter([])
497 if (defined(invoker.testonly)) {
498 testonly = invoker.testonly
501 assert(defined(invoker.resources))
502 assert(defined(invoker.res_dir))
504 _base_path = "$target_gen_dir/$target_name"
505 _resources_zip = _base_path + ".resources.zip"
506 _build_config = _base_path + ".build_config"
508 write_build_config("${target_name}__build_config") {
509 build_config = _build_config
510 resources_zip = _resources_zip
511 type = "android_resources"
514 action("${target_name}__template") {
515 sources = invoker.resources
516 script = "//build/android/gyp/jinja_template.py"
517 depfile = "$target_gen_dir/$target_name.d"
524 rebased_resources = rebase_path(invoker.resources, root_build_dir)
526 "--inputs=${rebased_resources}",
528 rebase_path(invoker.res_dir, root_build_dir),
530 rebase_path(_resources_zip, root_build_dir),
532 rebase_path(depfile, root_build_dir),
534 if (defined(invoker.variables)) {
535 variables = invoker.variables
536 args += [ "--variables=${variables}" ]
542 ":${target_name}__build_config",
543 ":${target_name}__template",
548 # Creates a resources.zip with locale.pak files placed into appropriate
549 # resource configs (e.g. en-GB.pak -> res/raw-en/en_gb.pak). Also generates
550 # a locale_paks TypedArray so that resource files can be enumerated at runtime.
552 # If this target is included in the deps of an android resources/library/apk,
553 # the resources will be included with that target.
556 # sources: List of .pak files. Names must be of the form "en.pak" or
558 # deps: (optional) List of dependencies that might be needed to generate
562 # locale_pak_resources("locale_paks") {
563 # sources = [ "path/en-US.pak", "path/fr.pak", ... ]
565 template("locale_pak_resources") {
566 set_sources_assignment_filter([])
567 assert(defined(invoker.sources))
569 _base_path = "$target_gen_dir/$target_name"
570 _resources_zip = _base_path + ".resources.zip"
571 _build_config = _base_path + ".build_config"
573 write_build_config("${target_name}__build_config") {
574 build_config = _build_config
575 resources_zip = _resources_zip
576 type = "android_resources"
579 action("${target_name}__create_resources_zip") {
580 sources = invoker.sources
581 script = "//build/android/gyp/locale_pak_resources.py"
582 depfile = "$target_gen_dir/$target_name.d"
589 _rebased_sources = rebase_path(invoker.sources, root_build_dir)
591 "--locale-paks=${_rebased_sources}",
593 rebase_path(_resources_zip, root_build_dir),
595 rebase_path(depfile, root_build_dir),
598 if (defined(invoker.deps)) {
605 ":${target_name}__build_config",
606 ":${target_name}__create_resources_zip",
611 # Declare an Android resources target
613 # This creates a resources zip file that will be used when building an Android
614 # library or apk and included into a final apk.
616 # To include these resources in a library/apk, this target should be listed in
617 # the library's deps. A library/apk will also include any resources used by its
621 # deps: Specifies the dependencies of this target. Any Android resources
622 # listed in deps will be included by libraries/apks that depend on this
624 # resource_dirs: List of directories containing resources for this target.
625 # android_manifest: AndroidManifest.xml for this target. Defaults to
626 # //build/android/AndroidManifest.xml.
627 # custom_package: java package for generated .java files.
628 # v14_skip: If true, don't run v14 resource generator on this. Defaults to
629 # false. (see build/android/gyp/generate_v14_compatible_resources.py)
631 # shared_resources: If true make a resource package that can be loaded by a
632 # different application at runtime to access the package's resources.
636 # android_resources("foo_resources") {
637 # deps = [":foo_strings_grd"]
638 # resource_dirs = ["res"]
639 # custom_package = "org.chromium.foo"
641 template("android_resources") {
642 set_sources_assignment_filter([])
643 if (defined(invoker.testonly)) {
644 testonly = invoker.testonly
647 assert(defined(invoker.resource_dirs))
648 assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
650 base_path = "$target_gen_dir/$target_name"
651 zip_path = base_path + ".resources.zip"
652 srcjar_path = base_path + ".srcjar"
653 r_text_path = base_path + "_R.txt"
654 build_config = base_path + ".build_config"
656 build_config_target_name = "${target_name}__build_config"
657 process_resources_target_name = "${target_name}__process_resources"
658 final_target_name = target_name
660 write_build_config(build_config_target_name) {
661 visibility = [ ":$process_resources_target_name" ]
663 type = "android_resources"
664 resources_zip = zip_path
667 if (defined(invoker.deps)) {
670 if (defined(invoker.android_manifest)) {
671 android_manifest = invoker.android_manifest
673 if (defined(invoker.custom_package)) {
674 custom_package = invoker.custom_package
678 android_manifest = "//build/android/AndroidManifest.xml"
679 if (defined(invoker.android_manifest)) {
680 android_manifest = invoker.android_manifest
683 process_resources(process_resources_target_name) {
684 visibility = [ ":$final_target_name" ]
686 resource_dirs = invoker.resource_dirs
687 if (defined(invoker.custom_package)) {
688 custom_package = invoker.custom_package
691 if (defined(invoker.v14_skip)) {
692 v14_skip = invoker.v14_skip
695 if (defined(invoker.shared_resources)) {
696 shared_resources = invoker.shared_resources
700 ":$build_config_target_name",
702 if (defined(invoker.deps)) {
703 # Invoker may have added deps that generate the input resources.
708 group(final_target_name) {
709 if (defined(invoker.visibility)) {
710 visibility = invoker.visibility
713 ":${target_name}__process_resources",
718 # Declare a target that generates localized strings.xml from a .grd file.
720 # If this target is included in the deps of an android resources/library/apk,
721 # the strings.xml will be included with that target.
724 # deps: Specifies the dependencies of this target.
725 # grd_file: Path to the .grd file to generate strings.xml from.
726 # outputs: Expected grit outputs (see grit rule).
729 # java_strings_grd("foo_strings_grd") {
730 # grd_file = "foo_strings.grd"
732 template("java_strings_grd") {
733 set_sources_assignment_filter([])
734 if (defined(invoker.testonly)) {
735 testonly = invoker.testonly
738 base_path = "$target_gen_dir/$target_name"
739 resources_zip = base_path + ".resources.zip"
740 build_config = base_path + ".build_config"
742 write_build_config("${target_name}__build_config") {
743 type = "android_resources"
744 if (defined(invoker.deps)) {
749 # Put grit files into this subdirectory of target_gen_dir.
750 extra_output_path = target_name + "_grit_output"
752 grit_target_name = "${target_name}__grit"
753 grit_output_dir = "$target_gen_dir/$extra_output_path"
754 grit(grit_target_name) {
757 "ANDROID_JAVA_TAGGED_ONLY=false",
759 output_dir = grit_output_dir
761 source = invoker.grd_file
762 outputs = invoker.outputs
765 # This needs to get outputs from grit's internal target, not the final
767 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
769 zip("${target_name}__zip") {
770 base_dir = grit_output_dir
771 inputs = generate_strings_outputs
772 output = resources_zip
774 ":$grit_target_name",
780 ":${target_name}__build_config",
781 ":${target_name}__zip",
786 # Declare a target that packages strings.xml generated from a grd file.
788 # If this target is included in the deps of an android resources/library/apk,
789 # the strings.xml will be included with that target.
792 # grit_output_dir: directory containing grit-generated files.
793 # generated_files: list of android resource files to package.
796 # java_strings_grd_prebuilt("foo_strings_grd") {
797 # grit_output_dir = "$root_gen_dir/foo/grit"
798 # generated_files = [
799 # "values/strings.xml"
802 template("java_strings_grd_prebuilt") {
803 set_sources_assignment_filter([])
804 if (defined(invoker.testonly)) {
805 testonly = invoker.testonly
808 base_path = "$target_gen_dir/$target_name"
809 resources_zip = base_path + ".resources.zip"
810 build_config = base_path + ".build_config"
812 build_config_target_name = "${target_name}__build_config"
813 zip_target_name = "${target_name}__zip"
814 final_target_name = target_name
816 write_build_config(build_config_target_name) {
817 visibility = [ ":$zip_target_name" ]
818 type = "android_resources"
821 zip(zip_target_name) {
822 visibility = [ ":$final_target_name" ]
824 base_dir = invoker.grit_output_dir
825 inputs = rebase_path(invoker.generated_files, ".", base_dir)
826 output = resources_zip
828 ":$build_config_target_name",
830 if (defined(invoker.deps)) {
835 group(final_target_name) {
836 if (defined(invoker.visibility)) {
837 visibility = invoker.visibility
845 # Declare a Java executable target
847 # This target creates an executable from java code and libraries. The executable
848 # will be in the output folder's /bin/ directory.
851 # deps: Specifies the dependencies of this target. Java targets in this list
852 # will be included in the executable (and the javac classpath).
854 # java_files: List of .java files included in this library.
855 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
856 # will be added to java_files and be included in this library.
857 # srcjars: List of srcjars to be included in this library, together with the
858 # ones obtained from srcjar_deps.
860 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
861 # dependencies for this target. This will allow depending on an
862 # android_library target, for example.
864 # chromium_code: If true, extra analysis warning/errors will be enabled.
865 # enable_errorprone: If true, enables the errorprone compiler.
867 # data_deps, testonly
870 # java_binary("foo") {
871 # java_files = [ "org/chromium/foo/FooMain.java" ]
872 # deps = [ ":bar_java" ]
873 # main_class = "org.chromium.foo.FooMain"
875 template("java_binary") {
876 set_sources_assignment_filter([])
878 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
879 # dependents shouldn't get the jar in their classpath, etc.).
880 java_library_impl(target_name) {
881 if (defined(invoker.DEPRECATED_java_in_dir)) {
882 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
884 if (defined(invoker.chromium_code)) {
885 chromium_code = invoker.chromium_code
887 if (defined(invoker.data_deps)) {
888 deps = invoker.data_deps
890 if (defined(invoker.deps)) {
893 if (defined(invoker.enable_errorprone)) {
894 enable_errorprone = invoker.enable_errorprone
896 if (defined(invoker.java_files)) {
897 java_files = invoker.java_files
899 if (defined(invoker.srcjar_deps)) {
900 srcjar_deps = invoker.srcjar_deps
902 if (defined(invoker.srcjars)) {
903 srcjars = invoker.srcjars
905 if (defined(invoker.bypass_platform_checks)) {
906 bypass_platform_checks = invoker.bypass_platform_checks
908 if (defined(invoker.testonly)) {
909 testonly = invoker.testonly
912 supports_android = false
913 main_class = invoker.main_class
917 # Declare a Junit executable target
919 # This target creates an executable from java code for running as a junit test
920 # suite. The executable will be in the output folder's /bin/ directory.
923 # deps: Specifies the dependencies of this target. Java targets in this list
924 # will be included in the executable (and the javac classpath).
926 # java_files: List of .java files included in this library.
927 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
928 # will be added to java_files and be included in this library.
929 # srcjars: List of srcjars to be included in this library, together with the
930 # ones obtained from srcjar_deps.
932 # chromium_code: If true, extra analysis warning/errors will be enabled.
935 # junit_binary("foo") {
936 # java_files = [ "org/chromium/foo/FooTest.java" ]
937 # deps = [ ":bar_java" ]
939 template("junit_binary") {
940 set_sources_assignment_filter([])
942 java_binary(target_name) {
943 bypass_platform_checks = true
944 main_class = "org.chromium.testing.local.JunitTestMain"
947 if (defined(invoker.DEPRECATED_java_in_dir)) {
948 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
950 if (defined(invoker.chromium_code)) {
951 chromium_code = invoker.chromium_code
954 "//testing/android/junit:junit_test_support",
955 "//third_party/junit",
956 "//third_party/mockito:mockito_java",
957 "//third_party/robolectric:robolectric_java",
958 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
960 if (defined(invoker.deps)) {
963 if (defined(invoker.java_files)) {
964 java_files = invoker.java_files
966 if (defined(invoker.srcjar_deps)) {
967 srcjar_deps = invoker.srcjar_deps
969 if (defined(invoker.srcjars)) {
970 srcjars = invoker.srcjars
975 # Declare a java library target
978 # deps: Specifies the dependencies of this target. Java targets in this list
979 # will be added to the javac classpath.
981 # java_files: List of .java files included in this library.
982 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
983 # will be added to java_files and be included in this library.
984 # srcjars: List of srcjars to be included in this library, together with the
985 # ones obtained from srcjar_deps.
986 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
987 # this directory will be included in the library. This is only supported to
988 # ease the gyp->gn conversion and will be removed in the future.
990 # chromium_code: If true, extra analysis warning/errors will be enabled.
991 # enable_errorprone: If true, enables the errorprone compiler.
993 # jar_excluded_patterns: List of patterns of .class files to exclude from the
996 # proguard_preprocess: If true, proguard preprocessing will be run. This can
997 # be used to remove unwanted parts of the library.
998 # proguard_config: Path to the proguard config for preprocessing.
1000 # supports_android: If true, Android targets (android_library, android_apk)
1001 # may depend on this target. Note: if true, this target must only use the
1002 # subset of Java available on Android.
1003 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
1004 # dependencies for this target. This will allow depending on an
1005 # android_library target, for example.
1007 # data_deps, testonly
1010 # java_library("foo_java") {
1012 # "org/chromium/foo/Foo.java",
1013 # "org/chromium/foo/FooInterface.java",
1014 # "org/chromium/foo/FooService.java",
1020 # ":foo_generated_enum"
1022 # jar_excluded_patterns = [
1023 # "*/FooService.class", "*/FooService##*.class"
1026 template("java_library") {
1027 set_sources_assignment_filter([])
1028 java_library_impl(target_name) {
1029 if (defined(invoker.DEPRECATED_java_in_dir)) {
1030 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1032 if (defined(invoker.chromium_code)) {
1033 chromium_code = invoker.chromium_code
1035 if (defined(invoker.data_deps)) {
1036 deps = invoker.data_deps
1038 if (defined(invoker.deps)) {
1041 if (defined(invoker.enable_errorprone)) {
1042 enable_errorprone = invoker.enable_errorprone
1044 if (defined(invoker.jar_excluded_patterns)) {
1045 jar_excluded_patterns = invoker.jar_excluded_patterns
1047 if (defined(invoker.java_files)) {
1048 java_files = invoker.java_files
1050 if (defined(invoker.proguard_config)) {
1051 proguard_config = invoker.proguard_config
1053 if (defined(invoker.proguard_preprocess)) {
1054 proguard_preprocess = invoker.proguard_preprocess
1056 if (defined(invoker.srcjar_deps)) {
1057 srcjar_deps = invoker.srcjar_deps
1059 if (defined(invoker.srcjars)) {
1060 srcjars = invoker.srcjars
1062 if (defined(invoker.bypass_platform_checks)) {
1063 bypass_platform_checks = invoker.bypass_platform_checks
1065 if (defined(invoker.testonly)) {
1066 testonly = invoker.testonly
1068 if (defined(invoker.jar_path)) {
1069 jar_path = invoker.jar_path
1072 if (defined(invoker.supports_android) && invoker.supports_android) {
1073 supports_android = true
1078 # Declare a java library target for a prebuilt jar
1081 # deps: Specifies the dependencies of this target. Java targets in this list
1082 # will be added to the javac classpath.
1083 # jar_path: Path to the prebuilt jar.
1084 # jar_dep: Target that builds jar_path (optional).
1085 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1086 # be used to remove unwanted parts of the library.
1087 # proguard_config: Path to the proguard config for preprocessing.
1090 # java_prebuilt("foo_java") {
1091 # jar_path = "foo.jar"
1097 template("java_prebuilt") {
1098 set_sources_assignment_filter([])
1099 java_prebuilt_impl(target_name) {
1100 jar_path = invoker.jar_path
1101 if (defined(invoker.jar_dep)) {
1102 jar_dep = invoker.jar_dep
1104 if (defined(invoker.testonly)) {
1105 testonly = invoker.testonly
1107 if (defined(invoker.deps)) {
1110 if (defined(invoker.data_deps)) {
1111 data_deps = invoker.data_deps
1113 if (defined(invoker.proguard_config)) {
1114 proguard_config = invoker.proguard_config
1116 if (defined(invoker.proguard_preprocess)) {
1117 proguard_preprocess = invoker.proguard_preprocess
1122 # Declare an Android library target
1124 # This target creates an Android library containing java code and Android
1128 # deps: Specifies the dependencies of this target. Java targets in this list
1129 # will be added to the javac classpath. Android resources in dependencies
1130 # will be used when building this library.
1132 # java_files: List of .java files included in this library.
1133 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1134 # will be added to java_files and be included in this library.
1135 # srcjars: List of srcjars to be included in this library, together with the
1136 # ones obtained from srcjar_deps.
1137 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1138 # this directory will be included in the library. This is only supported to
1139 # ease the gyp->gn conversion and will be removed in the future.
1141 # chromium_code: If true, extra analysis warning/errors will be enabled.
1142 # enable_errorprone: If true, enables the errorprone compiler.
1144 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1147 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1148 # be used to remove unwanted parts of the library.
1149 # proguard_config: Path to the proguard config for preprocessing.
1151 # dex_path: If set, the resulting .dex.jar file will be placed under this
1156 # android_library("foo_java") {
1158 # "android/org/chromium/foo/Foo.java",
1159 # "android/org/chromium/foo/FooInterface.java",
1160 # "android/org/chromium/foo/FooService.java",
1166 # ":foo_generated_enum"
1168 # jar_excluded_patterns = [
1169 # "*/FooService.class", "*/FooService##*.class"
1172 template("android_library") {
1173 set_sources_assignment_filter([])
1174 assert(!defined(invoker.jar_path),
1175 "android_library does not support a custom jar path")
1176 java_library_impl(target_name) {
1177 if (defined(invoker.DEPRECATED_java_in_dir)) {
1178 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1180 if (defined(invoker.chromium_code)) {
1181 chromium_code = invoker.chromium_code
1183 if (defined(invoker.data_deps)) {
1184 deps = invoker.data_deps
1186 if (defined(invoker.deps)) {
1189 if (defined(invoker.enable_errorprone)) {
1190 enable_errorprone = invoker.enable_errorprone
1192 if (defined(invoker.jar_excluded_patterns)) {
1193 jar_excluded_patterns = invoker.jar_excluded_patterns
1195 if (defined(invoker.java_files)) {
1196 java_files = invoker.java_files
1198 if (defined(invoker.proguard_config)) {
1199 proguard_config = invoker.proguard_config
1201 if (defined(invoker.proguard_preprocess)) {
1202 proguard_preprocess = invoker.proguard_preprocess
1204 if (defined(invoker.srcjar_deps)) {
1205 srcjar_deps = invoker.srcjar_deps
1207 if (defined(invoker.srcjars)) {
1208 srcjars = invoker.srcjars
1210 if (defined(invoker.testonly)) {
1211 testonly = invoker.testonly
1213 if (defined(invoker.visibility)) {
1214 visibility = invoker.visibility
1216 if (defined(invoker.dex_path)) {
1217 dex_path = invoker.dex_path
1219 if (defined(invoker.manifest_entries)) {
1220 manifest_entries = invoker.manifest_entries
1223 supports_android = true
1224 requires_android = true
1226 if (!defined(jar_excluded_patterns)) {
1227 jar_excluded_patterns = []
1229 jar_excluded_patterns += [
1233 "*/Manifest##*.class",
1238 # Declare a target that packages a set of Java dependencies into a standalone
1242 # deps: specifies the dependencies of this target. Android libraries in deps
1243 # will be packaged into the resulting .dex.jar file.
1244 # dex_path: location at which the output file will be put
1245 template("android_standalone_library") {
1246 set_sources_assignment_filter([])
1247 deps_dex(target_name) {
1249 dex_path = invoker.dex_path
1250 if (defined(invoker.excluded_jars)) {
1251 excluded_jars = invoker.excluded_jars
1256 # Declare an Android library target for a prebuilt jar
1258 # This target creates an Android library containing java code and Android
1262 # deps: Specifies the dependencies of this target. Java targets in this list
1263 # will be added to the javac classpath. Android resources in dependencies
1264 # will be used when building this library.
1265 # jar_path: Path to the prebuilt jar.
1266 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1267 # be used to remove unwanted parts of the library.
1268 # proguard_config: Path to the proguard config for preprocessing.
1271 # android_java_prebuilt("foo_java") {
1272 # jar_path = "foo.jar"
1278 template("android_java_prebuilt") {
1279 set_sources_assignment_filter([])
1280 java_prebuilt_impl(target_name) {
1281 jar_path = invoker.jar_path
1282 supports_android = true
1283 requires_android = true
1284 if (defined(invoker.testonly)) {
1285 testonly = invoker.testonly
1287 if (defined(invoker.deps)) {
1290 if (defined(invoker.data_deps)) {
1291 data_deps = invoker.data_deps
1293 if (defined(invoker.proguard_config)) {
1294 proguard_config = invoker.proguard_config
1296 if (defined(invoker.proguard_preprocess)) {
1297 proguard_preprocess = invoker.proguard_preprocess
1302 # Declare an Android apk target
1304 # This target creates an Android APK containing java code, resources, assets,
1305 # and (possibly) native libraries.
1308 # android_manifest: Path to AndroidManifest.xml.
1309 # android_manifest_dep: Target that generates AndroidManifest (if applicable)
1310 # data_deps: List of dependencies needed at runtime. These will be built but
1311 # won't change the generated .apk in any way (in fact they may be built
1312 # after the .apk is).
1313 # deps: List of dependencies. All Android java resources and libraries in the
1314 # "transitive closure" of these dependencies will be included in the apk.
1315 # Note: this "transitive closure" actually only includes such targets if
1316 # they are depended on through android_library or android_resources targets
1317 # (and so not through builtin targets like 'action', 'group', etc).
1318 # java_files: List of .java files to include in the apk.
1319 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1320 # will be added to java_files and be included in this apk.
1321 # apk_name: Name for final apk.
1322 # final_apk_path: Path to final built apk. Default is
1323 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1324 # native_libs: List paths of native libraries to include in this apk. If these
1325 # libraries depend on other shared_library targets, those dependencies will
1326 # also be included in the apk.
1327 # apk_under_test: For an instrumentation test apk, this is the target of the
1329 # include_all_resources - If true include all resource IDs in all generated
1331 # testonly: Marks this target as "test-only".
1333 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1334 # this directory will be included in the library. This is only supported to
1335 # ease the gyp->gn conversion and will be removed in the future.
1338 # android_apk("foo_apk") {
1339 # android_manifest = "AndroidManifest.xml"
1341 # "android/org/chromium/foo/FooApplication.java",
1342 # "android/org/chromium/foo/FooActivity.java",
1345 # ":foo_support_java"
1349 # ":foo_generated_enum"
1355 template("android_apk") {
1356 set_sources_assignment_filter([])
1357 if (defined(invoker.testonly)) {
1358 testonly = invoker.testonly
1361 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1362 assert(defined(invoker.android_manifest))
1363 gen_dir = "$target_gen_dir/$target_name"
1364 base_path = "$gen_dir/$target_name"
1365 _build_config = "$target_gen_dir/$target_name.build_config"
1366 resources_zip_path = "$base_path.resources.zip"
1367 _all_resources_zip_path = "$base_path.resources.all.zip"
1368 jar_path = "$base_path.jar"
1369 _template_name = target_name
1371 final_dex_path = "$gen_dir/classes.dex"
1372 final_dex_target_name = "${_template_name}__final_dex"
1374 _final_apk_path = ""
1375 if (defined(invoker.final_apk_path)) {
1376 _final_apk_path = invoker.final_apk_path
1377 } else if (defined(invoker.apk_name)) {
1378 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1380 _dist_jar_path_list =
1381 process_file_template(
1382 [ _final_apk_path ],
1383 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1384 _dist_jar_path = _dist_jar_path_list[0]
1389 if (defined(invoker.version_code)) {
1390 _version_code = invoker.version_code
1393 _version_name = "Developer Build"
1394 if (defined(invoker.version_name)) {
1395 _version_name = invoker.version_name
1397 _keystore_path = android_default_keystore_path
1398 _keystore_name = android_default_keystore_name
1399 _keystore_password = android_default_keystore_password
1401 if (defined(invoker.keystore_path)) {
1402 _keystore_path = invoker.keystore_path
1403 _keystore_name = invoker.keystore_name
1404 _keystore_password = invoker.keystore_password
1408 if (defined(invoker.srcjar_deps)) {
1409 _srcjar_deps += invoker.srcjar_deps
1412 _load_library_from_apk = false
1414 # The dependency that makes the chromium linker, if any is needed.
1415 _chromium_linker_dep = []
1417 if (defined(invoker.native_libs)) {
1418 _use_chromium_linker = false
1419 if (defined(invoker.use_chromium_linker)) {
1420 _use_chromium_linker =
1421 invoker.use_chromium_linker && chromium_linker_supported
1422 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1425 if (defined(invoker.load_library_from_apk) &&
1426 invoker.load_library_from_apk) {
1427 _load_library_from_apk = true
1428 assert(_use_chromium_linker,
1429 "Loading library from the apk requires use" +
1430 " of the Chromium linker.")
1433 _enable_relocation_packing = false
1434 if (defined(invoker.enable_relocation_packing) &&
1435 invoker.enable_relocation_packing) {
1436 _enable_relocation_packing = relocation_packing_supported
1437 assert(_use_chromium_linker,
1438 "Relocation packing requires use of the" + " Chromium linker.")
1441 if (is_component_build) {
1442 _native_libs += [ "$root_shlib_dir/libc++_shared.so" ]
1443 _chromium_linker_dep += [ "//build/android:cpplib_stripped" ]
1446 # Allow native_libs to be in the form "foo.so" or "foo.cr.so"
1447 _first_ext_removed =
1448 process_file_template(invoker.native_libs, "{{source_name_part}}")
1449 _native_libs += process_file_template(
1451 "$root_shlib_dir/{{source_name_part}}$shlib_extension")
1453 _native_libs_dir = base_path + "/libs"
1455 if (_use_chromium_linker) {
1457 [ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
1460 _enable_relocation_packing = false
1461 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1462 invoker.enable_relocation_packing) {
1463 _enable_relocation_packing = true
1466 _native_lib_version_rule = ""
1467 if (defined(invoker.native_lib_version_rule)) {
1468 _native_lib_version_rule = invoker.native_lib_version_rule
1470 _native_lib_version_arg = "\"\""
1471 if (defined(invoker.native_lib_version_arg)) {
1472 _native_lib_version_arg = invoker.native_lib_version_arg
1476 _android_manifest_deps = []
1477 if (defined(invoker.android_manifest_dep)) {
1478 _android_manifest_deps = [ invoker.android_manifest_dep ]
1480 _android_manifest = invoker.android_manifest
1482 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1484 defined(invoker.create_abi_split) && invoker.create_abi_split
1485 _create_density_splits =
1486 defined(invoker.create_density_splits) && invoker.create_density_splits
1488 # Help GN understand that _create_abi_split is not unused (bug in GN).
1489 assert(_create_abi_split || true)
1491 build_config_target = "${_template_name}__build_config"
1492 write_build_config(build_config_target) {
1493 type = "android_apk"
1494 dex_path = final_dex_path
1495 resources_zip = resources_zip_path
1496 build_config = _build_config
1497 android_manifest = _android_manifest
1499 deps = _chromium_linker_dep + _android_manifest_deps
1500 if (defined(invoker.deps)) {
1501 deps += invoker.deps
1504 if (defined(invoker.apk_under_test)) {
1505 apk_under_test = invoker.apk_under_test
1508 native_libs = _native_libs
1513 process_resources_target = "${_template_name}__process_resources"
1514 final_deps += [ ":$process_resources_target" ]
1515 process_resources(process_resources_target) {
1516 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1517 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1518 android_manifest = _android_manifest
1519 resource_dirs = [ "//build/android/ant/empty/res" ]
1520 zip_path = resources_zip_path
1521 all_resources_zip_path = _all_resources_zip_path
1522 generate_constant_ids = true
1524 if (defined(invoker.include_all_resources)) {
1525 include_all_resources = invoker.include_all_resources
1528 build_config = _build_config
1529 deps = _android_manifest_deps + [ ":$build_config_target" ]
1530 if (defined(invoker.deps)) {
1531 deps += invoker.deps
1534 _srcjar_deps += [ ":$process_resources_target" ]
1536 if (_native_libs != []) {
1537 _enable_chromium_linker_tests = false
1538 if (defined(invoker.enable_chromium_linker_tests)) {
1539 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1542 java_cpp_template("${_template_name}__native_libraries_java") {
1543 package_name = "org/chromium/base/library_loader"
1545 "//base/android/java/templates/NativeLibraries.template",
1551 ":$build_config_target",
1553 if (_native_lib_version_rule != "") {
1554 deps += [ _native_lib_version_rule ]
1558 "NATIVE_LIBRARIES_LIST=" +
1559 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1560 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
1562 if (_use_chromium_linker) {
1563 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1565 if (_load_library_from_apk) {
1566 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1568 if (_enable_chromium_linker_tests) {
1569 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1572 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1575 java_target = "${_template_name}__java"
1576 final_deps += [ ":$java_target" ]
1577 java_library_impl(java_target) {
1578 supports_android = true
1579 requires_android = true
1580 override_build_config = _build_config
1581 deps = _android_manifest_deps + [ ":$build_config_target" ]
1583 android_manifest = _android_manifest
1584 chromium_code = true
1585 if (defined(invoker.java_files)) {
1586 java_files = invoker.java_files
1587 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1588 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1592 srcjar_deps = _srcjar_deps
1593 dex_path = base_path + ".dex.jar"
1595 if (defined(invoker.deps)) {
1596 deps += invoker.deps
1600 if (_dist_jar_path != "") {
1601 create_dist_target = "${_template_name}__create_dist_jar"
1602 final_deps += [ ":$create_dist_target" ]
1604 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1605 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1606 # able to just do that calculation at build time instead.
1607 action(create_dist_target) {
1608 script = "//build/android/gyp/create_dist_jar.py"
1609 depfile = "$target_gen_dir/$target_name.d"
1619 rebase_path(depfile, root_build_dir),
1621 rebase_path(_dist_jar_path, root_build_dir),
1622 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1624 inputs += [ jar_path ]
1625 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1626 args += [ "--inputs=$_rebased_jar_path" ]
1628 ":$build_config_target", # Generates the build config file.
1629 ":$java_target", # Generates the jar file.
1634 final_deps += [ ":$final_dex_target_name" ]
1635 dex("$final_dex_target_name") {
1637 ":$build_config_target",
1646 output = final_dex_path
1647 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1648 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1651 if (_native_libs != []) {
1652 action("${_template_name}__prepare_native") {
1653 script = "//build/android/gyp/pack_relocations.py"
1654 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1655 depfile = "$target_gen_dir/$target_name.d"
1660 inputs = _native_libs
1661 deps = _chromium_linker_dep
1663 inputs += [ _build_config ]
1664 deps += [ ":$build_config_target" ]
1666 skip_packing_list = [
1668 "libchromium_android_linker$shlib_extension",
1671 enable_packing_arg = 0
1672 if (_enable_relocation_packing) {
1673 enable_packing_arg = 1
1674 deps += [ relocation_packer_target ]
1679 rebase_path(depfile, root_build_dir),
1680 "--enable-packing=$enable_packing_arg",
1681 "--exclude-packing-list=$skip_packing_list",
1682 "--android-pack-relocations",
1683 rebase_path(relocation_packer_exe, root_build_dir),
1684 "--stripped-libraries-dir",
1685 rebase_path(root_build_dir, root_build_dir),
1686 "--packed-libraries-dir",
1687 rebase_path(packed_libraries_dir, root_build_dir),
1688 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1692 if (defined(invoker.deps)) {
1693 deps += invoker.deps
1695 if (defined(invoker.public_deps)) {
1696 public_deps = invoker.public_deps
1698 if (defined(invoker.data_deps)) {
1699 data_deps = invoker.data_deps
1703 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1704 inputs += [ android_gdbserver ]
1705 args += [ "--libraries=$rebased_gdbserver" ]
1710 final_deps += [ ":${_template_name}__create" ]
1711 create_apk("${_template_name}__create") {
1712 apk_path = _final_apk_path
1713 android_manifest = _android_manifest
1714 resources_zip = _all_resources_zip_path
1715 dex_path = final_dex_path
1716 load_library_from_apk = _load_library_from_apk
1717 create_density_splits = _create_density_splits
1718 if (defined(invoker.language_splits)) {
1719 language_splits = invoker.language_splits
1721 if (defined(invoker.extensions_to_not_compress)) {
1722 extensions_to_not_compress = invoker.extensions_to_not_compress
1724 # Allow icu data, v8 snapshots, and pak files to be loaded directly from
1726 # Note: These are actually suffix matches, not necessarily extensions.
1727 extensions_to_not_compress = ".dat,.bin,.pak"
1730 version_code = _version_code
1731 version_name = _version_name
1733 keystore_name = _keystore_name
1734 keystore_path = _keystore_path
1735 keystore_password = _keystore_password
1737 # This target generates the input file _all_resources_zip_path.
1738 deps = _android_manifest_deps + [
1739 ":$process_resources_target",
1740 ":$final_dex_target_name",
1742 if (defined(invoker.deps)) {
1743 deps += invoker.deps
1746 if (defined(invoker.asset_location)) {
1747 asset_location = invoker.asset_location
1749 # We don't know the exact dependencies that create the assets in
1750 # |asset_location|; we depend on all caller deps until a better solution
1751 # is figured out (http://crbug.com/433330).
1752 if (defined(invoker.deps)) {
1753 deps += invoker.deps
1757 if (_native_libs != [] && !_create_abi_split) {
1758 native_libs_dir = _native_libs_dir
1759 deps += [ ":${_template_name}__prepare_native" ]
1763 if (_native_libs != [] && _create_abi_split) {
1764 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1765 generate_split_manifest(_manifest_rule) {
1766 main_manifest = _android_manifest
1768 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1769 split_name = "abi_${android_app_abi}"
1770 deps = _android_manifest_deps
1773 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1774 final_deps += [ ":$_apk_rule" ]
1775 create_apk(_apk_rule) {
1776 _split_paths = process_file_template(
1777 [ _final_apk_path ],
1778 "{{source_dir}}/{{source_name_part}}-abi-${android_app_abi}.apk")
1779 apk_path = _split_paths[0]
1780 base_path = "$gen_dir/$_apk_rule"
1782 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1783 android_manifest = manifest_outputs[1]
1784 load_library_from_apk = _load_library_from_apk
1786 version_code = _version_code
1787 version_name = _version_name
1789 keystore_name = _keystore_name
1790 keystore_path = _keystore_path
1791 keystore_password = _keystore_password
1793 native_libs_dir = _native_libs_dir
1795 ":${_template_name}__prepare_native",
1796 ":${_manifest_rule}",
1801 group(target_name) {
1803 if (defined(invoker.data_deps)) {
1804 data_deps = invoker.data_deps
1809 # Declare an Android instrumentation test apk
1811 # This target creates an Android instrumentation test apk.
1814 # android_manifest: Path to AndroidManifest.xml.
1815 # data_deps: List of dependencies needed at runtime. These will be built but
1816 # won't change the generated .apk in any way (in fact they may be built
1817 # after the .apk is).
1818 # deps: List of dependencies. All Android java resources and libraries in the
1819 # "transitive closure" of these dependencies will be included in the apk.
1820 # Note: this "transitive closure" actually only includes such targets if
1821 # they are depended on through android_library or android_resources targets
1822 # (and so not through builtin targets like 'action', 'group', etc).
1823 # java_files: List of .java files to include in the apk.
1824 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1825 # will be added to java_files and be included in this apk.
1826 # apk_name: Name for final apk.
1827 # final_apk_path: Path to final built apk. Default is
1828 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1829 # native_libs: List paths of native libraries to include in this apk. If these
1830 # libraries depend on other shared_library targets, those dependencies will
1831 # also be included in the apk.
1832 # apk_under_test: The apk being tested.
1833 # isolate_file: Isolate file containing the list of test data dependencies.
1835 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1836 # this directory will be included in the library. This is only supported to
1837 # ease the gyp->gn conversion and will be removed in the future.
1840 # instrumentation_test_apk("foo_test_apk") {
1841 # android_manifest = "AndroidManifest.xml"
1842 # apk_name = "FooTest"
1843 # apk_under_test = "Foo"
1845 # "android/org/chromium/foo/FooTestCase.java",
1846 # "android/org/chromium/foo/FooExampleTest.java",
1849 # ":foo_test_support_java"
1852 template("instrumentation_test_apk") {
1853 set_sources_assignment_filter([])
1855 _template_name = target_name
1857 if (defined(invoker.apk_name)) {
1858 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1859 test_runner_script("${_template_name}__test_runner_script") {
1860 test_name = invoker.target_name
1861 test_type = "instrumentation"
1862 test_apk = invoker.apk_name
1863 if (defined(invoker.isolate_file)) {
1864 isolate_file = invoker.isolate_file
1869 android_apk(target_name) {
1870 if (defined(invoker.android_manifest)) {
1871 android_manifest = invoker.android_manifest
1874 "//testing/android/driver:driver_apk",
1875 "//tools/android/forwarder2",
1876 "//tools/android/md5sum",
1878 if (defined(test_runner_data_dep)) {
1879 data_deps += test_runner_data_dep
1881 if (defined(invoker.data_deps)) {
1882 data_deps += invoker.data_deps
1885 "//testing/android/broker:broker_java",
1887 if (defined(invoker.deps)) {
1888 deps += invoker.deps
1890 if (defined(invoker.java_files)) {
1891 java_files = invoker.java_files
1893 if (defined(invoker.srcjar_deps)) {
1894 srcjar_deps = invoker.srcjar_deps
1896 if (defined(invoker.apk_name)) {
1897 apk_name = invoker.apk_name
1899 if (defined(invoker.final_apk_path)) {
1900 final_apk_path = invoker.final_apk_path
1902 if (defined(invoker.native_libs)) {
1903 native_libs = invoker.native_libs
1905 if (defined(invoker.apk_under_test)) {
1906 apk_under_test = invoker.apk_under_test
1908 if (defined(invoker.DEPRECATED_java_in_dir)) {
1909 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1914 # Declare an Android gtest apk
1916 # This target creates an Android apk for running gtest-based unittests.
1919 # deps: Specifies the dependencies of this target. These will be passed to
1920 # the underlying android_apk invocation and should include the java and
1921 # resource dependencies of the apk.
1922 # unittests_dep: This should be the label of the gtest native target. This
1923 # target must be defined previously in the same file.
1924 # unittests_binary: The basename of the library produced by the unittests_dep
1925 # target. If unspecified, it assumes the name of the unittests_dep target
1926 # (which will be correct unless that target specifies an "output_name".
1927 # TODO(brettw) make this automatic by allowing get_target_outputs to
1928 # support executables.
1929 # apk_name: The name of the produced apk. If unspecified, it uses the name
1930 # of the unittests_dep target postfixed with "_apk"
1933 # unittest_apk("foo_unittests_apk") {
1934 # deps = [ ":foo_java", ":foo_resources" ]
1935 # unittests_dep = ":foo_unittests"
1937 template("unittest_apk") {
1938 set_sources_assignment_filter([])
1941 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1943 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1945 # This trivial assert is needed in case both unittests_binary and apk_name
1946 # are defined, as otherwise test_suite_name would not be used.
1947 assert(test_suite_name != "")
1949 if (defined(invoker.unittests_binary)) {
1950 unittests_binary = invoker.unittests_binary
1952 unittests_binary = "lib${test_suite_name}${shlib_extension}"
1955 if (defined(invoker.apk_name)) {
1956 apk_name = invoker.apk_name
1958 apk_name = test_suite_name
1961 android_apk(target_name) {
1962 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1964 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
1965 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
1966 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
1967 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
1969 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1970 native_libs = [ unittests_binary ]
1971 if (defined(invoker.asset_location)) {
1972 asset_location = invoker.asset_location
1976 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1977 "//testing/android/appurify_support:appurify_support_java",
1978 "//testing/android/reporter:reporter_java",
1980 if (defined(invoker.deps)) {
1981 deps += invoker.deps
1983 data_deps = [ "//tools/android/md5sum" ]
1984 if (host_os == "linux") {
1985 data_deps += [ "//tools/android/forwarder2" ]
1987 if (defined(invoker.data_deps)) {
1988 data_deps += invoker.data_deps
1993 # Generate .java files from .aidl files.
1995 # This target will store the .java files in a srcjar and should be included in
1996 # an android_library or android_apk's srcjar_deps.
1999 # sources: Paths to .aidl files to compile.
2000 # import_include: Path to directory containing .java files imported by the
2002 # interface_file: Preprocessed aidl file to import.
2005 # android_aidl("foo_aidl") {
2006 # import_include = "java/src"
2008 # "java/src/com/foo/bar/FooBarService.aidl",
2009 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
2012 template("android_aidl") {
2013 set_sources_assignment_filter([])
2014 if (defined(invoker.testonly)) {
2015 testonly = invoker.testonly
2018 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
2019 aidl_path = "${android_sdk_build_tools}/aidl"
2020 framework_aidl = "$android_sdk/framework.aidl"
2022 action(target_name) {
2023 script = "//build/android/gyp/aidl.py"
2024 sources = invoker.sources
2026 imports = [ framework_aidl ]
2027 if (defined(invoker.interface_file)) {
2028 assert(invoker.interface_file != "")
2029 imports += [ invoker.interface_file ]
2032 inputs = [ aidl_path ] + imports
2034 depfile = "${target_gen_dir}/${target_name}.d"
2039 rebased_imports = rebase_path(imports, root_build_dir)
2042 rebase_path(depfile, root_build_dir),
2044 rebase_path(aidl_path, root_build_dir),
2045 "--imports=$rebased_imports",
2047 rebase_path(srcjar_path, root_build_dir),
2049 if (defined(invoker.import_include) && invoker.import_include != "") {
2050 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
2051 # switch to constructing a depfile for the overall action from that
2052 # instead of having all the .java files in the include paths as inputs.
2053 rebased_import_includes =
2054 rebase_path([ invoker.import_include ], root_build_dir)
2055 args += [ "--includes=$rebased_import_includes" ]
2057 _java_files_build_rel =
2058 exec_script("//build/android/gyp/find.py",
2059 rebase_path([ invoker.import_include ], root_build_dir),
2061 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
2062 inputs += _java_files
2064 args += rebase_path(sources, root_build_dir)
2068 # Creates a dist directory for a native executable.
2070 # Running a native executable on a device requires all the shared library
2071 # dependencies of that executable. To make it easier to install and run such an
2072 # executable, this will create a directory containing the native exe and all
2073 # it's library dependencies.
2075 # Note: It's usually better to package things as an APK than as a native
2079 # dist_dir: Directory for the exe and libraries. Everything in this directory
2080 # will be deleted before copying in the exe and libraries.
2081 # binary: Path to (stripped) executable.
2084 # create_native_executable_dist("foo_dist") {
2085 # dist_dir = "$root_build_dir/foo_dist"
2086 # binary = "$root_build_dir/foo"
2087 # deps = [ ":the_thing_that_makes_foo" ]
2089 template("create_native_executable_dist") {
2090 set_sources_assignment_filter([])
2091 if (defined(invoker.testonly)) {
2092 testonly = invoker.testonly
2095 dist_dir = invoker.dist_dir
2096 binary = invoker.binary
2097 template_name = target_name
2100 "${target_gen_dir}/${template_name}_library_dependencies.list"
2102 find_deps_target_name = "${template_name}__find_library_dependencies"
2103 copy_target_name = "${template_name}__copy_libraries_and_exe"
2105 action(find_deps_target_name) {
2106 visibility = [ ":$copy_target_name" ]
2108 script = "//build/android/gyp/write_ordered_libraries.py"
2109 depfile = "$target_gen_dir/$target_name.d"
2118 rebased_binaries = rebase_path([ binary ], root_build_dir)
2121 rebase_path(depfile, root_build_dir),
2122 "--input-libraries=$rebased_binaries",
2124 rebase_path(root_shlib_dir, root_build_dir),
2126 rebase_path(libraries_list, root_build_dir),
2128 rebase_path(android_readelf, root_build_dir),
2130 if (defined(invoker.deps)) {
2135 copy_ex(copy_target_name) {
2136 visibility = [ ":$template_name" ]
2144 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
2145 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
2147 "--files=$rebased_binaries_list",
2148 "--files=@FileArg($rebased_libraries_list:lib_paths)",
2152 ":$find_deps_target_name",
2154 if (defined(invoker.deps)) {
2155 deps += invoker.deps
2159 group(template_name) {
2160 if (defined(invoker.visibility)) {
2161 visibility = invoker.visibility
2164 ":$copy_target_name",
2169 # Compile a protocol buffer to java.
2171 # This generates java files from protocol buffers and creates an Android library
2172 # containing the classes.
2175 # sources: Paths to .proto files to compile.
2176 # proto_path: Root directory of .proto files.
2179 # proto_java_library("foo_proto_java") {
2180 # proto_path = [ "src/foo" ]
2181 # sources = [ "$proto_path/foo.proto" ]
2183 template("proto_java_library") {
2184 set_sources_assignment_filter([])
2185 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
2186 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
2187 _protoc_bin = "$_protoc_out_dir/android_protoc"
2188 _proto_path = invoker.proto_path
2190 _template_name = target_name
2192 action("${_template_name}__protoc_java") {
2193 srcjar_path = "$target_gen_dir/$target_name.srcjar"
2194 script = "//build/protoc_java.py"
2198 sources = invoker.sources
2199 depfile = "$target_gen_dir/$target_name.d"
2206 rebase_path(depfile, root_build_dir),
2208 rebase_path(_protoc_bin, root_build_dir),
2210 rebase_path(_proto_path, root_build_dir),
2212 rebase_path(srcjar_path, root_build_dir),
2213 ] + rebase_path(sources, root_build_dir)
2216 android_library(target_name) {
2218 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2220 "//third_party/android_protobuf:protobuf_nano_javalib",
2225 # TODO(GYP): implement this.
2226 template("uiautomator_test") {
2227 set_sources_assignment_filter([])
2228 if (defined(invoker.testonly)) {
2229 testonly = invoker.testonly
2231 assert(target_name != "")
2232 assert(invoker.deps != [] || true)
2233 group(target_name) {