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("//tools/grit/grit_rule.gni")
9 import("//tools/relocation_packer/config.gni")
13 # Declare a jni target
15 # This target generates the native jni bindings for a set of .java files.
17 # See base/android/jni_generator/jni_generator.py for more info about the
18 # format of generating JNI bindings.
21 # sources: list of .java files to generate jni for
22 # jni_package: subdirectory path for generated bindings
25 # generate_jni("foo_jni") {
27 # "android/java/src/org/chromium/foo/Foo.java",
28 # "android/java/src/org/chromium/foo/FooUtil.java",
32 template("generate_jni") {
33 set_sources_assignment_filter([])
34 if (defined(invoker.testonly)) {
35 testonly = invoker.testonly
38 assert(defined(invoker.sources))
39 assert(defined(invoker.jni_package))
40 jni_package = invoker.jni_package
41 base_output_dir = "${target_gen_dir}/${target_name}"
42 package_output_dir = "${base_output_dir}/${jni_package}"
43 jni_output_dir = "${package_output_dir}/jni"
45 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
47 foreach_target_name = "${target_name}__jni_gen"
48 action_foreach(foreach_target_name) {
49 script = "//base/android/jni_generator/jni_generator.py"
50 depfile = "$target_gen_dir/$target_name.{{source_name_part}}.d"
51 sources = invoker.sources
53 jni_generator_include,
57 "${jni_output_dir}/{{source_name_part}}_jni.h",
62 rebase_path(depfile, root_build_dir),
63 "--input_file={{source}}",
64 "--optimize_generation=1",
67 rebase_path(jni_output_dir, root_build_dir),
69 rebase_path(jni_generator_include, "//"),
70 "--native_exports_optional",
72 if (defined(invoker.jni_generator_jarjar_file)) {
75 rebase_path(jni_generator_jarjar_file, root_build_dir),
80 config("jni_includes_${target_name}") {
81 # TODO(cjhopman): #includes should probably all be relative to
82 # base_output_dir. Remove that from this config once the includes are
92 ":$foreach_target_name",
94 public_configs = [ ":jni_includes_${target_name}" ]
96 if (defined(invoker.deps)) {
99 if (defined(invoker.public_deps)) {
100 public_deps = invoker.public_deps
103 if (defined(invoker.visibility)) {
104 visibility = invoker.visibility
109 # Declare a jni target for a prebuilt jar
111 # This target generates the native jni bindings for a set of classes in a .jar.
113 # See base/android/jni_generator/jni_generator.py for more info about the
114 # format of generating JNI bindings.
117 # classes: list of .class files in the jar to generate jni for. These should
118 # include the full path to the .class file.
119 # jni_package: subdirectory path for generated bindings
120 # jar_file: the path to the .jar. If not provided, will default to the sdk's
123 # deps, public_deps: As normal
126 # generate_jar_jni("foo_jni") {
128 # "android/view/Foo.class",
130 # jni_package = "foo"
132 template("generate_jar_jni") {
133 set_sources_assignment_filter([])
134 if (defined(invoker.testonly)) {
135 testonly = invoker.testonly
138 assert(defined(invoker.classes))
139 assert(defined(invoker.jni_package))
141 if (defined(invoker.jar_file)) {
142 jar_file = invoker.jar_file
144 jar_file = android_sdk_jar
147 jni_package = invoker.jni_package
148 base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}"
149 jni_output_dir = "${base_output_dir}/jni"
151 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
153 # TODO(cjhopman): make jni_generator.py support generating jni for multiple
154 # .class files from a .jar.
156 foreach(class, invoker.classes) {
158 _classname_list = process_file_template([ class ], "{{source_name_part}}")
159 classname = _classname_list[0]
160 jni_target_name = "${target_name}__jni_${classname}"
161 jni_actions += [ ":$jni_target_name" ]
162 action(jni_target_name) {
163 # The sources aren't compiled so don't check their dependencies.
164 check_includes = false
165 depfile = "$target_gen_dir/$target_name.d"
166 script = "//base/android/jni_generator/jni_generator.py"
169 jni_generator_include,
173 "${jni_output_dir}/${classname}_jni.h",
178 rebase_path(depfile, root_build_dir),
180 rebase_path(jar_file, root_build_dir),
183 "--optimize_generation=1",
186 rebase_path(jni_output_dir, root_build_dir),
188 rebase_path(jni_generator_include, root_build_dir),
189 "--native_exports_optional",
194 config("jni_includes_${target_name}") {
195 include_dirs = [ base_output_dir ]
200 if (defined(invoker.deps)) {
203 if (defined(invoker.public_deps)) {
204 public_deps = invoker.public_deps
206 public_configs = [ ":jni_includes_${target_name}" ]
210 # Declare a target for c-preprocessor-generated java files
212 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
215 # This target generates java files using the host C pre-processor. Each file in
216 # sources will be compiled using the C pre-processor. If include_path is
217 # specified, it will be passed (with --I) to the pre-processor.
219 # This target will create a single .srcjar. Adding this target to an
220 # android_library target's srcjar_deps will make the generated java files be
221 # included in that library's final outputs.
224 # sources: list of files to be processed by the C pre-processor. For each
225 # file in sources, there will be one .java file in the final .srcjar. For a
226 # file named FooBar.template, a java file will be created with name
228 # inputs: additional compile-time dependencies. Any files
229 # `#include`-ed in the templates should be listed here.
230 # package_name: this will be the subdirectory for each .java file in the
234 # java_cpp_template("foo_generated_enum") {
236 # "android/java/templates/Foo.template",
239 # "android/java/templates/native_foo_header.h",
242 # package_name = "org/chromium/base/library_loader"
243 # include_path = "android/java/templates"
245 template("java_cpp_template") {
246 set_sources_assignment_filter([])
247 if (defined(invoker.testonly)) {
248 testonly = invoker.testonly
251 assert(defined(invoker.sources))
252 package_name = invoker.package_name + ""
254 if (defined(invoker.include_path)) {
255 include_path = invoker.include_path + ""
260 action_foreach("${target_name}__apply_gcc") {
261 script = "//build/android/gyp/gcc_preprocess.py"
262 if (defined(invoker.inputs)) {
263 inputs = invoker.inputs + []
265 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
267 sources = invoker.sources
270 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
271 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
275 gcc_template_output_pattern,
280 rebase_path(depfile, root_build_dir),
282 rebase_path(include_path, root_build_dir),
284 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
285 "--template={{source}}",
288 if (defined(invoker.defines)) {
289 foreach(def, invoker.defines) {
298 apply_gcc_outputs = get_target_outputs(":${target_name}__apply_gcc")
299 base_gen_dir = get_label_info(":${target_name}__apply_gcc", "target_gen_dir")
301 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
302 zip("${target_name}__zip_srcjar") {
303 inputs = apply_gcc_outputs
305 base_dir = base_gen_dir
310 ":${target_name}__zip_srcjar",
315 # Declare a target for generating Java classes from C++ enums.
317 # This target generates Java files from C++ enums using a script.
319 # This target will create a single .srcjar. Adding this target to an
320 # android_library target's srcjar_deps will make the generated java files be
321 # included in that library's final outputs.
324 # sources: list of files to be processed by the script. For each annotated
325 # enum contained in the sources files the script will generate a .java
326 # file with the same name as the name of the enum.
328 # outputs: list of outputs, relative to the output_dir. These paths are
329 # verified at build time by the script. To get the list programatically run:
330 # python build/android/gyp/java_cpp_enum.py \
331 # --print_output_only . path/to/header/file.h
334 # java_cpp_enum("foo_generated_enum") {
336 # "src/native_foo_header.h",
339 # "org/chromium/FooEnum.java",
342 template("java_cpp_enum") {
343 set_sources_assignment_filter([])
344 if (defined(invoker.testonly)) {
345 testonly = invoker.testonly
348 assert(defined(invoker.sources))
349 assert(defined(invoker.outputs))
351 action("${target_name}__generate_enum") {
352 # The sources aren't compiled so don't check their dependencies.
353 check_includes = false
355 sources = invoker.sources
356 script = "//build/android/gyp/java_cpp_enum.py"
357 gen_dir = "${target_gen_dir}/${target_name}/enums"
359 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
362 foreach(output, rebase_path(outputs, root_build_dir)) {
368 args += [ rebase_path(gen_dir, root_build_dir) ]
369 args += rebase_path(invoker.sources, root_build_dir)
372 generate_enum_outputs = get_target_outputs(":${target_name}__generate_enum")
374 get_label_info(":${target_name}__generate_enum", "target_gen_dir")
376 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
377 zip("${target_name}__zip_srcjar") {
378 inputs = generate_enum_outputs
380 base_dir = base_gen_dir
385 ":${target_name}__zip_srcjar",
390 # Declare a target for processing a Jinja template.
393 # input: The template file to be processed.
394 # output: Where to save the result.
395 # variables: (Optional) A list of variables to make available to the template
396 # processing environment, e.g. ["name=foo", "color=red"].
399 # jinja_template("chrome_shell_manifest") {
400 # input = "shell/java/AndroidManifest.xml"
401 # output = "$target_gen_dir/AndroidManifest.xml"
403 template("jinja_template") {
404 set_sources_assignment_filter([])
405 if (defined(invoker.testonly)) {
406 testonly = invoker.testonly
409 assert(defined(invoker.input))
410 assert(defined(invoker.output))
412 action(target_name) {
416 script = "//build/android/gyp/jinja_template.py"
417 depfile = "$target_gen_dir/$target_name.d"
426 rebase_path(invoker.input, root_build_dir),
428 rebase_path(invoker.output, root_build_dir),
430 rebase_path(depfile, root_build_dir),
432 if (defined(invoker.variables)) {
433 variables = invoker.variables
434 args += [ "--variables=${variables}" ]
439 # Declare a target for processing Android resources as Jinja templates.
441 # This takes an Android resource directory where each resource is a Jinja
442 # template, processes each template, then packages the results in a zip file
443 # which can be consumed by an android resources, library, or apk target.
445 # If this target is included in the deps of an android resources/library/apk,
446 # the resources will be included with that target.
449 # resources: The list of resources files to process.
450 # res_dir: The resource directory containing the resources.
451 # variables: (Optional) A list of variables to make available to the template
452 # processing environment, e.g. ["name=foo", "color=red"].
455 # jinja_template_resources("chrome_shell_template_resources") {
456 # res_dir = "shell/res_template"
457 # resources = ["shell/res_template/xml/syncable.xml"]
458 # variables = ["color=red"]
460 template("jinja_template_resources") {
461 set_sources_assignment_filter([])
462 if (defined(invoker.testonly)) {
463 testonly = invoker.testonly
466 assert(defined(invoker.resources))
467 assert(defined(invoker.res_dir))
469 _base_path = "$target_gen_dir/$target_name"
470 _resources_zip = _base_path + ".resources.zip"
471 _build_config = _base_path + ".build_config"
473 write_build_config("${target_name}__build_config") {
474 build_config = _build_config
475 resources_zip = _resources_zip
476 type = "android_resources"
479 action("${target_name}__template") {
480 sources = invoker.resources
481 script = "//build/android/gyp/jinja_template.py"
482 depfile = "$target_gen_dir/$target_name.d"
489 rebased_resources = rebase_path(invoker.resources, root_build_dir)
491 "--inputs=${rebased_resources}",
493 rebase_path(invoker.res_dir, root_build_dir),
495 rebase_path(_resources_zip, root_build_dir),
497 rebase_path(depfile, root_build_dir),
499 if (defined(invoker.variables)) {
500 variables = invoker.variables
501 args += [ "--variables=${variables}" ]
507 ":${target_name}__build_config",
508 ":${target_name}__template",
513 # Declare an Android resources target
515 # This creates a resources zip file that will be used when building an Android
516 # library or apk and included into a final apk.
518 # To include these resources in a library/apk, this target should be listed in
519 # the library's deps. A library/apk will also include any resources used by its
523 # deps: Specifies the dependencies of this target. Any Android resources
524 # listed in deps will be included by libraries/apks that depend on this
526 # resource_dirs: List of directories containing resources for this target.
527 # android_manifest: AndroidManifest.xml for this target. Defaults to
528 # //build/android/AndroidManifest.xml.
529 # custom_package: java package for generated .java files.
530 # v14_verify_only: If true, don't generate v14/v17 resources and just verify
531 # that the resources are v14-compliant (see
532 # build/android/gyp/generate_v14_compatible_resources.py). Defaults to
534 # shared_resources: If true make a resource package that can be loaded by a
535 # different application at runtime to access the package's resources.
538 # android_resources("foo_resources") {
539 # deps = [":foo_strings_grd"]
540 # resource_dirs = ["res"]
541 # custom_package = "org.chromium.foo"
543 template("android_resources") {
544 set_sources_assignment_filter([])
545 if (defined(invoker.testonly)) {
546 testonly = invoker.testonly
549 assert(defined(invoker.resource_dirs))
550 assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
552 base_path = "$target_gen_dir/$target_name"
553 zip_path = base_path + ".resources.zip"
554 srcjar_path = base_path + ".srcjar"
555 build_config = base_path + ".build_config"
557 write_build_config("${target_name}__build_config") {
558 type = "android_resources"
559 resources_zip = zip_path
561 if (defined(invoker.deps)) {
564 if (defined(invoker.android_manifest)) {
565 android_manifest = invoker.android_manifest
567 if (defined(invoker.custom_package)) {
568 custom_package = invoker.custom_package
572 android_manifest = "//build/android/AndroidManifest.xml"
573 if (defined(invoker.android_manifest)) {
574 android_manifest = invoker.android_manifest
577 process_resources("${target_name}__process_resources") {
578 resource_dirs = invoker.resource_dirs
579 if (defined(invoker.custom_package)) {
580 custom_package = invoker.custom_package
583 if (defined(invoker.v14_verify_only)) {
584 v14_verify_only = invoker.v14_verify_only
587 if (defined(invoker.shared_resources)) {
588 shared_resources = invoker.shared_resources
594 ":${target_name}__build_config",
595 ":${target_name}__process_resources",
600 # Declare a target that generates localized strings.xml from a .grd file.
602 # If this target is included in the deps of an android resources/library/apk,
603 # the strings.xml will be included with that target.
606 # deps: Specifies the dependencies of this target.
607 # grd_file: Path to the .grd file to generate strings.xml from.
608 # outputs: Expected grit outputs (see grit rule).
611 # java_strings_grd("foo_strings_grd") {
612 # grd_file = "foo_strings.grd"
614 template("java_strings_grd") {
615 set_sources_assignment_filter([])
616 if (defined(invoker.testonly)) {
617 testonly = invoker.testonly
620 base_path = "$target_gen_dir/$target_name"
621 resources_zip = base_path + ".resources.zip"
622 build_config = base_path + ".build_config"
624 write_build_config("${target_name}__build_config") {
625 type = "android_resources"
626 if (defined(invoker.deps)) {
631 # Put grit files into this subdirectory of target_gen_dir.
632 extra_output_path = target_name + "_grit_output"
634 grit_target_name = "${target_name}__grit"
635 grit_output_dir = "$target_gen_dir/$extra_output_path"
636 grit(grit_target_name) {
639 "ANDROID_JAVA_TAGGED_ONLY=false",
641 output_dir = grit_output_dir
643 source = invoker.grd_file
644 outputs = invoker.outputs
647 # This needs to get outputs from grit's internal target, not the final
649 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
651 zip("${target_name}__zip") {
652 base_dir = grit_output_dir
653 inputs = generate_strings_outputs
654 output = resources_zip
659 ":${target_name}__build_config",
660 ":${target_name}__zip",
665 # Declare a target that packages strings.xml generated from a grd file.
667 # If this target is included in the deps of an android resources/library/apk,
668 # the strings.xml will be included with that target.
671 # grit_output_dir: directory containing grit-generated files.
672 # generated_files: list of android resource files to package.
675 # java_strings_grd_prebuilt("foo_strings_grd") {
676 # grit_output_dir = "$root_gen_dir/foo/grit"
677 # generated_files = [
678 # "values/strings.xml"
681 template("java_strings_grd_prebuilt") {
682 set_sources_assignment_filter([])
683 if (defined(invoker.testonly)) {
684 testonly = invoker.testonly
687 base_path = "$target_gen_dir/$target_name"
688 resources_zip = base_path + ".resources.zip"
689 build_config = base_path + ".build_config"
691 write_build_config("${target_name}__build_config") {
692 type = "android_resources"
693 if (defined(invoker.deps)) {
698 zip("${target_name}__zip") {
699 base_dir = invoker.grit_output_dir
700 inputs = rebase_path(invoker.generated_files, ".", base_dir)
701 output = resources_zip
706 ":${target_name}__build_config",
707 ":${target_name}__zip",
712 # Declare a Java executable target
714 # This target creates an executable from java code and libraries. The executable
715 # will be in the output folder's /bin/ directory.
718 # deps: Specifies the dependencies of this target. Java targets in this list
719 # will be included in the executable (and the javac classpath).
721 # java_files: List of .java files included in this library.
722 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
723 # will be added to java_files and be included in this library.
724 # srcjars: List of srcjars to be included in this library, together with the
725 # ones obtained from srcjar_deps.
727 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
728 # dependencies for this target. This will allow depending on an
729 # android_library target, for example.
731 # chromium_code: If true, extra analysis warning/errors will be enabled.
736 # java_library("foo") {
737 # java_files = [ "org/chromium/foo/FooMain.java" ]
738 # deps = [ ":bar_java" ]
739 # main_class = "org.chromium.foo.FooMain"
741 template("java_binary") {
742 set_sources_assignment_filter([])
744 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
745 # dependents shouldn't get the jar in their classpath, etc.).
746 java_library_impl(target_name) {
747 if (defined(invoker.DEPRECATED_java_in_dir)) {
748 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
750 if (defined(invoker.chromium_code)) {
751 chromium_code = invoker.chromium_code
753 if (defined(invoker.datadeps)) {
754 deps = invoker.datadeps
756 if (defined(invoker.deps)) {
759 if (defined(invoker.java_files)) {
760 java_files = invoker.java_files
762 if (defined(invoker.srcjar_deps)) {
763 srcjar_deps = invoker.srcjar_deps
765 if (defined(invoker.srcjars)) {
766 srcjars = invoker.srcjars
768 if (defined(invoker.bypass_platform_checks)) {
769 bypass_platform_checks = invoker.bypass_platform_checks
771 if (defined(invoker.testonly)) {
772 testonly = invoker.testonly
775 main_class = invoker.main_class
779 # Declare an java library target
782 # deps: Specifies the dependencies of this target. Java targets in this list
783 # will be added to the javac classpath.
785 # java_files: List of .java files included in this library.
786 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
787 # will be added to java_files and be included in this library.
788 # srcjars: List of srcjars to be included in this library, together with the
789 # ones obtained from srcjar_deps.
790 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
791 # this directory will be included in the library. This is only supported to
792 # ease the gyp->gn conversion and will be removed in the future.
794 # chromium_code: If true, extra analysis warning/errors will be enabled.
795 # jar_excluded_patterns: List of patterns of .class files to exclude from the
798 # proguard_preprocess: If true, proguard preprocessing will be run. This can
799 # be used to remove unwanted parts of the library.
800 # proguard_config: Path to the proguard config for preprocessing.
802 # supports_android: If true, Android targets (android_library, android_apk)
803 # may depend on this target. Note: if true, this target must only use the
804 # subset of Java available on Android.
805 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
806 # dependencies for this target. This will allow depending on an
807 # android_library target, for example.
812 # java_library("foo_java") {
814 # "org/chromium/foo/Foo.java",
815 # "org/chromium/foo/FooInterface.java",
816 # "org/chromium/foo/FooService.java",
822 # ":foo_generated_enum"
824 # jar_excluded_patterns = [
825 # "*/FooService.class", "*/FooService##*.class"
828 template("java_library") {
829 set_sources_assignment_filter([])
830 java_library_impl(target_name) {
831 if (defined(invoker.DEPRECATED_java_in_dir)) {
832 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
834 if (defined(invoker.chromium_code)) {
835 chromium_code = invoker.chromium_code
837 if (defined(invoker.datadeps)) {
838 deps = invoker.datadeps
840 if (defined(invoker.deps)) {
843 if (defined(invoker.jar_excluded_patterns)) {
844 jar_excluded_patterns = invoker.jar_excluded_patterns
846 if (defined(invoker.java_files)) {
847 java_files = invoker.java_files
849 if (defined(invoker.proguard_config)) {
850 proguard_config = invoker.proguard_config
852 if (defined(invoker.proguard_preprocess)) {
853 proguard_preprocess = invoker.proguard_preprocess
855 if (defined(invoker.srcjar_deps)) {
856 srcjar_deps = invoker.srcjar_deps
858 if (defined(invoker.srcjars)) {
859 srcjars = invoker.srcjars
861 if (defined(invoker.bypass_platform_checks)) {
862 bypass_platform_checks = invoker.bypass_platform_checks
864 if (defined(invoker.testonly)) {
865 testonly = invoker.testonly
867 if (defined(invoker.jar_path)) {
868 jar_path = invoker.jar_path
871 if (defined(invoker.supports_android) && invoker.supports_android) {
872 supports_android = true
877 # Declare an java library target for a prebuilt jar
880 # deps: Specifies the dependencies of this target. Java targets in this list
881 # will be added to the javac classpath.
882 # jar_path: Path to the prebuilt jar.
883 # proguard_preprocess: If true, proguard preprocessing will be run. This can
884 # be used to remove unwanted parts of the library.
885 # proguard_config: Path to the proguard config for preprocessing.
888 # java_prebuilt("foo_java") {
889 # jar_path = "foo.jar"
895 template("java_prebuilt") {
896 set_sources_assignment_filter([])
897 java_prebuilt_impl(target_name) {
898 jar_path = invoker.jar_path
899 if (defined(invoker.testonly)) {
900 testonly = invoker.testonly
902 if (defined(invoker.deps)) {
905 if (defined(invoker.proguard_config)) {
906 proguard_config = invoker.proguard_config
908 if (defined(invoker.proguard_preprocess)) {
909 proguard_preprocess = invoker.proguard_preprocess
914 # Declare an Android library target
916 # This target creates an Android library containing java code and Android
920 # deps: Specifies the dependencies of this target. Java targets in this list
921 # will be added to the javac classpath. Android resources in dependencies
922 # will be used when building this library.
924 # java_files: List of .java files included in this library.
925 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
926 # will be added to java_files and be included in this library.
927 # srcjars: List of srcjars to be included in this library, together with the
928 # ones obtained from srcjar_deps.
929 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
930 # this directory will be included in the library. This is only supported to
931 # ease the gyp->gn conversion and will be removed in the future.
933 # chromium_code: If true, extra analysis warning/errors will be enabled.
934 # jar_excluded_patterns: List of patterns of .class files to exclude from the
937 # proguard_preprocess: If true, proguard preprocessing will be run. This can
938 # be used to remove unwanted parts of the library.
939 # proguard_config: Path to the proguard config for preprocessing.
941 # dex_path: If set, the resulting .dex.jar file will be placed under this
946 # android_library("foo_java") {
948 # "android/org/chromium/foo/Foo.java",
949 # "android/org/chromium/foo/FooInterface.java",
950 # "android/org/chromium/foo/FooService.java",
956 # ":foo_generated_enum"
958 # jar_excluded_patterns = [
959 # "*/FooService.class", "*/FooService##*.class"
962 template("android_library") {
963 set_sources_assignment_filter([])
964 assert(!defined(invoker.jar_path),
965 "android_library does not support a custom jar path")
966 java_library_impl(target_name) {
967 if (defined(invoker.DEPRECATED_java_in_dir)) {
968 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
970 if (defined(invoker.chromium_code)) {
971 chromium_code = invoker.chromium_code
973 if (defined(invoker.datadeps)) {
974 deps = invoker.datadeps
976 if (defined(invoker.deps)) {
979 if (defined(invoker.jar_excluded_patterns)) {
980 jar_excluded_patterns = invoker.jar_excluded_patterns
982 if (defined(invoker.java_files)) {
983 java_files = invoker.java_files
985 if (defined(invoker.proguard_config)) {
986 proguard_config = invoker.proguard_config
988 if (defined(invoker.proguard_preprocess)) {
989 proguard_preprocess = invoker.proguard_preprocess
991 if (defined(invoker.srcjar_deps)) {
992 srcjar_deps = invoker.srcjar_deps
994 if (defined(invoker.srcjars)) {
995 srcjars = invoker.srcjars
997 if (defined(invoker.testonly)) {
998 testonly = invoker.testonly
1000 if (defined(invoker.visibility)) {
1001 visibility = invoker.visibility
1003 if (defined(invoker.dex_path)) {
1004 dex_path = invoker.dex_path
1006 if (defined(invoker.manifest_entries)) {
1007 manifest_entries = invoker.manifest_entries
1010 supports_android = true
1011 requires_android = true
1013 if (!defined(jar_excluded_patterns)) {
1014 jar_excluded_patterns = []
1016 jar_excluded_patterns += [
1020 "*/Manifest##*.class",
1025 # Declare a target that packages a set of Java dependencies into a standalone
1029 # deps: specifies the dependencies of this target. Android libraries in deps
1030 # will be packaged into the resulting .dex.jar file.
1031 # dex_path: location at which the output file will be put
1032 template("android_standalone_library") {
1033 set_sources_assignment_filter([])
1034 deps_dex(target_name) {
1036 dex_path = invoker.dex_path
1037 if (defined(invoker.excluded_jars)) {
1038 excluded_jars = invoker.excluded_jars
1043 # Declare an Android library target for a prebuilt jar
1045 # This target creates an Android library containing java code and Android
1049 # deps: Specifies the dependencies of this target. Java targets in this list
1050 # will be added to the javac classpath. Android resources in dependencies
1051 # will be used when building this library.
1052 # jar_path: Path to the prebuilt jar.
1053 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1054 # be used to remove unwanted parts of the library.
1055 # proguard_config: Path to the proguard config for preprocessing.
1058 # android_java_prebuilt("foo_java") {
1059 # jar_path = "foo.jar"
1065 template("android_java_prebuilt") {
1066 set_sources_assignment_filter([])
1067 java_prebuilt_impl(target_name) {
1068 jar_path = invoker.jar_path
1069 supports_android = true
1070 requires_android = true
1071 if (defined(invoker.testonly)) {
1072 testonly = invoker.testonly
1074 if (defined(invoker.deps)) {
1077 if (defined(invoker.proguard_config)) {
1078 proguard_config = invoker.proguard_config
1080 if (defined(invoker.proguard_preprocess)) {
1081 proguard_preprocess = invoker.proguard_preprocess
1086 # Declare an Android apk target
1088 # This target creates an Android APK containing java code, resources, assets,
1089 # and (possibly) native libraries.
1092 # android_manifest: Path to AndroidManifest.xml.
1093 # datadeps: List of dependencies needed at runtime. These will be built but
1094 # won't change the generated .apk in any way (in fact they may be built
1095 # after the .apk is).
1096 # deps: List of dependencies. All Android java resources and libraries in the
1097 # "transitive closure" of these dependencies will be included in the apk.
1098 # Note: this "transitive closure" actually only includes such targets if
1099 # they are depended on through android_library or android_resources targets
1100 # (and so not through builtin targets like 'action', 'group', etc).
1101 # java_files: List of .java files to include in the apk.
1102 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1103 # will be added to java_files and be included in this apk.
1104 # apk_name: Name for final apk.
1105 # final_apk_path: Path to final built apk. Default is
1106 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1107 # native_libs: List paths of native libraries to include in this apk. If these
1108 # libraries depend on other shared_library targets, those dependencies will
1109 # also be included in the apk.
1110 # testonly: Marks this target as "test-only".
1112 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1113 # this directory will be included in the library. This is only supported to
1114 # ease the gyp->gn conversion and will be removed in the future.
1117 # android_apk("foo_apk") {
1118 # android_manifest = "AndroidManifest.xml"
1120 # "android/org/chromium/foo/FooApplication.java",
1121 # "android/org/chromium/foo/FooActivity.java",
1124 # ":foo_support_java"
1128 # ":foo_generated_enum"
1134 template("android_apk") {
1135 set_sources_assignment_filter([])
1136 if (defined(invoker.testonly)) {
1137 testonly = invoker.testonly
1140 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1141 gen_dir = "$target_gen_dir/$target_name"
1142 base_path = "$gen_dir/$target_name"
1143 _build_config = "$base_path.build_config"
1144 resources_zip_path = "$base_path.resources.zip"
1145 all_resources_zip_path = "$base_path.resources.all.zip"
1146 jar_path = "$base_path.jar"
1147 final_dex_path = "$gen_dir/classes.dex"
1148 _template_name = target_name
1149 _final_apk_path = ""
1150 if (defined(invoker.final_apk_path)) {
1151 _final_apk_path = invoker.final_apk_path
1152 } else if (defined(invoker.apk_name)) {
1153 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1155 _dist_jar_path_list =
1156 process_file_template(
1157 [ _final_apk_path ],
1158 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1159 _dist_jar_path = _dist_jar_path_list[0]
1163 _keystore_path = android_default_keystore_path
1164 _keystore_name = android_default_keystore_name
1165 _keystore_password = android_default_keystore_password
1167 if (defined(invoker.keystore_path)) {
1168 _keystore_path = invoker.keystore_path
1169 _keystore_name = invoker.keystore_name
1170 _keystore_password = invoker.keystore_password
1174 if (defined(invoker.srcjar_deps)) {
1175 _srcjar_deps += invoker.srcjar_deps
1178 _load_library_from_apk = false
1180 if (defined(invoker.native_libs)) {
1181 _use_chromium_linker = false
1182 if (defined(invoker.use_chromium_linker)) {
1183 _use_chromium_linker =
1184 invoker.use_chromium_linker && chromium_linker_supported
1187 if (defined(invoker.load_library_from_apk) &&
1188 invoker.load_library_from_apk) {
1189 _load_library_from_apk = true
1190 assert(_use_chromium_linker,
1191 "Loading library from the apk requires use" +
1192 " of the Chromium linker.")
1195 _enable_relocation_packing = false
1196 if (defined(invoker.enable_relocation_packing) &&
1197 invoker.enable_relocation_packing) {
1198 _enable_relocation_packing = relocation_packing_supported
1199 assert(_use_chromium_linker,
1200 "Relocation packing requires use of the" + " Chromium linker.")
1203 _native_libs = process_file_template(
1204 invoker.native_libs,
1205 "$root_build_dir/lib.stripped/{{source_file_part}}")
1207 _native_libs_dir = base_path + "/libs"
1209 if (_use_chromium_linker) {
1211 [ "$root_build_dir/lib.stripped/libchromium_android_linker.so" ]
1214 _enable_relocation_packing = false
1215 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1216 invoker.enable_relocation_packing) {
1217 _enable_relocation_packing = true
1220 _native_lib_version_name = ""
1221 if (defined(invoker.native_lib_version_name)) {
1222 _native_lib_version_name = invoker.native_lib_version_name
1226 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1228 write_build_config("${_template_name}__build_config") {
1229 type = "android_apk"
1230 dex_path = final_dex_path
1231 resources_zip = resources_zip_path
1232 build_config = _build_config
1234 if (defined(invoker.deps)) {
1238 native_libs = _native_libs
1243 final_deps += [ ":${_template_name}__process_resources" ]
1244 process_resources("${_template_name}__process_resources") {
1245 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1246 android_manifest = invoker.android_manifest
1247 resource_dirs = [ "//build/android/ant/empty/res" ]
1248 zip_path = resources_zip_path
1249 generate_constant_ids = true
1250 build_config = _build_config
1252 _srcjar_deps += [ ":${_template_name}__process_resources" ]
1254 if (_native_libs != []) {
1255 _enable_chromium_linker_tests = false
1256 if (defined(invoker.enable_chromium_linker_tests)) {
1257 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1260 java_cpp_template("${_template_name}__native_libraries_java") {
1261 package_name = "org/chromium/base/library_loader"
1263 "//base/android/java/templates/NativeLibraries.template",
1270 "NATIVE_LIBRARIES_LIST=" +
1271 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1272 "NATIVE_LIBRARIES_VERSION_NUMBER=\"$_native_lib_version_name\"",
1274 if (_use_chromium_linker) {
1275 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1277 if (_load_library_from_apk) {
1278 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1280 if (_enable_chromium_linker_tests) {
1281 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1284 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1287 final_deps += [ ":${_template_name}__java" ]
1288 java_library_impl("${_template_name}__java") {
1289 supports_android = true
1290 requires_android = true
1291 override_build_config = _build_config
1292 android_manifest = invoker.android_manifest
1293 chromium_code = true
1294 if (defined(invoker.java_files)) {
1295 java_files = invoker.java_files
1296 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1297 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1301 srcjar_deps = _srcjar_deps
1302 dex_path = base_path + ".dex.jar"
1305 if (_dist_jar_path != "") {
1306 final_deps += [ ":${_template_name}__create_dist_jar" ]
1308 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1309 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1310 # able to just do that calculation at build time instead.
1311 action("${_template_name}__create_dist_jar") {
1312 script = "//build/android/gyp/create_dist_jar.py"
1313 depfile = "$target_gen_dir/$target_name.d"
1323 rebase_path(depfile, root_build_dir),
1325 rebase_path(_dist_jar_path, root_build_dir),
1326 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1328 inputs += [ jar_path ]
1329 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1330 args += [ "--inputs=$_rebased_jar_path" ]
1334 final_deps += [ ":${_template_name}__final_dex" ]
1335 dex("${_template_name}__final_dex") {
1337 ":${_template_name}__java",
1345 output = final_dex_path
1346 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1347 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1350 if (_native_libs != []) {
1351 action("${_template_name}__prepare_native") {
1352 script = "//build/android/gyp/pack_arm_relocations.py"
1353 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1354 depfile = "$target_gen_dir/$target_name.d"
1358 inputs = [ _build_config ] + _native_libs
1360 skip_packing_list = [
1362 "libchromium_android_linker.so",
1365 enable_packing_arg = 0
1366 if (_enable_relocation_packing) {
1367 enable_packing_arg = 1
1368 deps += [ relocation_packer_target ]
1373 rebase_path(depfile, root_build_dir),
1374 "--enable-packing=$enable_packing_arg",
1375 "--has-relocations-with-addends=$relocations_have_addends",
1376 "--exclude-packing-list=$skip_packing_list",
1377 "--android-pack-relocations",
1378 rebase_path(relocation_packer_exe, root_build_dir),
1379 "--android-objcopy",
1380 rebase_path(android_objcopy, root_build_dir),
1381 "--stripped-libraries-dir",
1382 rebase_path(root_build_dir, root_build_dir),
1383 "--packed-libraries-dir",
1384 rebase_path(packed_libraries_dir, root_build_dir),
1385 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1390 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1391 inputs += [ android_gdbserver ]
1392 args += [ "--libraries=$rebased_gdbserver" ]
1397 final_deps += [ ":${_template_name}__create" ]
1398 create_apk("${_template_name}__create") {
1399 apk_path = _final_apk_path
1400 android_manifest = invoker.android_manifest
1401 resources_zip = all_resources_zip_path
1402 dex_path = final_dex_path
1403 load_library_from_apk = _load_library_from_apk
1406 if (defined(invoker.version_code)) {
1407 version_code = invoker.version_code
1410 version_name = "Developer Build"
1411 if (defined(invoker.version_name)) {
1412 version_name = invoker.version_name
1415 keystore_name = _keystore_name
1416 keystore_path = _keystore_path
1417 keystore_password = _keystore_password
1420 if (defined(invoker.asset_location)) {
1421 asset_location = invoker.asset_location
1423 # We don't know the exact dependencies that create the assets in
1424 # |asset_location|; we depend on all caller deps until a better solution
1425 # is figured out (http://crbug.com/433330).
1426 if (defined(invoker.deps)) {
1427 deps += invoker.deps
1431 if (_native_libs != []) {
1432 native_libs_dir = _native_libs_dir
1433 deps += [ ":${_template_name}__prepare_native" ]
1437 group(target_name) {
1439 if (defined(invoker.datadeps)) {
1440 datadeps = invoker.datadeps
1445 # Declare an Android gtest apk
1447 # This target creates an Android apk for running gtest-based unittests.
1450 # deps: Specifies the dependencies of this target. These will be passed to
1451 # the underlying android_apk invocation and should include the java and
1452 # resource dependencies of the apk.
1453 # unittests_dep: This should be the label of the gtest native target. This
1454 # target must be defined previously in the same file.
1455 # unittests_binary: The basename of the library produced by the unittests_dep
1456 # target. If unspecified, it assumes the name of the unittests_dep target
1457 # (which will be correct unless that target specifies an "output_name".
1458 # TODO(brettw) make this automatic by allowing get_target_outputs to
1459 # support executables.
1460 # apk_name: The name of the produced apk. If unspecified, it uses the name
1461 # of the unittests_dep target postfixed with "_apk"
1464 # unittest_apk("foo_unittests_apk") {
1465 # deps = [ ":foo_java", ":foo_resources" ]
1466 # unittests_dep = ":foo_unittests"
1468 template("unittest_apk") {
1469 set_sources_assignment_filter([])
1472 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1474 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1476 # This trivial assert is needed in case both unittests_binary and apk_name
1477 # are defined, as otherwise test_suite_name would not be used.
1478 assert(test_suite_name != "")
1480 if (defined(invoker.unittests_binary)) {
1481 unittests_binary = invoker.unittests_binary
1483 unittests_binary = "lib" + test_suite_name + ".so"
1486 if (defined(invoker.apk_name)) {
1487 apk_name = invoker.apk_name
1489 apk_name = test_suite_name
1492 android_apk(target_name) {
1493 _apk_name = apk_name
1494 final_apk_path = "$root_build_dir/${_apk_name}_apk/${_apk_name}-debug.apk"
1496 "//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java",
1497 "//testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java",
1499 android_manifest = "//testing/android/java/AndroidManifest.xml"
1500 native_libs = [ unittests_binary ]
1501 if (defined(invoker.asset_location)) {
1502 asset_location = invoker.asset_location
1506 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1508 if (defined(invoker.deps)) {
1509 deps += invoker.deps
1512 "//tools/android/forwarder2",
1513 "//tools/android/md5sum",
1515 if (defined(invoker.datadeps)) {
1516 datadeps += invoker.datadeps
1521 # Generate .java files from .aidl files.
1523 # This target will store the .java files in a srcjar and should be included in
1524 # an android_library or android_apk's srcjar_deps.
1527 # sources: Paths to .aidl files to compile.
1528 # import_include: Path to directory containing .java files imported by the
1530 # interface_file: Preprocessed aidl file to import.
1533 # android_aidl("foo_aidl") {
1534 # import_include = "java/src"
1536 # "java/src/com/foo/bar/FooBarService.aidl",
1537 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1540 template("android_aidl") {
1541 set_sources_assignment_filter([])
1542 if (defined(invoker.testonly)) {
1543 testonly = invoker.testonly
1546 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1547 aidl_path = "${android_sdk_build_tools}/aidl"
1548 framework_aidl = "$android_sdk/framework.aidl"
1550 action(target_name) {
1551 script = "//build/android/gyp/aidl.py"
1552 sources = invoker.sources
1554 imports = [ framework_aidl ]
1555 if (defined(invoker.interface_file)) {
1556 assert(invoker.interface_file != "")
1557 imports += [ invoker.interface_file ]
1560 inputs = [ aidl_path ] + imports
1562 depfile = "${target_gen_dir}/${target_name}.d"
1567 rebased_imports = rebase_path(imports, root_build_dir)
1570 rebase_path(depfile, root_build_dir),
1572 rebase_path(aidl_path, root_build_dir),
1573 "--imports=$rebased_imports",
1575 rebase_path(srcjar_path, root_build_dir),
1577 if (defined(invoker.import_include) && invoker.import_include != "") {
1578 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1579 # switch to constructing a depfile for the overall action from that
1580 # instead of having all the .java files in the include paths as inputs.
1581 rebased_import_includes =
1582 rebase_path([ invoker.import_include ], root_build_dir)
1583 args += [ "--includes=$rebased_import_includes" ]
1585 _java_files_build_rel =
1586 exec_script("//build/android/gyp/find.py",
1587 rebase_path([ invoker.import_include ], root_build_dir),
1589 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1590 inputs += _java_files
1592 args += rebase_path(sources, root_build_dir)
1596 # Creates a dist directory for a native executable.
1598 # Running a native executable on a device requires all the shared library
1599 # dependencies of that executable. To make it easier to install and run such an
1600 # executable, this will create a directory containing the native exe and all
1601 # it's library dependencies.
1603 # Note: It's usually better to package things as an APK than as a native
1607 # dist_dir: Directory for the exe and libraries. Everything in this directory
1608 # will be deleted before copying in the exe and libraries.
1609 # binary: Path to (stripped) executable.
1612 # create_native_executable_dist("foo_dist") {
1613 # dist_dir = "$root_build_dir/foo_dist"
1614 # binary = "$root_build_dir/exe.stripped/foo"
1616 template("create_native_executable_dist") {
1617 set_sources_assignment_filter([])
1618 if (defined(invoker.testonly)) {
1619 testonly = invoker.testonly
1622 dist_dir = invoker.dist_dir
1623 binary = invoker.binary
1625 template_name = target_name
1628 "${target_gen_dir}/${template_name}_library_dependencies.list"
1632 #'<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
1635 stripped_libraries_dir = "$root_build_dir/lib.stripped"
1636 final_deps += [ ":${template_name}__find_library_dependencies" ]
1637 action("${template_name}__find_library_dependencies") {
1638 script = "//build/android/gyp/write_ordered_libraries.py"
1639 depfile = "$target_gen_dir/$target_name.d"
1648 rebased_binaries = rebase_path([ binary ], root_build_dir)
1651 rebase_path(depfile, root_build_dir),
1652 "--input-libraries=$rebased_binaries",
1654 rebase_path(stripped_libraries_dir, root_build_dir),
1656 rebase_path(libraries_list, root_build_dir),
1658 rebase_path(android_readelf, root_build_dir),
1662 final_deps += [ ":${template_name}__copy_libraries_and_exe" ]
1663 copy_ex("${template_name}__copy_libraries_and_exe") {
1670 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
1671 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
1673 "--files=$rebased_binaries_list",
1674 "--files=@FileArg($rebased_libraries_list:libraries)",
1678 group(target_name) {
1683 # Compile a protocol buffer to java.
1685 # This generates java files from protocol buffers and creates an Android library
1686 # containing the classes.
1689 # sources: Paths to .proto files to compile.
1690 # proto_path: Root directory of .proto files.
1693 # proto_java_library("foo_proto_java") {
1694 # proto_path = [ "src/foo" ]
1695 # sources = [ "$proto_path/foo.proto" ]
1697 template("proto_java_library") {
1698 set_sources_assignment_filter([])
1699 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
1700 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
1701 _protoc_bin = "$_protoc_out_dir/android_protoc"
1702 _proto_path = invoker.proto_path
1704 _template_name = target_name
1706 action("${_template_name}__protoc_java") {
1707 srcjar_path = "$target_gen_dir/$target_name.srcjar"
1708 script = "//build/protoc_java.py"
1712 sources = invoker.sources
1713 depfile = "$target_gen_dir/$target_name.d"
1720 rebase_path(depfile, root_build_dir),
1722 rebase_path(_protoc_bin, root_build_dir),
1724 rebase_path(_proto_path, root_build_dir),
1726 rebase_path(srcjar_path, root_build_dir),
1727 ] + rebase_path(sources, root_build_dir)
1730 android_library(target_name) {
1732 srcjar_deps = [ ":${_template_name}__protoc_java" ]
1734 "//third_party/android_protobuf:protobuf_nano_javalib",
1739 # TODO(GYP): implement this.
1740 template("uiautomator_test") {
1741 set_sources_assignment_filter([])
1742 if (defined(invoker.testonly)) {
1743 testonly = invoker.testonly
1745 assert(target_name != "")
1746 assert(invoker.deps != [] || true)
1747 group(target_name) {