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 depfile = "$target_gen_dir/$target_name.d"
164 script = "//base/android/jni_generator/jni_generator.py"
167 jni_generator_include,
171 "${jni_output_dir}/${classname}_jni.h",
176 rebase_path(depfile, root_build_dir),
178 rebase_path(jar_file, root_build_dir),
181 "--optimize_generation=1",
184 rebase_path(jni_output_dir, root_build_dir),
186 rebase_path(jni_generator_include, root_build_dir),
187 "--native_exports_optional",
192 config("jni_includes_${target_name}") {
193 include_dirs = [ base_output_dir ]
198 if (defined(invoker.deps)) {
201 if (defined(invoker.public_deps)) {
202 public_deps = invoker.public_deps
204 public_configs = [ ":jni_includes_${target_name}" ]
208 # Declare a target for c-preprocessor-generated java files
210 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
213 # This target generates java files using the host C pre-processor. Each file in
214 # sources will be compiled using the C pre-processor. If include_path is
215 # specified, it will be passed (with --I) to the pre-processor.
217 # This target will create a single .srcjar. Adding this target to an
218 # android_library target's srcjar_deps will make the generated java files be
219 # included in that library's final outputs.
222 # sources: list of files to be processed by the C pre-processor. For each
223 # file in sources, there will be one .java file in the final .srcjar. For a
224 # file named FooBar.template, a java file will be created with name
226 # inputs: additional compile-time dependencies. Any files
227 # `#include`-ed in the templates should be listed here.
228 # package_name: this will be the subdirectory for each .java file in the
232 # java_cpp_template("foo_generated_enum") {
234 # "android/java/templates/Foo.template",
237 # "android/java/templates/native_foo_header.h",
240 # package_name = "org/chromium/base/library_loader"
241 # include_path = "android/java/templates"
243 template("java_cpp_template") {
244 set_sources_assignment_filter([])
245 if (defined(invoker.testonly)) {
246 testonly = invoker.testonly
249 assert(defined(invoker.sources))
250 package_name = invoker.package_name + ""
252 if (defined(invoker.include_path)) {
253 include_path = invoker.include_path + ""
258 action_foreach("${target_name}__apply_gcc") {
259 script = "//build/android/gyp/gcc_preprocess.py"
260 if (defined(invoker.inputs)) {
261 inputs = invoker.inputs + []
263 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
265 sources = invoker.sources
268 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
269 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
273 gcc_template_output_pattern,
278 rebase_path(depfile, root_build_dir),
280 rebase_path(include_path, root_build_dir),
282 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
283 "--template={{source}}",
286 if (defined(invoker.defines)) {
287 foreach(def, invoker.defines) {
296 apply_gcc_outputs = get_target_outputs(":${target_name}__apply_gcc")
297 base_gen_dir = get_label_info(":${target_name}__apply_gcc", "target_gen_dir")
299 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
300 zip("${target_name}__zip_srcjar") {
301 inputs = apply_gcc_outputs
303 base_dir = base_gen_dir
308 ":${target_name}__zip_srcjar",
313 # Declare a target for generating Java classes from C++ enums.
315 # This target generates Java files from C++ enums using a script.
317 # This target will create a single .srcjar. Adding this target to an
318 # android_library target's srcjar_deps will make the generated java files be
319 # included in that library's final outputs.
322 # sources: list of files to be processed by the script. For each annotated
323 # enum contained in the sources files the script will generate a .java
324 # file with the same name as the name of the enum.
326 # outputs: list of outputs, relative to the output_dir. These paths are
327 # verified at build time by the script. To get the list programatically run:
328 # python build/android/gyp/java_cpp_enum.py \
329 # --print_output_only . path/to/header/file.h
332 # java_cpp_enum("foo_generated_enum") {
334 # "src/native_foo_header.h",
337 # "org/chromium/FooEnum.java",
340 template("java_cpp_enum") {
341 set_sources_assignment_filter([])
342 if (defined(invoker.testonly)) {
343 testonly = invoker.testonly
346 assert(defined(invoker.sources))
347 assert(defined(invoker.outputs))
349 action("${target_name}__generate_enum") {
350 # The sources aren't compiled so don't check their dependencies.
351 check_includes = false
353 sources = invoker.sources
354 script = "//build/android/gyp/java_cpp_enum.py"
355 gen_dir = "${target_gen_dir}/${target_name}/enums"
357 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
360 foreach(output, rebase_path(outputs, root_build_dir)) {
366 args += [ rebase_path(gen_dir, root_build_dir) ]
367 args += rebase_path(invoker.sources, root_build_dir)
370 generate_enum_outputs = get_target_outputs(":${target_name}__generate_enum")
372 get_label_info(":${target_name}__generate_enum", "target_gen_dir")
374 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
375 zip("${target_name}__zip_srcjar") {
376 inputs = generate_enum_outputs
378 base_dir = base_gen_dir
383 ":${target_name}__zip_srcjar",
388 # Declare a target for processing a Jinja template.
391 # input: The template file to be processed.
392 # output: Where to save the result.
393 # variables: (Optional) A list of variables to make available to the template
394 # processing environment, e.g. ["name=foo", "color=red"].
397 # jinja_template("chrome_shell_manifest") {
398 # input = "shell/java/AndroidManifest.xml"
399 # output = "$target_gen_dir/AndroidManifest.xml"
401 template("jinja_template") {
402 set_sources_assignment_filter([])
403 if (defined(invoker.testonly)) {
404 testonly = invoker.testonly
407 assert(defined(invoker.input))
408 assert(defined(invoker.output))
410 action(target_name) {
414 script = "//build/android/gyp/jinja_template.py"
415 depfile = "$target_gen_dir/$target_name.d"
424 rebase_path(invoker.input, root_build_dir),
426 rebase_path(invoker.output, root_build_dir),
428 rebase_path(depfile, root_build_dir),
430 if (defined(invoker.variables)) {
431 variables = invoker.variables
432 args += [ "--variables=${variables}" ]
437 # Declare a target for processing Android resources as Jinja templates.
439 # This takes an Android resource directory where each resource is a Jinja
440 # template, processes each template, then packages the results in a zip file
441 # which can be consumed by an android resources, library, or apk target.
443 # If this target is included in the deps of an android resources/library/apk,
444 # the resources will be included with that target.
447 # resources: The list of resources files to process.
448 # res_dir: The resource directory containing the resources.
449 # variables: (Optional) A list of variables to make available to the template
450 # processing environment, e.g. ["name=foo", "color=red"].
453 # jinja_template_resources("chrome_shell_template_resources") {
454 # res_dir = "shell/res_template"
455 # resources = ["shell/res_template/xml/syncable.xml"]
456 # variables = ["color=red"]
458 template("jinja_template_resources") {
459 set_sources_assignment_filter([])
460 if (defined(invoker.testonly)) {
461 testonly = invoker.testonly
464 assert(defined(invoker.resources))
465 assert(defined(invoker.res_dir))
467 _base_path = "$target_gen_dir/$target_name"
468 _resources_zip = _base_path + ".resources.zip"
469 _build_config = _base_path + ".build_config"
471 write_build_config("${target_name}__build_config") {
472 build_config = _build_config
473 resources_zip = _resources_zip
474 type = "android_resources"
477 action("${target_name}__template") {
478 sources = invoker.resources
479 script = "//build/android/gyp/jinja_template.py"
480 depfile = "$target_gen_dir/$target_name.d"
487 rebased_resources = rebase_path(invoker.resources, root_build_dir)
489 "--inputs=${rebased_resources}",
491 rebase_path(invoker.res_dir, root_build_dir),
493 rebase_path(_resources_zip, root_build_dir),
495 rebase_path(depfile, root_build_dir),
497 if (defined(invoker.variables)) {
498 variables = invoker.variables
499 args += [ "--variables=${variables}" ]
505 ":${target_name}__build_config",
506 ":${target_name}__template",
511 # Declare an Android resources target
513 # This creates a resources zip file that will be used when building an Android
514 # library or apk and included into a final apk.
516 # To include these resources in a library/apk, this target should be listed in
517 # the library's deps. A library/apk will also include any resources used by its
521 # deps: Specifies the dependencies of this target. Any Android resources
522 # listed in deps will be included by libraries/apks that depend on this
524 # resource_dirs: List of directories containing resources for this target.
525 # android_manifest: AndroidManifest.xml for this target. Defaults to
526 # //build/android/AndroidManifest.xml.
527 # custom_package: java package for generated .java files.
528 # v14_verify_only: If true, don't generate v14/v17 resources and just verify
529 # that the resources are v14-compliant (see
530 # build/android/gyp/generate_v14_compatible_resources.py). Defaults to
532 # shared_resources: If true make a resource package that can be loaded by a
533 # different application at runtime to access the package's resources.
536 # android_resources("foo_resources") {
537 # deps = [":foo_strings_grd"]
538 # resource_dirs = ["res"]
539 # custom_package = "org.chromium.foo"
541 template("android_resources") {
542 set_sources_assignment_filter([])
543 if (defined(invoker.testonly)) {
544 testonly = invoker.testonly
547 assert(defined(invoker.resource_dirs))
548 assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
550 base_path = "$target_gen_dir/$target_name"
551 zip_path = base_path + ".resources.zip"
552 srcjar_path = base_path + ".srcjar"
553 build_config = base_path + ".build_config"
555 write_build_config("${target_name}__build_config") {
556 type = "android_resources"
557 resources_zip = zip_path
559 if (defined(invoker.deps)) {
562 if (defined(invoker.android_manifest)) {
563 android_manifest = invoker.android_manifest
565 if (defined(invoker.custom_package)) {
566 custom_package = invoker.custom_package
570 android_manifest = "//build/android/AndroidManifest.xml"
571 if (defined(invoker.android_manifest)) {
572 android_manifest = invoker.android_manifest
575 process_resources("${target_name}__process_resources") {
576 resource_dirs = invoker.resource_dirs
577 if (defined(invoker.custom_package)) {
578 custom_package = invoker.custom_package
581 if (defined(invoker.v14_verify_only)) {
582 v14_verify_only = invoker.v14_verify_only
585 if (defined(invoker.shared_resources)) {
586 shared_resources = invoker.shared_resources
592 ":${target_name}__build_config",
593 ":${target_name}__process_resources",
598 # Declare a target that generates localized strings.xml from a .grd file.
600 # If this target is included in the deps of an android resources/library/apk,
601 # the strings.xml will be included with that target.
604 # deps: Specifies the dependencies of this target.
605 # grd_file: Path to the .grd file to generate strings.xml from.
606 # outputs: Expected grit outputs (see grit rule).
609 # java_strings_grd("foo_strings_grd") {
610 # grd_file = "foo_strings.grd"
612 template("java_strings_grd") {
613 set_sources_assignment_filter([])
614 if (defined(invoker.testonly)) {
615 testonly = invoker.testonly
618 base_path = "$target_gen_dir/$target_name"
619 resources_zip = base_path + ".resources.zip"
620 build_config = base_path + ".build_config"
622 write_build_config("${target_name}__build_config") {
623 type = "android_resources"
624 if (defined(invoker.deps)) {
629 # Put grit files into this subdirectory of target_gen_dir.
630 extra_output_path = target_name + "_grit_output"
632 grit_target_name = "${target_name}__grit"
633 grit_output_dir = "$target_gen_dir/$extra_output_path"
634 grit(grit_target_name) {
637 "ANDROID_JAVA_TAGGED_ONLY=false",
639 output_dir = grit_output_dir
641 source = invoker.grd_file
642 outputs = invoker.outputs
645 # This needs to get outputs from grit's internal target, not the final
647 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
649 zip("${target_name}__zip") {
650 base_dir = grit_output_dir
651 inputs = generate_strings_outputs
652 output = resources_zip
657 ":${target_name}__build_config",
658 ":${target_name}__zip",
663 # Declare a target that packages strings.xml generated from a grd file.
665 # If this target is included in the deps of an android resources/library/apk,
666 # the strings.xml will be included with that target.
669 # grit_output_dir: directory containing grit-generated files.
670 # generated_files: list of android resource files to package.
673 # java_strings_grd_prebuilt("foo_strings_grd") {
674 # grit_output_dir = "$root_gen_dir/foo/grit"
675 # generated_files = [
676 # "values/strings.xml"
679 template("java_strings_grd_prebuilt") {
680 set_sources_assignment_filter([])
681 if (defined(invoker.testonly)) {
682 testonly = invoker.testonly
685 base_path = "$target_gen_dir/$target_name"
686 resources_zip = base_path + ".resources.zip"
687 build_config = base_path + ".build_config"
689 write_build_config("${target_name}__build_config") {
690 type = "android_resources"
691 if (defined(invoker.deps)) {
696 zip("${target_name}__zip") {
697 base_dir = invoker.grit_output_dir
698 inputs = rebase_path(invoker.generated_files, ".", base_dir)
699 output = resources_zip
704 ":${target_name}__build_config",
705 ":${target_name}__zip",
710 # Declare a Java executable target
712 # This target creates an executable from java code and libraries. The executable
713 # will be in the output folder's /bin/ directory.
716 # deps: Specifies the dependencies of this target. Java targets in this list
717 # will be included in the executable (and the javac classpath).
719 # java_files: List of .java files included in this library.
720 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
721 # will be added to java_files and be included in this library.
722 # srcjars: List of srcjars to be included in this library, together with the
723 # ones obtained from srcjar_deps.
725 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
726 # dependencies for this target. This will allow depending on an
727 # android_library target, for example.
729 # chromium_code: If true, extra analysis warning/errors will be enabled.
734 # java_library("foo") {
735 # java_files = [ "org/chromium/foo/FooMain.java" ]
736 # deps = [ ":bar_java" ]
737 # main_class = "org.chromium.foo.FooMain"
739 template("java_binary") {
740 set_sources_assignment_filter([])
742 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
743 # dependents shouldn't get the jar in their classpath, etc.).
744 java_library_impl(target_name) {
745 if (defined(invoker.DEPRECATED_java_in_dir)) {
746 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
748 if (defined(invoker.chromium_code)) {
749 chromium_code = invoker.chromium_code
751 if (defined(invoker.datadeps)) {
752 deps = invoker.datadeps
754 if (defined(invoker.deps)) {
757 if (defined(invoker.java_files)) {
758 java_files = invoker.java_files
760 if (defined(invoker.srcjar_deps)) {
761 srcjar_deps = invoker.srcjar_deps
763 if (defined(invoker.srcjars)) {
764 srcjars = invoker.srcjars
766 if (defined(invoker.bypass_platform_checks)) {
767 bypass_platform_checks = invoker.bypass_platform_checks
769 if (defined(invoker.testonly)) {
770 testonly = invoker.testonly
773 main_class = invoker.main_class
777 # Declare an java library target
780 # deps: Specifies the dependencies of this target. Java targets in this list
781 # will be added to the javac classpath.
783 # java_files: List of .java files included in this library.
784 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
785 # will be added to java_files and be included in this library.
786 # srcjars: List of srcjars to be included in this library, together with the
787 # ones obtained from srcjar_deps.
788 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
789 # this directory will be included in the library. This is only supported to
790 # ease the gyp->gn conversion and will be removed in the future.
792 # chromium_code: If true, extra analysis warning/errors will be enabled.
793 # jar_excluded_patterns: List of patterns of .class files to exclude from the
796 # proguard_preprocess: If true, proguard preprocessing will be run. This can
797 # be used to remove unwanted parts of the library.
798 # proguard_config: Path to the proguard config for preprocessing.
800 # supports_android: If true, Android targets (android_library, android_apk)
801 # may depend on this target. Note: if true, this target must only use the
802 # subset of Java available on Android.
803 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
804 # dependencies for this target. This will allow depending on an
805 # android_library target, for example.
810 # java_library("foo_java") {
812 # "org/chromium/foo/Foo.java",
813 # "org/chromium/foo/FooInterface.java",
814 # "org/chromium/foo/FooService.java",
820 # ":foo_generated_enum"
822 # jar_excluded_patterns = [
823 # "*/FooService.class", "*/FooService##*.class"
826 template("java_library") {
827 set_sources_assignment_filter([])
828 java_library_impl(target_name) {
829 if (defined(invoker.DEPRECATED_java_in_dir)) {
830 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
832 if (defined(invoker.chromium_code)) {
833 chromium_code = invoker.chromium_code
835 if (defined(invoker.datadeps)) {
836 deps = invoker.datadeps
838 if (defined(invoker.deps)) {
841 if (defined(invoker.jar_excluded_patterns)) {
842 jar_excluded_patterns = invoker.jar_excluded_patterns
844 if (defined(invoker.java_files)) {
845 java_files = invoker.java_files
847 if (defined(invoker.proguard_config)) {
848 proguard_config = invoker.proguard_config
850 if (defined(invoker.proguard_preprocess)) {
851 proguard_preprocess = invoker.proguard_preprocess
853 if (defined(invoker.srcjar_deps)) {
854 srcjar_deps = invoker.srcjar_deps
856 if (defined(invoker.srcjars)) {
857 srcjars = invoker.srcjars
859 if (defined(invoker.bypass_platform_checks)) {
860 bypass_platform_checks = invoker.bypass_platform_checks
862 if (defined(invoker.testonly)) {
863 testonly = invoker.testonly
865 if (defined(invoker.jar_path)) {
866 jar_path = invoker.jar_path
869 if (defined(invoker.supports_android) && invoker.supports_android) {
870 supports_android = true
875 # Declare an java library target for a prebuilt jar
878 # deps: Specifies the dependencies of this target. Java targets in this list
879 # will be added to the javac classpath.
880 # jar_path: Path to the prebuilt jar.
881 # proguard_preprocess: If true, proguard preprocessing will be run. This can
882 # be used to remove unwanted parts of the library.
883 # proguard_config: Path to the proguard config for preprocessing.
886 # java_prebuilt("foo_java") {
887 # jar_path = "foo.jar"
893 template("java_prebuilt") {
894 set_sources_assignment_filter([])
895 java_prebuilt_impl(target_name) {
896 jar_path = invoker.jar_path
897 if (defined(invoker.testonly)) {
898 testonly = invoker.testonly
900 if (defined(invoker.deps)) {
903 if (defined(invoker.proguard_config)) {
904 proguard_config = invoker.proguard_config
906 if (defined(invoker.proguard_preprocess)) {
907 proguard_preprocess = invoker.proguard_preprocess
912 # Declare an Android library target
914 # This target creates an Android library containing java code and Android
918 # deps: Specifies the dependencies of this target. Java targets in this list
919 # will be added to the javac classpath. Android resources in dependencies
920 # will be used when building this library.
922 # java_files: List of .java files included in this library.
923 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
924 # will be added to java_files and be included in this library.
925 # srcjars: List of srcjars to be included in this library, together with the
926 # ones obtained from srcjar_deps.
927 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
928 # this directory will be included in the library. This is only supported to
929 # ease the gyp->gn conversion and will be removed in the future.
931 # chromium_code: If true, extra analysis warning/errors will be enabled.
932 # jar_excluded_patterns: List of patterns of .class files to exclude from the
935 # proguard_preprocess: If true, proguard preprocessing will be run. This can
936 # be used to remove unwanted parts of the library.
937 # proguard_config: Path to the proguard config for preprocessing.
939 # dex_path: If set, the resulting .dex.jar file will be placed under this
944 # android_library("foo_java") {
946 # "android/org/chromium/foo/Foo.java",
947 # "android/org/chromium/foo/FooInterface.java",
948 # "android/org/chromium/foo/FooService.java",
954 # ":foo_generated_enum"
956 # jar_excluded_patterns = [
957 # "*/FooService.class", "*/FooService##*.class"
960 template("android_library") {
961 set_sources_assignment_filter([])
962 assert(!defined(invoker.jar_path),
963 "android_library does not support a custom jar path")
964 java_library_impl(target_name) {
965 if (defined(invoker.DEPRECATED_java_in_dir)) {
966 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
968 if (defined(invoker.chromium_code)) {
969 chromium_code = invoker.chromium_code
971 if (defined(invoker.datadeps)) {
972 deps = invoker.datadeps
974 if (defined(invoker.deps)) {
977 if (defined(invoker.jar_excluded_patterns)) {
978 jar_excluded_patterns = invoker.jar_excluded_patterns
980 if (defined(invoker.java_files)) {
981 java_files = invoker.java_files
983 if (defined(invoker.proguard_config)) {
984 proguard_config = invoker.proguard_config
986 if (defined(invoker.proguard_preprocess)) {
987 proguard_preprocess = invoker.proguard_preprocess
989 if (defined(invoker.srcjar_deps)) {
990 srcjar_deps = invoker.srcjar_deps
992 if (defined(invoker.srcjars)) {
993 srcjars = invoker.srcjars
995 if (defined(invoker.testonly)) {
996 testonly = invoker.testonly
998 if (defined(invoker.visibility)) {
999 visibility = invoker.visibility
1001 if (defined(invoker.dex_path)) {
1002 dex_path = invoker.dex_path
1004 if (defined(invoker.manifest_entries)) {
1005 manifest_entries = invoker.manifest_entries
1008 supports_android = true
1009 requires_android = true
1011 if (!defined(jar_excluded_patterns)) {
1012 jar_excluded_patterns = []
1014 jar_excluded_patterns += [
1018 "*/Manifest##*.class",
1023 # Declare a target that packages a set of Java dependencies into a standalone
1027 # deps: specifies the dependencies of this target. Android libraries in deps
1028 # will be packaged into the resulting .dex.jar file.
1029 # dex_path: location at which the output file will be put
1030 template("android_standalone_library") {
1031 set_sources_assignment_filter([])
1032 deps_dex(target_name) {
1034 dex_path = invoker.dex_path
1035 if (defined(invoker.excluded_jars)) {
1036 excluded_jars = invoker.excluded_jars
1041 # Declare an Android library target for a prebuilt jar
1043 # This target creates an Android library containing java code and Android
1047 # deps: Specifies the dependencies of this target. Java targets in this list
1048 # will be added to the javac classpath. Android resources in dependencies
1049 # will be used when building this library.
1050 # jar_path: Path to the prebuilt jar.
1051 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1052 # be used to remove unwanted parts of the library.
1053 # proguard_config: Path to the proguard config for preprocessing.
1056 # android_java_prebuilt("foo_java") {
1057 # jar_path = "foo.jar"
1063 template("android_java_prebuilt") {
1064 set_sources_assignment_filter([])
1065 java_prebuilt_impl(target_name) {
1066 jar_path = invoker.jar_path
1067 supports_android = true
1068 requires_android = true
1069 if (defined(invoker.testonly)) {
1070 testonly = invoker.testonly
1072 if (defined(invoker.deps)) {
1075 if (defined(invoker.proguard_config)) {
1076 proguard_config = invoker.proguard_config
1078 if (defined(invoker.proguard_preprocess)) {
1079 proguard_preprocess = invoker.proguard_preprocess
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 # datadeps: List of dependencies needed at runtime. These will be built but
1092 # won't change the generated .apk in any way (in fact they may be built
1093 # after the .apk is).
1094 # deps: List of dependencies. All Android java resources and libraries in the
1095 # "transitive closure" of these dependencies will be included in the apk.
1096 # Note: this "transitive closure" actually only includes such targets if
1097 # they are depended on through android_library or android_resources targets
1098 # (and so not through builtin targets like 'action', 'group', etc).
1099 # java_files: List of .java files to include in the apk.
1100 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1101 # will be added to java_files and be included in this apk.
1102 # apk_name: Name for final apk.
1103 # final_apk_path: Path to final built apk. Default is
1104 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1105 # native_libs: List paths of native libraries to include in this apk. If these
1106 # libraries depend on other shared_library targets, those dependencies will
1107 # also be included in the apk.
1108 # testonly: Marks this target as "test-only".
1110 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1111 # this directory will be included in the library. This is only supported to
1112 # ease the gyp->gn conversion and will be removed in the future.
1115 # android_apk("foo_apk") {
1116 # android_manifest = "AndroidManifest.xml"
1118 # "android/org/chromium/foo/FooApplication.java",
1119 # "android/org/chromium/foo/FooActivity.java",
1122 # ":foo_support_java"
1126 # ":foo_generated_enum"
1132 template("android_apk") {
1133 set_sources_assignment_filter([])
1134 if (defined(invoker.testonly)) {
1135 testonly = invoker.testonly
1138 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1139 gen_dir = "$target_gen_dir/$target_name"
1140 base_path = "$gen_dir/$target_name"
1141 _build_config = "$base_path.build_config"
1142 resources_zip_path = "$base_path.resources.zip"
1143 all_resources_zip_path = "$base_path.resources.all.zip"
1144 jar_path = "$base_path.jar"
1145 final_dex_path = "$gen_dir/classes.dex"
1146 _template_name = target_name
1147 _final_apk_path = ""
1148 if (defined(invoker.final_apk_path)) {
1149 _final_apk_path = invoker.final_apk_path
1150 } else if (defined(invoker.apk_name)) {
1151 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1153 _dist_jar_path_list =
1154 process_file_template(
1155 [ _final_apk_path ],
1156 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1157 _dist_jar_path = _dist_jar_path_list[0]
1161 _keystore_path = android_default_keystore_path
1162 _keystore_name = android_default_keystore_name
1163 _keystore_password = android_default_keystore_password
1165 if (defined(invoker.keystore_path)) {
1166 _keystore_path = invoker.keystore_path
1167 _keystore_name = invoker.keystore_name
1168 _keystore_password = invoker.keystore_password
1172 if (defined(invoker.srcjar_deps)) {
1173 _srcjar_deps += invoker.srcjar_deps
1176 _load_library_from_apk = false
1178 if (defined(invoker.native_libs)) {
1179 _use_chromium_linker = false
1180 if (defined(invoker.use_chromium_linker)) {
1181 _use_chromium_linker =
1182 invoker.use_chromium_linker && chromium_linker_supported
1185 if (defined(invoker.load_library_from_apk) &&
1186 invoker.load_library_from_apk) {
1187 _load_library_from_apk = true
1188 assert(_use_chromium_linker,
1189 "Loading library from the apk requires use" +
1190 " of the Chromium linker.")
1193 _enable_relocation_packing = false
1194 if (defined(invoker.enable_relocation_packing) &&
1195 invoker.enable_relocation_packing) {
1196 _enable_relocation_packing = relocation_packing_supported
1197 assert(_use_chromium_linker,
1198 "Relocation packing requires use of the" + " Chromium linker.")
1201 _native_libs = process_file_template(
1202 invoker.native_libs,
1203 "$root_build_dir/lib.stripped/{{source_file_part}}")
1205 _native_libs_dir = base_path + "/libs"
1207 if (_use_chromium_linker) {
1209 [ "$root_build_dir/lib.stripped/libchromium_android_linker.so" ]
1212 _enable_relocation_packing = false
1213 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1214 invoker.enable_relocation_packing) {
1215 _enable_relocation_packing = true
1219 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1221 write_build_config("${_template_name}__build_config") {
1222 type = "android_apk"
1223 dex_path = final_dex_path
1224 resources_zip = resources_zip_path
1225 build_config = _build_config
1227 if (defined(invoker.deps)) {
1231 native_libs = _native_libs
1236 final_deps += [ ":${_template_name}__process_resources" ]
1237 process_resources("${_template_name}__process_resources") {
1238 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1239 android_manifest = invoker.android_manifest
1240 resource_dirs = [ "//build/android/ant/empty/res" ]
1241 zip_path = resources_zip_path
1242 generate_constant_ids = true
1243 build_config = _build_config
1245 _srcjar_deps += [ ":${_template_name}__process_resources" ]
1247 if (_native_libs != []) {
1248 _enable_chromium_linker_tests = false
1249 if (defined(invoker.enable_chromium_linker_tests)) {
1250 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1253 _native_lib_version_name = ""
1255 java_cpp_template("${_template_name}__native_libraries_java") {
1256 package_name = "org/chromium/base/library_loader"
1258 "//base/android/java/templates/NativeLibraries.template",
1265 "NATIVE_LIBRARIES_LIST=" +
1266 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1267 "NATIVE_LIBRARIES_VERSION_NUMBER=\"$_native_lib_version_name\"",
1269 if (_use_chromium_linker) {
1270 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1272 if (_load_library_from_apk) {
1273 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1275 if (_enable_chromium_linker_tests) {
1276 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1279 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1282 final_deps += [ ":${_template_name}__java" ]
1283 java_library_impl("${_template_name}__java") {
1284 supports_android = true
1285 requires_android = true
1286 override_build_config = _build_config
1287 android_manifest = invoker.android_manifest
1288 chromium_code = true
1289 if (defined(invoker.java_files)) {
1290 java_files = invoker.java_files
1291 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1292 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1296 srcjar_deps = _srcjar_deps
1297 dex_path = base_path + ".dex.jar"
1300 if (_dist_jar_path != "") {
1301 final_deps += [ ":${_template_name}__create_dist_jar" ]
1303 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1304 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1305 # able to just do that calculation at build time instead.
1306 action("${_template_name}__create_dist_jar") {
1307 script = "//build/android/gyp/create_dist_jar.py"
1308 depfile = "$target_gen_dir/$target_name.d"
1318 rebase_path(depfile, root_build_dir),
1320 rebase_path(_dist_jar_path, root_build_dir),
1321 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1323 inputs += [ jar_path ]
1324 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1325 args += [ "--inputs=$_rebased_jar_path" ]
1329 final_deps += [ ":${_template_name}__final_dex" ]
1330 dex("${_template_name}__final_dex") {
1332 ":${_template_name}__java",
1340 output = final_dex_path
1341 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1342 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1345 if (_native_libs != []) {
1346 action("${_template_name}__prepare_native") {
1347 script = "//build/android/gyp/pack_arm_relocations.py"
1348 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1349 depfile = "$target_gen_dir/$target_name.d"
1353 inputs = [ _build_config ] + _native_libs
1355 skip_packing_list = [
1357 "libchromium_android_linker.so",
1360 enable_packing_arg = 0
1361 if (_enable_relocation_packing) {
1362 enable_packing_arg = 1
1363 deps += [ relocation_packer_target ]
1368 rebase_path(depfile, root_build_dir),
1369 "--enable-packing=$enable_packing_arg",
1370 "--has-relocations-with-addends=$relocations_have_addends",
1371 "--exclude-packing-list=$skip_packing_list",
1372 "--android-pack-relocations",
1373 rebase_path(relocation_packer_exe, root_build_dir),
1374 "--android-objcopy",
1375 rebase_path(android_objcopy, root_build_dir),
1376 "--stripped-libraries-dir",
1377 rebase_path(root_build_dir, root_build_dir),
1378 "--packed-libraries-dir",
1379 rebase_path(packed_libraries_dir, root_build_dir),
1380 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1385 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1386 inputs += [ android_gdbserver ]
1387 args += [ "--libraries=$rebased_gdbserver" ]
1392 final_deps += [ ":${_template_name}__create" ]
1393 create_apk("${_template_name}__create") {
1394 apk_path = _final_apk_path
1395 android_manifest = invoker.android_manifest
1396 resources_zip = all_resources_zip_path
1397 dex_path = final_dex_path
1398 load_library_from_apk = _load_library_from_apk
1401 if (defined(invoker.version_code)) {
1402 version_code = invoker.version_code
1405 version_name = "Developer Build"
1406 if (defined(invoker.version_name)) {
1407 version_name = invoker.version_name
1410 keystore_name = _keystore_name
1411 keystore_path = _keystore_path
1412 keystore_password = _keystore_password
1415 if (defined(invoker.asset_location)) {
1416 asset_location = invoker.asset_location
1418 # We don't know the exact dependencies that create the assets in
1419 # |asset_location|; we depend on all caller deps until a better solution
1420 # is figured out (http://crbug.com/433330).
1421 if (defined(invoker.deps)) {
1422 deps += invoker.deps
1426 if (_native_libs != []) {
1427 native_libs_dir = _native_libs_dir
1428 deps += [ ":${_template_name}__prepare_native" ]
1432 group(target_name) {
1434 if (defined(invoker.datadeps)) {
1435 datadeps = invoker.datadeps
1440 # Declare an Android gtest apk
1442 # This target creates an Android apk for running gtest-based unittests.
1445 # deps: Specifies the dependencies of this target. These will be passed to
1446 # the underlying android_apk invocation and should include the java and
1447 # resource dependencies of the apk.
1448 # unittests_dep: This should be the label of the gtest native target. This
1449 # target must be defined previously in the same file.
1450 # unittests_binary: The basename of the library produced by the unittests_dep
1451 # target. If unspecified, it assumes the name of the unittests_dep target
1452 # (which will be correct unless that target specifies an "output_name".
1453 # TODO(brettw) make this automatic by allowing get_target_outputs to
1454 # support executables.
1455 # apk_name: The name of the produced apk. If unspecified, it uses the name
1456 # of the unittests_dep target postfixed with "_apk"
1459 # unittest_apk("foo_unittests_apk") {
1460 # deps = [ ":foo_java", ":foo_resources" ]
1461 # unittests_dep = ":foo_unittests"
1463 template("unittest_apk") {
1464 set_sources_assignment_filter([])
1467 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1469 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1471 # This trivial assert is needed in case both unittests_binary and apk_name
1472 # are defined, as otherwise test_suite_name would not be used.
1473 assert(test_suite_name != "")
1475 if (defined(invoker.unittests_binary)) {
1476 unittests_binary = invoker.unittests_binary
1478 unittests_binary = "lib" + test_suite_name + ".so"
1481 if (defined(invoker.apk_name)) {
1482 apk_name = invoker.apk_name
1484 apk_name = test_suite_name
1487 android_apk(target_name) {
1488 _apk_name = apk_name
1489 final_apk_path = "$root_build_dir/${_apk_name}_apk/${_apk_name}-debug.apk"
1491 "//testing/android/java/src/org/chromium/native_test/ChromeNativeTestActivity.java",
1492 "//testing/android/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java",
1494 android_manifest = "//testing/android/java/AndroidManifest.xml"
1495 native_libs = [ unittests_binary ]
1496 if (defined(invoker.asset_location)) {
1497 asset_location = invoker.asset_location
1501 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1503 if (defined(invoker.deps)) {
1504 deps += invoker.deps
1507 "//tools/android/forwarder2",
1508 "//tools/android/md5sum",
1510 if (defined(invoker.datadeps)) {
1511 datadeps += invoker.datadeps
1516 # Generate .java files from .aidl files.
1518 # This target will store the .java files in a srcjar and should be included in
1519 # an android_library or android_apk's srcjar_deps.
1522 # sources: Paths to .aidl files to compile.
1523 # import_include: Path to directory containing .java files imported by the
1525 # interface_file: Preprocessed aidl file to import.
1528 # android_aidl("foo_aidl") {
1529 # import_include = "java/src"
1531 # "java/src/com/foo/bar/FooBarService.aidl",
1532 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1535 template("android_aidl") {
1536 set_sources_assignment_filter([])
1537 if (defined(invoker.testonly)) {
1538 testonly = invoker.testonly
1541 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1542 aidl_path = "${android_sdk_build_tools}/aidl"
1543 framework_aidl = "$android_sdk/framework.aidl"
1545 action(target_name) {
1546 script = "//build/android/gyp/aidl.py"
1547 sources = invoker.sources
1549 imports = [ framework_aidl ]
1550 if (defined(invoker.interface_file)) {
1551 assert(invoker.interface_file != "")
1552 imports += [ invoker.interface_file ]
1555 inputs = [ aidl_path ] + imports
1557 depfile = "${target_gen_dir}/${target_name}.d"
1562 rebased_imports = rebase_path(imports, root_build_dir)
1565 rebase_path(depfile, root_build_dir),
1567 rebase_path(aidl_path, root_build_dir),
1568 "--imports=$rebased_imports",
1570 rebase_path(srcjar_path, root_build_dir),
1572 if (defined(invoker.import_include) && invoker.import_include != "") {
1573 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1574 # switch to constructing a depfile for the overall action from that
1575 # instead of having all the .java files in the include paths as inputs.
1576 rebased_import_includes =
1577 rebase_path([ invoker.import_include ], root_build_dir)
1578 args += [ "--includes=$rebased_import_includes" ]
1580 _java_files_build_rel =
1581 exec_script("//build/android/gyp/find.py",
1582 rebase_path([ invoker.import_include ], root_build_dir),
1584 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1585 inputs += _java_files
1587 args += rebase_path(sources, root_build_dir)
1591 # Creates a dist directory for a native executable.
1593 # Running a native executable on a device requires all the shared library
1594 # dependencies of that executable. To make it easier to install and run such an
1595 # executable, this will create a directory containing the native exe and all
1596 # it's library dependencies.
1598 # Note: It's usually better to package things as an APK than as a native
1602 # dist_dir: Directory for the exe and libraries. Everything in this directory
1603 # will be deleted before copying in the exe and libraries.
1604 # binary: Path to (stripped) executable.
1607 # create_native_executable_dist("foo_dist") {
1608 # dist_dir = "$root_build_dir/foo_dist"
1609 # binary = "$root_build_dir/exe.stripped/foo"
1611 template("create_native_executable_dist") {
1612 set_sources_assignment_filter([])
1613 if (defined(invoker.testonly)) {
1614 testonly = invoker.testonly
1617 dist_dir = invoker.dist_dir
1618 binary = invoker.binary
1620 template_name = target_name
1623 "${target_gen_dir}/${template_name}_library_dependencies.list"
1627 #'<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
1630 stripped_libraries_dir = "$root_build_dir/lib.stripped"
1631 final_deps += [ ":${template_name}__find_library_dependencies" ]
1632 action("${template_name}__find_library_dependencies") {
1633 script = "//build/android/gyp/write_ordered_libraries.py"
1634 depfile = "$target_gen_dir/$target_name.d"
1643 rebased_binaries = rebase_path([ binary ], root_build_dir)
1646 rebase_path(depfile, root_build_dir),
1647 "--input-libraries=$rebased_binaries",
1649 rebase_path(stripped_libraries_dir, root_build_dir),
1651 rebase_path(libraries_list, root_build_dir),
1653 rebase_path(android_readelf, root_build_dir),
1657 final_deps += [ ":${template_name}__copy_libraries_and_exe" ]
1658 copy_ex("${template_name}__copy_libraries_and_exe") {
1665 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
1666 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
1668 "--files=$rebased_binaries_list",
1669 "--files=@FileArg($rebased_libraries_list:libraries)",
1673 group(target_name) {
1678 # Compile a protocol buffer to java.
1680 # This generates java files from protocol buffers and creates an Android library
1681 # containing the classes.
1684 # sources: Paths to .proto files to compile.
1685 # proto_path: Root directory of .proto files.
1688 # proto_java_library("foo_proto_java") {
1689 # proto_path = [ "src/foo" ]
1690 # sources = [ "$proto_path/foo.proto" ]
1692 template("proto_java_library") {
1693 set_sources_assignment_filter([])
1694 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
1695 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
1696 _protoc_bin = "$_protoc_out_dir/android_protoc"
1697 _proto_path = invoker.proto_path
1699 _template_name = target_name
1701 action("${_template_name}__protoc_java") {
1702 srcjar_path = "$target_gen_dir/$target_name.srcjar"
1703 script = "//build/protoc_java.py"
1707 sources = invoker.sources
1708 depfile = "$target_gen_dir/$target_name.d"
1715 rebase_path(depfile, root_build_dir),
1717 rebase_path(_protoc_bin, root_build_dir),
1719 rebase_path(_proto_path, root_build_dir),
1721 rebase_path(srcjar_path, root_build_dir),
1722 ] + rebase_path(sources, root_build_dir)
1725 android_library(target_name) {
1727 srcjar_deps = [ ":${_template_name}__protoc_java" ]
1729 "//third_party/android_protobuf:protobuf_nano_javalib",
1734 # TODO(GYP): implement this.
1735 template("uiautomator_test") {
1736 set_sources_assignment_filter([])
1737 if (defined(invoker.testonly)) {
1738 testonly = invoker.testonly
1740 assert(target_name != "")
1741 assert(invoker.deps != [] || true)
1742 group(target_name) {