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).
800 # java_files: List of .java files included in this library.
801 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
802 # will be added to java_files and be included in this library.
803 # srcjars: List of srcjars to be included in this library, together with the
804 # ones obtained from srcjar_deps.
806 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
807 # dependencies for this target. This will allow depending on an
808 # android_library target, for example.
810 # chromium_code: If true, extra analysis warning/errors will be enabled.
811 # enable_errorprone: If true, enables the errorprone compiler.
813 # data_deps, testonly
816 # java_binary("foo") {
817 # java_files = [ "org/chromium/foo/FooMain.java" ]
818 # deps = [ ":bar_java" ]
819 # main_class = "org.chromium.foo.FooMain"
821 template("java_binary") {
822 set_sources_assignment_filter([])
824 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
825 # dependents shouldn't get the jar in their classpath, etc.).
826 java_library_impl(target_name) {
827 forward_variables_from(invoker, "*")
828 supports_android = false
829 main_class = invoker.main_class
833 # Declare a Junit executable target
835 # This target creates an executable from java code for running as a junit test
836 # suite. The executable will be in the output folder's /bin/ directory.
839 # deps: Specifies the dependencies of this target. Java targets in this list
840 # will be included in the executable (and the javac classpath).
842 # java_files: List of .java files included in this library.
843 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
844 # will be added to java_files and be included in this library.
845 # srcjars: List of srcjars to be included in this library, together with the
846 # ones obtained from srcjar_deps.
848 # chromium_code: If true, extra analysis warning/errors will be enabled.
851 # junit_binary("foo") {
852 # java_files = [ "org/chromium/foo/FooTest.java" ]
853 # deps = [ ":bar_java" ]
855 template("junit_binary") {
856 set_sources_assignment_filter([])
858 java_binary(target_name) {
860 forward_variables_from(invoker, "*")
861 bypass_platform_checks = true
862 main_class = "org.chromium.testing.local.JunitTestMain"
866 "//testing/android/junit:junit_test_support",
867 "//third_party/junit",
868 "//third_party/mockito:mockito_java",
869 "//third_party/robolectric:robolectric_java",
870 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
875 # Declare a java library target
878 # deps: Specifies the dependencies of this target. Java targets in this list
879 # will be added to the javac classpath.
881 # java_files: List of .java files included in this library.
882 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
883 # will be added to java_files and be included in this library.
884 # srcjars: List of srcjars to be included in this library, together with the
885 # ones obtained from srcjar_deps.
886 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
887 # this directory will be included in the library. This is only supported to
888 # ease the gyp->gn conversion and will be removed in the future.
890 # chromium_code: If true, extra analysis warning/errors will be enabled.
891 # enable_errorprone: If true, enables the errorprone compiler.
893 # jar_excluded_patterns: List of patterns of .class files to exclude from the
896 # proguard_preprocess: If true, proguard preprocessing will be run. This can
897 # be used to remove unwanted parts of the library.
898 # proguard_config: Path to the proguard config for preprocessing.
900 # supports_android: If true, Android targets (android_library, android_apk)
901 # may depend on this target. Note: if true, this target must only use the
902 # subset of Java available on Android.
903 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
904 # dependencies for this target. This will allow depending on an
905 # android_library target, for example.
907 # data_deps, testonly
910 # java_library("foo_java") {
912 # "org/chromium/foo/Foo.java",
913 # "org/chromium/foo/FooInterface.java",
914 # "org/chromium/foo/FooService.java",
920 # ":foo_generated_enum"
922 # jar_excluded_patterns = [
923 # "*/FooService.class", "*/FooService##*.class"
926 template("java_library") {
927 set_sources_assignment_filter([])
928 java_library_impl(target_name) {
929 forward_variables_from(invoker, "*")
933 # Declare a java library target for a prebuilt jar
936 # deps: Specifies the dependencies of this target. Java targets in this list
937 # will be added to the javac classpath.
938 # jar_path: Path to the prebuilt jar.
939 # jar_dep: Target that builds jar_path (optional).
940 # proguard_preprocess: If true, proguard preprocessing will be run. This can
941 # be used to remove unwanted parts of the library.
942 # proguard_config: Path to the proguard config for preprocessing.
943 # supports_android: If true, Android targets (android_library, android_apk)
944 # may depend on this target. Note: if true, this target must only use the
945 # subset of Java available on Android.
948 # java_prebuilt("foo_java") {
949 # jar_path = "foo.jar"
955 template("java_prebuilt") {
956 set_sources_assignment_filter([])
957 java_prebuilt_impl(target_name) {
958 forward_variables_from(invoker, "*")
962 # Declare an Android library target
964 # This target creates an Android library containing java code and Android
968 # deps: Specifies the dependencies of this target. Java targets in this list
969 # will be added to the javac classpath. Android resources in dependencies
970 # will be used when building this library.
972 # java_files: List of .java files included in this library.
973 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
974 # will be added to java_files and be included in this library.
975 # srcjars: List of srcjars to be included in this library, together with the
976 # ones obtained from srcjar_deps.
977 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
978 # this directory will be included in the library. This is only supported to
979 # ease the gyp->gn conversion and will be removed in the future.
981 # chromium_code: If true, extra analysis warning/errors will be enabled.
982 # enable_errorprone: If true, enables the errorprone compiler.
984 # jar_excluded_patterns: List of patterns of .class files to exclude from the
987 # proguard_preprocess: If true, proguard preprocessing will be run. This can
988 # be used to remove unwanted parts of the library.
989 # proguard_config: Path to the proguard config for preprocessing.
991 # dex_path: If set, the resulting .dex.jar file will be placed under this
996 # android_library("foo_java") {
998 # "android/org/chromium/foo/Foo.java",
999 # "android/org/chromium/foo/FooInterface.java",
1000 # "android/org/chromium/foo/FooService.java",
1006 # ":foo_generated_enum"
1008 # jar_excluded_patterns = [
1009 # "*/FooService.class", "*/FooService##*.class"
1012 template("android_library") {
1013 set_sources_assignment_filter([])
1014 assert(!defined(invoker.jar_path),
1015 "android_library does not support a custom jar path")
1016 java_library_impl(target_name) {
1017 forward_variables_from(invoker, "*")
1019 supports_android = true
1020 requires_android = true
1022 if (!defined(jar_excluded_patterns)) {
1023 jar_excluded_patterns = []
1025 jar_excluded_patterns += [
1029 "*/Manifest##*.class",
1034 # Declare a target that packages a set of Java dependencies into a standalone
1038 # deps: specifies the dependencies of this target. Android libraries in deps
1039 # will be packaged into the resulting .dex.jar file.
1040 # dex_path: location at which the output file will be put
1041 template("android_standalone_library") {
1042 set_sources_assignment_filter([])
1043 deps_dex(target_name) {
1044 forward_variables_from(invoker,
1053 # Declare an Android library target for a prebuilt jar
1055 # This target creates an Android library containing java code and Android
1059 # deps: Specifies the dependencies of this target. Java targets in this list
1060 # will be added to the javac classpath. Android resources in dependencies
1061 # will be used when building this library.
1062 # jar_path: Path to the prebuilt jar.
1063 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1064 # be used to remove unwanted parts of the library.
1065 # proguard_config: Path to the proguard config for preprocessing.
1068 # android_java_prebuilt("foo_java") {
1069 # jar_path = "foo.jar"
1075 template("android_java_prebuilt") {
1076 set_sources_assignment_filter([])
1077 java_prebuilt_impl(target_name) {
1078 forward_variables_from(invoker, "*")
1079 supports_android = true
1080 requires_android = true
1084 # Declare an Android apk target
1086 # This target creates an Android APK containing java code, resources, assets,
1087 # and (possibly) native libraries.
1090 # android_manifest: Path to AndroidManifest.xml.
1091 # android_manifest_dep: Target that generates AndroidManifest (if applicable)
1092 # data_deps: List of dependencies needed at runtime. These will be built but
1093 # won't change the generated .apk in any way (in fact they may be built
1094 # after the .apk is).
1095 # deps: List of dependencies. All Android java resources and libraries in the
1096 # "transitive closure" of these dependencies will be included in the apk.
1097 # Note: this "transitive closure" actually only includes such targets if
1098 # they are depended on through android_library or android_resources targets
1099 # (and so not through builtin targets like 'action', 'group', etc).
1100 # java_files: List of .java files to include in the apk.
1101 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1102 # will be added to java_files and be included in this apk.
1103 # apk_name: Name for final apk.
1104 # final_apk_path: Path to final built apk. Default is
1105 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1106 # native_libs: List paths of native libraries to include in this apk. If these
1107 # libraries depend on other shared_library targets, those dependencies will
1108 # also be included in the apk.
1109 # apk_under_test: For an instrumentation test apk, this is the target of the
1111 # include_all_resources - If true include all resource IDs in all generated
1113 # testonly: Marks this target as "test-only".
1115 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1116 # this directory will be included in the library. This is only supported to
1117 # ease the gyp->gn conversion and will be removed in the future.
1120 # android_apk("foo_apk") {
1121 # android_manifest = "AndroidManifest.xml"
1123 # "android/org/chromium/foo/FooApplication.java",
1124 # "android/org/chromium/foo/FooActivity.java",
1127 # ":foo_support_java"
1131 # ":foo_generated_enum"
1137 template("android_apk") {
1138 set_sources_assignment_filter([])
1139 forward_variables_from(invoker, [ "testonly" ])
1141 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1142 assert(defined(invoker.android_manifest))
1143 gen_dir = "$target_gen_dir/$target_name"
1144 base_path = "$gen_dir/$target_name"
1145 _build_config = "$target_gen_dir/$target_name.build_config"
1146 resources_zip_path = "$base_path.resources.zip"
1147 _all_resources_zip_path = "$base_path.resources.all.zip"
1148 jar_path = "$base_path.jar"
1149 _template_name = target_name
1151 final_dex_path = "$gen_dir/classes.dex"
1152 final_dex_target_name = "${_template_name}__final_dex"
1154 _final_apk_path = ""
1155 if (defined(invoker.final_apk_path)) {
1156 _final_apk_path = invoker.final_apk_path
1157 } else if (defined(invoker.apk_name)) {
1158 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1160 _dist_jar_path_list =
1161 process_file_template(
1162 [ _final_apk_path ],
1163 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1164 _dist_jar_path = _dist_jar_path_list[0]
1165 _final_apk_path_no_ext_list =
1166 process_file_template([ _final_apk_path ],
1167 "{{source_dir}}/{{source_name_part}}")
1168 _final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
1169 assert(_final_apk_path_no_ext != "") # Mark as used.
1174 if (defined(invoker.version_code)) {
1175 _version_code = invoker.version_code
1178 _version_name = "Developer Build"
1179 if (defined(invoker.version_name)) {
1180 _version_name = invoker.version_name
1182 _keystore_path = android_default_keystore_path
1183 _keystore_name = android_default_keystore_name
1184 _keystore_password = android_default_keystore_password
1186 if (defined(invoker.keystore_path)) {
1187 _keystore_path = invoker.keystore_path
1188 _keystore_name = invoker.keystore_name
1189 _keystore_password = invoker.keystore_password
1193 if (defined(invoker.srcjar_deps)) {
1194 _srcjar_deps += invoker.srcjar_deps
1197 _load_library_from_apk = false
1199 # The dependency that makes the chromium linker, if any is needed.
1200 _chromium_linker_dep = []
1202 if (defined(invoker.native_libs)) {
1203 _use_chromium_linker = false
1204 if (defined(invoker.use_chromium_linker)) {
1205 _use_chromium_linker =
1206 invoker.use_chromium_linker && chromium_linker_supported
1207 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1210 if (defined(invoker.load_library_from_apk) &&
1211 invoker.load_library_from_apk) {
1212 _load_library_from_apk = true
1213 assert(_use_chromium_linker,
1214 "Loading library from the apk requires use" +
1215 " of the Chromium linker.")
1218 _enable_relocation_packing = false
1219 if (defined(invoker.enable_relocation_packing) &&
1220 invoker.enable_relocation_packing) {
1221 _enable_relocation_packing = relocation_packing_supported
1222 assert(_use_chromium_linker,
1223 "Relocation packing requires use of the" + " Chromium linker.")
1226 if (is_component_build) {
1227 _native_libs += [ "$root_shlib_dir/libc++_shared.so" ]
1228 _chromium_linker_dep += [ "//build/android:cpplib_stripped" ]
1231 # Allow native_libs to be in the form "foo.so" or "foo.cr.so"
1232 _first_ext_removed =
1233 process_file_template(invoker.native_libs, "{{source_name_part}}")
1234 _native_libs += process_file_template(
1236 "$root_shlib_dir/{{source_name_part}}$shlib_extension")
1238 # Add in target_cpu so that other architectures are not accidentally
1239 # included when switching target_cpu without doing a clean build.
1240 _native_libs_dir = gen_dir + "/lib-$target_cpu"
1242 if (_use_chromium_linker) {
1244 [ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
1247 _enable_relocation_packing = false
1248 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1249 invoker.enable_relocation_packing) {
1250 _enable_relocation_packing = true
1253 _native_lib_version_rule = ""
1254 if (defined(invoker.native_lib_version_rule)) {
1255 _native_lib_version_rule = invoker.native_lib_version_rule
1257 _native_lib_version_arg = "\"\""
1258 if (defined(invoker.native_lib_version_arg)) {
1259 _native_lib_version_arg = invoker.native_lib_version_arg
1263 _android_manifest_deps = []
1264 if (defined(invoker.android_manifest_dep)) {
1265 _android_manifest_deps = [ invoker.android_manifest_dep ]
1267 _android_manifest = invoker.android_manifest
1269 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1271 defined(invoker.create_abi_split) && invoker.create_abi_split
1272 _create_density_splits =
1273 defined(invoker.create_density_splits) && invoker.create_density_splits
1274 _create_language_splits =
1275 defined(invoker.language_splits) && invoker.language_splits != []
1277 # Help GN understand that _create_abi_split is not unused (bug in GN).
1278 assert(_create_abi_split || true)
1280 build_config_target = "${_template_name}__build_config"
1281 write_build_config(build_config_target) {
1282 forward_variables_from(invoker, [ "apk_under_test" ])
1283 type = "android_apk"
1284 dex_path = final_dex_path
1285 resources_zip = resources_zip_path
1286 build_config = _build_config
1287 android_manifest = _android_manifest
1289 deps = _chromium_linker_dep + _android_manifest_deps
1290 if (defined(invoker.deps)) {
1291 deps += invoker.deps
1294 native_libs = _native_libs
1298 _incremental_final_deps = []
1300 process_resources_target = "${_template_name}__process_resources"
1301 process_resources(process_resources_target) {
1302 forward_variables_from(invoker, [ "include_all_resources" ])
1303 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1304 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1305 android_manifest = _android_manifest
1306 resource_dirs = [ "//build/android/ant/empty/res" ]
1307 zip_path = resources_zip_path
1308 all_resources_zip_path = _all_resources_zip_path
1309 generate_constant_ids = true
1311 build_config = _build_config
1312 deps = _android_manifest_deps + [ ":$build_config_target" ]
1313 if (defined(invoker.deps)) {
1314 deps += invoker.deps
1317 _srcjar_deps += [ ":$process_resources_target" ]
1319 if (_native_libs != []) {
1320 _enable_chromium_linker_tests = false
1321 if (defined(invoker.enable_chromium_linker_tests)) {
1322 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1325 java_cpp_template("${_template_name}__native_libraries_java") {
1326 package_name = "org/chromium/base/library_loader"
1328 "//base/android/java/templates/NativeLibraries.template",
1334 ":$build_config_target",
1336 if (_native_lib_version_rule != "") {
1337 deps += [ _native_lib_version_rule ]
1341 "NATIVE_LIBRARIES_LIST=" +
1342 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1343 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
1345 if (_use_chromium_linker) {
1346 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1348 if (_load_library_from_apk) {
1349 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1351 if (_enable_chromium_linker_tests) {
1352 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1355 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1358 java_target = "${_template_name}__java"
1359 java_library_impl(java_target) {
1360 forward_variables_from(invoker, [ "run_findbugs" ])
1361 supports_android = true
1362 requires_android = true
1363 override_build_config = _build_config
1364 deps = _android_manifest_deps + [ ":$build_config_target" ]
1366 android_manifest = _android_manifest
1367 chromium_code = true
1368 if (defined(invoker.java_files)) {
1369 java_files = invoker.java_files
1370 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1371 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1375 srcjar_deps = _srcjar_deps
1376 dex_path = base_path + ".dex.jar"
1378 if (defined(invoker.deps)) {
1379 deps += invoker.deps
1383 if (_dist_jar_path != "") {
1384 create_dist_target = "${_template_name}__create_dist_jar"
1385 _final_deps += [ ":$create_dist_target" ]
1386 _incremental_final_deps += [ ":$create_dist_target" ]
1388 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1389 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1390 # able to just do that calculation at build time instead.
1391 action(create_dist_target) {
1392 script = "//build/android/gyp/create_dist_jar.py"
1393 depfile = "$target_gen_dir/$target_name.d"
1403 rebase_path(depfile, root_build_dir),
1405 rebase_path(_dist_jar_path, root_build_dir),
1406 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1408 inputs += [ jar_path ]
1409 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1410 args += [ "--inputs=$_rebased_jar_path" ]
1412 ":$build_config_target", # Generates the build config file.
1413 ":$java_target", # Generates the jar file.
1418 dex("$final_dex_target_name") {
1420 ":$build_config_target",
1429 output = final_dex_path
1430 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1431 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1434 if (_native_libs != []) {
1435 action("${_template_name}__prepare_native") {
1436 forward_variables_from(invoker,
1441 script = "//build/android/gyp/pack_relocations.py"
1442 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1443 depfile = "$target_gen_dir/$target_name.d"
1448 inputs = _native_libs
1449 deps = _chromium_linker_dep
1451 inputs += [ _build_config ]
1452 deps += [ ":$build_config_target" ]
1454 skip_packing_list = [
1456 "libchromium_android_linker$shlib_extension",
1459 enable_packing_arg = 0
1460 if (_enable_relocation_packing) {
1461 enable_packing_arg = 1
1462 deps += [ relocation_packer_target ]
1467 rebase_path(depfile, root_build_dir),
1468 "--enable-packing=$enable_packing_arg",
1469 "--exclude-packing-list=$skip_packing_list",
1470 "--android-pack-relocations",
1471 rebase_path(relocation_packer_exe, root_build_dir),
1472 "--stripped-libraries-dir",
1473 rebase_path(root_build_dir, root_build_dir),
1474 "--packed-libraries-dir",
1475 rebase_path(packed_libraries_dir, root_build_dir),
1476 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1480 if (defined(invoker.deps)) {
1481 deps += invoker.deps
1485 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1486 inputs += [ android_gdbserver ]
1487 args += [ "--libraries=$rebased_gdbserver" ]
1492 _final_deps += [ ":${_template_name}__create" ]
1493 _incremental_final_deps += [ ":${_template_name}__create_incremental" ]
1494 create_apk("${_template_name}__create") {
1495 forward_variables_from(invoker, [ "language_splits" ])
1496 apk_path = _final_apk_path
1497 android_manifest = _android_manifest
1498 resources_zip = _all_resources_zip_path
1499 dex_path = final_dex_path
1500 load_library_from_apk = _load_library_from_apk
1501 create_density_splits = _create_density_splits
1502 if (defined(invoker.extensions_to_not_compress)) {
1503 extensions_to_not_compress = invoker.extensions_to_not_compress
1505 # Allow icu data, v8 snapshots, and pak files to be loaded directly from
1507 # Note: These are actually suffix matches, not necessarily extensions.
1508 extensions_to_not_compress = ".dat,.bin,.pak"
1511 version_code = _version_code
1512 version_name = _version_name
1514 keystore_name = _keystore_name
1515 keystore_path = _keystore_path
1516 keystore_password = _keystore_password
1518 # This target generates the input file _all_resources_zip_path.
1519 deps = _android_manifest_deps + [
1520 ":$process_resources_target",
1521 ":$final_dex_target_name",
1523 if (defined(invoker.deps)) {
1524 deps += invoker.deps
1527 if (defined(invoker.asset_location)) {
1528 asset_location = invoker.asset_location
1530 # We don't know the exact dependencies that create the assets in
1531 # |asset_location|; we depend on all caller deps until a better solution
1532 # is figured out (http://crbug.com/433330).
1533 if (defined(invoker.deps)) {
1534 deps += invoker.deps
1538 if (_native_libs != [] && !_create_abi_split) {
1539 native_libs_dir = _native_libs_dir
1540 deps += [ ":${_template_name}__prepare_native" ]
1544 if (_native_libs != [] && _create_abi_split) {
1545 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1546 generate_split_manifest(_manifest_rule) {
1547 main_manifest = _android_manifest
1549 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1550 split_name = "abi_${android_app_abi}"
1551 deps = _android_manifest_deps
1554 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1555 _final_deps += [ ":$_apk_rule" ]
1557 # Don't add this to _incremental_final_deps since for incremental installs
1558 # we skip abi splits altogether.
1559 create_apk(_apk_rule) {
1560 apk_path = "${_final_apk_path_no_ext}-abi-${android_app_abi}.apk"
1561 base_path = "$gen_dir/$_apk_rule"
1563 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1564 android_manifest = manifest_outputs[1]
1565 load_library_from_apk = _load_library_from_apk
1567 version_code = _version_code
1568 version_name = _version_name
1570 keystore_name = _keystore_name
1571 keystore_path = _keystore_path
1572 keystore_password = _keystore_password
1574 native_libs_dir = _native_libs_dir
1576 ":${_template_name}__prepare_native",
1577 ":${_manifest_rule}",
1582 _create_incremental_script_rule_name = "${_template_name}__incremental_script"
1583 _incremental_final_deps += [ ":${_create_incremental_script_rule_name}" ]
1584 action(_create_incremental_script_rule_name) {
1585 script = "//build/android/gn/create_incremental_install_script.py"
1586 depfile = "$target_gen_dir/$target_name.d"
1588 _generated_script_path =
1589 "${root_out_dir}/bin/install_incremental_${_template_name}"
1592 _generated_script_path,
1595 _rebased_apk_path_no_ext =
1596 rebase_path(_final_apk_path_no_ext, root_build_dir)
1597 _rebased_generated_script_path =
1598 rebase_path(_generated_script_path, root_build_dir)
1599 _rebased_depfile = rebase_path(depfile, root_build_dir)
1601 "--apk-path=${_rebased_apk_path_no_ext}_incremental.apk",
1602 "--script-output-path=$_rebased_generated_script_path",
1603 "--depfile=$_rebased_depfile",
1605 if (defined(_native_libs_dir)) {
1606 _rebased_native_libs_dir = rebase_path(_native_libs_dir, root_build_dir)
1607 args += [ "--lib-dir=$_rebased_native_libs_dir/$android_app_abi" ]
1609 if (_create_density_splits) {
1610 args += [ "--split=${_rebased_apk_path_no_ext}-density-*.apk" ]
1612 if (_create_language_splits) {
1613 args += [ "--split=${_rebased_apk_path_no_ext}-language-*.apk" ]
1617 group(target_name) {
1618 forward_variables_from(invoker, [ "data_deps" ])
1621 group("${target_name}_incremental") {
1623 forward_variables_from(invoker, [ "data_deps" ])
1624 data_deps += [ "//build/android/pylib/device/commands" ]
1625 deps = _incremental_final_deps
1629 # Declare an Android instrumentation test apk
1631 # This target creates an Android instrumentation test apk.
1634 # android_manifest: Path to AndroidManifest.xml.
1635 # data_deps: List of dependencies needed at runtime. These will be built but
1636 # won't change the generated .apk in any way (in fact they may be built
1637 # after the .apk is).
1638 # deps: List of dependencies. All Android java resources and libraries in the
1639 # "transitive closure" of these dependencies will be included in the apk.
1640 # Note: this "transitive closure" actually only includes such targets if
1641 # they are depended on through android_library or android_resources targets
1642 # (and so not through builtin targets like 'action', 'group', etc).
1643 # java_files: List of .java files to include in the apk.
1644 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1645 # will be added to java_files and be included in this apk.
1646 # apk_name: Name for final apk.
1647 # final_apk_path: Path to final built apk. Default is
1648 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1649 # native_libs: List paths of native libraries to include in this apk. If these
1650 # libraries depend on other shared_library targets, those dependencies will
1651 # also be included in the apk.
1652 # apk_under_test: The apk being tested.
1653 # isolate_file: Isolate file containing the list of test data dependencies.
1655 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1656 # this directory will be included in the library. This is only supported to
1657 # ease the gyp->gn conversion and will be removed in the future.
1660 # instrumentation_test_apk("foo_test_apk") {
1661 # android_manifest = "AndroidManifest.xml"
1662 # apk_name = "FooTest"
1663 # apk_under_test = "Foo"
1665 # "android/org/chromium/foo/FooTestCase.java",
1666 # "android/org/chromium/foo/FooExampleTest.java",
1669 # ":foo_test_support_java"
1672 template("instrumentation_test_apk") {
1673 set_sources_assignment_filter([])
1675 _template_name = target_name
1677 if (defined(invoker.apk_name)) {
1678 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1679 test_runner_script("${_template_name}__test_runner_script") {
1680 forward_variables_from(invoker, [ "isolate_file" ])
1681 test_name = invoker.target_name
1682 test_type = "instrumentation"
1683 test_apk = invoker.apk_name
1687 android_apk(target_name) {
1690 forward_variables_from(invoker, "*")
1692 "//testing/android/driver:driver_apk",
1693 "//tools/android/forwarder2",
1694 "//tools/android/md5sum",
1696 if (defined(test_runner_data_dep)) {
1697 data_deps += test_runner_data_dep
1699 deps += [ "//testing/android/broker:broker_java" ]
1700 run_findbugs = false
1704 # Declare an Android gtest apk
1706 # This target creates an Android apk for running gtest-based unittests.
1709 # deps: Specifies the dependencies of this target. These will be passed to
1710 # the underlying android_apk invocation and should include the java and
1711 # resource dependencies of the apk.
1712 # unittests_dep: This should be the label of the gtest native target. This
1713 # target must be defined previously in the same file.
1714 # unittests_binary: The basename of the library produced by the unittests_dep
1715 # target. If unspecified, it assumes the name of the unittests_dep target
1716 # (which will be correct unless that target specifies an "output_name".
1717 # TODO(brettw) make this automatic by allowing get_target_outputs to
1718 # support executables.
1719 # apk_name: The name of the produced apk. If unspecified, it uses the name
1720 # of the unittests_dep target postfixed with "_apk"
1723 # unittest_apk("foo_unittests_apk") {
1724 # deps = [ ":foo_java", ":foo_resources" ]
1725 # unittests_dep = ":foo_unittests"
1727 template("unittest_apk") {
1728 set_sources_assignment_filter([])
1731 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1733 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1735 # This trivial assert is needed in case both unittests_binary and apk_name
1736 # are defined, as otherwise test_suite_name would not be used.
1737 assert(test_suite_name != "")
1739 if (defined(invoker.unittests_binary)) {
1740 unittests_binary = invoker.unittests_binary
1742 unittests_binary = "lib${test_suite_name}${shlib_extension}"
1745 if (defined(invoker.apk_name)) {
1746 apk_name = invoker.apk_name
1748 apk_name = test_suite_name
1751 android_apk(target_name) {
1752 forward_variables_from(invoker, [ "asset_location" ])
1753 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1755 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBrowserTestActivity.java",
1756 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestActivity.java",
1757 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUnitTestActivity.java",
1758 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTestInstrumentationTestRunner.java",
1760 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1761 native_libs = [ unittests_binary ]
1764 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1765 "//testing/android/appurify_support:appurify_support_java",
1766 "//testing/android/reporter:reporter_java",
1768 if (defined(invoker.deps)) {
1769 deps += invoker.deps
1771 data_deps = [ "//tools/android/md5sum" ]
1772 if (host_os == "linux") {
1773 data_deps += [ "//tools/android/forwarder2" ]
1775 if (defined(invoker.data_deps)) {
1776 data_deps += invoker.data_deps
1781 # Generate .java files from .aidl files.
1783 # This target will store the .java files in a srcjar and should be included in
1784 # an android_library or android_apk's srcjar_deps.
1787 # sources: Paths to .aidl files to compile.
1788 # import_include: Path to directory containing .java files imported by the
1790 # interface_file: Preprocessed aidl file to import.
1793 # android_aidl("foo_aidl") {
1794 # import_include = "java/src"
1796 # "java/src/com/foo/bar/FooBarService.aidl",
1797 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1800 template("android_aidl") {
1801 set_sources_assignment_filter([])
1802 forward_variables_from(invoker, [ "testonly" ])
1804 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1805 aidl_path = "${android_sdk_build_tools}/aidl"
1806 framework_aidl = "$android_sdk/framework.aidl"
1808 action(target_name) {
1809 script = "//build/android/gyp/aidl.py"
1810 sources = invoker.sources
1812 imports = [ framework_aidl ]
1813 if (defined(invoker.interface_file)) {
1814 assert(invoker.interface_file != "")
1815 imports += [ invoker.interface_file ]
1818 inputs = [ aidl_path ] + imports
1820 depfile = "${target_gen_dir}/${target_name}.d"
1825 rebased_imports = rebase_path(imports, root_build_dir)
1828 rebase_path(depfile, root_build_dir),
1830 rebase_path(aidl_path, root_build_dir),
1831 "--imports=$rebased_imports",
1833 rebase_path(srcjar_path, root_build_dir),
1835 if (defined(invoker.import_include) && invoker.import_include != "") {
1836 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1837 # switch to constructing a depfile for the overall action from that
1838 # instead of having all the .java files in the include paths as inputs.
1839 rebased_import_includes =
1840 rebase_path([ invoker.import_include ], root_build_dir)
1841 args += [ "--includes=$rebased_import_includes" ]
1843 _java_files_build_rel =
1844 exec_script("//build/android/gyp/find.py",
1845 rebase_path([ invoker.import_include ], root_build_dir),
1847 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1848 inputs += _java_files
1850 args += rebase_path(sources, root_build_dir)
1854 # Creates a dist directory for a native executable.
1856 # Running a native executable on a device requires all the shared library
1857 # dependencies of that executable. To make it easier to install and run such an
1858 # executable, this will create a directory containing the native exe and all
1859 # it's library dependencies.
1861 # Note: It's usually better to package things as an APK than as a native
1865 # dist_dir: Directory for the exe and libraries. Everything in this directory
1866 # will be deleted before copying in the exe and libraries.
1867 # binary: Path to (stripped) executable.
1870 # create_native_executable_dist("foo_dist") {
1871 # dist_dir = "$root_build_dir/foo_dist"
1872 # binary = "$root_build_dir/foo"
1873 # deps = [ ":the_thing_that_makes_foo" ]
1875 template("create_native_executable_dist") {
1876 set_sources_assignment_filter([])
1877 forward_variables_from(invoker, [ "testonly" ])
1879 dist_dir = invoker.dist_dir
1880 binary = invoker.binary
1881 template_name = target_name
1884 "${target_gen_dir}/${template_name}_library_dependencies.list"
1886 find_deps_target_name = "${template_name}__find_library_dependencies"
1887 copy_target_name = "${template_name}__copy_libraries_and_exe"
1889 action(find_deps_target_name) {
1890 forward_variables_from(invoker, [ "deps" ])
1891 visibility = [ ":$copy_target_name" ]
1893 script = "//build/android/gyp/write_ordered_libraries.py"
1894 depfile = "$target_gen_dir/$target_name.d"
1903 rebased_binaries = rebase_path([ binary ], root_build_dir)
1906 rebase_path(depfile, root_build_dir),
1907 "--input-libraries=$rebased_binaries",
1909 rebase_path(root_shlib_dir, root_build_dir),
1911 rebase_path(libraries_list, root_build_dir),
1913 rebase_path(android_readelf, root_build_dir),
1917 copy_ex(copy_target_name) {
1918 visibility = [ ":$template_name" ]
1926 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
1927 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
1929 "--files=$rebased_binaries_list",
1930 "--files=@FileArg($rebased_libraries_list:lib_paths)",
1934 ":$find_deps_target_name",
1936 if (defined(invoker.deps)) {
1937 deps += invoker.deps
1941 group(template_name) {
1942 forward_variables_from(invoker, [ "visibility" ])
1944 ":$copy_target_name",
1949 # Compile a protocol buffer to java.
1951 # This generates java files from protocol buffers and creates an Android library
1952 # containing the classes.
1955 # sources: Paths to .proto files to compile.
1956 # proto_path: Root directory of .proto files.
1959 # proto_java_library("foo_proto_java") {
1960 # proto_path = [ "src/foo" ]
1961 # sources = [ "$proto_path/foo.proto" ]
1963 template("proto_java_library") {
1964 set_sources_assignment_filter([])
1965 forward_variables_from(invoker, [ "testonly" ])
1966 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
1967 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
1968 _protoc_bin = "$_protoc_out_dir/android_protoc"
1969 _proto_path = invoker.proto_path
1971 _template_name = target_name
1973 action("${_template_name}__protoc_java") {
1974 srcjar_path = "$target_gen_dir/$target_name.srcjar"
1975 script = "//build/protoc_java.py"
1979 sources = invoker.sources
1980 depfile = "$target_gen_dir/$target_name.d"
1987 rebase_path(depfile, root_build_dir),
1989 rebase_path(_protoc_bin, root_build_dir),
1991 rebase_path(_proto_path, root_build_dir),
1993 rebase_path(srcjar_path, root_build_dir),
1994 ] + rebase_path(sources, root_build_dir)
1997 android_library(target_name) {
1999 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2001 "//third_party/android_protobuf:protobuf_nano_javalib",
2006 # TODO(GYP): implement this.
2007 template("uiautomator_test") {
2008 set_sources_assignment_filter([])
2009 forward_variables_from(invoker, [ "testonly" ])
2010 assert(target_name != "")
2011 assert(invoker.deps != [] || true)
2012 group(target_name) {