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 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,
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"
614 template("android_resources") {
615 set_sources_assignment_filter([])
616 forward_variables_from(invoker, [ "testonly" ])
618 assert(defined(invoker.resource_dirs))
619 assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
621 base_path = "$target_gen_dir/$target_name"
622 zip_path = base_path + ".resources.zip"
623 srcjar_path = base_path + ".srcjar"
624 r_text_path = base_path + "_R.txt"
625 build_config = base_path + ".build_config"
627 build_config_target_name = "${target_name}__build_config"
628 process_resources_target_name = "${target_name}__process_resources"
629 final_target_name = target_name
631 write_build_config(build_config_target_name) {
632 forward_variables_from(invoker,
638 visibility = [ ":$process_resources_target_name" ]
640 type = "android_resources"
641 resources_zip = zip_path
646 process_resources(process_resources_target_name) {
647 visibility = [ ":$final_target_name" ]
649 forward_variables_from(invoker,
658 deps += [ ":$build_config_target_name" ]
659 if (!defined(android_manifest)) {
660 android_manifest = "//build/android/AndroidManifest.xml"
664 group(final_target_name) {
665 forward_variables_from(invoker, [ "visibility" ])
667 ":${target_name}__process_resources",
672 # Declare a target that generates localized strings.xml from a .grd file.
674 # If this target is included in the deps of an android resources/library/apk,
675 # the strings.xml will be included with that target.
678 # deps: Specifies the dependencies of this target.
679 # grd_file: Path to the .grd file to generate strings.xml from.
680 # outputs: Expected grit outputs (see grit rule).
683 # java_strings_grd("foo_strings_grd") {
684 # grd_file = "foo_strings.grd"
686 template("java_strings_grd") {
687 set_sources_assignment_filter([])
688 forward_variables_from(invoker, [ "testonly" ])
690 base_path = "$target_gen_dir/$target_name"
691 resources_zip = base_path + ".resources.zip"
692 build_config = base_path + ".build_config"
694 write_build_config("${target_name}__build_config") {
695 forward_variables_from(invoker, [ "deps" ])
696 type = "android_resources"
699 # Put grit files into this subdirectory of target_gen_dir.
700 extra_output_path = target_name + "_grit_output"
702 grit_target_name = "${target_name}__grit"
703 grit_output_dir = "$target_gen_dir/$extra_output_path"
704 grit(grit_target_name) {
707 "ANDROID_JAVA_TAGGED_ONLY=false",
709 output_dir = grit_output_dir
711 source = invoker.grd_file
712 outputs = invoker.outputs
715 # This needs to get outputs from grit's internal target, not the final
717 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
719 zip("${target_name}__zip") {
720 base_dir = grit_output_dir
721 inputs = generate_strings_outputs
722 output = resources_zip
724 ":$grit_target_name",
730 ":${target_name}__build_config",
731 ":${target_name}__zip",
736 # Declare a target that packages strings.xml generated from a grd file.
738 # If this target is included in the deps of an android resources/library/apk,
739 # the strings.xml will be included with that target.
742 # grit_output_dir: directory containing grit-generated files.
743 # generated_files: list of android resource files to package.
746 # java_strings_grd_prebuilt("foo_strings_grd") {
747 # grit_output_dir = "$root_gen_dir/foo/grit"
748 # generated_files = [
749 # "values/strings.xml"
752 template("java_strings_grd_prebuilt") {
753 set_sources_assignment_filter([])
754 forward_variables_from(invoker, [ "testonly" ])
756 base_path = "$target_gen_dir/$target_name"
757 resources_zip = base_path + ".resources.zip"
758 build_config = base_path + ".build_config"
760 build_config_target_name = "${target_name}__build_config"
761 zip_target_name = "${target_name}__zip"
762 final_target_name = target_name
764 write_build_config(build_config_target_name) {
765 visibility = [ ":$zip_target_name" ]
766 type = "android_resources"
769 zip(zip_target_name) {
770 visibility = [ ":$final_target_name" ]
772 base_dir = invoker.grit_output_dir
773 inputs = rebase_path(invoker.generated_files, ".", base_dir)
774 output = resources_zip
776 ":$build_config_target_name",
778 if (defined(invoker.deps)) {
783 group(final_target_name) {
784 forward_variables_from(invoker, [ "visibility" ])
791 # Declare a Java executable target
793 # This target creates an executable from java code and libraries. The executable
794 # will be in the output folder's /bin/ directory.
797 # deps: Specifies the dependencies of this target. Java targets in this list
798 # will be included in the executable (and the javac classpath).
799 # java_files: List of .java files included in this library.
800 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
801 # will be added to java_files and be included in this library.
802 # srcjars: List of srcjars to be included in this library, together with the
803 # ones obtained from srcjar_deps.
804 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
805 # dependencies for this target. This will allow depending on an
806 # android_library target, for example.
807 # chromium_code: If true, extra analysis warning/errors will be enabled.
808 # enable_errorprone: If true, enables the errorprone compiler.
809 # main_class: When specified, a wrapper script is created within
810 # $target_out_dir/bin to launch the binary with the given class as the
812 # wrapper_script_args: List of additional arguments for the wrapper script.
814 # data_deps, testonly
817 # java_binary("foo") {
818 # java_files = [ "org/chromium/foo/FooMain.java" ]
819 # deps = [ ":bar_java" ]
820 # main_class = "org.chromium.foo.FooMain"
822 template("java_binary") {
823 set_sources_assignment_filter([])
825 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
826 # dependents shouldn't get the jar in their classpath, etc.).
827 java_library_impl(target_name) {
828 forward_variables_from(invoker, "*")
829 supports_android = false
830 main_class = invoker.main_class
834 # Declare a Junit executable target
836 # This target creates an executable from java code for running as a junit test
837 # suite. The executable will be in the output folder's /bin/ directory.
840 # deps: Specifies the dependencies of this target. Java targets in this list
841 # will be included in the executable (and the javac classpath).
843 # java_files: List of .java files included in this library.
844 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
845 # will be added to java_files and be included in this library.
846 # srcjars: List of srcjars to be included in this library, together with the
847 # ones obtained from srcjar_deps.
849 # chromium_code: If true, extra analysis warning/errors will be enabled.
852 # junit_binary("foo") {
853 # java_files = [ "org/chromium/foo/FooTest.java" ]
854 # deps = [ ":bar_java" ]
856 template("junit_binary") {
857 set_sources_assignment_filter([])
859 java_binary(target_name) {
861 forward_variables_from(invoker, "*")
862 bypass_platform_checks = true
863 main_class = "org.chromium.testing.local.JunitTestMain"
864 wrapper_script_args = [
871 "//testing/android/junit:junit_test_support",
872 "//third_party/junit",
873 "//third_party/mockito:mockito_java",
874 "//third_party/robolectric:robolectric_java",
875 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
880 # Declare a java library target
883 # deps: Specifies the dependencies of this target. Java targets in this list
884 # will be added to the javac classpath.
886 # java_files: List of .java files included in this library.
887 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
888 # will be added to java_files and be included in this library.
889 # srcjars: List of srcjars to be included in this library, together with the
890 # ones obtained from srcjar_deps.
891 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
892 # this directory will be included in the library. This is only supported to
893 # ease the gyp->gn conversion and will be removed in the future.
895 # chromium_code: If true, extra analysis warning/errors will be enabled.
896 # enable_errorprone: If true, enables the errorprone compiler.
898 # jar_excluded_patterns: List of patterns of .class files to exclude from the
901 # proguard_preprocess: If true, proguard preprocessing will be run. This can
902 # be used to remove unwanted parts of the library.
903 # proguard_config: Path to the proguard config for preprocessing.
905 # supports_android: If true, Android targets (android_library, android_apk)
906 # may depend on this target. Note: if true, this target must only use the
907 # subset of Java available on Android.
908 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
909 # dependencies for this target. This will allow depending on an
910 # android_library target, for example.
912 # data_deps, testonly
915 # java_library("foo_java") {
917 # "org/chromium/foo/Foo.java",
918 # "org/chromium/foo/FooInterface.java",
919 # "org/chromium/foo/FooService.java",
925 # ":foo_generated_enum"
927 # jar_excluded_patterns = [
928 # "*/FooService.class", "*/FooService##*.class"
931 template("java_library") {
932 set_sources_assignment_filter([])
933 java_library_impl(target_name) {
934 forward_variables_from(invoker, "*")
938 # Declare a java library target for a prebuilt jar
941 # deps: Specifies the dependencies of this target. Java targets in this list
942 # will be added to the javac classpath.
943 # jar_path: Path to the prebuilt jar.
944 # jar_dep: Target that builds jar_path (optional).
945 # proguard_preprocess: If true, proguard preprocessing will be run. This can
946 # be used to remove unwanted parts of the library.
947 # proguard_config: Path to the proguard config for preprocessing.
948 # supports_android: If true, Android targets (android_library, android_apk)
949 # may depend on this target. Note: if true, this target must only use the
950 # subset of Java available on Android.
953 # java_prebuilt("foo_java") {
954 # jar_path = "foo.jar"
960 template("java_prebuilt") {
961 set_sources_assignment_filter([])
962 java_prebuilt_impl(target_name) {
963 forward_variables_from(invoker, "*")
967 # Declare an Android library target
969 # This target creates an Android library containing java code and Android
973 # deps: Specifies the dependencies of this target. Java targets in this list
974 # will be added to the javac classpath. Android resources in dependencies
975 # will be used when building this library.
977 # java_files: List of .java files included in this library.
978 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
979 # will be added to java_files and be included in this library.
980 # srcjars: List of srcjars to be included in this library, together with the
981 # ones obtained from srcjar_deps.
982 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
983 # this directory will be included in the library. This is only supported to
984 # ease the gyp->gn conversion and will be removed in the future.
986 # chromium_code: If true, extra analysis warning/errors will be enabled.
987 # enable_errorprone: If true, enables the errorprone compiler.
989 # jar_excluded_patterns: List of patterns of .class files to exclude from the
992 # proguard_preprocess: If true, proguard preprocessing will be run. This can
993 # be used to remove unwanted parts of the library.
994 # proguard_config: Path to the proguard config for preprocessing.
996 # dex_path: If set, the resulting .dex.jar file will be placed under this
1001 # android_library("foo_java") {
1003 # "android/org/chromium/foo/Foo.java",
1004 # "android/org/chromium/foo/FooInterface.java",
1005 # "android/org/chromium/foo/FooService.java",
1011 # ":foo_generated_enum"
1013 # jar_excluded_patterns = [
1014 # "*/FooService.class", "*/FooService##*.class"
1017 template("android_library") {
1018 set_sources_assignment_filter([])
1019 assert(!defined(invoker.jar_path),
1020 "android_library does not support a custom jar path")
1021 java_library_impl(target_name) {
1022 forward_variables_from(invoker, "*")
1024 supports_android = true
1025 requires_android = true
1027 if (!defined(jar_excluded_patterns)) {
1028 jar_excluded_patterns = []
1030 jar_excluded_patterns += [
1034 "*/Manifest##*.class",
1039 # Declare a target that packages a set of Java dependencies into a standalone
1043 # deps: specifies the dependencies of this target. Android libraries in deps
1044 # will be packaged into the resulting .dex.jar file.
1045 # dex_path: location at which the output file will be put
1046 template("android_standalone_library") {
1047 set_sources_assignment_filter([])
1048 deps_dex(target_name) {
1049 forward_variables_from(invoker,
1058 # Declare an Android library target for a prebuilt jar
1060 # This target creates an Android library containing java code and Android
1064 # deps: Specifies the dependencies of this target. Java targets in this list
1065 # will be added to the javac classpath. Android resources in dependencies
1066 # will be used when building this library.
1067 # jar_path: Path to the prebuilt jar.
1068 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1069 # be used to remove unwanted parts of the library.
1070 # proguard_config: Path to the proguard config for preprocessing.
1073 # android_java_prebuilt("foo_java") {
1074 # jar_path = "foo.jar"
1080 template("android_java_prebuilt") {
1081 set_sources_assignment_filter([])
1082 java_prebuilt_impl(target_name) {
1083 forward_variables_from(invoker, "*")
1084 supports_android = true
1085 requires_android = true
1089 # Declare an Android apk target
1091 # This target creates an Android APK containing java code, resources, assets,
1092 # and (possibly) native libraries.
1095 # android_manifest: Path to AndroidManifest.xml.
1096 # android_manifest_dep: Target that generates AndroidManifest (if applicable)
1097 # data_deps: List of dependencies needed at runtime. These will be built but
1098 # won't change the generated .apk in any way (in fact they may be built
1099 # after the .apk is).
1100 # deps: List of dependencies. All Android java resources and libraries in the
1101 # "transitive closure" of these dependencies will be included in the apk.
1102 # Note: this "transitive closure" actually only includes such targets if
1103 # they are depended on through android_library or android_resources targets
1104 # (and so not through builtin targets like 'action', 'group', etc).
1105 # java_files: List of .java files to include in the apk.
1106 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1107 # will be added to java_files and be included in this apk.
1108 # apk_name: Name for final apk.
1109 # final_apk_path: Path to final built apk. Default is
1110 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1111 # native_libs: List paths of native libraries to include in this apk. If these
1112 # libraries depend on other shared_library targets, those dependencies will
1113 # also be included in the apk.
1114 # apk_under_test: For an instrumentation test apk, this is the target of the
1116 # include_all_resources - If true include all resource IDs in all generated
1118 # testonly: Marks this target as "test-only".
1120 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1121 # this directory will be included in the library. This is only supported to
1122 # ease the gyp->gn conversion and will be removed in the future.
1125 # android_apk("foo_apk") {
1126 # android_manifest = "AndroidManifest.xml"
1128 # "android/org/chromium/foo/FooApplication.java",
1129 # "android/org/chromium/foo/FooActivity.java",
1132 # ":foo_support_java"
1136 # ":foo_generated_enum"
1142 template("android_apk") {
1143 set_sources_assignment_filter([])
1144 forward_variables_from(invoker, [ "testonly" ])
1146 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1147 assert(defined(invoker.android_manifest))
1148 gen_dir = "$target_gen_dir/$target_name"
1149 base_path = "$gen_dir/$target_name"
1150 _build_config = "$target_gen_dir/$target_name.build_config"
1151 resources_zip_path = "$base_path.resources.zip"
1152 _all_resources_zip_path = "$base_path.resources.all.zip"
1153 jar_path = "$base_path.jar"
1154 _template_name = target_name
1156 final_dex_path = "$gen_dir/classes.dex"
1157 final_dex_target_name = "${_template_name}__final_dex"
1159 _final_apk_path = ""
1160 if (defined(invoker.final_apk_path)) {
1161 _final_apk_path = invoker.final_apk_path
1162 } else if (defined(invoker.apk_name)) {
1163 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1165 _dist_jar_path_list =
1166 process_file_template(
1167 [ _final_apk_path ],
1168 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1169 _dist_jar_path = _dist_jar_path_list[0]
1170 _final_apk_path_no_ext_list =
1171 process_file_template([ _final_apk_path ],
1172 "{{source_dir}}/{{source_name_part}}")
1173 _final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
1174 assert(_final_apk_path_no_ext != "") # Mark as used.
1179 if (defined(invoker.version_code)) {
1180 _version_code = invoker.version_code
1183 _version_name = "Developer Build"
1184 if (defined(invoker.version_name)) {
1185 _version_name = invoker.version_name
1187 _keystore_path = android_keystore_path
1188 _keystore_name = android_keystore_name
1189 _keystore_password = android_keystore_password
1191 if (defined(invoker.keystore_path)) {
1192 _keystore_path = invoker.keystore_path
1193 _keystore_name = invoker.keystore_name
1194 _keystore_password = invoker.keystore_password
1198 if (defined(invoker.srcjar_deps)) {
1199 _srcjar_deps += invoker.srcjar_deps
1202 _load_library_from_apk = false
1204 # The dependency that makes the chromium linker, if any is needed.
1205 _chromium_linker_dep = []
1207 if (defined(invoker.native_libs)) {
1208 _use_chromium_linker = false
1209 if (defined(invoker.use_chromium_linker)) {
1210 _use_chromium_linker =
1211 invoker.use_chromium_linker && chromium_linker_supported
1212 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1215 if (defined(invoker.load_library_from_apk) &&
1216 invoker.load_library_from_apk) {
1217 _load_library_from_apk = true
1218 assert(_use_chromium_linker,
1219 "Loading library from the apk requires use" +
1220 " of the Chromium linker.")
1223 _enable_relocation_packing = false
1224 if (defined(invoker.enable_relocation_packing) &&
1225 invoker.enable_relocation_packing) {
1226 _enable_relocation_packing = relocation_packing_supported
1227 assert(_use_chromium_linker,
1228 "Relocation packing requires use of the" + " Chromium linker.")
1231 if (is_component_build) {
1232 _native_libs += [ "$root_shlib_dir/libc++_shared.so" ]
1233 _chromium_linker_dep += [ "//build/android:cpplib_stripped" ]
1236 # Allow native_libs to be in the form "foo.so" or "foo.cr.so"
1237 _first_ext_removed =
1238 process_file_template(invoker.native_libs, "{{source_name_part}}")
1239 _native_libs += process_file_template(
1241 "$root_shlib_dir/{{source_name_part}}$shlib_extension")
1243 # Add in target_cpu so that other architectures are not accidentally
1244 # included when switching target_cpu without doing a clean build.
1245 _native_libs_dir = gen_dir + "/lib-$target_cpu"
1247 if (_use_chromium_linker) {
1249 [ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
1252 _enable_relocation_packing = false
1253 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1254 invoker.enable_relocation_packing) {
1255 _enable_relocation_packing = true
1258 _native_lib_version_rule = ""
1259 if (defined(invoker.native_lib_version_rule)) {
1260 _native_lib_version_rule = invoker.native_lib_version_rule
1262 _native_lib_version_arg = "\"\""
1263 if (defined(invoker.native_lib_version_arg)) {
1264 _native_lib_version_arg = invoker.native_lib_version_arg
1268 _android_manifest_deps = []
1269 if (defined(invoker.android_manifest_dep)) {
1270 _android_manifest_deps = [ invoker.android_manifest_dep ]
1272 _android_manifest = invoker.android_manifest
1274 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1276 defined(invoker.create_abi_split) && invoker.create_abi_split
1277 _create_density_splits =
1278 defined(invoker.create_density_splits) && invoker.create_density_splits
1279 _create_language_splits =
1280 defined(invoker.language_splits) && invoker.language_splits != []
1282 # Help GN understand that _create_abi_split is not unused (bug in GN).
1283 assert(_create_abi_split || true)
1285 build_config_target = "${_template_name}__build_config"
1286 write_build_config(build_config_target) {
1287 forward_variables_from(invoker, [ "apk_under_test" ])
1288 type = "android_apk"
1289 dex_path = final_dex_path
1290 resources_zip = resources_zip_path
1291 build_config = _build_config
1292 android_manifest = _android_manifest
1294 deps = _chromium_linker_dep + _android_manifest_deps
1295 if (defined(invoker.deps)) {
1296 deps += invoker.deps
1299 native_libs = _native_libs
1303 _incremental_final_deps = []
1305 process_resources_target = "${_template_name}__process_resources"
1306 process_resources(process_resources_target) {
1307 forward_variables_from(invoker, [ "include_all_resources" ])
1308 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1309 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1310 android_manifest = _android_manifest
1311 resource_dirs = [ "//build/android/ant/empty/res" ]
1312 zip_path = resources_zip_path
1313 all_resources_zip_path = _all_resources_zip_path
1314 generate_constant_ids = true
1316 build_config = _build_config
1317 deps = _android_manifest_deps + [ ":$build_config_target" ]
1318 if (defined(invoker.deps)) {
1319 deps += invoker.deps
1322 _srcjar_deps += [ ":$process_resources_target" ]
1324 if (_native_libs != []) {
1325 _enable_chromium_linker_tests = false
1326 if (defined(invoker.enable_chromium_linker_tests)) {
1327 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1330 java_cpp_template("${_template_name}__native_libraries_java") {
1331 package_name = "org/chromium/base/library_loader"
1333 "//base/android/java/templates/NativeLibraries.template",
1339 ":$build_config_target",
1341 if (_native_lib_version_rule != "") {
1342 deps += [ _native_lib_version_rule ]
1346 "NATIVE_LIBRARIES_LIST=" +
1347 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1348 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
1350 if (_use_chromium_linker) {
1351 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1353 if (_load_library_from_apk) {
1354 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1356 if (_enable_chromium_linker_tests) {
1357 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1360 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1363 java_target = "${_template_name}__java"
1364 java_library_impl(java_target) {
1365 forward_variables_from(invoker, [ "run_findbugs" ])
1366 supports_android = true
1367 requires_android = true
1368 override_build_config = _build_config
1369 deps = _android_manifest_deps + [ ":$build_config_target" ]
1371 android_manifest = _android_manifest
1372 chromium_code = true
1373 if (defined(invoker.java_files)) {
1374 java_files = invoker.java_files
1375 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1376 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1380 srcjar_deps = _srcjar_deps
1381 dex_path = base_path + ".dex.jar"
1383 if (defined(invoker.deps)) {
1384 deps += invoker.deps
1388 if (_dist_jar_path != "") {
1389 create_dist_target = "${_template_name}__create_dist_jar"
1390 _final_deps += [ ":$create_dist_target" ]
1391 _incremental_final_deps += [ ":$create_dist_target" ]
1393 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1394 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1395 # able to just do that calculation at build time instead.
1396 action(create_dist_target) {
1397 script = "//build/android/gyp/create_dist_jar.py"
1398 depfile = "$target_gen_dir/$target_name.d"
1408 rebase_path(depfile, root_build_dir),
1410 rebase_path(_dist_jar_path, root_build_dir),
1411 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1413 inputs += [ jar_path ]
1414 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1415 args += [ "--inputs=$_rebased_jar_path" ]
1417 ":$build_config_target", # Generates the build config file.
1418 ":$java_target", # Generates the jar file.
1423 dex("$final_dex_target_name") {
1425 ":$build_config_target",
1434 output = final_dex_path
1435 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1436 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1439 if (_native_libs != []) {
1440 action("${_template_name}__prepare_native") {
1441 forward_variables_from(invoker,
1446 script = "//build/android/gyp/pack_relocations.py"
1447 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1448 depfile = "$target_gen_dir/$target_name.d"
1453 inputs = _native_libs
1454 deps = _chromium_linker_dep
1456 inputs += [ _build_config ]
1457 deps += [ ":$build_config_target" ]
1459 skip_packing_list = [
1461 "libchromium_android_linker$shlib_extension",
1464 enable_packing_arg = 0
1465 if (_enable_relocation_packing) {
1466 enable_packing_arg = 1
1467 deps += [ relocation_packer_target ]
1472 rebase_path(depfile, root_build_dir),
1473 "--enable-packing=$enable_packing_arg",
1474 "--exclude-packing-list=$skip_packing_list",
1475 "--android-pack-relocations",
1476 rebase_path(relocation_packer_exe, root_build_dir),
1477 "--stripped-libraries-dir",
1478 rebase_path(root_build_dir, root_build_dir),
1479 "--packed-libraries-dir",
1480 rebase_path(packed_libraries_dir, root_build_dir),
1481 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1485 if (defined(invoker.deps)) {
1486 deps += invoker.deps
1490 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1491 inputs += [ android_gdbserver ]
1492 args += [ "--libraries=$rebased_gdbserver" ]
1497 _final_deps += [ ":${_template_name}__create" ]
1498 _incremental_final_deps += [ ":${_template_name}__create_incremental" ]
1499 create_apk("${_template_name}__create") {
1500 forward_variables_from(invoker, [ "language_splits" ])
1501 apk_path = _final_apk_path
1502 android_manifest = _android_manifest
1503 resources_zip = _all_resources_zip_path
1504 dex_path = final_dex_path
1505 load_library_from_apk = _load_library_from_apk
1506 create_density_splits = _create_density_splits
1507 if (defined(invoker.extensions_to_not_compress)) {
1508 extensions_to_not_compress = invoker.extensions_to_not_compress
1510 # Allow icu data, v8 snapshots, and pak files to be loaded directly from
1512 # Note: These are actually suffix matches, not necessarily extensions.
1513 extensions_to_not_compress = ".dat,.bin,.pak"
1516 version_code = _version_code
1517 version_name = _version_name
1519 keystore_name = _keystore_name
1520 keystore_path = _keystore_path
1521 keystore_password = _keystore_password
1523 # This target generates the input file _all_resources_zip_path.
1524 deps = _android_manifest_deps + [
1525 ":$process_resources_target",
1526 ":$final_dex_target_name",
1528 if (defined(invoker.deps)) {
1529 deps += invoker.deps
1532 if (defined(invoker.asset_location)) {
1533 asset_location = invoker.asset_location
1535 # We don't know the exact dependencies that create the assets in
1536 # |asset_location|; we depend on all caller deps until a better solution
1537 # is figured out (http://crbug.com/433330).
1538 if (defined(invoker.deps)) {
1539 deps += invoker.deps
1543 if (_native_libs != [] && !_create_abi_split) {
1544 native_libs_dir = _native_libs_dir
1545 deps += [ ":${_template_name}__prepare_native" ]
1549 if (_native_libs != [] && _create_abi_split) {
1550 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1551 generate_split_manifest(_manifest_rule) {
1552 main_manifest = _android_manifest
1554 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1555 split_name = "abi_${android_app_abi}"
1556 deps = _android_manifest_deps
1559 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1560 _final_deps += [ ":$_apk_rule" ]
1562 # Don't add this to _incremental_final_deps since for incremental installs
1563 # we skip abi splits altogether.
1564 create_apk(_apk_rule) {
1565 apk_path = "${_final_apk_path_no_ext}-abi-${android_app_abi}.apk"
1566 base_path = "$gen_dir/$_apk_rule"
1568 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1569 android_manifest = manifest_outputs[1]
1570 load_library_from_apk = _load_library_from_apk
1572 version_code = _version_code
1573 version_name = _version_name
1575 keystore_name = _keystore_name
1576 keystore_path = _keystore_path
1577 keystore_password = _keystore_password
1579 native_libs_dir = _native_libs_dir
1581 ":${_template_name}__prepare_native",
1582 ":${_manifest_rule}",
1587 _create_incremental_script_rule_name = "${_template_name}__incremental_script"
1588 _incremental_final_deps += [ ":${_create_incremental_script_rule_name}" ]
1589 action(_create_incremental_script_rule_name) {
1590 script = "//build/android/gn/create_incremental_install_script.py"
1591 depfile = "$target_gen_dir/$target_name.d"
1593 _generated_script_path =
1594 "${root_out_dir}/bin/install_incremental_${_template_name}"
1597 _generated_script_path,
1600 _rebased_apk_path_no_ext =
1601 rebase_path(_final_apk_path_no_ext, root_build_dir)
1602 _rebased_generated_script_path =
1603 rebase_path(_generated_script_path, root_build_dir)
1604 _rebased_depfile = rebase_path(depfile, root_build_dir)
1606 "--apk-path=${_rebased_apk_path_no_ext}_incremental.apk",
1607 "--script-output-path=$_rebased_generated_script_path",
1608 "--depfile=$_rebased_depfile",
1610 if (defined(_native_libs_dir)) {
1611 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
1612 args += [ "--lib-dir=$_rebased_native_libs_dir/$android_app_abi" ]
1614 if (_create_density_splits) {
1615 args += [ "--split=${_rebased_apk_path_no_ext}-density-*.apk" ]
1617 if (_create_language_splits) {
1618 args += [ "--split=${_rebased_apk_path_no_ext}-language-*.apk" ]
1622 group(target_name) {
1623 forward_variables_from(invoker, [ "data_deps" ])
1626 group("${target_name}_incremental") {
1628 forward_variables_from(invoker, [ "data_deps" ])
1629 data_deps += [ "//build/android/pylib/device/commands" ]
1630 deps = _incremental_final_deps
1634 # Declare an Android instrumentation test apk
1636 # This target creates an Android instrumentation test apk.
1639 # android_manifest: Path to AndroidManifest.xml.
1640 # data_deps: List of dependencies needed at runtime. These will be built but
1641 # won't change the generated .apk in any way (in fact they may be built
1642 # after the .apk is).
1643 # deps: List of dependencies. All Android java resources and libraries in the
1644 # "transitive closure" of these dependencies will be included in the apk.
1645 # Note: this "transitive closure" actually only includes such targets if
1646 # they are depended on through android_library or android_resources targets
1647 # (and so not through builtin targets like 'action', 'group', etc).
1648 # java_files: List of .java files to include in the apk.
1649 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1650 # will be added to java_files and be included in this apk.
1651 # apk_name: Name for final apk.
1652 # final_apk_path: Path to final built apk. Default is
1653 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1654 # native_libs: List paths of native libraries to include in this apk. If these
1655 # libraries depend on other shared_library targets, those dependencies will
1656 # also be included in the apk.
1657 # apk_under_test: The apk being tested.
1658 # isolate_file: Isolate file containing the list of test data dependencies.
1660 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1661 # this directory will be included in the library. This is only supported to
1662 # ease the gyp->gn conversion and will be removed in the future.
1665 # instrumentation_test_apk("foo_test_apk") {
1666 # android_manifest = "AndroidManifest.xml"
1667 # apk_name = "FooTest"
1668 # apk_under_test = "Foo"
1670 # "android/org/chromium/foo/FooTestCase.java",
1671 # "android/org/chromium/foo/FooExampleTest.java",
1674 # ":foo_test_support_java"
1677 template("instrumentation_test_apk") {
1678 set_sources_assignment_filter([])
1680 _template_name = target_name
1682 if (defined(invoker.apk_name)) {
1683 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1684 test_runner_script("${_template_name}__test_runner_script") {
1685 forward_variables_from(invoker, [ "isolate_file" ])
1686 test_name = invoker.target_name
1687 test_type = "instrumentation"
1688 test_apk = invoker.apk_name
1692 android_apk(target_name) {
1695 forward_variables_from(invoker, "*")
1697 "//testing/android/driver:driver_apk",
1698 "//tools/android/forwarder2",
1699 "//tools/android/md5sum",
1701 if (defined(test_runner_data_dep)) {
1702 data_deps += test_runner_data_dep
1704 deps += [ "//testing/android/broker:broker_java" ]
1705 run_findbugs = false
1709 # Declare an Android gtest apk
1711 # This target creates an Android apk for running gtest-based unittests.
1714 # deps: Specifies the dependencies of this target. These will be passed to
1715 # the underlying android_apk invocation and should include the java and
1716 # resource dependencies of the apk.
1717 # unittests_dep: This should be the label of the gtest native target. This
1718 # target must be defined previously in the same file.
1719 # unittests_binary: The basename of the library produced by the unittests_dep
1720 # target. If unspecified, it assumes the name of the unittests_dep target
1721 # (which will be correct unless that target specifies an "output_name".
1722 # TODO(brettw) make this automatic by allowing get_target_outputs to
1723 # support executables.
1724 # apk_name: The name of the produced apk. If unspecified, it uses the name
1725 # of the unittests_dep target postfixed with "_apk"
1728 # unittest_apk("foo_unittests_apk") {
1729 # deps = [ ":foo_java", ":foo_resources" ]
1730 # unittests_dep = ":foo_unittests"
1732 template("unittest_apk") {
1733 set_sources_assignment_filter([])
1736 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1738 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1740 # This trivial assert is needed in case both unittests_binary and apk_name
1741 # are defined, as otherwise test_suite_name would not be used.
1742 assert(test_suite_name != "")
1744 if (defined(invoker.unittests_binary)) {
1745 unittests_binary = invoker.unittests_binary
1747 unittests_binary = "lib${test_suite_name}${shlib_extension}"
1750 if (defined(invoker.apk_name)) {
1751 apk_name = invoker.apk_name
1753 apk_name = test_suite_name
1756 android_apk(target_name) {
1757 forward_variables_from(invoker, [ "asset_location" ])
1758 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1760 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
1761 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
1762 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
1763 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
1765 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1766 native_libs = [ unittests_binary ]
1769 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1770 "//testing/android/appurify_support:appurify_support_java",
1771 "//testing/android/reporter:reporter_java",
1773 if (defined(invoker.deps)) {
1774 deps += invoker.deps
1776 data_deps = [ "//tools/android/md5sum" ]
1777 if (host_os == "linux") {
1778 data_deps += [ "//tools/android/forwarder2" ]
1780 if (defined(invoker.data_deps)) {
1781 data_deps += invoker.data_deps
1786 # Generate .java files from .aidl files.
1788 # This target will store the .java files in a srcjar and should be included in
1789 # an android_library or android_apk's srcjar_deps.
1792 # sources: Paths to .aidl files to compile.
1793 # import_include: Path to directory containing .java files imported by the
1795 # interface_file: Preprocessed aidl file to import.
1798 # android_aidl("foo_aidl") {
1799 # import_include = "java/src"
1801 # "java/src/com/foo/bar/FooBarService.aidl",
1802 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1805 template("android_aidl") {
1806 set_sources_assignment_filter([])
1807 forward_variables_from(invoker, [ "testonly" ])
1809 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1810 aidl_path = "${android_sdk_build_tools}/aidl"
1811 framework_aidl = "$android_sdk/framework.aidl"
1813 action(target_name) {
1814 script = "//build/android/gyp/aidl.py"
1815 sources = invoker.sources
1817 imports = [ framework_aidl ]
1818 if (defined(invoker.interface_file)) {
1819 assert(invoker.interface_file != "")
1820 imports += [ invoker.interface_file ]
1823 inputs = [ aidl_path ] + imports
1825 depfile = "${target_gen_dir}/${target_name}.d"
1830 rebased_imports = rebase_path(imports, root_build_dir)
1833 rebase_path(depfile, root_build_dir),
1835 rebase_path(aidl_path, root_build_dir),
1836 "--imports=$rebased_imports",
1838 rebase_path(srcjar_path, root_build_dir),
1840 if (defined(invoker.import_include) && invoker.import_include != "") {
1841 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1842 # switch to constructing a depfile for the overall action from that
1843 # instead of having all the .java files in the include paths as inputs.
1844 rebased_import_includes =
1845 rebase_path([ invoker.import_include ], root_build_dir)
1846 args += [ "--includes=$rebased_import_includes" ]
1848 _java_files_build_rel =
1849 exec_script("//build/android/gyp/find.py",
1850 rebase_path([ invoker.import_include ], root_build_dir),
1852 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1853 inputs += _java_files
1855 args += rebase_path(sources, root_build_dir)
1859 # Creates a dist directory for a native executable.
1861 # Running a native executable on a device requires all the shared library
1862 # dependencies of that executable. To make it easier to install and run such an
1863 # executable, this will create a directory containing the native exe and all
1864 # it's library dependencies.
1866 # Note: It's usually better to package things as an APK than as a native
1870 # dist_dir: Directory for the exe and libraries. Everything in this directory
1871 # will be deleted before copying in the exe and libraries.
1872 # binary: Path to (stripped) executable.
1875 # create_native_executable_dist("foo_dist") {
1876 # dist_dir = "$root_build_dir/foo_dist"
1877 # binary = "$root_build_dir/foo"
1878 # deps = [ ":the_thing_that_makes_foo" ]
1880 template("create_native_executable_dist") {
1881 set_sources_assignment_filter([])
1882 forward_variables_from(invoker, [ "testonly" ])
1884 dist_dir = invoker.dist_dir
1885 binary = invoker.binary
1886 template_name = target_name
1889 "${target_gen_dir}/${template_name}_library_dependencies.list"
1891 find_deps_target_name = "${template_name}__find_library_dependencies"
1892 copy_target_name = "${template_name}__copy_libraries_and_exe"
1894 action(find_deps_target_name) {
1895 forward_variables_from(invoker, [ "deps" ])
1896 visibility = [ ":$copy_target_name" ]
1898 script = "//build/android/gyp/write_ordered_libraries.py"
1899 depfile = "$target_gen_dir/$target_name.d"
1908 rebased_binaries = rebase_path([ binary ], root_build_dir)
1911 rebase_path(depfile, root_build_dir),
1912 "--input-libraries=$rebased_binaries",
1914 rebase_path(root_shlib_dir, root_build_dir),
1916 rebase_path(libraries_list, root_build_dir),
1918 rebase_path(android_readelf, root_build_dir),
1922 copy_ex(copy_target_name) {
1923 visibility = [ ":$template_name" ]
1931 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
1932 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
1934 "--files=$rebased_binaries_list",
1935 "--files=@FileArg($rebased_libraries_list:lib_paths)",
1939 ":$find_deps_target_name",
1941 if (defined(invoker.deps)) {
1942 deps += invoker.deps
1946 group(template_name) {
1947 forward_variables_from(invoker, [ "visibility" ])
1949 ":$copy_target_name",
1954 # Compile a protocol buffer to java.
1956 # This generates java files from protocol buffers and creates an Android library
1957 # containing the classes.
1960 # sources: Paths to .proto files to compile.
1961 # proto_path: Root directory of .proto files.
1964 # proto_java_library("foo_proto_java") {
1965 # proto_path = [ "src/foo" ]
1966 # sources = [ "$proto_path/foo.proto" ]
1968 template("proto_java_library") {
1969 set_sources_assignment_filter([])
1970 forward_variables_from(invoker, [ "testonly" ])
1971 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
1972 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
1973 _protoc_bin = "$_protoc_out_dir/android_protoc"
1974 _proto_path = invoker.proto_path
1976 _template_name = target_name
1978 action("${_template_name}__protoc_java") {
1979 srcjar_path = "$target_gen_dir/$target_name.srcjar"
1980 script = "//build/protoc_java.py"
1984 sources = invoker.sources
1985 depfile = "$target_gen_dir/$target_name.d"
1992 rebase_path(depfile, root_build_dir),
1994 rebase_path(_protoc_bin, root_build_dir),
1996 rebase_path(_proto_path, root_build_dir),
1998 rebase_path(srcjar_path, root_build_dir),
1999 ] + rebase_path(sources, root_build_dir)
2002 android_library(target_name) {
2004 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2006 "//third_party/android_protobuf:protobuf_nano_javalib",
2011 # TODO(GYP): implement this.
2012 template("uiautomator_test") {
2013 set_sources_assignment_filter([])
2014 forward_variables_from(invoker, [ "testonly" ])
2015 assert(target_name != "")
2016 assert(invoker.deps != [] || true)
2017 group(target_name) {