Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / build / config / android / rules.gni
blobddd58ee38b858e1c6dd9e725a8c1d54f9972eca7
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")
11 assert(is_android)
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.
20 # Variables
21 #   sources: list of .java files to generate jni for
22 #   jni_package: subdirectory path for generated bindings
24 # Example
25 #   generate_jni("foo_jni") {
26 #     sources = [
27 #       "android/java/src/org/chromium/foo/Foo.java",
28 #       "android/java/src/org/chromium/foo/FooUtil.java",
29 #     ]
30 #     jni_package = "foo"
31 #   }
32 template("generate_jni") {
33   set_sources_assignment_filter([])
34   if (defined(invoker.testonly)) {
35     testonly = invoker.testonly
36   }
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
52     outputs = [
53       depfile,
54       "${jni_output_dir}/{{source_name_part}}_jni.h",
55     ]
57     args = [
58       "--depfile",
59       rebase_path(depfile, root_build_dir),
60       "--input_file={{source}}",
61       "--optimize_generation=1",
62       "--ptr_type=long",
63       "--output_dir",
64       rebase_path(jni_output_dir, root_build_dir),
65       "--includes",
66       rebase_path(jni_generator_include, jni_output_dir),
67       "--native_exports_optional",
68     ]
69     if (defined(invoker.jni_generator_jarjar_file)) {
70       args += [
71         "--jarjar",
72         rebase_path(jni_generator_jarjar_file, root_build_dir),
73       ]
74     }
75   }
77   config("jni_includes_${target_name}") {
78     # TODO(cjhopman): #includes should probably all be relative to
79     # base_output_dir. Remove that from this config once the includes are
80     # updated.
81     include_dirs = [
82       base_output_dir,
83       package_output_dir,
84     ]
85   }
87   group(target_name) {
88     deps = [
89       ":$foreach_target_name",
90     ]
91     public_configs = [ ":jni_includes_${target_name}" ]
93     if (defined(invoker.deps)) {
94       deps += invoker.deps
95     }
96     if (defined(invoker.public_deps)) {
97       public_deps = invoker.public_deps
98     }
100     if (defined(invoker.visibility)) {
101       visibility = invoker.visibility
102     }
103   }
106 # Declare a jni target for a prebuilt jar
108 # This target generates the native jni bindings for a set of classes in a .jar.
110 # See base/android/jni_generator/jni_generator.py for more info about the
111 # format of generating JNI bindings.
113 # Variables
114 #   classes: list of .class files in the jar to generate jni for. These should
115 #     include the full path to the .class file.
116 #   jni_package: subdirectory path for generated bindings
117 #   jar_file: the path to the .jar. If not provided, will default to the sdk's
118 #     android.jar
120 #   deps, public_deps: As normal
122 # Example
123 #   generate_jar_jni("foo_jni") {
124 #     classes = [
125 #       "android/view/Foo.class",
126 #     ]
127 #     jni_package = "foo"
128 #   }
129 template("generate_jar_jni") {
130   set_sources_assignment_filter([])
131   if (defined(invoker.testonly)) {
132     testonly = invoker.testonly
133   }
135   assert(defined(invoker.classes))
136   assert(defined(invoker.jni_package))
138   if (defined(invoker.jar_file)) {
139     jar_file = invoker.jar_file
140   } else {
141     jar_file = android_sdk_jar
142   }
144   jni_package = invoker.jni_package
145   base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}"
146   jni_output_dir = "${base_output_dir}/jni"
148   jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
150   # TODO(cjhopman): make jni_generator.py support generating jni for multiple
151   # .class files from a .jar.
152   jni_actions = []
153   foreach(class, invoker.classes) {
154     _classname_list = []
155     _classname_list = process_file_template([ class ], "{{source_name_part}}")
156     classname = _classname_list[0]
157     jni_target_name = "${target_name}__jni_${classname}"
158     jni_actions += [ ":$jni_target_name" ]
159     action(jni_target_name) {
160       # The sources aren't compiled so don't check their dependencies.
161       check_includes = false
162       depfile = "$target_gen_dir/$target_name.d"
163       script = "//base/android/jni_generator/jni_generator.py"
164       sources = [
165         jar_file,
166       ]
167       outputs = [
168         depfile,
169         "${jni_output_dir}/${classname}_jni.h",
170       ]
172       args = [
173         "--depfile",
174         rebase_path(depfile, root_build_dir),
175         "--jar_file",
176         rebase_path(jar_file, root_build_dir),
177         "--input_file",
178         class,
179         "--optimize_generation=1",
180         "--ptr_type=long",
181         "--output_dir",
182         rebase_path(jni_output_dir, root_build_dir),
183         "--includes",
184         rebase_path(jni_generator_include, jni_output_dir),
185         "--native_exports_optional",
186       ]
187     }
188   }
190   config("jni_includes_${target_name}") {
191     include_dirs = [ base_output_dir ]
192   }
194   group(target_name) {
195     deps = jni_actions
196     if (defined(invoker.deps)) {
197       deps += invoker.deps
198     }
199     if (defined(invoker.public_deps)) {
200       public_deps = invoker.public_deps
201     }
202     public_configs = [ ":jni_includes_${target_name}" ]
203   }
206 # Declare a target for c-preprocessor-generated java files
208 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
209 #       rule instead.
211 # This target generates java files using the host C pre-processor. Each file in
212 # sources will be compiled using the C pre-processor. If include_path is
213 # specified, it will be passed (with --I) to the pre-processor.
215 # This target will create a single .srcjar. Adding this target to an
216 # android_library target's srcjar_deps will make the generated java files be
217 # included in that library's final outputs.
219 # Variables
220 #   sources: list of files to be processed by the C pre-processor. For each
221 #     file in sources, there will be one .java file in the final .srcjar. For a
222 #     file named FooBar.template, a java file will be created with name
223 #     FooBar.java.
224 #   inputs: additional compile-time dependencies. Any files
225 #     `#include`-ed in the templates should be listed here.
226 #   package_name: this will be the subdirectory for each .java file in the
227 #     .srcjar.
229 # Example
230 #   java_cpp_template("foo_generated_enum") {
231 #     sources = [
232 #       "android/java/templates/Foo.template",
233 #     ]
234 #     inputs = [
235 #       "android/java/templates/native_foo_header.h",
236 #     ]
238 #     package_name = "org/chromium/base/library_loader"
239 #     include_path = "android/java/templates"
240 #   }
241 template("java_cpp_template") {
242   set_sources_assignment_filter([])
243   if (defined(invoker.testonly)) {
244     testonly = invoker.testonly
245   }
247   assert(defined(invoker.sources))
248   package_name = invoker.package_name + ""
250   if (defined(invoker.include_path)) {
251     include_path = invoker.include_path + ""
252   } else {
253     include_path = "//"
254   }
256   action_foreach("${target_name}__apply_gcc") {
257     script = "//build/android/gyp/gcc_preprocess.py"
258     if (defined(invoker.inputs)) {
259       inputs = invoker.inputs + []
260     }
261     depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
263     sources = invoker.sources
265     gen_dir =
266         "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
267     gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
269     outputs = [
270       depfile,
271       gcc_template_output_pattern,
272     ]
274     args = [
275       "--depfile",
276       rebase_path(depfile, root_build_dir),
277       "--include-path",
278       rebase_path(include_path, root_build_dir),
279       "--output",
280       rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
281       "--template={{source}}",
282     ]
284     if (defined(invoker.defines)) {
285       foreach(def, invoker.defines) {
286         args += [
287           "--defines",
288           def,
289         ]
290       }
291     }
292   }
294   apply_gcc_outputs = get_target_outputs(":${target_name}__apply_gcc")
295   base_gen_dir = get_label_info(":${target_name}__apply_gcc", "target_gen_dir")
297   srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
298   zip("${target_name}__zip_srcjar") {
299     inputs = apply_gcc_outputs
300     output = srcjar_path
301     base_dir = base_gen_dir
302   }
304   group(target_name) {
305     deps = [
306       ":${target_name}__zip_srcjar",
307     ]
308   }
311 # Declare a target for generating Java classes from C++ enums.
313 # This target generates Java files from C++ enums using a script.
315 # This target will create a single .srcjar. Adding this target to an
316 # android_library target's srcjar_deps will make the generated java files be
317 # included in that library's final outputs.
319 # Variables
320 #   sources: list of files to be processed by the script. For each annotated
321 #     enum contained in the sources files the script will generate a .java
322 #     file with the same name as the name of the enum.
324 #   outputs: list of outputs, relative to the output_dir. These paths are
325 #     verified at build time by the script. To get the list programatically run:
326 #       python build/android/gyp/java_cpp_enum.py \
327 #         --print_output_only . path/to/header/file.h
329 # Example
330 #   java_cpp_enum("foo_generated_enum") {
331 #     sources = [
332 #       "src/native_foo_header.h",
333 #     ]
334 #     outputs = [
335 #       "org/chromium/FooEnum.java",
336 #     ]
337 #   }
338 template("java_cpp_enum") {
339   set_sources_assignment_filter([])
340   if (defined(invoker.testonly)) {
341     testonly = invoker.testonly
342   }
344   assert(defined(invoker.sources))
345   assert(defined(invoker.outputs))
347   action("${target_name}__generate_enum") {
348     # The sources aren't compiled so don't check their dependencies.
349     check_includes = false
351     sources = invoker.sources
352     script = "//build/android/gyp/java_cpp_enum.py"
353     gen_dir = "${target_gen_dir}/${target_name}/enums"
354     outputs =
355         get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
357     args = []
358     foreach(output, rebase_path(outputs, root_build_dir)) {
359       args += [
360         "--assert_file",
361         output,
362       ]
363     }
364     args += [ rebase_path(gen_dir, root_build_dir) ]
365     args += rebase_path(invoker.sources, root_build_dir)
366   }
368   generate_enum_outputs = get_target_outputs(":${target_name}__generate_enum")
369   base_gen_dir =
370       get_label_info(":${target_name}__generate_enum", "target_gen_dir")
372   srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
373   zip("${target_name}__zip_srcjar") {
374     inputs = generate_enum_outputs
375     output = srcjar_path
376     base_dir = base_gen_dir
377   }
379   group(target_name) {
380     deps = [
381       ":${target_name}__zip_srcjar",
382     ]
383   }
386 # Declare a target for processing a Jinja template.
388 # Variables
389 #   input: The template file to be processed.
390 #   output: Where to save the result.
391 #   variables: (Optional) A list of variables to make available to the template
392 #     processing environment, e.g. ["name=foo", "color=red"].
394 # Example
395 #   jinja_template("chrome_shell_manifest") {
396 #     input = "shell/java/AndroidManifest.xml"
397 #     output = "$target_gen_dir/AndroidManifest.xml"
398 #   }
399 template("jinja_template") {
400   set_sources_assignment_filter([])
401   if (defined(invoker.testonly)) {
402     testonly = invoker.testonly
403   }
405   assert(defined(invoker.input))
406   assert(defined(invoker.output))
408   action(target_name) {
409     sources = [
410       invoker.input,
411     ]
412     script = "//build/android/gyp/jinja_template.py"
413     depfile = "$target_gen_dir/$target_name.d"
415     outputs = [
416       depfile,
417       invoker.output,
418     ]
420     args = [
421       "--inputs",
422       rebase_path(invoker.input, root_build_dir),
423       "--output",
424       rebase_path(invoker.output, root_build_dir),
425       "--depfile",
426       rebase_path(depfile, root_build_dir),
427     ]
428     if (defined(invoker.variables)) {
429       variables = invoker.variables
430       args += [ "--variables=${variables}" ]
431     }
432   }
435 # Declare a target for processing Android resources as Jinja templates.
437 # This takes an Android resource directory where each resource is a Jinja
438 # template, processes each template, then packages the results in a zip file
439 # which can be consumed by an android resources, library, or apk target.
441 # If this target is included in the deps of an android resources/library/apk,
442 # the resources will be included with that target.
444 # Variables
445 #   resources: The list of resources files to process.
446 #   res_dir: The resource directory containing the resources.
447 #   variables: (Optional) A list of variables to make available to the template
448 #     processing environment, e.g. ["name=foo", "color=red"].
450 # Example
451 #   jinja_template_resources("chrome_shell_template_resources") {
452 #     res_dir = "shell/res_template"
453 #     resources = ["shell/res_template/xml/syncable.xml"]
454 #     variables = ["color=red"]
455 #   }
456 template("jinja_template_resources") {
457   set_sources_assignment_filter([])
458   if (defined(invoker.testonly)) {
459     testonly = invoker.testonly
460   }
462   assert(defined(invoker.resources))
463   assert(defined(invoker.res_dir))
465   _base_path = "$target_gen_dir/$target_name"
466   _resources_zip = _base_path + ".resources.zip"
467   _build_config = _base_path + ".build_config"
469   write_build_config("${target_name}__build_config") {
470     build_config = _build_config
471     resources_zip = _resources_zip
472     type = "android_resources"
473   }
475   action("${target_name}__template") {
476     sources = invoker.resources
477     script = "//build/android/gyp/jinja_template.py"
478     depfile = "$target_gen_dir/$target_name.d"
480     outputs = [
481       depfile,
482       _resources_zip,
483     ]
485     rebased_resources = rebase_path(invoker.resources, root_build_dir)
486     args = [
487       "--inputs=${rebased_resources}",
488       "--inputs-base-dir",
489       rebase_path(invoker.res_dir, root_build_dir),
490       "--outputs-zip",
491       rebase_path(_resources_zip, root_build_dir),
492       "--depfile",
493       rebase_path(depfile, root_build_dir),
494     ]
495     if (defined(invoker.variables)) {
496       variables = invoker.variables
497       args += [ "--variables=${variables}" ]
498     }
499   }
501   group(target_name) {
502     deps = [
503       ":${target_name}__build_config",
504       ":${target_name}__template",
505     ]
506   }
509 # Declare an Android resources target
511 # This creates a resources zip file that will be used when building an Android
512 # library or apk and included into a final apk.
514 # To include these resources in a library/apk, this target should be listed in
515 # the library's deps. A library/apk will also include any resources used by its
516 # own dependencies.
518 # Variables
519 #   deps: Specifies the dependencies of this target. Any Android resources
520 #     listed in deps will be included by libraries/apks that depend on this
521 #     target.
522 #   resource_dirs: List of directories containing resources for this target.
523 #   android_manifest: AndroidManifest.xml for this target. Defaults to
524 #     //build/android/AndroidManifest.xml.
525 #   custom_package: java package for generated .java files.
526 #   v14_verify_only: If true, don't generate v14/v17 resources and just verify
527 #     that the resources are v14-compliant (see
528 #     build/android/gyp/generate_v14_compatible_resources.py). Defaults to
529 #     false.
530 #   shared_resources: If true make a resource package that can be loaded by a
531 #     different application at runtime to access the package's resources.
533 # Example
534 #   android_resources("foo_resources") {
535 #     deps = [":foo_strings_grd"]
536 #     resource_dirs = ["res"]
537 #     custom_package = "org.chromium.foo"
538 #   }
539 template("android_resources") {
540   set_sources_assignment_filter([])
541   if (defined(invoker.testonly)) {
542     testonly = invoker.testonly
543   }
545   assert(defined(invoker.resource_dirs))
546   assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
548   base_path = "$target_gen_dir/$target_name"
549   zip_path = base_path + ".resources.zip"
550   srcjar_path = base_path + ".srcjar"
551   build_config = base_path + ".build_config"
553   write_build_config("${target_name}__build_config") {
554     type = "android_resources"
555     resources_zip = zip_path
556     srcjar = srcjar_path
557     if (defined(invoker.deps)) {
558       deps = invoker.deps
559     }
560     if (defined(invoker.android_manifest)) {
561       android_manifest = invoker.android_manifest
562     }
563     if (defined(invoker.custom_package)) {
564       custom_package = invoker.custom_package
565     }
566   }
568   android_manifest = "//build/android/AndroidManifest.xml"
569   if (defined(invoker.android_manifest)) {
570     android_manifest = invoker.android_manifest
571   }
573   process_resources("${target_name}__process_resources") {
574     resource_dirs = invoker.resource_dirs
575     if (defined(invoker.custom_package)) {
576       custom_package = invoker.custom_package
577     }
579     if (defined(invoker.v14_verify_only)) {
580       v14_verify_only = invoker.v14_verify_only
581     }
583     if (defined(invoker.shared_resources)) {
584       shared_resources = invoker.shared_resources
585     }
586   }
588   group(target_name) {
589     deps = [
590       ":${target_name}__build_config",
591       ":${target_name}__process_resources",
592     ]
593   }
596 # Declare a target that generates localized strings.xml from a .grd file.
598 # If this target is included in the deps of an android resources/library/apk,
599 # the strings.xml will be included with that target.
601 # Variables
602 #   deps: Specifies the dependencies of this target.
603 #   grd_file: Path to the .grd file to generate strings.xml from.
604 #   outputs: Expected grit outputs (see grit rule).
606 # Example
607 #  java_strings_grd("foo_strings_grd") {
608 #    grd_file = "foo_strings.grd"
609 #  }
610 template("java_strings_grd") {
611   set_sources_assignment_filter([])
612   if (defined(invoker.testonly)) {
613     testonly = invoker.testonly
614   }
616   base_path = "$target_gen_dir/$target_name"
617   resources_zip = base_path + ".resources.zip"
618   build_config = base_path + ".build_config"
620   write_build_config("${target_name}__build_config") {
621     type = "android_resources"
622     if (defined(invoker.deps)) {
623       deps = invoker.deps
624     }
625   }
627   # Put grit files into this subdirectory of target_gen_dir.
628   extra_output_path = target_name + "_grit_output"
630   grit_target_name = "${target_name}__grit"
631   grit_output_dir = "$target_gen_dir/$extra_output_path"
632   grit(grit_target_name) {
633     grit_flags = [
634       "-E",
635       "ANDROID_JAVA_TAGGED_ONLY=false",
636     ]
637     output_dir = grit_output_dir
638     resource_ids = ""
639     source = invoker.grd_file
640     outputs = invoker.outputs
641   }
643   # This needs to get outputs from grit's internal target, not the final
644   # source_set.
645   generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
647   zip("${target_name}__zip") {
648     base_dir = grit_output_dir
649     inputs = generate_strings_outputs
650     output = resources_zip
651   }
653   group(target_name) {
654     deps = [
655       ":${target_name}__build_config",
656       ":${target_name}__zip",
657     ]
658   }
661 # Declare a target that packages strings.xml generated from a grd file.
663 # If this target is included in the deps of an android resources/library/apk,
664 # the strings.xml will be included with that target.
666 # Variables
667 #  grit_output_dir: directory containing grit-generated files.
668 #  generated_files: list of android resource files to package.
670 # Example
671 #  java_strings_grd_prebuilt("foo_strings_grd") {
672 #    grit_output_dir = "$root_gen_dir/foo/grit"
673 #    generated_files = [
674 #      "values/strings.xml"
675 #    ]
676 #  }
677 template("java_strings_grd_prebuilt") {
678   set_sources_assignment_filter([])
679   if (defined(invoker.testonly)) {
680     testonly = invoker.testonly
681   }
683   base_path = "$target_gen_dir/$target_name"
684   resources_zip = base_path + ".resources.zip"
685   build_config = base_path + ".build_config"
687   write_build_config("${target_name}__build_config") {
688     type = "android_resources"
689     if (defined(invoker.deps)) {
690       deps = invoker.deps
691     }
692   }
694   zip("${target_name}__zip") {
695     base_dir = invoker.grit_output_dir
696     inputs = rebase_path(invoker.generated_files, ".", base_dir)
697     output = resources_zip
698   }
700   group(target_name) {
701     deps = [
702       ":${target_name}__build_config",
703       ":${target_name}__zip",
704     ]
705   }
708 # Declare a Java executable target
710 # This target creates an executable from java code and libraries. The executable
711 # will be in the output folder's /bin/ directory.
713 # Variables
714 #   deps: Specifies the dependencies of this target. Java targets in this list
715 #     will be included in the executable (and the javac classpath).
717 #   java_files: List of .java files included in this library.
718 #   srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
719 #     will be added to java_files and be included in this library.
720 #   srcjars: List of srcjars to be included in this library, together with the
721 #     ones obtained from srcjar_deps.
723 #   bypass_platform_checks: Disables checks about cross-platform (Java/Android)
724 #     dependencies for this target. This will allow depending on an
725 #     android_library target, for example.
727 #   chromium_code: If true, extra analysis warning/errors will be enabled.
729 #   datadeps, testonly
731 # Example
732 #   java_binary("foo") {
733 #     java_files = [ "org/chromium/foo/FooMain.java" ]
734 #     deps = [ ":bar_java" ]
735 #     main_class = "org.chromium.foo.FooMain"
736 #   }
737 template("java_binary") {
738   set_sources_assignment_filter([])
740   # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
741   # dependents shouldn't get the jar in their classpath, etc.).
742   java_library_impl(target_name) {
743     if (defined(invoker.DEPRECATED_java_in_dir)) {
744       DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
745     }
746     if (defined(invoker.chromium_code)) {
747       chromium_code = invoker.chromium_code
748     }
749     if (defined(invoker.datadeps)) {
750       deps = invoker.datadeps
751     }
752     if (defined(invoker.deps)) {
753       deps = invoker.deps
754     }
755     if (defined(invoker.java_files)) {
756       java_files = invoker.java_files
757     }
758     if (defined(invoker.srcjar_deps)) {
759       srcjar_deps = invoker.srcjar_deps
760     }
761     if (defined(invoker.srcjars)) {
762       srcjars = invoker.srcjars
763     }
764     if (defined(invoker.bypass_platform_checks)) {
765       bypass_platform_checks = invoker.bypass_platform_checks
766     }
767     if (defined(invoker.testonly)) {
768       testonly = invoker.testonly
769     }
771     main_class = invoker.main_class
772   }
775 # Declare a Junit executable target
777 # This target creates an executable from java code for running as a junit test
778 # suite. The executable will be in the output folder's /bin/ directory.
780 # Variables
781 #   deps: Specifies the dependencies of this target. Java targets in this list
782 #     will be included in the executable (and the javac classpath).
784 #   java_files: List of .java files included in this library.
785 #   srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
786 #     will be added to java_files and be included in this library.
787 #   srcjars: List of srcjars to be included in this library, together with the
788 #     ones obtained from srcjar_deps.
790 #   chromium_code: If true, extra analysis warning/errors will be enabled.
792 # Example
793 #   junit_binary("foo") {
794 #     java_files = [ "org/chromium/foo/FooTest.java" ]
795 #     deps = [ ":bar_java" ]
796 #   }
797 template("junit_binary") {
798   set_sources_assignment_filter([])
800   java_binary(target_name) {
801     bypass_platform_checks = true
802     main_class = "org.chromium.testing.local.JunitTestMain"
803     testonly = true
805     if (defined(invoker.DEPRECATED_java_in_dir)) {
806       DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
807     }
808     if (defined(invoker.chromium_code)) {
809       chromium_code = invoker.chromium_code
810     }
811     deps = [
812       "//testing/android/junit:junit_test_support",
813       "//third_party/junit",
814       "//third_party/mockito:mockito_java",
815       "//third_party/robolectric:robolectric_java",
816       "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
817     ]
818     if (defined(invoker.deps)) {
819       deps += invoker.deps
820     }
821     if (defined(invoker.java_files)) {
822       java_files = invoker.java_files
823     }
824     if (defined(invoker.srcjar_deps)) {
825       srcjar_deps = invoker.srcjar_deps
826     }
827     if (defined(invoker.srcjars)) {
828       srcjars = invoker.srcjars
829     }
830   }
833 # Declare a java library target
835 # Variables
836 #   deps: Specifies the dependencies of this target. Java targets in this list
837 #     will be added to the javac classpath.
839 #   java_files: List of .java files included in this library.
840 #   srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
841 #     will be added to java_files and be included in this library.
842 #   srcjars: List of srcjars to be included in this library, together with the
843 #     ones obtained from srcjar_deps.
844 #   DEPRECATED_java_in_dir: Directory containing java files. All .java files in
845 #     this directory will be included in the library. This is only supported to
846 #     ease the gyp->gn conversion and will be removed in the future.
848 #   chromium_code: If true, extra analysis warning/errors will be enabled.
849 #   jar_excluded_patterns: List of patterns of .class files to exclude from the
850 #     final jar.
852 #   proguard_preprocess: If true, proguard preprocessing will be run. This can
853 #     be used to remove unwanted parts of the library.
854 #   proguard_config: Path to the proguard config for preprocessing.
856 #   supports_android: If true, Android targets (android_library, android_apk)
857 #     may depend on this target. Note: if true, this target must only use the
858 #     subset of Java available on Android.
859 #   bypass_platform_checks: Disables checks about cross-platform (Java/Android)
860 #     dependencies for this target. This will allow depending on an
861 #     android_library target, for example.
863 #   datadeps, testonly
865 # Example
866 #   java_library("foo_java") {
867 #     java_files = [
868 #       "org/chromium/foo/Foo.java",
869 #       "org/chromium/foo/FooInterface.java",
870 #       "org/chromium/foo/FooService.java",
871 #     ]
872 #     deps = [
873 #       ":bar_java"
874 #     ]
875 #     srcjar_deps = [
876 #       ":foo_generated_enum"
877 #     ]
878 #     jar_excluded_patterns = [
879 #       "*/FooService.class", "*/FooService##*.class"
880 #     ]
881 #   }
882 template("java_library") {
883   set_sources_assignment_filter([])
884   java_library_impl(target_name) {
885     if (defined(invoker.DEPRECATED_java_in_dir)) {
886       DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
887     }
888     if (defined(invoker.chromium_code)) {
889       chromium_code = invoker.chromium_code
890     }
891     if (defined(invoker.datadeps)) {
892       deps = invoker.datadeps
893     }
894     if (defined(invoker.deps)) {
895       deps = invoker.deps
896     }
897     if (defined(invoker.jar_excluded_patterns)) {
898       jar_excluded_patterns = invoker.jar_excluded_patterns
899     }
900     if (defined(invoker.java_files)) {
901       java_files = invoker.java_files
902     }
903     if (defined(invoker.proguard_config)) {
904       proguard_config = invoker.proguard_config
905     }
906     if (defined(invoker.proguard_preprocess)) {
907       proguard_preprocess = invoker.proguard_preprocess
908     }
909     if (defined(invoker.srcjar_deps)) {
910       srcjar_deps = invoker.srcjar_deps
911     }
912     if (defined(invoker.srcjars)) {
913       srcjars = invoker.srcjars
914     }
915     if (defined(invoker.bypass_platform_checks)) {
916       bypass_platform_checks = invoker.bypass_platform_checks
917     }
918     if (defined(invoker.testonly)) {
919       testonly = invoker.testonly
920     }
921     if (defined(invoker.jar_path)) {
922       jar_path = invoker.jar_path
923     }
925     if (defined(invoker.supports_android) && invoker.supports_android) {
926       supports_android = true
927     }
928   }
931 # Declare a java library target for a prebuilt jar
933 # Variables
934 #   deps: Specifies the dependencies of this target. Java targets in this list
935 #     will be added to the javac classpath.
936 #   jar_path: Path to the prebuilt jar.
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 # Example
942 #   java_prebuilt("foo_java") {
943 #     jar_path = "foo.jar"
944 #     deps = [
945 #       ":foo_resources",
946 #       ":bar_java"
947 #     ]
948 #   }
949 template("java_prebuilt") {
950   set_sources_assignment_filter([])
951   java_prebuilt_impl(target_name) {
952     jar_path = invoker.jar_path
953     if (defined(invoker.testonly)) {
954       testonly = invoker.testonly
955     }
956     if (defined(invoker.deps)) {
957       deps = invoker.deps
958     }
959     if (defined(invoker.proguard_config)) {
960       proguard_config = invoker.proguard_config
961     }
962     if (defined(invoker.proguard_preprocess)) {
963       proguard_preprocess = invoker.proguard_preprocess
964     }
965   }
968 # Declare an Android library target
970 # This target creates an Android library containing java code and Android
971 # resources.
973 # Variables
974 #   deps: Specifies the dependencies of this target. Java targets in this list
975 #     will be added to the javac classpath. Android resources in dependencies
976 #     will be used when building this library.
978 #   java_files: List of .java files included in this library.
979 #   srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
980 #     will be added to java_files and be included in this library.
981 #   srcjars: List of srcjars to be included in this library, together with the
982 #     ones obtained from srcjar_deps.
983 #   DEPRECATED_java_in_dir: Directory containing java files. All .java files in
984 #     this directory will be included in the library. This is only supported to
985 #     ease the gyp->gn conversion and will be removed in the future.
987 #   chromium_code: If true, extra analysis warning/errors will be enabled.
988 #   jar_excluded_patterns: List of patterns of .class files to exclude from the
989 #     final jar.
991 #   proguard_preprocess: If true, proguard preprocessing will be run. This can
992 #     be used to remove unwanted parts of the library.
993 #   proguard_config: Path to the proguard config for preprocessing.
995 #   dex_path: If set, the resulting .dex.jar file will be placed under this
996 #     path.
999 # Example
1000 #   android_library("foo_java") {
1001 #     java_files = [
1002 #       "android/org/chromium/foo/Foo.java",
1003 #       "android/org/chromium/foo/FooInterface.java",
1004 #       "android/org/chromium/foo/FooService.java",
1005 #     ]
1006 #     deps = [
1007 #       ":bar_java"
1008 #     ]
1009 #     srcjar_deps = [
1010 #       ":foo_generated_enum"
1011 #     ]
1012 #     jar_excluded_patterns = [
1013 #       "*/FooService.class", "*/FooService##*.class"
1014 #     ]
1015 #   }
1016 template("android_library") {
1017   set_sources_assignment_filter([])
1018   assert(!defined(invoker.jar_path),
1019          "android_library does not support a custom jar path")
1020   java_library_impl(target_name) {
1021     if (defined(invoker.DEPRECATED_java_in_dir)) {
1022       DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1023     }
1024     if (defined(invoker.chromium_code)) {
1025       chromium_code = invoker.chromium_code
1026     }
1027     if (defined(invoker.datadeps)) {
1028       deps = invoker.datadeps
1029     }
1030     if (defined(invoker.deps)) {
1031       deps = invoker.deps
1032     }
1033     if (defined(invoker.jar_excluded_patterns)) {
1034       jar_excluded_patterns = invoker.jar_excluded_patterns
1035     }
1036     if (defined(invoker.java_files)) {
1037       java_files = invoker.java_files
1038     }
1039     if (defined(invoker.proguard_config)) {
1040       proguard_config = invoker.proguard_config
1041     }
1042     if (defined(invoker.proguard_preprocess)) {
1043       proguard_preprocess = invoker.proguard_preprocess
1044     }
1045     if (defined(invoker.srcjar_deps)) {
1046       srcjar_deps = invoker.srcjar_deps
1047     }
1048     if (defined(invoker.srcjars)) {
1049       srcjars = invoker.srcjars
1050     }
1051     if (defined(invoker.testonly)) {
1052       testonly = invoker.testonly
1053     }
1054     if (defined(invoker.visibility)) {
1055       visibility = invoker.visibility
1056     }
1057     if (defined(invoker.dex_path)) {
1058       dex_path = invoker.dex_path
1059     }
1060     if (defined(invoker.manifest_entries)) {
1061       manifest_entries = invoker.manifest_entries
1062     }
1064     supports_android = true
1065     requires_android = true
1067     if (!defined(jar_excluded_patterns)) {
1068       jar_excluded_patterns = []
1069     }
1070     jar_excluded_patterns += [
1071       "*/R.class",
1072       "*/R##*.class",
1073       "*/Manifest.class",
1074       "*/Manifest##*.class",
1075     ]
1076   }
1079 # Declare a target that packages a set of Java dependencies into a standalone
1080 # .dex.jar.
1082 # Variables
1083 #   deps: specifies the dependencies of this target. Android libraries in deps
1084 #     will be packaged into the resulting .dex.jar file.
1085 #   dex_path: location at which the output file will be put
1086 template("android_standalone_library") {
1087   set_sources_assignment_filter([])
1088   deps_dex(target_name) {
1089     deps = invoker.deps
1090     dex_path = invoker.dex_path
1091     if (defined(invoker.excluded_jars)) {
1092       excluded_jars = invoker.excluded_jars
1093     }
1094   }
1097 # Declare an Android library target for a prebuilt jar
1099 # This target creates an Android library containing java code and Android
1100 # resources.
1102 # Variables
1103 #   deps: Specifies the dependencies of this target. Java targets in this list
1104 #     will be added to the javac classpath. Android resources in dependencies
1105 #     will be used when building this library.
1106 #   jar_path: Path to the prebuilt jar.
1107 #   proguard_preprocess: If true, proguard preprocessing will be run. This can
1108 #     be used to remove unwanted parts of the library.
1109 #   proguard_config: Path to the proguard config for preprocessing.
1111 # Example
1112 #   android_java_prebuilt("foo_java") {
1113 #     jar_path = "foo.jar"
1114 #     deps = [
1115 #       ":foo_resources",
1116 #       ":bar_java"
1117 #     ]
1118 #   }
1119 template("android_java_prebuilt") {
1120   set_sources_assignment_filter([])
1121   java_prebuilt_impl(target_name) {
1122     jar_path = invoker.jar_path
1123     supports_android = true
1124     requires_android = true
1125     if (defined(invoker.testonly)) {
1126       testonly = invoker.testonly
1127     }
1128     if (defined(invoker.deps)) {
1129       deps = invoker.deps
1130     }
1131     if (defined(invoker.proguard_config)) {
1132       proguard_config = invoker.proguard_config
1133     }
1134     if (defined(invoker.proguard_preprocess)) {
1135       proguard_preprocess = invoker.proguard_preprocess
1136     }
1137   }
1140 # Declare an Android apk target
1142 # This target creates an Android APK containing java code, resources, assets,
1143 # and (possibly) native libraries.
1145 # Variables
1146 #   android_manifest: Path to AndroidManifest.xml.
1147 #   datadeps: List of dependencies needed at runtime. These will be built but
1148 #     won't change the generated .apk in any way (in fact they may be built
1149 #     after the .apk is).
1150 #   deps: List of dependencies. All Android java resources and libraries in the
1151 #     "transitive closure" of these dependencies will be included in the apk.
1152 #     Note: this "transitive closure" actually only includes such targets if
1153 #     they are depended on through android_library or android_resources targets
1154 #     (and so not through builtin targets like 'action', 'group', etc).
1155 #   java_files: List of .java files to include in the apk.
1156 #   srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1157 #      will be added to java_files and be included in this apk.
1158 #   apk_name: Name for final apk.
1159 #   final_apk_path: Path to final built apk. Default is
1160 #     $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1161 #   native_libs: List paths of native libraries to include in this apk. If these
1162 #     libraries depend on other shared_library targets, those dependencies will
1163 #     also be included in the apk.
1164 #   apk_under_test: For an instrumentation test apk, this is the target of the
1165 #     tested apk.
1166 #   testonly: Marks this target as "test-only".
1168 #   DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1169 #     this directory will be included in the library. This is only supported to
1170 #     ease the gyp->gn conversion and will be removed in the future.
1172 # Example
1173 #   android_apk("foo_apk") {
1174 #     android_manifest = "AndroidManifest.xml"
1175 #     java_files = [
1176 #       "android/org/chromium/foo/FooApplication.java",
1177 #       "android/org/chromium/foo/FooActivity.java",
1178 #     ]
1179 #     deps = [
1180 #       ":foo_support_java"
1181 #       ":foo_resources"
1182 #     ]
1183 #     srcjar_deps = [
1184 #       ":foo_generated_enum"
1185 #     ]
1186 #     native_libs = [
1187 #       native_lib_path
1188 #     ]
1189 #   }
1190 template("android_apk") {
1191   set_sources_assignment_filter([])
1192   if (defined(invoker.testonly)) {
1193     testonly = invoker.testonly
1194   }
1196   assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1197   assert(defined(invoker.android_manifest))
1198   gen_dir = "$target_gen_dir/$target_name"
1199   base_path = "$gen_dir/$target_name"
1200   _build_config = "$target_gen_dir/$target_name.build_config"
1201   resources_zip_path = "$base_path.resources.zip"
1202   all_resources_zip_path = "$base_path.resources.all.zip"
1203   jar_path = "$base_path.jar"
1204   final_dex_path = "$gen_dir/classes.dex"
1205   _template_name = target_name
1206   _final_apk_path = ""
1207   if (defined(invoker.final_apk_path)) {
1208     _final_apk_path = invoker.final_apk_path
1209   } else if (defined(invoker.apk_name)) {
1210     _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1211   }
1212   _dist_jar_path_list =
1213       process_file_template(
1214           [ _final_apk_path ],
1215           "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1216   _dist_jar_path = _dist_jar_path_list[0]
1218   _native_libs = []
1220   _keystore_path = android_default_keystore_path
1221   _keystore_name = android_default_keystore_name
1222   _keystore_password = android_default_keystore_password
1224   if (defined(invoker.keystore_path)) {
1225     _keystore_path = invoker.keystore_path
1226     _keystore_name = invoker.keystore_name
1227     _keystore_password = invoker.keystore_password
1228   }
1230   _srcjar_deps = []
1231   if (defined(invoker.srcjar_deps)) {
1232     _srcjar_deps += invoker.srcjar_deps
1233   }
1235   _load_library_from_apk = false
1237   if (defined(invoker.native_libs)) {
1238     _use_chromium_linker = false
1239     if (defined(invoker.use_chromium_linker)) {
1240       _use_chromium_linker =
1241           invoker.use_chromium_linker && chromium_linker_supported
1242     }
1244     if (defined(invoker.load_library_from_apk) &&
1245         invoker.load_library_from_apk) {
1246       _load_library_from_apk = true
1247       assert(_use_chromium_linker,
1248              "Loading library from the apk requires use" +
1249                  " of the Chromium linker.")
1250     }
1252     _enable_relocation_packing = false
1253     if (defined(invoker.enable_relocation_packing) &&
1254         invoker.enable_relocation_packing) {
1255       _enable_relocation_packing = relocation_packing_supported
1256       assert(_use_chromium_linker,
1257              "Relocation packing requires use of the" + " Chromium linker.")
1258     }
1260     _native_libs = process_file_template(
1261             invoker.native_libs,
1262             "$root_build_dir/lib.stripped/{{source_file_part}}")
1264     _native_libs_dir = base_path + "/libs"
1266     if (_use_chromium_linker) {
1267       _native_libs +=
1268           [ "$root_build_dir/lib.stripped/libchromium_android_linker.so" ]
1269     }
1271     _enable_relocation_packing = false
1272     if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1273         invoker.enable_relocation_packing) {
1274       _enable_relocation_packing = true
1275     }
1277     _native_lib_version_name = ""
1278     if (defined(invoker.native_lib_version_name)) {
1279       _native_lib_version_name = invoker.native_lib_version_name
1280     }
1281   }
1283   _android_manifest = invoker.android_manifest
1284   _rebased_build_config = rebase_path(_build_config, root_build_dir)
1286   write_build_config("${_template_name}__build_config") {
1287     type = "android_apk"
1288     dex_path = final_dex_path
1289     resources_zip = resources_zip_path
1290     build_config = _build_config
1291     android_manifest = _android_manifest
1293     if (defined(invoker.deps)) {
1294       deps = invoker.deps
1295     }
1297     if (defined(invoker.apk_under_test)) {
1298       apk_under_test = invoker.apk_under_test
1299     }
1301     native_libs = _native_libs
1302   }
1304   final_deps = []
1306   final_deps += [ ":${_template_name}__process_resources" ]
1307   process_resources("${_template_name}__process_resources") {
1308     srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1309     android_manifest = _android_manifest
1310     resource_dirs = [ "//build/android/ant/empty/res" ]
1311     zip_path = resources_zip_path
1312     generate_constant_ids = true
1313     build_config = _build_config
1314   }
1315   _srcjar_deps += [ ":${_template_name}__process_resources" ]
1317   if (_native_libs != []) {
1318     _enable_chromium_linker_tests = false
1319     if (defined(invoker.enable_chromium_linker_tests)) {
1320       _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1321     }
1323     java_cpp_template("${_template_name}__native_libraries_java") {
1324       package_name = "org/chromium/base/library_loader"
1325       sources = [
1326         "//base/android/java/templates/NativeLibraries.template",
1327       ]
1328       inputs = [
1329         _build_config,
1330       ]
1332       defines = [
1333         "NATIVE_LIBRARIES_LIST=" +
1334             "@FileArg($_rebased_build_config:native:java_libraries_list)",
1335         "NATIVE_LIBRARIES_VERSION_NUMBER=\"$_native_lib_version_name\"",
1336       ]
1337       if (_use_chromium_linker) {
1338         defines += [ "ENABLE_CHROMIUM_LINKER" ]
1339       }
1340       if (_load_library_from_apk) {
1341         defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1342       }
1343       if (_enable_chromium_linker_tests) {
1344         defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1345       }
1346     }
1347     _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1348   }
1350   final_deps += [ ":${_template_name}__java" ]
1351   java_library_impl("${_template_name}__java") {
1352     supports_android = true
1353     requires_android = true
1354     override_build_config = _build_config
1355     android_manifest = _android_manifest
1356     chromium_code = true
1357     if (defined(invoker.java_files)) {
1358       java_files = invoker.java_files
1359     } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1360       DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1361     } else {
1362       java_files = []
1363     }
1364     srcjar_deps = _srcjar_deps
1365     dex_path = base_path + ".dex.jar"
1366   }
1368   if (_dist_jar_path != "") {
1369     final_deps += [ ":${_template_name}__create_dist_jar" ]
1371     # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1372     # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1373     # able to just do that calculation at build time instead.
1374     action("${_template_name}__create_dist_jar") {
1375       script = "//build/android/gyp/create_dist_jar.py"
1376       depfile = "$target_gen_dir/$target_name.d"
1377       inputs = [
1378         _build_config,
1379       ]
1380       outputs = [
1381         depfile,
1382         _dist_jar_path,
1383       ]
1384       args = [
1385         "--depfile",
1386         rebase_path(depfile, root_build_dir),
1387         "--output",
1388         rebase_path(_dist_jar_path, root_build_dir),
1389         "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1390       ]
1391       inputs += [ jar_path ]
1392       _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1393       args += [ "--inputs=$_rebased_jar_path" ]
1394     }
1395   }
1397   final_deps += [ ":${_template_name}__final_dex" ]
1398   dex("${_template_name}__final_dex") {
1399     deps = [
1400       ":${_template_name}__java",
1401     ]
1402     sources = [
1403       jar_path,
1404     ]
1405     inputs = [
1406       _build_config,
1407     ]
1408     output = final_dex_path
1409     dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1410     args = [ "--inputs=@FileArg($dex_arg_key)" ]
1411   }
1413   if (_native_libs != []) {
1414     action("${_template_name}__prepare_native") {
1415       script = "//build/android/gyp/pack_arm_relocations.py"
1416       packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1417       depfile = "$target_gen_dir/$target_name.d"
1418       outputs = [
1419         depfile,
1420       ]
1421       inputs = [ _build_config ] + _native_libs
1422       deps = []
1423       skip_packing_list = [
1424         "gdbserver",
1425         "libchromium_android_linker.so",
1426       ]
1428       enable_packing_arg = 0
1429       if (_enable_relocation_packing) {
1430         enable_packing_arg = 1
1431         deps += [ relocation_packer_target ]
1432       }
1434       args = [
1435         "--depfile",
1436         rebase_path(depfile, root_build_dir),
1437         "--enable-packing=$enable_packing_arg",
1438         "--has-relocations-with-addends=$relocations_have_addends",
1439         "--exclude-packing-list=$skip_packing_list",
1440         "--android-pack-relocations",
1441         rebase_path(relocation_packer_exe, root_build_dir),
1442         "--android-objcopy",
1443         rebase_path(android_objcopy, root_build_dir),
1444         "--stripped-libraries-dir",
1445         rebase_path(root_build_dir, root_build_dir),
1446         "--packed-libraries-dir",
1447         rebase_path(packed_libraries_dir, root_build_dir),
1448         "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1449         "--clear-dir",
1450       ]
1452       if (is_debug) {
1453         rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1454         inputs += [ android_gdbserver ]
1455         args += [ "--libraries=$rebased_gdbserver" ]
1456       }
1457     }
1458   }
1460   final_deps += [ ":${_template_name}__create" ]
1461   create_apk("${_template_name}__create") {
1462     apk_path = _final_apk_path
1463     android_manifest = _android_manifest
1464     resources_zip = all_resources_zip_path
1465     dex_path = final_dex_path
1466     load_library_from_apk = _load_library_from_apk
1468     version_code = "1"
1469     if (defined(invoker.version_code)) {
1470       version_code = invoker.version_code
1471     }
1473     version_name = "Developer Build"
1474     if (defined(invoker.version_name)) {
1475       version_name = invoker.version_name
1476     }
1478     keystore_name = _keystore_name
1479     keystore_path = _keystore_path
1480     keystore_password = _keystore_password
1482     deps = []
1483     if (defined(invoker.asset_location)) {
1484       asset_location = invoker.asset_location
1486       # We don't know the exact dependencies that create the assets in
1487       # |asset_location|; we depend on all caller deps until a better solution
1488       # is figured out (http://crbug.com/433330).
1489       if (defined(invoker.deps)) {
1490         deps += invoker.deps
1491       }
1492     }
1494     if (_native_libs != []) {
1495       native_libs_dir = _native_libs_dir
1496       deps += [ ":${_template_name}__prepare_native" ]
1497     }
1498   }
1500   group(target_name) {
1501     deps = final_deps
1502     if (defined(invoker.datadeps)) {
1503       datadeps = invoker.datadeps
1504     }
1505   }
1508 # Declare an Android gtest apk
1510 # This target creates an Android apk for running gtest-based unittests.
1512 # Variables
1513 #   deps: Specifies the dependencies of this target. These will be passed to
1514 #     the underlying android_apk invocation and should include the java and
1515 #     resource dependencies of the apk.
1516 #   unittests_dep: This should be the label of the gtest native target. This
1517 #     target must be defined previously in the same file.
1518 #   unittests_binary: The basename of the library produced by the unittests_dep
1519 #     target. If unspecified, it assumes the name of the unittests_dep target
1520 #     (which will be correct unless that target specifies an "output_name".
1521 #     TODO(brettw) make this automatic by allowing get_target_outputs to
1522 #     support executables.
1523 #   apk_name: The name of the produced apk. If unspecified, it uses the name
1524 #             of the unittests_dep target postfixed with "_apk"
1526 # Example
1527 #   unittest_apk("foo_unittests_apk") {
1528 #     deps = [ ":foo_java", ":foo_resources" ]
1529 #     unittests_dep = ":foo_unittests"
1530 #   }
1531 template("unittest_apk") {
1532   set_sources_assignment_filter([])
1533   testonly = true
1535   assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1537   test_suite_name = get_label_info(invoker.unittests_dep, "name")
1539   # This trivial assert is needed in case both unittests_binary and apk_name
1540   # are defined, as otherwise test_suite_name would not be used.
1541   assert(test_suite_name != "")
1543   if (defined(invoker.unittests_binary)) {
1544     unittests_binary = invoker.unittests_binary
1545   } else {
1546     unittests_binary = "lib" + test_suite_name + ".so"
1547   }
1549   if (defined(invoker.apk_name)) {
1550     apk_name = invoker.apk_name
1551   } else {
1552     apk_name = test_suite_name
1553   }
1555   android_apk(target_name) {
1556     final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1557     java_files = [
1558       "//testing/android/native_test/java/src/org/chromium/native_test/ChromeNativeTestActivity.java",
1559       "//testing/android/native_test/java/src/org/chromium/native_test/ChromeNativeTestInstrumentationTestRunner.java",
1560     ]
1561     android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1562     native_libs = [ unittests_binary ]
1563     if (defined(invoker.asset_location)) {
1564       asset_location = invoker.asset_location
1565     }
1566     deps = [
1567       "//base:base_java",
1568       "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1569       "//testing/android/appurify_support:appurify_support_java",
1570     ]
1571     if (defined(invoker.deps)) {
1572       deps += invoker.deps
1573     }
1574     datadeps = [
1575       "//tools/android/forwarder2",
1576       "//tools/android/md5sum",
1577     ]
1578     if (defined(invoker.datadeps)) {
1579       datadeps += invoker.datadeps
1580     }
1581   }
1584 # Generate .java files from .aidl files.
1586 # This target will store the .java files in a srcjar and should be included in
1587 # an android_library or android_apk's srcjar_deps.
1589 # Variables
1590 #   sources: Paths to .aidl files to compile.
1591 #   import_include: Path to directory containing .java files imported by the
1592 #     .aidl files.
1593 #   interface_file: Preprocessed aidl file to import.
1595 # Example
1596 #   android_aidl("foo_aidl") {
1597 #     import_include = "java/src"
1598 #     sources = [
1599 #       "java/src/com/foo/bar/FooBarService.aidl",
1600 #       "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1601 #     ]
1602 #   }
1603 template("android_aidl") {
1604   set_sources_assignment_filter([])
1605   if (defined(invoker.testonly)) {
1606     testonly = invoker.testonly
1607   }
1609   srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1610   aidl_path = "${android_sdk_build_tools}/aidl"
1611   framework_aidl = "$android_sdk/framework.aidl"
1613   action(target_name) {
1614     script = "//build/android/gyp/aidl.py"
1615     sources = invoker.sources
1617     imports = [ framework_aidl ]
1618     if (defined(invoker.interface_file)) {
1619       assert(invoker.interface_file != "")
1620       imports += [ invoker.interface_file ]
1621     }
1623     inputs = [ aidl_path ] + imports
1625     depfile = "${target_gen_dir}/${target_name}.d"
1626     outputs = [
1627       depfile,
1628       srcjar_path,
1629     ]
1630     rebased_imports = rebase_path(imports, root_build_dir)
1631     args = [
1632       "--depfile",
1633       rebase_path(depfile, root_build_dir),
1634       "--aidl-path",
1635       rebase_path(aidl_path, root_build_dir),
1636       "--imports=$rebased_imports",
1637       "--srcjar",
1638       rebase_path(srcjar_path, root_build_dir),
1639     ]
1640     if (defined(invoker.import_include) && invoker.import_include != "") {
1641       # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1642       # switch to constructing a depfile for the overall action from that
1643       # instead of having all the .java files in the include paths as inputs.
1644       rebased_import_includes =
1645           rebase_path([ invoker.import_include ], root_build_dir)
1646       args += [ "--includes=$rebased_import_includes" ]
1648       _java_files_build_rel =
1649           exec_script("//build/android/gyp/find.py",
1650                       rebase_path([ invoker.import_include ], root_build_dir),
1651                       "list lines")
1652       _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1653       inputs += _java_files
1654     }
1655     args += rebase_path(sources, root_build_dir)
1656   }
1659 # Creates a dist directory for a native executable.
1661 # Running a native executable on a device requires all the shared library
1662 # dependencies of that executable. To make it easier to install and run such an
1663 # executable, this will create a directory containing the native exe and all
1664 # it's library dependencies.
1666 # Note: It's usually better to package things as an APK than as a native
1667 # executable.
1669 # Variables
1670 #   dist_dir: Directory for the exe and libraries. Everything in this directory
1671 #     will be deleted before copying in the exe and libraries.
1672 #   binary: Path to (stripped) executable.
1674 # Example
1675 #   create_native_executable_dist("foo_dist") {
1676 #     dist_dir = "$root_build_dir/foo_dist"
1677 #     binary = "$root_build_dir/exe.stripped/foo"
1678 #   }
1679 template("create_native_executable_dist") {
1680   set_sources_assignment_filter([])
1681   if (defined(invoker.testonly)) {
1682     testonly = invoker.testonly
1683   }
1685   dist_dir = invoker.dist_dir
1686   binary = invoker.binary
1687   final_deps = []
1688   template_name = target_name
1690   libraries_list =
1691       "${target_gen_dir}/${template_name}_library_dependencies.list"
1693   # TODO(gyp)
1694   #'dependencies': [
1695   #'<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
1696   #],
1698   stripped_libraries_dir = "$root_build_dir/lib.stripped"
1699   final_deps += [ ":${template_name}__find_library_dependencies" ]
1700   action("${template_name}__find_library_dependencies") {
1701     script = "//build/android/gyp/write_ordered_libraries.py"
1702     depfile = "$target_gen_dir/$target_name.d"
1703     inputs = [
1704       binary,
1705       android_readelf,
1706     ]
1707     outputs = [
1708       depfile,
1709       libraries_list,
1710     ]
1711     rebased_binaries = rebase_path([ binary ], root_build_dir)
1712     args = [
1713       "--depfile",
1714       rebase_path(depfile, root_build_dir),
1715       "--input-libraries=$rebased_binaries",
1716       "--libraries-dir",
1717       rebase_path(stripped_libraries_dir, root_build_dir),
1718       "--output",
1719       rebase_path(libraries_list, root_build_dir),
1720       "--readelf",
1721       rebase_path(android_readelf, root_build_dir),
1722     ]
1723   }
1725   final_deps += [ ":${template_name}__copy_libraries_and_exe" ]
1726   copy_ex("${template_name}__copy_libraries_and_exe") {
1727     clear_dir = true
1728     inputs = [
1729       binary,
1730       libraries_list,
1731     ]
1732     dest = dist_dir
1733     rebased_binaries_list = rebase_path([ binary ], root_build_dir)
1734     rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
1735     args = [
1736       "--files=$rebased_binaries_list",
1737       "--files=@FileArg($rebased_libraries_list:libraries)",
1738     ]
1739   }
1741   group(target_name) {
1742     deps = final_deps
1743   }
1746 # Compile a protocol buffer to java.
1748 # This generates java files from protocol buffers and creates an Android library
1749 # containing the classes.
1751 # Variables
1752 #   sources: Paths to .proto files to compile.
1753 #   proto_path: Root directory of .proto files.
1755 # Example:
1756 #  proto_java_library("foo_proto_java") {
1757 #    proto_path = [ "src/foo" ]
1758 #    sources = [ "$proto_path/foo.proto" ]
1759 #  }
1760 template("proto_java_library") {
1761   set_sources_assignment_filter([])
1762   _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
1763   _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
1764   _protoc_bin = "$_protoc_out_dir/android_protoc"
1765   _proto_path = invoker.proto_path
1767   _template_name = target_name
1769   action("${_template_name}__protoc_java") {
1770     srcjar_path = "$target_gen_dir/$target_name.srcjar"
1771     script = "//build/protoc_java.py"
1772     deps = [
1773       _protoc_dep,
1774     ]
1775     sources = invoker.sources
1776     depfile = "$target_gen_dir/$target_name.d"
1777     outputs = [
1778       depfile,
1779       srcjar_path,
1780     ]
1781     args = [
1782              "--depfile",
1783              rebase_path(depfile, root_build_dir),
1784              "--protoc",
1785              rebase_path(_protoc_bin, root_build_dir),
1786              "--proto-path",
1787              rebase_path(_proto_path, root_build_dir),
1788              "--srcjar",
1789              rebase_path(srcjar_path, root_build_dir),
1790            ] + rebase_path(sources, root_build_dir)
1791   }
1793   android_library(target_name) {
1794     java_files = []
1795     srcjar_deps = [ ":${_template_name}__protoc_java" ]
1796     deps = [
1797       "//third_party/android_protobuf:protobuf_nano_javalib",
1798     ]
1799   }
1802 # TODO(GYP): implement this.
1803 template("uiautomator_test") {
1804   set_sources_assignment_filter([])
1805   if (defined(invoker.testonly)) {
1806     testonly = invoker.testonly
1807   }
1808   assert(target_name != "")
1809   assert(invoker.deps != [] || true)
1810   group(target_name) {
1811   }