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 forward_variables_from(invoker, [ "testonly" ])
37 assert(defined(invoker.sources))
38 assert(defined(invoker.jni_package))
39 jni_package = invoker.jni_package
40 base_output_dir = "${target_gen_dir}/${target_name}"
41 package_output_dir = "${base_output_dir}/${jni_package}"
42 jni_output_dir = "${package_output_dir}/jni"
44 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
46 foreach_target_name = "${target_name}__jni_gen"
47 action_foreach(foreach_target_name) {
48 script = "//base/android/jni_generator/jni_generator.py"
49 depfile = "$target_gen_dir/$target_name.{{source_name_part}}.d"
50 sources = invoker.sources
53 "${jni_output_dir}/{{source_name_part}}_jni.h",
58 rebase_path(depfile, root_build_dir),
59 "--input_file={{source}}",
60 "--optimize_generation=1",
63 rebase_path(jni_output_dir, root_build_dir),
65 rebase_path(jni_generator_include, jni_output_dir),
66 "--native_exports_optional",
68 if (defined(invoker.jni_generator_jarjar_file)) {
71 rebase_path(jni_generator_jarjar_file, root_build_dir),
76 config("jni_includes_${target_name}") {
77 # TODO(cjhopman): #includes should probably all be relative to
78 # base_output_dir. Remove that from this config once the includes are
88 forward_variables_from(invoker,
94 public_deps += [ ":$foreach_target_name" ]
95 public_configs = [ ":jni_includes_${target_name}" ]
99 # Declare a jni target for a prebuilt jar
101 # This target generates the native jni bindings for a set of classes in a .jar.
103 # See base/android/jni_generator/jni_generator.py for more info about the
104 # format of generating JNI bindings.
107 # classes: list of .class files in the jar to generate jni for. These should
108 # include the full path to the .class file.
109 # jni_package: subdirectory path for generated bindings
110 # jar_file: the path to the .jar. If not provided, will default to the sdk's
113 # deps, public_deps: As normal
116 # generate_jar_jni("foo_jni") {
118 # "android/view/Foo.class",
120 # jni_package = "foo"
122 template("generate_jar_jni") {
123 set_sources_assignment_filter([])
124 forward_variables_from(invoker, [ "testonly" ])
126 assert(defined(invoker.classes))
127 assert(defined(invoker.jni_package))
129 if (defined(invoker.jar_file)) {
130 jar_file = invoker.jar_file
132 jar_file = android_sdk_jar
135 jni_package = invoker.jni_package
136 base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}"
137 jni_output_dir = "${base_output_dir}/jni"
139 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
141 # TODO(cjhopman): make jni_generator.py support generating jni for multiple
142 # .class files from a .jar.
144 foreach(class, invoker.classes) {
146 _classname_list = process_file_template([ class ], "{{source_name_part}}")
147 classname = _classname_list[0]
148 jni_target_name = "${target_name}__jni_${classname}"
149 jni_actions += [ ":$jni_target_name" ]
150 action(jni_target_name) {
151 # The sources aren't compiled so don't check their dependencies.
152 check_includes = false
153 depfile = "$target_gen_dir/$target_name.d"
154 script = "//base/android/jni_generator/jni_generator.py"
160 "${jni_output_dir}/${classname}_jni.h",
165 rebase_path(depfile, root_build_dir),
167 rebase_path(jar_file, root_build_dir),
170 "--optimize_generation=1",
173 rebase_path(jni_output_dir, root_build_dir),
175 rebase_path(jni_generator_include, jni_output_dir),
176 "--native_exports_optional",
181 config("jni_includes_${target_name}") {
182 include_dirs = [ base_output_dir ]
187 forward_variables_from(invoker,
193 public_deps += jni_actions
194 public_configs = [ ":jni_includes_${target_name}" ]
198 # Declare a target for c-preprocessor-generated java files
200 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
203 # This target generates java files using the host C pre-processor. Each file in
204 # sources will be compiled using the C pre-processor. If include_path is
205 # specified, it will be passed (with --I) to the pre-processor.
207 # This target will create a single .srcjar. Adding this target to an
208 # android_library target's srcjar_deps will make the generated java files be
209 # included in that library's final outputs.
212 # sources: list of files to be processed by the C pre-processor. For each
213 # file in sources, there will be one .java file in the final .srcjar. For a
214 # file named FooBar.template, a java file will be created with name
216 # inputs: additional compile-time dependencies. Any files
217 # `#include`-ed in the templates should be listed here.
218 # package_name: this will be the subdirectory for each .java file in the
222 # java_cpp_template("foo_generated_enum") {
224 # "android/java/templates/Foo.template",
227 # "android/java/templates/native_foo_header.h",
230 # package_name = "org/chromium/base/library_loader"
231 # include_path = "android/java/templates"
233 template("java_cpp_template") {
234 set_sources_assignment_filter([])
235 forward_variables_from(invoker, [ "testonly" ])
237 assert(defined(invoker.sources))
238 package_name = invoker.package_name + ""
240 if (defined(invoker.include_path)) {
241 include_path = invoker.include_path + ""
246 apply_gcc_target_name = "${target_name}__apply_gcc"
247 zip_srcjar_target_name = "${target_name}__zip_srcjar"
248 final_target_name = target_name
250 action_foreach(apply_gcc_target_name) {
251 forward_variables_from(invoker,
257 visibility = [ ":$zip_srcjar_target_name" ]
258 script = "//build/android/gyp/gcc_preprocess.py"
259 if (defined(invoker.inputs)) {
260 inputs = invoker.inputs + []
262 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
264 sources = invoker.sources
267 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
268 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
272 gcc_template_output_pattern,
277 rebase_path(depfile, root_build_dir),
279 rebase_path(include_path, root_build_dir),
281 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
282 "--template={{source}}",
285 if (defined(invoker.defines)) {
286 foreach(def, invoker.defines) {
295 apply_gcc_outputs = get_target_outputs(":$apply_gcc_target_name")
296 base_gen_dir = get_label_info(":$apply_gcc_target_name", "target_gen_dir")
298 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
299 zip(zip_srcjar_target_name) {
300 visibility = [ ":$final_target_name" ]
301 inputs = apply_gcc_outputs
303 base_dir = base_gen_dir
305 ":$apply_gcc_target_name",
309 group(final_target_name) {
310 forward_variables_from(invoker, [ "visibility" ])
312 ":$zip_srcjar_target_name",
317 # Declare a target for generating Java classes from C++ enums.
319 # This target generates Java files from C++ enums using a script.
321 # This target will create a single .srcjar. Adding this target to an
322 # android_library target's srcjar_deps will make the generated java files be
323 # included in that library's final outputs.
326 # sources: list of files to be processed by the script. For each annotated
327 # enum contained in the sources files the script will generate a .java
328 # file with the same name as the name of the enum.
330 # outputs: list of outputs, relative to the output_dir. These paths are
331 # verified at build time by the script. To get the list programatically run:
332 # python build/android/gyp/java_cpp_enum.py \
333 # --print_output_only . path/to/header/file.h
336 # java_cpp_enum("foo_generated_enum") {
338 # "src/native_foo_header.h",
341 # "org/chromium/FooEnum.java",
344 template("java_cpp_enum") {
345 set_sources_assignment_filter([])
346 forward_variables_from(invoker, [ "testonly" ])
348 assert(defined(invoker.sources))
349 assert(defined(invoker.outputs))
351 generate_enum_target_name = "${target_name}__generate_enum"
352 zip_srcjar_target_name = "${target_name}__zip_srcjar"
353 final_target_name = target_name
355 action(generate_enum_target_name) {
356 visibility = [ ":$zip_srcjar_target_name" ]
358 # The sources aren't compiled so don't check their dependencies.
359 check_includes = false
361 sources = invoker.sources
362 script = "//build/android/gyp/java_cpp_enum.py"
363 gen_dir = "${target_gen_dir}/${target_name}/enums"
365 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
368 foreach(output, rebase_path(outputs, root_build_dir)) {
374 args += [ rebase_path(gen_dir, root_build_dir) ]
375 args += rebase_path(invoker.sources, root_build_dir)
378 generate_enum_outputs = get_target_outputs(":$generate_enum_target_name")
379 base_gen_dir = get_label_info(":$generate_enum_target_name", "target_gen_dir")
381 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
382 zip(zip_srcjar_target_name) {
383 visibility = [ ":$final_target_name" ]
384 inputs = generate_enum_outputs
386 base_dir = base_gen_dir
388 ":$generate_enum_target_name",
392 group(final_target_name) {
393 forward_variables_from(invoker, [ "visibility" ])
395 ":$zip_srcjar_target_name",
400 # Declare a target for processing a Jinja template.
403 # input: The template file to be processed.
404 # output: Where to save the result.
405 # variables: (Optional) A list of variables to make available to the template
406 # processing environment, e.g. ["name=foo", "color=red"].
409 # jinja_template("chrome_public_manifest") {
410 # input = "java/AndroidManifest.xml"
411 # output = "$target_gen_dir/AndroidManifest.xml"
413 template("jinja_template") {
414 set_sources_assignment_filter([])
415 forward_variables_from(invoker, [ "testonly" ])
417 assert(defined(invoker.input))
418 assert(defined(invoker.output))
420 action(target_name) {
421 forward_variables_from(invoker, [ "visibility" ])
426 script = "//build/android/gyp/jinja_template.py"
427 depfile = "$target_gen_dir/$target_name.d"
436 rebase_path(invoker.input, root_build_dir),
438 rebase_path(invoker.output, root_build_dir),
440 rebase_path(depfile, root_build_dir),
442 if (defined(invoker.variables)) {
443 variables = invoker.variables
444 args += [ "--variables=${variables}" ]
449 # Declare a target for processing Android resources as Jinja templates.
451 # This takes an Android resource directory where each resource is a Jinja
452 # template, processes each template, then packages the results in a zip file
453 # which can be consumed by an android resources, library, or apk target.
455 # If this target is included in the deps of an android resources/library/apk,
456 # the resources will be included with that target.
459 # resources: The list of resources files to process.
460 # res_dir: The resource directory containing the resources.
461 # variables: (Optional) A list of variables to make available to the template
462 # processing environment, e.g. ["name=foo", "color=red"].
465 # jinja_template_resources("chrome_public_template_resources") {
466 # res_dir = "res_template"
467 # resources = ["res_template/xml/syncable.xml"]
468 # variables = ["color=red"]
470 template("jinja_template_resources") {
471 set_sources_assignment_filter([])
472 forward_variables_from(invoker, [ "testonly" ])
474 assert(defined(invoker.resources))
475 assert(defined(invoker.res_dir))
477 _base_path = "$target_gen_dir/$target_name"
478 _resources_zip = _base_path + ".resources.zip"
479 _build_config = _base_path + ".build_config"
481 write_build_config("${target_name}__build_config") {
482 build_config = _build_config
483 resources_zip = _resources_zip
484 type = "android_resources"
487 action("${target_name}__template") {
488 sources = invoker.resources
489 script = "//build/android/gyp/jinja_template.py"
490 depfile = "$target_gen_dir/$target_name.d"
497 rebased_resources = rebase_path(invoker.resources, root_build_dir)
499 "--inputs=${rebased_resources}",
501 rebase_path(invoker.res_dir, root_build_dir),
503 rebase_path(_resources_zip, root_build_dir),
505 rebase_path(depfile, root_build_dir),
507 if (defined(invoker.variables)) {
508 variables = invoker.variables
509 args += [ "--variables=${variables}" ]
515 ":${target_name}__build_config",
516 ":${target_name}__template",
521 # Creates a resources.zip with locale.pak files placed into appropriate
522 # resource configs (e.g. en-GB.pak -> res/raw-en/en_gb.pak). Also generates
523 # a locale_paks TypedArray so that resource files can be enumerated at runtime.
525 # If this target is included in the deps of an android resources/library/apk,
526 # the resources will be included with that target.
529 # sources: List of .pak files. Names must be of the form "en.pak" or
531 # deps: (optional) List of dependencies that might be needed to generate
535 # locale_pak_resources("locale_paks") {
536 # sources = [ "path/en-US.pak", "path/fr.pak", ... ]
538 template("locale_pak_resources") {
539 set_sources_assignment_filter([])
540 assert(defined(invoker.sources))
542 _base_path = "$target_gen_dir/$target_name"
543 _resources_zip = _base_path + ".resources.zip"
544 _build_config = _base_path + ".build_config"
546 write_build_config("${target_name}__build_config") {
547 build_config = _build_config
548 resources_zip = _resources_zip
549 type = "android_resources"
552 action("${target_name}__create_resources_zip") {
553 forward_variables_from(invoker,
558 script = "//build/android/gyp/locale_pak_resources.py"
559 depfile = "$target_gen_dir/$target_name.d"
566 _rebased_sources = rebase_path(sources, root_build_dir)
568 "--locale-paks=${_rebased_sources}",
570 rebase_path(_resources_zip, root_build_dir),
572 rebase_path(depfile, root_build_dir),
578 ":${target_name}__build_config",
579 ":${target_name}__create_resources_zip",
584 # Declare an Android resources target
586 # This creates a resources zip file that will be used when building an Android
587 # library or apk and included into a final apk.
589 # To include these resources in a library/apk, this target should be listed in
590 # the library's deps. A library/apk will also include any resources used by its
594 # deps: Specifies the dependencies of this target. Any Android resources
595 # listed in deps will be included by libraries/apks that depend on this
597 # resource_dirs: List of directories containing resources for this target.
598 # android_manifest: AndroidManifest.xml for this target. Defaults to
599 # //build/android/AndroidManifest.xml.
600 # custom_package: java package for generated .java files.
601 # v14_skip: If true, don't run v14 resource generator on this. Defaults to
602 # false. (see build/android/gyp/generate_v14_compatible_resources.py)
604 # shared_resources: If true make a resource package that can be loaded by a
605 # different application at runtime to access the package's resources.
609 # android_resources("foo_resources") {
610 # deps = [":foo_strings_grd"]
611 # resource_dirs = ["res"]
612 # custom_package = "org.chromium.foo"
615 # android_resources("foo_resources_overrides") {
616 # deps = [":foo_resources"]
617 # resource_dirs = ["res_overrides"]
619 template("android_resources") {
620 set_sources_assignment_filter([])
621 forward_variables_from(invoker, [ "testonly" ])
623 assert(defined(invoker.resource_dirs))
625 base_path = "$target_gen_dir/$target_name"
626 zip_path = base_path + ".resources.zip"
627 srcjar_path = base_path + ".srcjar"
628 r_text_path = base_path + "_R.txt"
629 build_config = base_path + ".build_config"
631 build_config_target_name = "${target_name}__build_config"
632 process_resources_target_name = "${target_name}__process_resources"
633 final_target_name = target_name
635 write_build_config(build_config_target_name) {
636 forward_variables_from(invoker,
643 # No package means resources override their deps.
644 if (defined(custom_package) || defined(android_manifest)) {
647 assert(defined(invoker.deps),
648 "Must specify deps when custom_package is omitted.")
650 visibility = [ ":$process_resources_target_name" ]
652 type = "android_resources"
653 resources_zip = zip_path
657 process_resources(process_resources_target_name) {
658 visibility = [ ":$final_target_name" ]
660 forward_variables_from(invoker,
669 deps += [ ":$build_config_target_name" ]
670 if (!defined(android_manifest)) {
671 android_manifest = "//build/android/AndroidManifest.xml"
675 group(final_target_name) {
676 forward_variables_from(invoker, [ "visibility" ])
678 ":${target_name}__process_resources",
683 # Declare a target that generates localized strings.xml from a .grd file.
685 # If this target is included in the deps of an android resources/library/apk,
686 # the strings.xml will be included with that target.
689 # deps: Specifies the dependencies of this target.
690 # grd_file: Path to the .grd file to generate strings.xml from.
691 # outputs: Expected grit outputs (see grit rule).
694 # java_strings_grd("foo_strings_grd") {
695 # grd_file = "foo_strings.grd"
697 template("java_strings_grd") {
698 set_sources_assignment_filter([])
699 forward_variables_from(invoker, [ "testonly" ])
701 base_path = "$target_gen_dir/$target_name"
702 resources_zip = base_path + ".resources.zip"
703 build_config = base_path + ".build_config"
705 write_build_config("${target_name}__build_config") {
706 forward_variables_from(invoker, [ "deps" ])
707 type = "android_resources"
710 # Put grit files into this subdirectory of target_gen_dir.
711 extra_output_path = target_name + "_grit_output"
713 grit_target_name = "${target_name}__grit"
714 grit_output_dir = "$target_gen_dir/$extra_output_path"
715 grit(grit_target_name) {
718 "ANDROID_JAVA_TAGGED_ONLY=false",
720 output_dir = grit_output_dir
722 source = invoker.grd_file
723 outputs = invoker.outputs
726 # This needs to get outputs from grit's internal target, not the final
728 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
730 zip("${target_name}__zip") {
731 base_dir = grit_output_dir
732 inputs = generate_strings_outputs
733 output = resources_zip
735 ":$grit_target_name",
741 ":${target_name}__build_config",
742 ":${target_name}__zip",
747 # Declare a target that packages strings.xml generated from a grd file.
749 # If this target is included in the deps of an android resources/library/apk,
750 # the strings.xml will be included with that target.
753 # grit_output_dir: directory containing grit-generated files.
754 # generated_files: list of android resource files to package.
757 # java_strings_grd_prebuilt("foo_strings_grd") {
758 # grit_output_dir = "$root_gen_dir/foo/grit"
759 # generated_files = [
760 # "values/strings.xml"
763 template("java_strings_grd_prebuilt") {
764 set_sources_assignment_filter([])
765 forward_variables_from(invoker, [ "testonly" ])
767 base_path = "$target_gen_dir/$target_name"
768 resources_zip = base_path + ".resources.zip"
769 build_config = base_path + ".build_config"
771 build_config_target_name = "${target_name}__build_config"
772 zip_target_name = "${target_name}__zip"
773 final_target_name = target_name
775 write_build_config(build_config_target_name) {
776 visibility = [ ":$zip_target_name" ]
777 type = "android_resources"
780 zip(zip_target_name) {
781 visibility = [ ":$final_target_name" ]
783 base_dir = invoker.grit_output_dir
784 inputs = rebase_path(invoker.generated_files, ".", base_dir)
785 output = resources_zip
787 ":$build_config_target_name",
789 if (defined(invoker.deps)) {
794 group(final_target_name) {
795 forward_variables_from(invoker, [ "visibility" ])
802 # Declare a Java executable target
804 # This target creates an executable from java code and libraries. The executable
805 # will be in the output folder's /bin/ directory.
808 # deps: Specifies the dependencies of this target. Java targets in this list
809 # will be included in the executable (and the javac classpath).
810 # java_files: List of .java files included in this library.
811 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
812 # will be added to java_files and be included in this library.
813 # srcjars: List of srcjars to be included in this library, together with the
814 # ones obtained from srcjar_deps.
815 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
816 # dependencies for this target. This will allow depending on an
817 # android_library target, for example.
818 # chromium_code: If true, extra analysis warning/errors will be enabled.
819 # enable_errorprone: If true, enables the errorprone compiler.
820 # main_class: When specified, a wrapper script is created within
821 # $target_out_dir/bin to launch the binary with the given class as the
823 # wrapper_script_args: List of additional arguments for the wrapper script.
825 # data_deps, testonly
828 # java_binary("foo") {
829 # java_files = [ "org/chromium/foo/FooMain.java" ]
830 # deps = [ ":bar_java" ]
831 # main_class = "org.chromium.foo.FooMain"
833 template("java_binary") {
834 set_sources_assignment_filter([])
836 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
837 # dependents shouldn't get the jar in their classpath, etc.).
838 java_library_impl(target_name) {
839 forward_variables_from(invoker, "*")
840 supports_android = false
841 main_class = invoker.main_class
845 # Declare a Junit executable target
847 # This target creates an executable from java code for running as a junit test
848 # suite. The executable 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 # chromium_code: If true, extra analysis warning/errors will be enabled.
863 # junit_binary("foo") {
864 # java_files = [ "org/chromium/foo/FooTest.java" ]
865 # deps = [ ":bar_java" ]
867 template("junit_binary") {
868 set_sources_assignment_filter([])
870 java_binary(target_name) {
872 forward_variables_from(invoker, "*")
873 bypass_platform_checks = true
874 main_class = "org.chromium.testing.local.JunitTestMain"
875 wrapper_script_args = [
882 "//testing/android/junit:junit_test_support",
883 "//third_party/junit",
884 "//third_party/mockito:mockito_java",
885 "//third_party/robolectric:robolectric_java",
886 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
891 # Declare a java library target
894 # deps: Specifies the dependencies of this target. Java targets in this list
895 # will be added to the javac classpath.
897 # java_files: List of .java files included in this library.
898 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
899 # will be added to java_files and be included in this library.
900 # srcjars: List of srcjars to be included in this library, together with the
901 # ones obtained from srcjar_deps.
902 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
903 # this directory will be included in the library. This is only supported to
904 # ease the gyp->gn conversion and will be removed in the future.
906 # chromium_code: If true, extra analysis warning/errors will be enabled.
907 # enable_errorprone: If true, enables the errorprone compiler.
909 # jar_excluded_patterns: List of patterns of .class files to exclude from the
912 # proguard_preprocess: If true, proguard preprocessing will be run. This can
913 # be used to remove unwanted parts of the library.
914 # proguard_config: Path to the proguard config for preprocessing.
916 # supports_android: If true, Android targets (android_library, android_apk)
917 # may depend on this target. Note: if true, this target must only use the
918 # subset of Java available on Android.
919 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
920 # dependencies for this target. This will allow depending on an
921 # android_library target, for example.
923 # data_deps, testonly
926 # java_library("foo_java") {
928 # "org/chromium/foo/Foo.java",
929 # "org/chromium/foo/FooInterface.java",
930 # "org/chromium/foo/FooService.java",
936 # ":foo_generated_enum"
938 # jar_excluded_patterns = [
939 # "*/FooService.class", "*/FooService##*.class"
942 template("java_library") {
943 set_sources_assignment_filter([])
944 java_library_impl(target_name) {
945 forward_variables_from(invoker, "*")
949 # Declare a java library target for a prebuilt jar
952 # deps: Specifies the dependencies of this target. Java targets in this list
953 # will be added to the javac classpath.
954 # jar_path: Path to the prebuilt jar.
955 # jar_dep: Target that builds jar_path (optional).
956 # proguard_preprocess: If true, proguard preprocessing will be run. This can
957 # be used to remove unwanted parts of the library.
958 # proguard_config: Path to the proguard config for preprocessing.
959 # supports_android: If true, Android targets (android_library, android_apk)
960 # may depend on this target. Note: if true, this target must only use the
961 # subset of Java available on Android.
964 # java_prebuilt("foo_java") {
965 # jar_path = "foo.jar"
971 template("java_prebuilt") {
972 set_sources_assignment_filter([])
973 java_prebuilt_impl(target_name) {
974 forward_variables_from(invoker, "*")
978 # Declare an Android library target
980 # This target creates an Android library containing java code and Android
984 # deps: Specifies the dependencies of this target. Java targets in this list
985 # will be added to the javac classpath. Android resources in dependencies
986 # will be used when building this library.
988 # java_files: List of .java files included in this library.
989 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
990 # will be added to java_files and be included in this library.
991 # srcjars: List of srcjars to be included in this library, together with the
992 # ones obtained from srcjar_deps.
993 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
994 # this directory will be included in the library. This is only supported to
995 # ease the gyp->gn conversion and will be removed in the future.
997 # chromium_code: If true, extra analysis warning/errors will be enabled.
998 # enable_errorprone: If true, enables the errorprone compiler.
1000 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1003 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1004 # be used to remove unwanted parts of the library.
1005 # proguard_config: Path to the proguard config for preprocessing.
1007 # dex_path: If set, the resulting .dex.jar file will be placed under this
1012 # android_library("foo_java") {
1014 # "android/org/chromium/foo/Foo.java",
1015 # "android/org/chromium/foo/FooInterface.java",
1016 # "android/org/chromium/foo/FooService.java",
1022 # ":foo_generated_enum"
1024 # jar_excluded_patterns = [
1025 # "*/FooService.class", "*/FooService##*.class"
1028 template("android_library") {
1029 set_sources_assignment_filter([])
1030 assert(!defined(invoker.jar_path),
1031 "android_library does not support a custom jar path")
1032 java_library_impl(target_name) {
1033 forward_variables_from(invoker, "*")
1035 supports_android = true
1036 requires_android = true
1038 if (!defined(jar_excluded_patterns)) {
1039 jar_excluded_patterns = []
1041 jar_excluded_patterns += [
1045 "*/Manifest##*.class",
1050 # Declare a target that packages a set of Java dependencies into a standalone
1054 # deps: specifies the dependencies of this target. Android libraries in deps
1055 # will be packaged into the resulting .dex.jar file.
1056 # dex_path: location at which the output file will be put
1057 template("android_standalone_library") {
1058 set_sources_assignment_filter([])
1059 deps_dex(target_name) {
1060 forward_variables_from(invoker,
1069 # Declare an Android library target for a prebuilt jar
1071 # This target creates an Android library containing java code and Android
1075 # deps: Specifies the dependencies of this target. Java targets in this list
1076 # will be added to the javac classpath. Android resources in dependencies
1077 # will be used when building this library.
1078 # jar_path: Path to the prebuilt jar.
1079 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1080 # be used to remove unwanted parts of the library.
1081 # proguard_config: Path to the proguard config for preprocessing.
1084 # android_java_prebuilt("foo_java") {
1085 # jar_path = "foo.jar"
1091 template("android_java_prebuilt") {
1092 set_sources_assignment_filter([])
1093 java_prebuilt_impl(target_name) {
1094 forward_variables_from(invoker, "*")
1095 supports_android = true
1096 requires_android = true
1100 # Declare an Android apk target
1102 # This target creates an Android APK containing java code, resources, assets,
1103 # and (possibly) native libraries.
1106 # android_manifest: Path to AndroidManifest.xml.
1107 # android_manifest_dep: Target that generates AndroidManifest (if applicable)
1108 # data_deps: List of dependencies needed at runtime. These will be built but
1109 # won't change the generated .apk in any way (in fact they may be built
1110 # after the .apk is).
1111 # deps: List of dependencies. All Android java resources and libraries in the
1112 # "transitive closure" of these dependencies will be included in the apk.
1113 # Note: this "transitive closure" actually only includes such targets if
1114 # they are depended on through android_library or android_resources targets
1115 # (and so not through builtin targets like 'action', 'group', etc).
1116 # java_files: List of .java files to include in the apk.
1117 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1118 # will be added to java_files and be included in this apk.
1119 # apk_name: Name for final apk.
1120 # final_apk_path: Path to final built apk. Default is
1121 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1122 # native_libs: List paths of native libraries to include in this apk. If these
1123 # libraries depend on other shared_library targets, those dependencies will
1124 # also be included in the apk.
1125 # apk_under_test: For an instrumentation test apk, this is the target of the
1127 # include_all_resources - If true include all resource IDs in all generated
1129 # testonly: Marks this target as "test-only".
1131 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1132 # this directory will be included in the library. This is only supported to
1133 # ease the gyp->gn conversion and will be removed in the future.
1136 # android_apk("foo_apk") {
1137 # android_manifest = "AndroidManifest.xml"
1139 # "android/org/chromium/foo/FooApplication.java",
1140 # "android/org/chromium/foo/FooActivity.java",
1143 # ":foo_support_java"
1147 # ":foo_generated_enum"
1153 template("android_apk") {
1154 set_sources_assignment_filter([])
1155 forward_variables_from(invoker, [ "testonly" ])
1157 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1158 assert(defined(invoker.android_manifest))
1159 gen_dir = "$target_gen_dir/$target_name"
1160 base_path = "$gen_dir/$target_name"
1161 _build_config = "$target_gen_dir/$target_name.build_config"
1162 resources_zip_path = "$base_path.resources.zip"
1163 _all_resources_zip_path = "$base_path.resources.all.zip"
1164 _jar_path = "$base_path.jar"
1165 _lib_dex_path = "$base_path.dex.jar"
1166 _rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir)
1167 _template_name = target_name
1169 final_dex_path = "$gen_dir/classes.dex"
1170 final_dex_target_name = "${_template_name}__final_dex"
1172 _final_apk_path = ""
1173 if (defined(invoker.final_apk_path)) {
1174 _final_apk_path = invoker.final_apk_path
1175 } else if (defined(invoker.apk_name)) {
1176 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1178 _dist_jar_path_list =
1179 process_file_template(
1180 [ _final_apk_path ],
1181 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1182 _dist_jar_path = _dist_jar_path_list[0]
1183 _final_apk_path_no_ext_list =
1184 process_file_template([ _final_apk_path ],
1185 "{{source_dir}}/{{source_name_part}}")
1186 _final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
1187 assert(_final_apk_path_no_ext != "") # Mark as used.
1192 if (defined(invoker.version_code)) {
1193 _version_code = invoker.version_code
1196 _version_name = "Developer Build"
1197 if (defined(invoker.version_name)) {
1198 _version_name = invoker.version_name
1200 _keystore_path = android_keystore_path
1201 _keystore_name = android_keystore_name
1202 _keystore_password = android_keystore_password
1204 if (defined(invoker.keystore_path)) {
1205 _keystore_path = invoker.keystore_path
1206 _keystore_name = invoker.keystore_name
1207 _keystore_password = invoker.keystore_password
1211 if (defined(invoker.srcjar_deps)) {
1212 _srcjar_deps += invoker.srcjar_deps
1215 _load_library_from_apk = false
1217 # The dependency that makes the chromium linker, if any is needed.
1218 _chromium_linker_dep = []
1220 if (defined(invoker.native_libs)) {
1221 _use_chromium_linker = false
1222 if (defined(invoker.use_chromium_linker)) {
1223 _use_chromium_linker =
1224 invoker.use_chromium_linker && chromium_linker_supported
1225 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1228 if (defined(invoker.load_library_from_apk) &&
1229 invoker.load_library_from_apk) {
1230 _load_library_from_apk = true
1231 assert(_use_chromium_linker,
1232 "Loading library from the apk requires use" +
1233 " of the Chromium linker.")
1236 _enable_relocation_packing = false
1237 if (defined(invoker.enable_relocation_packing) &&
1238 invoker.enable_relocation_packing) {
1239 _enable_relocation_packing = relocation_packing_supported
1240 assert(_use_chromium_linker,
1241 "Relocation packing requires use of the" + " Chromium linker.")
1244 if (is_component_build) {
1245 _native_libs += [ "$root_shlib_dir/libc++_shared.so" ]
1246 _chromium_linker_dep += [ "//build/android:cpplib_stripped" ]
1249 # Allow native_libs to be in the form "foo.so" or "foo.cr.so"
1250 _first_ext_removed =
1251 process_file_template(invoker.native_libs, "{{source_name_part}}")
1252 _native_libs += process_file_template(
1254 "$root_shlib_dir/{{source_name_part}}$shlib_extension")
1256 # Add in target_cpu so that other architectures are not accidentally
1257 # included when switching target_cpu without doing a clean build.
1258 _native_libs_dir = gen_dir + "/lib-$target_cpu"
1260 if (_use_chromium_linker) {
1262 [ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
1265 _enable_relocation_packing = false
1266 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1267 invoker.enable_relocation_packing) {
1268 _enable_relocation_packing = true
1271 _native_lib_version_rule = ""
1272 if (defined(invoker.native_lib_version_rule)) {
1273 _native_lib_version_rule = invoker.native_lib_version_rule
1275 _native_lib_version_arg = "\"\""
1276 if (defined(invoker.native_lib_version_arg)) {
1277 _native_lib_version_arg = invoker.native_lib_version_arg
1281 _android_manifest_deps = []
1282 if (defined(invoker.android_manifest_dep)) {
1283 _android_manifest_deps = [ invoker.android_manifest_dep ]
1285 _android_manifest = invoker.android_manifest
1287 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1289 defined(invoker.create_abi_split) && invoker.create_abi_split
1290 _create_density_splits =
1291 defined(invoker.create_density_splits) && invoker.create_density_splits
1292 _create_language_splits =
1293 defined(invoker.language_splits) && invoker.language_splits != []
1295 # Help GN understand that _create_abi_split is not unused (bug in GN).
1296 assert(_create_abi_split || true)
1298 build_config_target = "${_template_name}__build_config"
1299 write_build_config(build_config_target) {
1300 forward_variables_from(invoker, [ "apk_under_test" ])
1301 type = "android_apk"
1302 jar_path = _jar_path
1303 dex_path = final_dex_path
1304 resources_zip = resources_zip_path
1305 build_config = _build_config
1306 android_manifest = _android_manifest
1308 deps = _chromium_linker_dep + _android_manifest_deps
1309 if (defined(invoker.deps)) {
1310 deps += invoker.deps
1313 native_libs = _native_libs
1317 _incremental_final_deps = []
1319 process_resources_target = "${_template_name}__process_resources"
1320 process_resources(process_resources_target) {
1321 forward_variables_from(invoker, [ "include_all_resources" ])
1322 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1323 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1324 android_manifest = _android_manifest
1325 resource_dirs = [ "//build/android/ant/empty/res" ]
1326 zip_path = resources_zip_path
1327 all_resources_zip_path = _all_resources_zip_path
1328 generate_constant_ids = true
1330 build_config = _build_config
1331 deps = _android_manifest_deps + [ ":$build_config_target" ]
1332 if (defined(invoker.deps)) {
1333 deps += invoker.deps
1336 _srcjar_deps += [ ":$process_resources_target" ]
1338 if (_native_libs != []) {
1339 _enable_chromium_linker_tests = false
1340 if (defined(invoker.enable_chromium_linker_tests)) {
1341 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1344 java_cpp_template("${_template_name}__native_libraries_java") {
1345 package_name = "org/chromium/base/library_loader"
1347 "//base/android/java/templates/NativeLibraries.template",
1353 ":$build_config_target",
1355 if (_native_lib_version_rule != "") {
1356 deps += [ _native_lib_version_rule ]
1360 "NATIVE_LIBRARIES_LIST=" +
1361 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1362 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
1364 if (_use_chromium_linker) {
1365 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1367 if (_load_library_from_apk) {
1368 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1370 if (_enable_chromium_linker_tests) {
1371 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1374 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1377 java_target = "${_template_name}__java"
1378 java_library_impl(java_target) {
1379 forward_variables_from(invoker, [ "run_findbugs" ])
1380 supports_android = true
1381 requires_android = true
1382 override_build_config = _build_config
1383 deps = _android_manifest_deps + [ ":$build_config_target" ]
1385 android_manifest = _android_manifest
1386 chromium_code = true
1387 if (defined(invoker.java_files)) {
1388 java_files = invoker.java_files
1389 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1390 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1394 srcjar_deps = _srcjar_deps
1395 jar_path = _jar_path
1396 dex_path = _lib_dex_path
1398 if (defined(invoker.deps)) {
1399 deps += invoker.deps
1403 if (_dist_jar_path != "") {
1404 create_dist_target = "${_template_name}__create_dist_jar"
1405 _final_deps += [ ":$create_dist_target" ]
1406 _incremental_final_deps += [ ":$create_dist_target" ]
1408 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1409 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1410 # able to just do that calculation at build time instead.
1411 action(create_dist_target) {
1412 script = "//build/android/gyp/create_dist_jar.py"
1413 depfile = "$target_gen_dir/$target_name.d"
1423 rebase_path(depfile, root_build_dir),
1425 rebase_path(_dist_jar_path, root_build_dir),
1426 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1428 inputs += [ _jar_path ]
1429 _rebased_jar_path = rebase_path([ _jar_path ], root_build_dir)
1430 args += [ "--inputs=$_rebased_jar_path" ]
1432 ":$build_config_target", # Generates the build config file.
1433 ":$java_target", # Generates the jar file.
1438 dex("$final_dex_target_name") {
1440 ":$build_config_target",
1446 output = final_dex_path
1447 _dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1449 "--inputs=@FileArg($_dex_arg_key)",
1450 _rebased_lib_dex_path,
1454 if (_native_libs != []) {
1455 action("${_template_name}__prepare_native") {
1456 forward_variables_from(invoker,
1461 script = "//build/android/gyp/pack_relocations.py"
1462 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1463 depfile = "$target_gen_dir/$target_name.d"
1468 inputs = _native_libs
1469 deps = _chromium_linker_dep
1471 inputs += [ _build_config ]
1472 deps += [ ":$build_config_target" ]
1474 skip_packing_list = [
1476 "libchromium_android_linker$shlib_extension",
1479 enable_packing_arg = 0
1480 if (_enable_relocation_packing) {
1481 enable_packing_arg = 1
1482 deps += [ relocation_packer_target ]
1487 rebase_path(depfile, root_build_dir),
1488 "--enable-packing=$enable_packing_arg",
1489 "--exclude-packing-list=$skip_packing_list",
1490 "--android-pack-relocations",
1491 rebase_path(relocation_packer_exe, root_build_dir),
1492 "--stripped-libraries-dir",
1493 rebase_path(root_build_dir, root_build_dir),
1494 "--packed-libraries-dir",
1495 rebase_path(packed_libraries_dir, root_build_dir),
1496 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1500 if (defined(invoker.deps)) {
1501 deps += invoker.deps
1505 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1506 inputs += [ android_gdbserver ]
1507 args += [ "--libraries=$rebased_gdbserver" ]
1512 _final_deps += [ ":${_template_name}__create" ]
1513 _incremental_final_deps += [ ":${_template_name}__create_incremental" ]
1514 create_apk("${_template_name}__create") {
1515 forward_variables_from(invoker, [ "language_splits" ])
1516 apk_path = _final_apk_path
1517 android_manifest = _android_manifest
1518 resources_zip = _all_resources_zip_path
1519 dex_path = final_dex_path
1520 load_library_from_apk = _load_library_from_apk
1521 create_density_splits = _create_density_splits
1522 if (defined(invoker.extensions_to_not_compress)) {
1523 extensions_to_not_compress = invoker.extensions_to_not_compress
1525 # Allow icu data, v8 snapshots, and pak files to be loaded directly from
1527 # Note: These are actually suffix matches, not necessarily extensions.
1528 extensions_to_not_compress = ".dat,.bin,.pak"
1531 version_code = _version_code
1532 version_name = _version_name
1534 keystore_name = _keystore_name
1535 keystore_path = _keystore_path
1536 keystore_password = _keystore_password
1538 # This target generates the input file _all_resources_zip_path.
1539 deps = _android_manifest_deps + [
1540 ":$process_resources_target",
1541 ":$final_dex_target_name",
1543 if (defined(invoker.deps)) {
1544 deps += invoker.deps
1547 if (defined(invoker.asset_location)) {
1548 asset_location = invoker.asset_location
1550 # We don't know the exact dependencies that create the assets in
1551 # |asset_location|; we depend on all caller deps until a better solution
1552 # is figured out (http://crbug.com/433330).
1553 if (defined(invoker.deps)) {
1554 deps += invoker.deps
1558 if (_native_libs != [] && !_create_abi_split) {
1559 native_libs_dir = _native_libs_dir
1560 deps += [ ":${_template_name}__prepare_native" ]
1564 if (_native_libs != [] && _create_abi_split) {
1565 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1566 generate_split_manifest(_manifest_rule) {
1567 main_manifest = _android_manifest
1569 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1570 split_name = "abi_${android_app_abi}"
1571 deps = _android_manifest_deps
1574 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1575 _final_deps += [ ":$_apk_rule" ]
1577 # Don't add this to _incremental_final_deps since for incremental installs
1578 # we skip abi splits altogether.
1579 create_apk(_apk_rule) {
1580 apk_path = "${_final_apk_path_no_ext}-abi-${android_app_abi}.apk"
1581 base_path = "$gen_dir/$_apk_rule"
1583 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1584 android_manifest = manifest_outputs[1]
1585 load_library_from_apk = _load_library_from_apk
1587 version_code = _version_code
1588 version_name = _version_name
1590 keystore_name = _keystore_name
1591 keystore_path = _keystore_path
1592 keystore_password = _keystore_password
1594 native_libs_dir = _native_libs_dir
1596 ":${_template_name}__prepare_native",
1597 ":${_manifest_rule}",
1602 _create_incremental_script_rule_name = "${_template_name}__incremental_script"
1603 _incremental_final_deps += [ ":${_create_incremental_script_rule_name}" ]
1604 action(_create_incremental_script_rule_name) {
1605 script = "//build/android/incremental_install/create_install_script.py"
1606 depfile = "$target_gen_dir/$target_name.d"
1608 ":$build_config_target",
1611 _generated_script_path =
1612 "${root_out_dir}/bin/install_incremental_${_template_name}"
1615 _generated_script_path,
1618 _rebased_apk_path_no_ext =
1619 rebase_path(_final_apk_path_no_ext, root_build_dir)
1620 _rebased_generated_script_path =
1621 rebase_path(_generated_script_path, root_build_dir)
1622 _rebased_depfile = rebase_path(depfile, root_build_dir)
1623 _dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1625 "--apk-path=${_rebased_apk_path_no_ext}_incremental.apk",
1626 "--script-output-path=$_rebased_generated_script_path",
1627 "--dex-file=$_rebased_lib_dex_path",
1628 "--dex-file-list=@FileArg($_dex_arg_key)",
1629 "--depfile=$_rebased_depfile",
1631 if (defined(_native_libs_dir)) {
1632 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
1633 args += [ "--lib-dir=$_rebased_native_libs_dir/$android_app_abi" ]
1635 if (_create_density_splits) {
1636 args += [ "--split=${_rebased_apk_path_no_ext}-density-*.apk" ]
1638 if (_create_language_splits) {
1639 args += [ "--split=${_rebased_apk_path_no_ext}-language-*.apk" ]
1643 group(target_name) {
1644 forward_variables_from(invoker, [ "data_deps" ])
1645 public_deps = _final_deps
1647 group("${target_name}_incremental") {
1649 forward_variables_from(invoker, [ "data_deps" ])
1650 data_deps += [ "//build/android/pylib/device/commands" ]
1651 public_deps = _incremental_final_deps
1655 # Declare an Android instrumentation test apk
1657 # This target creates an Android instrumentation test apk.
1660 # android_manifest: Path to AndroidManifest.xml.
1661 # data_deps: List of dependencies needed at runtime. These will be built but
1662 # won't change the generated .apk in any way (in fact they may be built
1663 # after the .apk is).
1664 # deps: List of dependencies. All Android java resources and libraries in the
1665 # "transitive closure" of these dependencies will be included in the apk.
1666 # Note: this "transitive closure" actually only includes such targets if
1667 # they are depended on through android_library or android_resources targets
1668 # (and so not through builtin targets like 'action', 'group', etc).
1669 # java_files: List of .java files to include in the apk.
1670 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1671 # will be added to java_files and be included in this apk.
1672 # apk_name: Name for final apk.
1673 # final_apk_path: Path to final built apk. Default is
1674 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1675 # native_libs: List paths of native libraries to include in this apk. If these
1676 # libraries depend on other shared_library targets, those dependencies will
1677 # also be included in the apk.
1678 # apk_under_test: The apk being tested.
1679 # isolate_file: Isolate file containing the list of test data dependencies.
1681 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1682 # this directory will be included in the library. This is only supported to
1683 # ease the gyp->gn conversion and will be removed in the future.
1686 # instrumentation_test_apk("foo_test_apk") {
1687 # android_manifest = "AndroidManifest.xml"
1688 # apk_name = "FooTest"
1689 # apk_under_test = "Foo"
1691 # "android/org/chromium/foo/FooTestCase.java",
1692 # "android/org/chromium/foo/FooExampleTest.java",
1695 # ":foo_test_support_java"
1698 template("instrumentation_test_apk") {
1699 set_sources_assignment_filter([])
1701 _template_name = target_name
1703 if (defined(invoker.apk_name)) {
1704 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1705 test_runner_script("${_template_name}__test_runner_script") {
1706 forward_variables_from(invoker, [ "isolate_file" ])
1707 test_name = invoker.target_name
1708 test_type = "instrumentation"
1709 test_apk = invoker.apk_name
1713 android_apk(target_name) {
1716 forward_variables_from(invoker, "*")
1718 "//testing/android/driver:driver_apk",
1719 "//tools/android/forwarder2",
1720 "//tools/android/md5sum",
1722 if (defined(test_runner_data_dep)) {
1723 data_deps += test_runner_data_dep
1725 deps += [ "//testing/android/broker:broker_java" ]
1726 run_findbugs = false
1730 # Declare an Android gtest apk
1732 # This target creates an Android apk for running gtest-based unittests.
1735 # deps: Specifies the dependencies of this target. These will be passed to
1736 # the underlying android_apk invocation and should include the java and
1737 # resource dependencies of the apk.
1738 # unittests_dep: This should be the label of the gtest native target. This
1739 # target must be defined previously in the same file.
1740 # unittests_binary: The basename of the library produced by the unittests_dep
1741 # target. If unspecified, it assumes the name of the unittests_dep target
1742 # (which will be correct unless that target specifies an "output_name".
1743 # TODO(brettw) make this automatic by allowing get_target_outputs to
1744 # support executables.
1745 # apk_name: The name of the produced apk. If unspecified, it uses the name
1746 # of the unittests_dep target postfixed with "_apk"
1749 # unittest_apk("foo_unittests_apk") {
1750 # deps = [ ":foo_java", ":foo_resources" ]
1751 # unittests_dep = ":foo_unittests"
1753 template("unittest_apk") {
1754 set_sources_assignment_filter([])
1757 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1759 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1761 # This trivial assert is needed in case both unittests_binary and apk_name
1762 # are defined, as otherwise test_suite_name would not be used.
1763 assert(test_suite_name != "")
1765 if (defined(invoker.unittests_binary)) {
1766 unittests_binary = invoker.unittests_binary
1768 unittests_binary = "lib${test_suite_name}${shlib_extension}"
1771 if (defined(invoker.apk_name)) {
1772 apk_name = invoker.apk_name
1774 apk_name = test_suite_name
1777 android_apk(target_name) {
1778 forward_variables_from(invoker, [ "asset_location" ])
1779 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1781 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
1782 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
1783 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
1784 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
1786 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1787 native_libs = [ unittests_binary ]
1790 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1791 "//testing/android/appurify_support:appurify_support_java",
1792 "//testing/android/reporter:reporter_java",
1794 if (defined(invoker.deps)) {
1795 deps += invoker.deps
1797 data_deps = [ "//tools/android/md5sum" ]
1798 if (host_os == "linux") {
1799 data_deps += [ "//tools/android/forwarder2" ]
1801 if (defined(invoker.data_deps)) {
1802 data_deps += invoker.data_deps
1807 # Generate .java files from .aidl files.
1809 # This target will store the .java files in a srcjar and should be included in
1810 # an android_library or android_apk's srcjar_deps.
1813 # sources: Paths to .aidl files to compile.
1814 # import_include: Path to directory containing .java files imported by the
1816 # interface_file: Preprocessed aidl file to import.
1819 # android_aidl("foo_aidl") {
1820 # import_include = "java/src"
1822 # "java/src/com/foo/bar/FooBarService.aidl",
1823 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1826 template("android_aidl") {
1827 set_sources_assignment_filter([])
1828 forward_variables_from(invoker, [ "testonly" ])
1830 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1831 aidl_path = "${android_sdk_build_tools}/aidl"
1832 framework_aidl = "$android_sdk/framework.aidl"
1834 action(target_name) {
1835 script = "//build/android/gyp/aidl.py"
1836 sources = invoker.sources
1838 imports = [ framework_aidl ]
1839 if (defined(invoker.interface_file)) {
1840 assert(invoker.interface_file != "")
1841 imports += [ invoker.interface_file ]
1844 inputs = [ aidl_path ] + imports
1846 depfile = "${target_gen_dir}/${target_name}.d"
1851 rebased_imports = rebase_path(imports, root_build_dir)
1854 rebase_path(depfile, root_build_dir),
1856 rebase_path(aidl_path, root_build_dir),
1857 "--imports=$rebased_imports",
1859 rebase_path(srcjar_path, root_build_dir),
1861 if (defined(invoker.import_include) && invoker.import_include != "") {
1862 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1863 # switch to constructing a depfile for the overall action from that
1864 # instead of having all the .java files in the include paths as inputs.
1865 rebased_import_includes =
1866 rebase_path([ invoker.import_include ], root_build_dir)
1867 args += [ "--includes=$rebased_import_includes" ]
1869 _java_files_build_rel =
1870 exec_script("//build/android/gyp/find.py",
1871 rebase_path([ invoker.import_include ], root_build_dir),
1873 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1874 inputs += _java_files
1876 args += rebase_path(sources, root_build_dir)
1880 # Creates a dist directory for a native executable.
1882 # Running a native executable on a device requires all the shared library
1883 # dependencies of that executable. To make it easier to install and run such an
1884 # executable, this will create a directory containing the native exe and all
1885 # it's library dependencies.
1887 # Note: It's usually better to package things as an APK than as a native
1891 # dist_dir: Directory for the exe and libraries. Everything in this directory
1892 # will be deleted before copying in the exe and libraries.
1893 # binary: Path to (stripped) executable.
1896 # create_native_executable_dist("foo_dist") {
1897 # dist_dir = "$root_build_dir/foo_dist"
1898 # binary = "$root_build_dir/foo"
1899 # deps = [ ":the_thing_that_makes_foo" ]
1901 template("create_native_executable_dist") {
1902 set_sources_assignment_filter([])
1903 forward_variables_from(invoker, [ "testonly" ])
1905 dist_dir = invoker.dist_dir
1906 binary = invoker.binary
1907 template_name = target_name
1910 "${target_gen_dir}/${template_name}_library_dependencies.list"
1912 find_deps_target_name = "${template_name}__find_library_dependencies"
1913 copy_target_name = "${template_name}__copy_libraries_and_exe"
1915 action(find_deps_target_name) {
1916 forward_variables_from(invoker, [ "deps" ])
1917 visibility = [ ":$copy_target_name" ]
1919 script = "//build/android/gyp/write_ordered_libraries.py"
1920 depfile = "$target_gen_dir/$target_name.d"
1929 rebased_binaries = rebase_path([ binary ], root_build_dir)
1932 rebase_path(depfile, root_build_dir),
1933 "--input-libraries=$rebased_binaries",
1935 rebase_path(root_shlib_dir, root_build_dir),
1937 rebase_path(libraries_list, root_build_dir),
1939 rebase_path(android_readelf, root_build_dir),
1943 copy_ex(copy_target_name) {
1944 visibility = [ ":$template_name" ]
1952 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
1953 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
1955 "--files=$rebased_binaries_list",
1956 "--files=@FileArg($rebased_libraries_list:lib_paths)",
1960 ":$find_deps_target_name",
1962 if (defined(invoker.deps)) {
1963 deps += invoker.deps
1967 group(template_name) {
1968 forward_variables_from(invoker, [ "visibility" ])
1970 ":$copy_target_name",
1975 # Compile a protocol buffer to java.
1977 # This generates java files from protocol buffers and creates an Android library
1978 # containing the classes.
1981 # sources: Paths to .proto files to compile.
1982 # proto_path: Root directory of .proto files.
1985 # proto_java_library("foo_proto_java") {
1986 # proto_path = [ "src/foo" ]
1987 # sources = [ "$proto_path/foo.proto" ]
1989 template("proto_java_library") {
1990 set_sources_assignment_filter([])
1991 forward_variables_from(invoker, [ "testonly" ])
1992 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
1993 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
1994 _protoc_bin = "$_protoc_out_dir/android_protoc"
1995 _proto_path = invoker.proto_path
1997 _template_name = target_name
1999 action("${_template_name}__protoc_java") {
2000 srcjar_path = "$target_gen_dir/$target_name.srcjar"
2001 script = "//build/protoc_java.py"
2005 sources = invoker.sources
2006 depfile = "$target_gen_dir/$target_name.d"
2013 rebase_path(depfile, root_build_dir),
2015 rebase_path(_protoc_bin, root_build_dir),
2017 rebase_path(_proto_path, root_build_dir),
2019 rebase_path(srcjar_path, root_build_dir),
2020 ] + rebase_path(sources, root_build_dir)
2023 android_library(target_name) {
2025 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2027 "//third_party/android_protobuf:protobuf_nano_javalib",
2032 # TODO(GYP): implement this.
2033 template("uiautomator_test") {
2034 set_sources_assignment_filter([])
2035 forward_variables_from(invoker, [ "testonly" ])
2036 assert(target_name != "")
2037 assert(invoker.deps != [] || true)
2038 group(target_name) {