Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: build/config/android/rules.gni

Issue 2023703002: Beginning work on GN build (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Really add //build. Add dart_bootstrap rule. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/config/android/internal_rules.gni ('k') | build/config/arm.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 import("//base/android/linker/config.gni")
6 import("//build/config/android/config.gni")
7 import("//build/config/android/internal_rules.gni")
8 import("//build/config/sanitizers/sanitizers.gni")
9 import("//build/toolchain/toolchain.gni")
10 import("//third_party/android_platform/config.gni")
11 import("//tools/grit/grit_rule.gni")
12
13 assert(is_android)
14
15 # Declare a jni target
16 #
17 # This target generates the native jni bindings for a set of .java files.
18 #
19 # See base/android/jni_generator/jni_generator.py for more info about the
20 # format of generating JNI bindings.
21 #
22 # Variables
23 # sources: list of .java files to generate jni for
24 # jni_package: subdirectory path for generated bindings
25 #
26 # Example
27 # generate_jni("foo_jni") {
28 # sources = [
29 # "android/java/src/org/chromium/foo/Foo.java",
30 # "android/java/src/org/chromium/foo/FooUtil.java",
31 # ]
32 # jni_package = "foo"
33 # }
34 template("generate_jni") {
35 set_sources_assignment_filter([])
36 forward_variables_from(invoker, [ "testonly" ])
37
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"
44
45 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
46
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 ]
56
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 }
70
71 config("jni_includes_${target_name}") {
72 # TODO(cjhopman): #includes should probably all be relative to
73 # base_output_dir. Remove that from this config once the includes are
74 # updated.
75 include_dirs = [
76 base_output_dir,
77 package_output_dir,
78 ]
79 }
80
81 group(target_name) {
82 forward_variables_from(invoker,
83 [
84 "deps",
85 "public_deps",
86 "visibility",
87 ])
88 if (!defined(public_deps)) {
89 public_deps = []
90 }
91 public_deps += [ ":$foreach_target_name" ]
92 public_configs = [ ":jni_includes_${target_name}" ]
93 }
94 }
95
96 # Declare a jni target for a prebuilt jar
97 #
98 # This target generates the native jni bindings for a set of classes in a .jar.
99 #
100 # See base/android/jni_generator/jni_generator.py for more info about the
101 # format of generating JNI bindings.
102 #
103 # Variables
104 # classes: list of .class files in the jar to generate jni for. These should
105 # include the full path to the .class file.
106 # jni_package: subdirectory path for generated bindings
107 # jar_file: the path to the .jar. If not provided, will default to the sdk's
108 # android.jar
109 #
110 # deps, public_deps: As normal
111 #
112 # Example
113 # generate_jar_jni("foo_jni") {
114 # classes = [
115 # "android/view/Foo.class",
116 # ]
117 # jni_package = "foo"
118 # }
119 template("generate_jar_jni") {
120 set_sources_assignment_filter([])
121 forward_variables_from(invoker, [ "testonly" ])
122
123 assert(defined(invoker.classes))
124 assert(defined(invoker.jni_package))
125
126 if (defined(invoker.jar_file)) {
127 jar_file = invoker.jar_file
128 } else {
129 jar_file = android_sdk_jar
130 }
131
132 jni_package = invoker.jni_package
133 base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}"
134 jni_output_dir = "${base_output_dir}/jni"
135
136 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
137
138 # TODO(cjhopman): make jni_generator.py support generating jni for multiple
139 # .class files from a .jar.
140 jni_actions = []
141 foreach(class, invoker.classes) {
142 _classname_list = []
143 _classname_list = process_file_template([ class ], "{{source_name_part}}")
144 classname = _classname_list[0]
145 jni_target_name = "${target_name}__jni_${classname}"
146 jni_actions += [ ":$jni_target_name" ]
147 action(jni_target_name) {
148 # The sources aren't compiled so don't check their dependencies.
149 check_includes = false
150 depfile = "$target_gen_dir/$target_name.d"
151 script = "//base/android/jni_generator/jni_generator.py"
152 sources = [
153 jar_file,
154 ]
155 outputs = [
156 depfile,
157 "${jni_output_dir}/${classname}_jni.h",
158 ]
159
160 args = [
161 "--depfile",
162 rebase_path(depfile, root_build_dir),
163 "--jar_file",
164 rebase_path(jar_file, root_build_dir),
165 "--input_file",
166 class,
167 "--optimize_generation=1",
168 "--ptr_type=long",
169 "--output_dir",
170 rebase_path(jni_output_dir, root_build_dir),
171 "--includes",
172 rebase_path(jni_generator_include, jni_output_dir),
173 "--native_exports_optional",
174 ]
175 }
176 }
177
178 config("jni_includes_${target_name}") {
179 include_dirs = [ base_output_dir ]
180 }
181
182 group(target_name) {
183 public_deps = []
184 forward_variables_from(invoker,
185 [
186 "deps",
187 "public_deps",
188 "visibility",
189 ])
190 public_deps += jni_actions
191 public_configs = [ ":jni_includes_${target_name}" ]
192 }
193 }
194
195 # Declare a target for c-preprocessor-generated java files
196 #
197 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
198 # rule instead.
199 #
200 # This target generates java files using the host C pre-processor. Each file in
201 # sources will be compiled using the C pre-processor. If include_path is
202 # specified, it will be passed (with --I) to the pre-processor.
203 #
204 # This target will create a single .srcjar. Adding this target to an
205 # android_library target's srcjar_deps will make the generated java files be
206 # included in that library's final outputs.
207 #
208 # Variables
209 # sources: list of files to be processed by the C pre-processor. For each
210 # file in sources, there will be one .java file in the final .srcjar. For a
211 # file named FooBar.template, a java file will be created with name
212 # FooBar.java.
213 # inputs: additional compile-time dependencies. Any files
214 # `#include`-ed in the templates should be listed here.
215 # package_name: this will be the subdirectory for each .java file in the
216 # .srcjar.
217 #
218 # Example
219 # java_cpp_template("foo_generated_enum") {
220 # sources = [
221 # "android/java/templates/Foo.template",
222 # ]
223 # inputs = [
224 # "android/java/templates/native_foo_header.h",
225 # ]
226 #
227 # package_name = "org/chromium/base/library_loader"
228 # include_path = "android/java/templates"
229 # }
230 template("java_cpp_template") {
231 set_sources_assignment_filter([])
232 forward_variables_from(invoker, [ "testonly" ])
233
234 assert(defined(invoker.sources))
235 package_name = invoker.package_name + ""
236
237 if (defined(invoker.include_path)) {
238 include_path = invoker.include_path + ""
239 } else {
240 include_path = "//"
241 }
242
243 apply_gcc_target_name = "${target_name}__apply_gcc"
244 zip_srcjar_target_name = "${target_name}__zip_srcjar"
245 final_target_name = target_name
246
247 action_foreach(apply_gcc_target_name) {
248 forward_variables_from(invoker,
249 [
250 "deps",
251 "public_deps",
252 "data_deps",
253 ])
254 visibility = [ ":$zip_srcjar_target_name" ]
255 script = "//build/android/gyp/gcc_preprocess.py"
256 if (defined(invoker.inputs)) {
257 inputs = invoker.inputs + []
258 }
259 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
260
261 sources = invoker.sources
262
263 gen_dir =
264 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
265 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
266
267 outputs = [
268 depfile,
269 gcc_template_output_pattern,
270 ]
271
272 args = [
273 "--depfile",
274 rebase_path(depfile, root_build_dir),
275 "--include-path",
276 rebase_path(include_path, root_build_dir),
277 "--output",
278 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
279 "--template={{source}}",
280 ]
281
282 if (defined(invoker.defines)) {
283 foreach(def, invoker.defines) {
284 args += [
285 "--defines",
286 def,
287 ]
288 }
289 }
290 }
291
292 apply_gcc_outputs = get_target_outputs(":$apply_gcc_target_name")
293 base_gen_dir = get_label_info(":$apply_gcc_target_name", "target_gen_dir")
294
295 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
296 zip(zip_srcjar_target_name) {
297 visibility = [ ":$final_target_name" ]
298 inputs = apply_gcc_outputs
299 output = srcjar_path
300 base_dir = base_gen_dir
301 deps = [
302 ":$apply_gcc_target_name",
303 ]
304 }
305
306 group(final_target_name) {
307 forward_variables_from(invoker, [ "visibility" ])
308 public_deps = [
309 ":$zip_srcjar_target_name",
310 ]
311 }
312 }
313
314 # Declare a target for generating Java classes from C++ enums.
315 #
316 # This target generates Java files from C++ enums using a script.
317 #
318 # This target will create a single .srcjar. Adding this target to an
319 # android_library target's srcjar_deps will make the generated java files be
320 # included in that library's final outputs.
321 #
322 # Variables
323 # sources: list of files to be processed by the script. For each annotated
324 # enum contained in the sources files the script will generate a .java
325 # file with the same name as the name of the enum.
326 #
327 # Example
328 # java_cpp_enum("foo_generated_enum") {
329 # sources = [
330 # "src/native_foo_header.h",
331 # ]
332 # }
333 template("java_cpp_enum") {
334 action(target_name) {
335 # The sources aren't compiled so don't check their dependencies.
336 check_includes = false
337 set_sources_assignment_filter([])
338
339 assert(defined(invoker.sources))
340 forward_variables_from(invoker,
341 [
342 "sources",
343 "testonly",
344 "visibility",
345 ])
346
347 script = "//build/android/gyp/java_cpp_enum.py"
348 depfile = "$target_gen_dir/$target_name.d"
349
350 _srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
351 _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir)
352 _rebased_sources = rebase_path(invoker.sources, root_build_dir)
353
354 args = [
355 "--depfile",
356 rebase_path(depfile, root_build_dir),
357 "--srcjar=$_rebased_srcjar_path",
358 ] + _rebased_sources
359 outputs = [
360 depfile,
361 _srcjar_path,
362 ]
363 }
364 }
365
366 # Declare a target for processing a Jinja template.
367 #
368 # Variables
369 # input: The template file to be processed.
370 # output: Where to save the result.
371 # variables: (Optional) A list of variables to make available to the template
372 # processing environment, e.g. ["name=foo", "color=red"].
373 #
374 # Example
375 # jinja_template("chrome_public_manifest") {
376 # input = "java/AndroidManifest.xml"
377 # output = "$target_gen_dir/AndroidManifest.xml"
378 # }
379 template("jinja_template") {
380 set_sources_assignment_filter([])
381 forward_variables_from(invoker, [ "testonly" ])
382
383 assert(defined(invoker.input))
384 assert(defined(invoker.output))
385
386 action(target_name) {
387 forward_variables_from(invoker,
388 [
389 "visibility",
390 "deps",
391 ])
392
393 sources = [
394 invoker.input,
395 ]
396 script = "//build/android/gyp/jinja_template.py"
397 depfile = "$target_gen_dir/$target_name.d"
398
399 outputs = [
400 depfile,
401 invoker.output,
402 ]
403
404 args = [
405 "--inputs",
406 rebase_path(invoker.input, root_build_dir),
407 "--output",
408 rebase_path(invoker.output, root_build_dir),
409 "--depfile",
410 rebase_path(depfile, root_build_dir),
411 ]
412 if (defined(invoker.variables)) {
413 variables = invoker.variables
414 args += [ "--variables=${variables}" ]
415 }
416 }
417 }
418
419 # Declare a target for processing Android resources as Jinja templates.
420 #
421 # This takes an Android resource directory where each resource is a Jinja
422 # template, processes each template, then packages the results in a zip file
423 # which can be consumed by an android resources, library, or apk target.
424 #
425 # If this target is included in the deps of an android resources/library/apk,
426 # the resources will be included with that target.
427 #
428 # Variables
429 # resources: The list of resources files to process.
430 # res_dir: The resource directory containing the resources.
431 # variables: (Optional) A list of variables to make available to the template
432 # processing environment, e.g. ["name=foo", "color=red"].
433 #
434 # Example
435 # jinja_template_resources("chrome_public_template_resources") {
436 # res_dir = "res_template"
437 # resources = ["res_template/xml/syncable.xml"]
438 # variables = ["color=red"]
439 # }
440 template("jinja_template_resources") {
441 set_sources_assignment_filter([])
442 forward_variables_from(invoker, [ "testonly" ])
443
444 assert(defined(invoker.resources))
445 assert(defined(invoker.res_dir))
446
447 _base_path = "$target_gen_dir/$target_name"
448 _resources_zip = _base_path + ".resources.zip"
449 _build_config = _base_path + ".build_config"
450
451 write_build_config("${target_name}__build_config") {
452 build_config = _build_config
453 resources_zip = _resources_zip
454 type = "android_resources"
455 }
456
457 action("${target_name}__template") {
458 sources = invoker.resources
459 script = "//build/android/gyp/jinja_template.py"
460 depfile = "$target_gen_dir/$target_name.d"
461
462 outputs = [
463 depfile,
464 _resources_zip,
465 ]
466
467 rebased_resources = rebase_path(invoker.resources, root_build_dir)
468 args = [
469 "--inputs=${rebased_resources}",
470 "--inputs-base-dir",
471 rebase_path(invoker.res_dir, root_build_dir),
472 "--outputs-zip",
473 rebase_path(_resources_zip, root_build_dir),
474 "--depfile",
475 rebase_path(depfile, root_build_dir),
476 ]
477 if (defined(invoker.variables)) {
478 variables = invoker.variables
479 args += [ "--variables=${variables}" ]
480 }
481 }
482
483 group(target_name) {
484 public_deps = [
485 ":${target_name}__build_config",
486 ":${target_name}__template",
487 ]
488 }
489 }
490
491 # Creates a resources.zip with locale.pak files placed into appropriate
492 # resource configs (e.g. en-GB.pak -> res/raw-en/en_gb.pak). Also generates
493 # a locale_paks TypedArray so that resource files can be enumerated at runtime.
494 #
495 # If this target is included in the deps of an android resources/library/apk,
496 # the resources will be included with that target.
497 #
498 # Variables:
499 # sources: List of .pak files. Names must be of the form "en.pak" or
500 # "en-US.pak".
501 # deps: (optional) List of dependencies that might be needed to generate
502 # the .pak files.
503 #
504 # Example
505 # locale_pak_resources("locale_paks") {
506 # sources = [ "path/en-US.pak", "path/fr.pak", ... ]
507 # }
508 template("locale_pak_resources") {
509 set_sources_assignment_filter([])
510 assert(defined(invoker.sources))
511
512 _base_path = "$target_gen_dir/$target_name"
513 _resources_zip = _base_path + ".resources.zip"
514 _build_config = _base_path + ".build_config"
515
516 write_build_config("${target_name}__build_config") {
517 build_config = _build_config
518 resources_zip = _resources_zip
519 type = "android_resources"
520 is_locale_resource = true
521 }
522
523 action("${target_name}__create_resources_zip") {
524 forward_variables_from(invoker,
525 [
526 "deps",
527 "sources",
528 ])
529 script = "//build/android/gyp/locale_pak_resources.py"
530 depfile = "$target_gen_dir/$target_name.d"
531
532 outputs = [
533 depfile,
534 _resources_zip,
535 ]
536
537 _rebased_sources = rebase_path(sources, root_build_dir)
538 args = [
539 "--locale-paks=${_rebased_sources}",
540 "--resources-zip",
541 rebase_path(_resources_zip, root_build_dir),
542 "--depfile",
543 rebase_path(depfile, root_build_dir),
544 ]
545 }
546
547 group(target_name) {
548 public_deps = [
549 ":${target_name}__build_config",
550 ":${target_name}__create_resources_zip",
551 ]
552 }
553 }
554
555 # Declare an Android resources target
556 #
557 # This creates a resources zip file that will be used when building an Android
558 # library or apk and included into a final apk.
559 #
560 # To include these resources in a library/apk, this target should be listed in
561 # the library's deps. A library/apk will also include any resources used by its
562 # own dependencies.
563 #
564 # Variables
565 # deps: Specifies the dependencies of this target. Any Android resources
566 # listed in deps will be included by libraries/apks that depend on this
567 # target.
568 # resource_dirs: List of directories containing resources for this target.
569 # generated_resource_dirs: List of directories containing resources for this
570 # target which are *generated* by a dependency. |generated_resource_files|
571 # must be specified if |generated_resource_dirs| is specified.
572 # generated_resource_files: List of all files in |generated_resource_dirs|.
573 # |generated_resource_dirs| must be specified in |generated_resource_files|
574 # is specified.
575 # android_manifest: AndroidManifest.xml for this target. Defaults to
576 # //build/android/AndroidManifest.xml.
577 # custom_package: java package for generated .java files.
578 # v14_skip: If true, don't run v14 resource generator on this. Defaults to
579 # false. (see build/android/gyp/generate_v14_compatible_resources.py)
580 # shared_resources: If true make a resource package that can be loaded by a
581 # different application at runtime to access the package's resources.
582 # app_as_shared_lib: If true make a resource package that can be loaded as
583 # both shared_resources and normal application.
584
585 # Example:
586 # android_resources("foo_resources") {
587 # deps = [":foo_strings_grd"]
588 # resource_dirs = ["res"]
589 # custom_package = "org.chromium.foo"
590 # }
591 #
592 # android_resources("foo_resources_overrides") {
593 # deps = [":foo_resources"]
594 # resource_dirs = ["res_overrides"]
595 # }
596 template("android_resources") {
597 set_sources_assignment_filter([])
598 forward_variables_from(invoker, [ "testonly" ])
599
600 assert(defined(invoker.resource_dirs))
601
602 base_path = "$target_gen_dir/$target_name"
603 zip_path = base_path + ".resources.zip"
604 srcjar_path = base_path + ".srcjar"
605 r_text_path = base_path + "_R.txt"
606 build_config = base_path + ".build_config"
607
608 build_config_target_name = "${target_name}__build_config"
609 process_resources_target_name = "${target_name}__process_resources"
610 final_target_name = target_name
611
612 write_build_config(build_config_target_name) {
613 forward_variables_from(invoker,
614 [
615 "android_manifest",
616 "custom_package",
617 "deps",
618 ])
619
620 # No package means resources override their deps.
621 if (defined(custom_package) || defined(android_manifest)) {
622 r_text = r_text_path
623 } else {
624 assert(defined(invoker.deps),
625 "Must specify deps when custom_package is omitted.")
626 }
627 visibility = [ ":$process_resources_target_name" ]
628
629 type = "android_resources"
630 resources_zip = zip_path
631 srcjar = srcjar_path
632 }
633
634 process_resources(process_resources_target_name) {
635 visibility = [ ":$final_target_name" ]
636 forward_variables_from(invoker,
637 [
638 "app_as_shared_lib",
639 "android_manifest",
640 "custom_package",
641 "deps",
642 "generated_resource_dirs",
643 "generated_resource_files",
644 "resource_dirs",
645 "shared_resources",
646 "v14_skip",
647 ])
648 if (!defined(deps)) {
649 deps = []
650 }
651 deps += [ ":$build_config_target_name" ]
652
653 # Always generate R.onResourcesLoaded() method, it is required for
654 # compiling ResourceRewriter, there is no side effect because the
655 # generated R.class isn't used in final apk.
656 shared_resources = true
657 if (!defined(android_manifest)) {
658 android_manifest = "//build/android/AndroidManifest.xml"
659 }
660 }
661
662 group(final_target_name) {
663 forward_variables_from(invoker, [ "visibility" ])
664 public_deps = [
665 ":${target_name}__process_resources",
666 ]
667 }
668 }
669
670 # Declare an Android assets target.
671 #
672 # Defines a set of files to include as assets in a dependent apk.
673 #
674 # To include these assets in an apk, this target should be listed in
675 # the apk's deps, or in the deps of a library target used by an apk.
676 #
677 # Variables
678 # deps: Specifies the dependencies of this target. Any Android assets
679 # listed in deps will be included by libraries/apks that depend on this
680 # target.
681 # sources: List of files to include as assets.
682 # renaming_sources: List of files to include as assets and be renamed.
683 # renaming_destinations: List of asset paths for files in renaming_sources.
684 # disable_compression: Whether to disable compression for files that are
685 # known to be compressable (default: false).
686 #
687 # Example:
688 # android_assets("content_shell_assets") {
689 # deps = [
690 # ":generates_foo",
691 # ":other_assets",
692 # ]
693 # sources = [
694 # "//path/asset1.png",
695 # "//path/asset2.png",
696 # "$target_gen_dir/foo.dat",
697 # ]
698 # }
699 #
700 # android_assets("overriding_content_shell_assets") {
701 # deps = [ ":content_shell_assets" ]
702 # # Override foo.dat from content_shell_assets.
703 # sources = [ "//custom/foo.dat" ]
704 # renaming_sources = [ "//path/asset2.png" ]
705 # renaming_destinations = [ "renamed/asset2.png" ]
706 # }
707 template("android_assets") {
708 set_sources_assignment_filter([])
709 forward_variables_from(invoker, [ "testonly" ])
710
711 _build_config = "$target_gen_dir/$target_name.build_config"
712 _build_config_target_name = "${target_name}__build_config"
713
714 write_build_config(_build_config_target_name) {
715 forward_variables_from(invoker,
716 [
717 "deps",
718 "disable_compression",
719 ])
720 type = "android_assets"
721 build_config = _build_config
722 if (defined(invoker.sources)) {
723 asset_sources = invoker.sources
724 }
725 if (defined(invoker.renaming_sources)) {
726 assert(defined(invoker.renaming_destinations))
727 _source_count = 0
728 foreach(_, invoker.renaming_sources) {
729 _source_count += 1
730 }
731 _dest_count = 0
732 foreach(_, invoker.renaming_destinations) {
733 _dest_count += 1
734 }
735 assert(
736 _source_count == _dest_count,
737 "android_assets() renaming_sources.length != renaming_destinations.len gth")
738 asset_renaming_sources = invoker.renaming_sources
739 asset_renaming_destinations = invoker.renaming_destinations
740 }
741 }
742
743 group(target_name) {
744 forward_variables_from(invoker, [ "visibility" ])
745 public_deps = [
746 ":$_build_config_target_name",
747 ]
748 }
749 }
750
751 # Declare a group() that supports forwarding java dependency information.
752 #
753 # Example
754 # java_group("conditional_deps") {
755 # if (enable_foo) {
756 # deps = [":foo_java"]
757 # }
758 # }
759 template("java_group") {
760 write_build_config("${target_name}__build_config") {
761 forward_variables_from(invoker, [ "deps" ])
762 type = "group"
763 build_config = "$target_gen_dir/${invoker.target_name}.build_config"
764 }
765 group(target_name) {
766 deps = []
767 forward_variables_from(invoker, "*")
768 deps += [ ":${target_name}__build_config" ]
769 }
770 }
771
772 # Declare a target that generates localized strings.xml from a .grd file.
773 #
774 # If this target is included in the deps of an android resources/library/apk,
775 # the strings.xml will be included with that target.
776 #
777 # Variables
778 # deps: Specifies the dependencies of this target.
779 # grd_file: Path to the .grd file to generate strings.xml from.
780 # outputs: Expected grit outputs (see grit rule).
781 #
782 # Example
783 # java_strings_grd("foo_strings_grd") {
784 # grd_file = "foo_strings.grd"
785 # }
786 template("java_strings_grd") {
787 set_sources_assignment_filter([])
788 forward_variables_from(invoker, [ "testonly" ])
789
790 base_path = "$target_gen_dir/$target_name"
791 resources_zip = base_path + ".resources.zip"
792 build_config = base_path + ".build_config"
793
794 write_build_config("${target_name}__build_config") {
795 forward_variables_from(invoker, [ "deps" ])
796 type = "android_resources"
797 }
798
799 # Put grit files into this subdirectory of target_gen_dir.
800 extra_output_path = target_name + "_grit_output"
801
802 grit_target_name = "${target_name}__grit"
803 grit_output_dir = "$target_gen_dir/$extra_output_path"
804 grit(grit_target_name) {
805 grit_flags = [
806 "-E",
807 "ANDROID_JAVA_TAGGED_ONLY=false",
808 ]
809 output_dir = grit_output_dir
810 resource_ids = ""
811 source = invoker.grd_file
812 outputs = invoker.outputs
813 }
814
815 # This needs to get outputs from grit's internal target, not the final
816 # source_set.
817 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
818
819 zip("${target_name}__zip") {
820 base_dir = grit_output_dir
821 inputs = generate_strings_outputs
822 output = resources_zip
823 deps = [
824 ":$grit_target_name",
825 ]
826 }
827
828 group(target_name) {
829 public_deps = [
830 ":${target_name}__build_config",
831 ":${target_name}__zip",
832 ]
833 }
834 }
835
836 # Declare a target that packages strings.xml generated from a grd file.
837 #
838 # If this target is included in the deps of an android resources/library/apk,
839 # the strings.xml will be included with that target.
840 #
841 # Variables
842 # grit_output_dir: directory containing grit-generated files.
843 # generated_files: list of android resource files to package.
844 #
845 # Example
846 # java_strings_grd_prebuilt("foo_strings_grd") {
847 # grit_output_dir = "$root_gen_dir/foo/grit"
848 # generated_files = [
849 # "values/strings.xml"
850 # ]
851 # }
852 template("java_strings_grd_prebuilt") {
853 set_sources_assignment_filter([])
854 forward_variables_from(invoker, [ "testonly" ])
855
856 base_path = "$target_gen_dir/$target_name"
857 resources_zip = base_path + ".resources.zip"
858 build_config = base_path + ".build_config"
859
860 build_config_target_name = "${target_name}__build_config"
861 zip_target_name = "${target_name}__zip"
862 final_target_name = target_name
863
864 write_build_config(build_config_target_name) {
865 visibility = [ ":$zip_target_name" ]
866 type = "android_resources"
867 }
868
869 zip(zip_target_name) {
870 visibility = [ ":$final_target_name" ]
871
872 base_dir = invoker.grit_output_dir
873 inputs = rebase_path(invoker.generated_files, ".", base_dir)
874 output = resources_zip
875 deps = [
876 ":$build_config_target_name",
877 ]
878 if (defined(invoker.deps)) {
879 deps += invoker.deps
880 }
881 }
882
883 group(final_target_name) {
884 forward_variables_from(invoker, [ "visibility" ])
885 public_deps = [
886 ":$zip_target_name",
887 ]
888 }
889 }
890
891 # Declare a Java executable target
892 #
893 # This target creates an executable from java code and libraries. The executable
894 # will be in the output folder's /bin/ directory.
895 #
896 # Variables
897 # deps: Specifies the dependencies of this target. Java targets in this list
898 # will be included in the executable (and the javac classpath).
899 # java_files: List of .java files included in this library.
900 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
901 # will be added to java_files and be included in this library.
902 # srcjars: List of srcjars to be included in this library, together with the
903 # ones obtained from srcjar_deps.
904 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
905 # dependencies for this target. This will allow depending on an
906 # android_library target, for example.
907 # chromium_code: If true, extra analysis warning/errors will be enabled.
908 # enable_errorprone: If true, enables the errorprone compiler.
909 # enable_incremental_javac_override: Overrides the
910 # global enable_incremental_javac.
911 # main_class: When specified, a wrapper script is created within
912 # $root_build_dir/bin to launch the binary with the given class as the
913 # entrypoint.
914 # wrapper_script_args: List of additional arguments for the wrapper script.
915 #
916 # data_deps, testonly
917 #
918 # Example
919 # java_binary("foo") {
920 # java_files = [ "org/chromium/foo/FooMain.java" ]
921 # deps = [ ":bar_java" ]
922 # main_class = "org.chromium.foo.FooMain"
923 # }
924 template("java_binary") {
925 set_sources_assignment_filter([])
926
927 java_library_impl(target_name) {
928 forward_variables_from(invoker, "*")
929 supports_android = false
930 main_class = invoker.main_class
931 is_java_binary = true
932 }
933 }
934
935 # Declare a Junit executable target
936 #
937 # This target creates an executable from java code for running as a junit test
938 # suite. The executable will be in the output folder's /bin/ directory.
939 #
940 # Variables
941 # deps: Specifies the dependencies of this target. Java targets in this list
942 # will be included in the executable (and the javac classpath).
943 #
944 # java_files: List of .java files included in this library.
945 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
946 # will be added to java_files and be included in this library.
947 # srcjars: List of srcjars to be included in this library, together with the
948 # ones obtained from srcjar_deps.
949 #
950 # chromium_code: If true, extra analysis warning/errors will be enabled.
951 #
952 # Example
953 # junit_binary("foo") {
954 # java_files = [ "org/chromium/foo/FooTest.java" ]
955 # deps = [ ":bar_java" ]
956 # }
957 template("junit_binary") {
958 set_sources_assignment_filter([])
959 testonly = true
960
961 _java_binary_target_name = "${target_name}__java_binary"
962 _test_runner_target_name = "${target_name}__test_runner_script"
963
964 test_runner_script(_test_runner_target_name) {
965 test_name = invoker.target_name
966 test_suite = invoker.target_name
967 test_type = "junit"
968 }
969
970 java_binary(_java_binary_target_name) {
971 deps = []
972 jar_name = invoker.target_name
973 forward_variables_from(invoker, "*")
974 testonly = true
975 bypass_platform_checks = true
976 main_class = "org.chromium.testing.local.JunitTestMain"
977 wrapper_script_name = "helper/$target_name"
978
979 deps += [
980 "//testing/android/junit:junit_test_support",
981 "//third_party/junit",
982 "//third_party/mockito:mockito_java",
983 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
984 "//third_party/robolectric:robolectric_java",
985 ]
986 }
987 group(target_name) {
988 public_deps = [
989 ":$_java_binary_target_name",
990 ":$_test_runner_target_name",
991 ]
992 }
993 }
994
995 # Declare a java library target
996 #
997 # Variables
998 # deps: Specifies the dependencies of this target. Java targets in this list
999 # will be added to the javac classpath.
1000 #
1001 # java_files: List of .java files included in this library.
1002 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1003 # will be added to java_files and be included in this library.
1004 # srcjars: List of srcjars to be included in this library, together with the
1005 # ones obtained from srcjar_deps.
1006 #
1007 # input_jars_paths: A list of paths to the jars that should be included
1008 # in the classpath. These are in addition to library .jars that
1009 # appear in deps.
1010 #
1011 # chromium_code: If true, extra analysis warning/errors will be enabled.
1012 # enable_errorprone: If true, enables the errorprone compiler.
1013 # enable_incremental_javac_override: Overrides the global
1014 # enable_incremental_javac.
1015 #
1016 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1017 # final jar.
1018 #
1019 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1020 # be used to remove unwanted parts of the library.
1021 # proguard_config: Path to the proguard config for preprocessing.
1022 #
1023 # supports_android: If true, Android targets (android_library, android_apk)
1024 # may depend on this target. Note: if true, this target must only use the
1025 # subset of Java available on Android.
1026 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
1027 # dependencies for this target. This will allow depending on an
1028 # android_library target, for example.
1029 #
1030 # data_deps, testonly
1031 #
1032 # Example
1033 # java_library("foo_java") {
1034 # java_files = [
1035 # "org/chromium/foo/Foo.java",
1036 # "org/chromium/foo/FooInterface.java",
1037 # "org/chromium/foo/FooService.java",
1038 # ]
1039 # deps = [
1040 # ":bar_java"
1041 # ]
1042 # srcjar_deps = [
1043 # ":foo_generated_enum"
1044 # ]
1045 # jar_excluded_patterns = [
1046 # "*/FooService.class", "*/FooService##*.class"
1047 # ]
1048 # }
1049 template("java_library") {
1050 set_sources_assignment_filter([])
1051 java_library_impl(target_name) {
1052 forward_variables_from(invoker, "*")
1053 }
1054 }
1055
1056 # Declare a java library target for a prebuilt jar
1057 #
1058 # Variables
1059 # deps: Specifies the dependencies of this target. Java targets in this list
1060 # will be added to the javac classpath.
1061 # jar_path: Path to the prebuilt jar.
1062 # jar_dep: Target that builds jar_path (optional).
1063 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1064 # be used to remove unwanted parts of the library.
1065 # proguard_config: Path to the proguard config for preprocessing.
1066 # supports_android: If true, Android targets (android_library, android_apk)
1067 # may depend on this target. Note: if true, this target must only use the
1068 # subset of Java available on Android.
1069 #
1070 # Example
1071 # java_prebuilt("foo_java") {
1072 # jar_path = "foo.jar"
1073 # deps = [
1074 # ":foo_resources",
1075 # ":bar_java"
1076 # ]
1077 # }
1078 template("java_prebuilt") {
1079 set_sources_assignment_filter([])
1080 java_prebuilt_impl(target_name) {
1081 forward_variables_from(invoker, "*")
1082 }
1083 }
1084
1085 # Declare an Android library target
1086 #
1087 # This target creates an Android library containing java code and Android
1088 # resources.
1089 #
1090 # Variables
1091 # deps: Specifies the dependencies of this target. Java targets in this list
1092 # will be added to the javac classpath. Android resources in dependencies
1093 # will be used when building this library.
1094 #
1095 # java_files: List of .java files included in this library.
1096 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1097 # will be added to java_files and be included in this library.
1098 # srcjars: List of srcjars to be included in this library, together with the
1099 # ones obtained from srcjar_deps.
1100 #
1101 # input_jars_paths: A list of paths to the jars that should be included
1102 # in the classpath. These are in addition to library .jars that
1103 # appear in deps.
1104 #
1105 # chromium_code: If true, extra analysis warning/errors will be enabled.
1106 # enable_errorprone: If true, enables the errorprone compiler.
1107 # enable_incremental_javac_override: Overrides the global
1108 # enable_incremental_javac.
1109 #
1110 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1111 # final jar.
1112 #
1113 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1114 # be used to remove unwanted parts of the library.
1115 # proguard_config: Path to the proguard config for preprocessing.
1116 #
1117 # dex_path: If set, the resulting .dex.jar file will be placed under this
1118 # path.
1119 #
1120 # alternative_android_sdk_ijar: if set, the given android_sdk_ijar file
1121 # replaces the default android_sdk_ijar.
1122 #
1123 # alternative_android_sdk_ijar_dep: the target that generates
1124 # alternative_android_sdk_ijar, must be set if alternative_android_sdk_ijar
1125 # is used.
1126 #
1127 # emma_never_instrument: Disables EMMA Java code coverage for this target.
1128 #
1129 # Example
1130 # android_library("foo_java") {
1131 # java_files = [
1132 # "android/org/chromium/foo/Foo.java",
1133 # "android/org/chromium/foo/FooInterface.java",
1134 # "android/org/chromium/foo/FooService.java",
1135 # ]
1136 # deps = [
1137 # ":bar_java"
1138 # ]
1139 # srcjar_deps = [
1140 # ":foo_generated_enum"
1141 # ]
1142 # jar_excluded_patterns = [
1143 # "*/FooService.class", "*/FooService##*.class"
1144 # ]
1145 # }
1146 template("android_library") {
1147 set_sources_assignment_filter([])
1148 assert(!defined(invoker.jar_path),
1149 "android_library does not support a custom jar path")
1150
1151 if (defined(invoker.alternative_android_sdk_ijar)) {
1152 assert(defined(invoker.alternative_android_sdk_ijar_dep))
1153 }
1154
1155 java_library_impl(target_name) {
1156 forward_variables_from(invoker, "*")
1157
1158 supports_android = true
1159 requires_android = true
1160
1161 if (!defined(jar_excluded_patterns)) {
1162 jar_excluded_patterns = []
1163 }
1164 jar_excluded_patterns += [
1165 "*/R.class",
1166 "*/R##*.class",
1167 "*/Manifest.class",
1168 "*/Manifest##*.class",
1169 ]
1170 }
1171 }
1172
1173 # Declare a target that packages a set of Java dependencies into a standalone
1174 # .dex.jar.
1175 #
1176 # Variables
1177 # deps: specifies the dependencies of this target. Android libraries in deps
1178 # will be packaged into the resulting .dex.jar file.
1179 # dex_path: location at which the output file will be put
1180 template("android_standalone_library") {
1181 set_sources_assignment_filter([])
1182 deps_dex(target_name) {
1183 forward_variables_from(invoker,
1184 [
1185 "deps",
1186 "dex_path",
1187 "excluded_jars",
1188 ])
1189 }
1190 }
1191
1192 # Declare an Android library target for a prebuilt jar
1193 #
1194 # This target creates an Android library containing java code and Android
1195 # resources.
1196 #
1197 # Variables
1198 # deps: Specifies the dependencies of this target. Java targets in this list
1199 # will be added to the javac classpath. Android resources in dependencies
1200 # will be used when building this library.
1201 # jar_path: Path to the prebuilt jar.
1202 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1203 # be used to remove unwanted parts of the library.
1204 # proguard_config: Path to the proguard config for preprocessing.
1205 #
1206 # Example
1207 # android_java_prebuilt("foo_java") {
1208 # jar_path = "foo.jar"
1209 # deps = [
1210 # ":foo_resources",
1211 # ":bar_java"
1212 # ]
1213 # }
1214 template("android_java_prebuilt") {
1215 set_sources_assignment_filter([])
1216 java_prebuilt_impl(target_name) {
1217 forward_variables_from(invoker, "*")
1218 supports_android = true
1219 requires_android = true
1220 strip_resource_classes = true
1221 }
1222 }
1223
1224 # Declare an Android apk target
1225 #
1226 # This target creates an Android APK containing java code, resources, assets,
1227 # and (possibly) native libraries.
1228 #
1229 # Variables
1230 # alternative_android_sdk_jar: The alternative android sdk jar used in
1231 # proguard.
1232 # android_aapt_path: Android aapt tool to replace default one to build
1233 # resource.
1234 # android_manifest: Path to AndroidManifest.xml.
1235 # android_manifest_dep: Target that generates AndroidManifest (if applicable)
1236 # chromium_code: If true, extra analysis warning/errors will be enabled.
1237 # create_dist_ijar: Whether to define the "${target_name}_dist_ijar" target
1238 # (used by instrumentation_test_apk).
1239 # data_deps: List of dependencies needed at runtime. These will be built but
1240 # won't change the generated .apk in any way (in fact they may be built
1241 # after the .apk is).
1242 # deps: List of dependencies. All Android java resources and libraries in the
1243 # "transitive closure" of these dependencies will be included in the apk.
1244 # Note: this "transitive closure" actually only includes such targets if
1245 # they are depended on through android_library or android_resources targets
1246 # (and so not through builtin targets like 'action', 'group', etc).
1247 # install_script_name: Name of wrapper script (default=target_name).
1248 # java_files: List of .java files to include in the apk.
1249 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1250 # will be added to java_files and be included in this apk.
1251 # apk_name: Name for final apk.
1252 # final_apk_path: Path to final built apk. Default is
1253 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1254 # loadable_modules: List of paths to native libraries to include. Different
1255 # from |native_libs| in that:
1256 # * dependencies of this .so are not automatically included
1257 # * ".cr.so" is never added
1258 # * they are not side-loaded for _incremental targets.
1259 # * load_library_from_apk, use_chromium_linker,
1260 # and enable_relocation_packing do not apply
1261 # Use this instead of native_libs when you are going to load the library
1262 # conditionally, and only when native_libs doesn't work for you.
1263 # native_libs: List paths of native libraries to include in this apk. If these
1264 # libraries depend on other shared_library targets, those dependencies will
1265 # also be included in the apk. When building with is_component_build,
1266 # The extension is automatically changed to ".cr.so".
1267 # native_lib_placeholders: List of placeholder filenames to add to the apk
1268 # (optional).
1269 # apk_under_test: For an instrumentation test apk, this is the target of the
1270 # tested apk.
1271 # include_all_resources - If true include all resource IDs in all generated
1272 # R.java files.
1273 # testonly: Marks this target as "test-only".
1274 # write_asset_list: Adds an extra file to the assets, which contains a list of
1275 # all other asset files.
1276 # alternative_locale_resource_dep: The locale resource target which overrides
1277 # any exsting locale resources in dep graph.
1278 # requires_sdk_api_level_23: If defined and true, the apk is intended for
1279 # installation only on Android M or later. In these releases the system
1280 # linker does relocation unpacking, so we can enable it unconditionally.
1281 # secondary_native_libs: the path of native libraries for secondary app abi.
1282 # run_findbugs_override: Forces run_findbugs on or off. If undefined, the
1283 # default will use the build arg run_findbugs.
1284 #
1285 # Example
1286 # android_apk("foo_apk") {
1287 # android_manifest = "AndroidManifest.xml"
1288 # java_files = [
1289 # "android/org/chromium/foo/FooApplication.java",
1290 # "android/org/chromium/foo/FooActivity.java",
1291 # ]
1292 # deps = [
1293 # ":foo_support_java"
1294 # ":foo_resources"
1295 # ]
1296 # srcjar_deps = [
1297 # ":foo_generated_enum"
1298 # ]
1299 # native_libs = [
1300 # native_lib_path
1301 # ]
1302 # }
1303 template("android_apk") {
1304 set_sources_assignment_filter([])
1305 forward_variables_from(invoker, [ "testonly" ])
1306
1307 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1308 assert(defined(invoker.android_manifest))
1309 gen_dir = "$target_gen_dir/$target_name"
1310 base_path = "$gen_dir/$target_name"
1311 _build_config = "$target_gen_dir/$target_name.build_config"
1312 resources_zip_path = "$base_path.resources.zip"
1313 _all_resources_zip_path = "$base_path.resources.all.zip"
1314 _jar_path = "$base_path.jar"
1315 _lib_dex_path = "$base_path.dex.jar"
1316 _rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir)
1317 _template_name = target_name
1318
1319 enable_multidex = defined(invoker.enable_multidex) && invoker.enable_multidex
1320 if (enable_multidex) {
1321 final_dex_path = "$gen_dir/classes.dex.zip"
1322 } else {
1323 final_dex_path = "$gen_dir/classes.dex"
1324 }
1325 final_dex_target_name = "${_template_name}__final_dex"
1326
1327 _final_apk_path = ""
1328 if (defined(invoker.final_apk_path)) {
1329 _final_apk_path = invoker.final_apk_path
1330 } else if (defined(invoker.apk_name)) {
1331 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1332 }
1333 _final_apk_path_no_ext_list =
1334 process_file_template([ _final_apk_path ],
1335 "{{source_dir}}/{{source_name_part}}")
1336 _final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
1337 assert(_final_apk_path_no_ext != "") # Mark as used.
1338
1339 _install_script_name = "install_$_template_name"
1340 if (defined(invoker.install_script_name)) {
1341 _install_script_name = invoker.install_script_name
1342 }
1343 _incremental_install_script_path =
1344 "${root_out_dir}/bin/${_install_script_name}_incremental"
1345
1346 _native_libs = []
1347
1348 _version_code = android_default_version_code
1349 if (defined(invoker.version_code)) {
1350 _version_code = invoker.version_code
1351 }
1352
1353 _version_name = android_default_version_name
1354 if (defined(invoker.version_name)) {
1355 _version_name = invoker.version_name
1356 }
1357 _keystore_path = android_keystore_path
1358 _keystore_name = android_keystore_name
1359 _keystore_password = android_keystore_password
1360
1361 if (defined(invoker.keystore_path)) {
1362 _keystore_path = invoker.keystore_path
1363 _keystore_name = invoker.keystore_name
1364 _keystore_password = invoker.keystore_password
1365 }
1366
1367 _srcjar_deps = []
1368 if (defined(invoker.srcjar_deps)) {
1369 _srcjar_deps += invoker.srcjar_deps
1370 }
1371
1372 _use_chromium_linker =
1373 defined(invoker.use_chromium_linker) && invoker.use_chromium_linker
1374 _enable_relocation_packing = defined(invoker.enable_relocation_packing) &&
1375 invoker.enable_relocation_packing
1376 _load_library_from_apk =
1377 defined(invoker.load_library_from_apk) && invoker.load_library_from_apk
1378 _requires_sdk_api_level_23 = defined(invoker.requires_sdk_api_level_23) &&
1379 invoker.requires_sdk_api_level_23
1380
1381 assert(_use_chromium_linker || true) # Mark as used.
1382 assert(_requires_sdk_api_level_23 || true)
1383 if (_enable_relocation_packing) {
1384 assert(_use_chromium_linker || _requires_sdk_api_level_23,
1385 "enable_relocation_packing requires either use_chromium_linker " +
1386 "or requires_sdk_api_level_23")
1387 }
1388 if (_load_library_from_apk) {
1389 assert(_use_chromium_linker || _requires_sdk_api_level_23,
1390 "load_library_from_apk requires use_chromium_linker " +
1391 "or requires_sdk_api_level_23")
1392 }
1393
1394 # The dependency that makes the chromium linker, if any is needed.
1395 _native_libs_deps = []
1396
1397 if (defined(invoker.native_libs) && invoker.native_libs != []) {
1398 if (is_component_build || is_asan) {
1399 _native_libs += [ "$root_shlib_dir/libc++_shared.so" ]
1400 _native_libs_deps += [ "//build/android:cpplib_stripped" ]
1401 }
1402
1403 # Allow native_libs to be in the form "foo.so" or "foo.cr.so"
1404 _first_ext_removed =
1405 process_file_template(invoker.native_libs, "{{source_name_part}}")
1406 _native_libs += process_file_template(
1407 _first_ext_removed,
1408 "$root_shlib_dir/{{source_name_part}}$shlib_extension")
1409
1410 _native_lib_version_rule = ""
1411 if (defined(invoker.native_lib_version_rule)) {
1412 _native_lib_version_rule = invoker.native_lib_version_rule
1413 }
1414 _native_lib_version_arg = "\"\""
1415 if (defined(invoker.native_lib_version_arg)) {
1416 _native_lib_version_arg = invoker.native_lib_version_arg
1417 }
1418 }
1419
1420 _android_manifest_deps = []
1421 if (defined(invoker.android_manifest_dep)) {
1422 _android_manifest_deps = [ invoker.android_manifest_dep ]
1423 }
1424 _android_manifest = invoker.android_manifest
1425
1426 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1427 _create_abi_split =
1428 defined(invoker.create_abi_split) && invoker.create_abi_split
1429 _create_density_splits =
1430 defined(invoker.create_density_splits) && invoker.create_density_splits
1431 _create_language_splits =
1432 defined(invoker.language_splits) && invoker.language_splits != []
1433
1434 # Help GN understand that _create_abi_split is not unused (bug in GN).
1435 assert(_create_abi_split || true)
1436
1437 _proguard_enabled =
1438 defined(invoker.proguard_enabled) && invoker.proguard_enabled
1439 if (_proguard_enabled) {
1440 _proguard_jar_path = "$base_path.proguard.jar"
1441 }
1442
1443 _emma_never_instrument = defined(invoker.testonly) && invoker.testonly
1444
1445 build_config_target = "${_template_name}__build_config"
1446 write_build_config(build_config_target) {
1447 forward_variables_from(invoker, [ "apk_under_test" ])
1448 type = "android_apk"
1449 jar_path = _jar_path
1450 dex_path = final_dex_path
1451 apk_path = _final_apk_path
1452 incremental_apk_path = "${_final_apk_path_no_ext}_incremental.apk"
1453 incremental_install_script_path = _incremental_install_script_path
1454 resources_zip = resources_zip_path
1455 build_config = _build_config
1456 android_manifest = _android_manifest
1457
1458 deps = _native_libs_deps + _android_manifest_deps
1459 if (defined(invoker.deps)) {
1460 deps += invoker.deps
1461 }
1462
1463 if (defined(invoker.alternative_locale_resource_dep)) {
1464 deps += [ invoker.alternative_locale_resource_dep ]
1465 has_alternative_locale_resource = true
1466 }
1467
1468 # Added emma to the target's classpath via its .build_config.
1469 if (emma_coverage && !_emma_never_instrument) {
1470 deps += [ "//third_party/android_tools:emma_device" ]
1471 }
1472
1473 proguard_enabled = _proguard_enabled
1474 if (_proguard_enabled) {
1475 proguard_info = "$_proguard_jar_path.info"
1476 }
1477
1478 native_libs = _native_libs
1479 }
1480
1481 _final_deps = []
1482
1483 _generated_proguard_config = "$base_path.resources.proguard.txt"
1484 process_resources_target = "${_template_name}__process_resources"
1485 process_resources(process_resources_target) {
1486 forward_variables_from(invoker,
1487 [
1488 "alternative_android_sdk_jar",
1489 "android_aapt_path",
1490 "app_as_shared_lib",
1491 "include_all_resources",
1492 "shared_resources",
1493 ])
1494 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1495 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1496 android_manifest = _android_manifest
1497 resource_dirs = [ "//build/android/ant/empty/res" ]
1498 zip_path = resources_zip_path
1499 all_resources_zip_path = _all_resources_zip_path
1500 generate_constant_ids = true
1501 proguard_file = _generated_proguard_config
1502
1503 build_config = _build_config
1504 deps = _android_manifest_deps + [ ":$build_config_target" ]
1505 if (defined(invoker.deps)) {
1506 deps += invoker.deps
1507 }
1508 }
1509 _srcjar_deps += [ ":$process_resources_target" ]
1510
1511 if (_native_libs != []) {
1512 _enable_chromium_linker_tests = false
1513 if (defined(invoker.enable_chromium_linker_tests)) {
1514 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1515 }
1516
1517 java_cpp_template("${_template_name}__native_libraries_java") {
1518 package_name = "org/chromium/base/library_loader"
1519 sources = [
1520 "//base/android/java/templates/NativeLibraries.template",
1521 ]
1522 inputs = [
1523 _build_config,
1524 ]
1525 deps = [
1526 ":$build_config_target",
1527 ]
1528 if (_native_lib_version_rule != "") {
1529 deps += [ _native_lib_version_rule ]
1530 }
1531
1532 defines = [
1533 "NATIVE_LIBRARIES_LIST=" +
1534 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1535 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg",
1536 ]
1537 if (_use_chromium_linker) {
1538 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1539 }
1540 if (_load_library_from_apk) {
1541 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1542 }
1543 if (_enable_chromium_linker_tests) {
1544 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1545 }
1546 }
1547 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1548 }
1549
1550 if (!defined(invoker.apk_under_test)) {
1551 java_cpp_template("${_template_name}__build_config_java") {
1552 package_name = "org/chromium/base"
1553 sources = [
1554 "//base/android/java/templates/BuildConfig.template",
1555 ]
1556
1557 defines = []
1558 if (enable_multidex) {
1559 defines += [ "ENABLE_MULTIDEX" ]
1560 }
1561 }
1562 _srcjar_deps += [ ":${_template_name}__build_config_java" ]
1563 }
1564
1565 java_target = "${_template_name}__java"
1566 java_library_impl(java_target) {
1567 forward_variables_from(invoker,
1568 [
1569 "chromium_code",
1570 "java_files",
1571 "run_findbugs_override",
1572 ])
1573 supports_android = true
1574 requires_android = true
1575 override_build_config = _build_config
1576 deps = _android_manifest_deps + [ ":$build_config_target" ]
1577
1578 android_manifest = _android_manifest
1579 srcjar_deps = _srcjar_deps
1580 jar_path = _jar_path
1581 dex_path = _lib_dex_path
1582 emma_never_instrument = _emma_never_instrument
1583
1584 if (defined(invoker.deps)) {
1585 deps += invoker.deps
1586 }
1587 if (defined(invoker.apk_under_test)) {
1588 deps += [ "${invoker.apk_under_test}__java" ]
1589 }
1590 }
1591
1592 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1593 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1594 # able to just do that calculation at build time instead.
1595 if (defined(invoker.create_dist_ijar) && invoker.create_dist_ijar) {
1596 _dist_ijar_path = "$root_build_dir/test.lib.java/" +
1597 get_path_info(_final_apk_path, "name") + ".jar"
1598 action("${_template_name}_dist_ijar") {
1599 script = "//build/android/gyp/create_dist_jar.py"
1600 depfile = "$target_gen_dir/$target_name.d"
1601 inputs = [
1602 _build_config,
1603 ]
1604 outputs = [
1605 depfile,
1606 "${_dist_ijar_path}",
1607 ]
1608 data = [
1609 _dist_ijar_path,
1610 ]
1611 args = [
1612 "--depfile",
1613 rebase_path(depfile, root_build_dir),
1614 "--output",
1615 rebase_path("${_dist_ijar_path}", root_build_dir),
1616 "--inputs=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)",
1617 ]
1618 deps = [
1619 ":$build_config_target", # Generates the build config file.
1620 ":$java_target", # Generates the jar file.
1621 ]
1622 }
1623 }
1624
1625 if (_proguard_enabled) {
1626 _proguard_configs = [ _generated_proguard_config ]
1627 if (defined(invoker.proguard_configs)) {
1628 _proguard_configs += invoker.proguard_configs
1629 }
1630 _proguard_target = "${_template_name}__proguard"
1631 proguard(_proguard_target) {
1632 forward_variables_from(invoker, [ "alternative_android_sdk_jar" ])
1633 deps = [
1634 ":$build_config_target",
1635 ":$java_target",
1636 ":$process_resources_target",
1637 ]
1638 inputs = [
1639 _build_config,
1640 _jar_path,
1641 ] + _proguard_configs
1642
1643 output_jar_path = _proguard_jar_path
1644 _rebased_proguard_configs = rebase_path(_proguard_configs, root_build_dir)
1645 args = [
1646 "--proguard-configs=$_rebased_proguard_configs",
1647 "--input-paths=@FileArg($_rebased_build_config:proguard:input_paths)",
1648 ]
1649 if (defined(invoker.apk_under_test)) {
1650 deps += [
1651 "${invoker.apk_under_test}__build_config",
1652 "${invoker.apk_under_test}__proguard",
1653 ]
1654 _apk_under_test_build_config =
1655 get_label_info(invoker.apk_under_test, "target_gen_dir") + "/" +
1656 get_label_info(invoker.apk_under_test, "name") + ".build_config"
1657 _rebased_apk_under_test_build_config =
1658 rebase_path(_apk_under_test_build_config, root_build_dir)
1659 args += [ "--tested-apk-info=@FileArg($_rebased_apk_under_test_build_con fig:deps_info:proguard_info)" ]
1660 }
1661 }
1662 _dex_sources = [ _proguard_jar_path ]
1663 _dex_deps = [ ":$_proguard_target" ]
1664 } else {
1665 if (enable_multidex) {
1666 _dex_sources = [ _jar_path ]
1667 } else {
1668 _dex_sources = [ _lib_dex_path ]
1669 }
1670 _dex_deps = [ ":$java_target" ]
1671 }
1672
1673 dex("$final_dex_target_name") {
1674 deps = _dex_deps + [ ":$build_config_target" ]
1675 inputs = [
1676 _build_config,
1677 ]
1678 sources = _dex_sources
1679 output = final_dex_path
1680
1681 # All deps are already included in _dex_sources when proguard is used.
1682 if (!_proguard_enabled) {
1683 if (enable_multidex) {
1684 _dex_arg_key = "${_rebased_build_config}:dist_jar:dependency_jars"
1685 } else {
1686 _dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1687 }
1688 args = [ "--inputs=@FileArg($_dex_arg_key)" ]
1689 }
1690 }
1691
1692 _native_libs_file_arg_dep = ":$build_config_target"
1693 _native_libs_file_arg = "@FileArg($_rebased_build_config:native:libraries)"
1694
1695 if (_native_libs != [] && _enable_relocation_packing) {
1696 _prepare_native_target_name = "${_template_name}__prepare_native"
1697 _native_libs_dir = "$gen_dir/packed-libs"
1698 _native_libs_json = "$gen_dir/packed-libs/filelist.json"
1699 _rebased_native_libs_json = rebase_path(_native_libs_json, root_build_dir)
1700
1701 _native_libs_file_arg_dep = ":$_prepare_native_target_name"
1702 _native_libs_file_arg = "@FileArg($_rebased_native_libs_json:files)"
1703
1704 action(_prepare_native_target_name) {
1705 forward_variables_from(invoker,
1706 [
1707 "deps",
1708 "public_deps",
1709 ])
1710 script = "//build/android/gyp/pack_relocations.py"
1711 depfile = "$target_gen_dir/$target_name.d"
1712 outputs = [
1713 depfile,
1714 _native_libs_json,
1715 ]
1716
1717 inputs = _native_libs + [ _build_config ]
1718
1719 deps += _native_libs_deps
1720 deps += [
1721 ":$build_config_target",
1722 relocation_packer_target,
1723 ]
1724
1725 args = [
1726 "--depfile",
1727 rebase_path(depfile, root_build_dir),
1728 "--enable-packing=1",
1729 "--android-pack-relocations",
1730 rebase_path(relocation_packer_exe, root_build_dir),
1731 "--stripped-libraries-dir",
1732 rebase_path(root_build_dir, root_build_dir),
1733 "--packed-libraries-dir",
1734 rebase_path(_native_libs_dir, root_build_dir),
1735 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1736 "--filelistjson=$_rebased_native_libs_json",
1737 ]
1738 }
1739 }
1740
1741 _extra_native_libs = []
1742 _extra_native_libs_deps = []
1743 _extra_native_libs_even_when_incremental = []
1744 _extra_native_libs_even_when_incremental_deps = []
1745 assert(_extra_native_libs_even_when_incremental_deps == []) # Mark as used.
1746 if (_native_libs != []) {
1747 if (is_debug) {
1748 _extra_native_libs_even_when_incremental = [ android_gdbserver ]
1749 }
1750
1751 if (_use_chromium_linker) {
1752 _extra_native_libs =
1753 [ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ]
1754 _extra_native_libs_deps +=
1755 [ "//base/android/linker:chromium_android_linker" ]
1756 }
1757 }
1758 if (defined(invoker.loadable_modules) && invoker.loadable_modules != []) {
1759 _extra_native_libs_even_when_incremental += invoker.loadable_modules
1760 }
1761
1762 _final_deps += [ ":${_template_name}__create" ]
1763 create_apk("${_template_name}__create") {
1764 forward_variables_from(invoker,
1765 [
1766 "alternative_android_sdk_jar",
1767 "android_aapt_path",
1768 "app_as_shared_lib",
1769 "deps",
1770 "extensions_to_not_compress",
1771 "language_splits",
1772 "page_align_shared_libraries",
1773 "public_deps",
1774 "secondary_native_libs",
1775 "shared_resources",
1776 "uncompress_shared_libraries",
1777 "write_asset_list",
1778 ])
1779 if (!defined(deps)) {
1780 deps = []
1781 }
1782 apk_path = _final_apk_path
1783 android_manifest = _android_manifest
1784 assets_build_config = _build_config
1785 resources_zip = _all_resources_zip_path
1786 dex_path = final_dex_path
1787 load_library_from_apk = _load_library_from_apk
1788 create_density_splits = _create_density_splits
1789 emma_instrument = emma_coverage && !_emma_never_instrument
1790
1791 if (!defined(extensions_to_not_compress)) {
1792 # Allow icu data, v8 snapshots, and pak files to be loaded directly from
1793 # the .apk.
1794 # Note: These are actually suffix matches, not necessarily extensions.
1795 extensions_to_not_compress = ".dat,.bin,.pak"
1796 }
1797
1798 version_code = _version_code
1799 version_name = _version_name
1800
1801 keystore_name = _keystore_name
1802 keystore_path = _keystore_path
1803 keystore_password = _keystore_password
1804
1805 # Incremental apk does not use native libs nor final dex.
1806 incremental_deps = deps + _android_manifest_deps + [
1807 ":$build_config_target",
1808 ":$process_resources_target",
1809 ]
1810
1811 # This target generates the input file _all_resources_zip_path.
1812 deps += _android_manifest_deps + [
1813 ":$build_config_target",
1814 ":$process_resources_target",
1815 ":$final_dex_target_name",
1816 ]
1817
1818 if ((_native_libs != [] || _extra_native_libs_even_when_incremental != []) & & !_create_abi_split) {
1819 deps += _native_libs_deps + _extra_native_libs_deps +
1820 _extra_native_libs_even_when_incremental_deps +
1821 [ _native_libs_file_arg_dep ]
1822 native_libs_filearg = _native_libs_file_arg
1823 native_libs = _extra_native_libs
1824 native_libs_even_when_incremental =
1825 _extra_native_libs_even_when_incremental
1826 }
1827
1828 # Placeholders necessary for some older devices.
1829 # http://crbug.com/395038
1830 forward_variables_from(invoker, [ "native_lib_placeholders" ])
1831 }
1832
1833 if ((_native_libs != [] || _extra_native_libs_even_when_incremental != []) &&
1834 _create_abi_split) {
1835 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1836 generate_split_manifest(_manifest_rule) {
1837 main_manifest = _android_manifest
1838 out_manifest =
1839 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1840 split_name = "abi_${android_app_abi}"
1841 deps = _android_manifest_deps
1842 }
1843
1844 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1845 _final_deps += [ ":$_apk_rule" ]
1846
1847 create_apk(_apk_rule) {
1848 apk_path = "${_final_apk_path_no_ext}-abi-${android_app_abi}.apk"
1849 base_path = "$gen_dir/$_apk_rule"
1850
1851 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1852 android_manifest = manifest_outputs[1]
1853 load_library_from_apk = _load_library_from_apk
1854
1855 version_code = _version_code
1856 version_name = _version_name
1857
1858 keystore_name = _keystore_name
1859 keystore_path = _keystore_path
1860 keystore_password = _keystore_password
1861
1862 # Placeholders necessary for some older devices.
1863 # http://crbug.com/395038
1864 deps = []
1865 forward_variables_from(invoker,
1866 [
1867 "alternative_android_sdk_jar",
1868 "android_aapt_path",
1869 "deps",
1870 "native_lib_placeholders",
1871 "public_deps",
1872 ])
1873
1874 incremental_deps = deps + _extra_native_libs_even_when_incremental_deps +
1875 [ ":$_manifest_rule" ]
1876 deps = []
1877 deps = incremental_deps + _native_libs_deps + _extra_native_libs_deps +
1878 [ _native_libs_file_arg_dep ]
1879 native_libs_filearg = _native_libs_file_arg
1880 native_libs = _extra_native_libs
1881 native_libs_even_when_incremental =
1882 _extra_native_libs_even_when_incremental
1883 }
1884 }
1885
1886 _create_incremental_script_rule_name = "${_template_name}__incremental_script"
1887 action(_create_incremental_script_rule_name) {
1888 script = "//build/android/incremental_install/create_install_script.py"
1889 depfile = "$target_gen_dir/$target_name.d"
1890 deps = [
1891 _native_libs_file_arg_dep,
1892 ]
1893
1894 outputs = [
1895 depfile,
1896 _incremental_install_script_path,
1897 ]
1898
1899 _rebased_apk_path_no_ext =
1900 rebase_path(_final_apk_path_no_ext, root_build_dir)
1901 _rebased_incremental_install_script_path =
1902 rebase_path(_incremental_install_script_path, root_build_dir)
1903 _rebased_depfile = rebase_path(depfile, root_build_dir)
1904 _dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1905 args = [
1906 "--apk-path=${_rebased_apk_path_no_ext}_incremental.apk",
1907 "--script-output-path=$_rebased_incremental_install_script_path",
1908 "--dex-file=$_rebased_lib_dex_path",
1909 "--dex-file-list=@FileArg($_dex_arg_key)",
1910 "--depfile=$_rebased_depfile",
1911 ]
1912 if (_proguard_enabled) {
1913 args += [ "--show-proguard-warning" ]
1914 }
1915 if (defined(_native_libs_file_arg)) {
1916 args += [ "--native-libs=$_native_libs_file_arg" ]
1917 }
1918 if (_extra_native_libs != []) {
1919 # Don't pass in _extra_native_libs_even_when_incremental, since these are
1920 # end up in the apk and are not side-loaded.
1921 _rebased_extra_native_libs =
1922 rebase_path(_extra_native_libs, root_build_dir)
1923 args += [ "--native-libs=$_rebased_extra_native_libs" ]
1924 }
1925 if (_create_density_splits) {
1926 args += [ "--split=${_rebased_apk_path_no_ext}-density-*.apk" ]
1927 }
1928 if (_create_language_splits) {
1929 args += [ "--split=${_rebased_apk_path_no_ext}-language-*.apk" ]
1930 }
1931 if (_load_library_from_apk) {
1932 args += [ "--dont-even-try=Incremental builds do not work with load_librar y_from_apk. Try setting is_component_build=true in your GN args." ]
1933 }
1934 }
1935
1936 group(target_name) {
1937 forward_variables_from(invoker,
1938 [
1939 "data",
1940 "data_deps",
1941 ])
1942 public_deps = _final_deps
1943 }
1944 group("${target_name}_incremental") {
1945 forward_variables_from(invoker,
1946 [
1947 "data",
1948 "data_deps",
1949 ])
1950 if (!defined(data_deps)) {
1951 data_deps = []
1952 }
1953
1954 # device/commands is used by the installer script to push files via .zip.
1955 data_deps += [ "//build/android/pylib/device/commands" ] +
1956 _native_libs_deps + _extra_native_libs_deps
1957
1958 # Since the _incremental.apk does not include use .so nor .dex from the
1959 # actual target, but instead loads them at runtime, we need to explicitly
1960 # depend on them here.
1961 public_deps = [
1962 ":${_create_incremental_script_rule_name}",
1963 ":${_template_name}__create_incremental",
1964 ":${java_target}",
1965 ]
1966 }
1967 }
1968
1969 # Declare an Android instrumentation test apk
1970 #
1971 # This target creates an Android instrumentation test apk.
1972 #
1973 # Variables
1974 # android_manifest: Path to AndroidManifest.xml.
1975 # data_deps: List of dependencies needed at runtime. These will be built but
1976 # won't change the generated .apk in any way (in fact they may be built
1977 # after the .apk is).
1978 # deps: List of dependencies. All Android java resources and libraries in the
1979 # "transitive closure" of these dependencies will be included in the apk.
1980 # Note: this "transitive closure" actually only includes such targets if
1981 # they are depended on through android_library or android_resources targets
1982 # (and so not through builtin targets like 'action', 'group', etc).
1983 # java_files: List of .java files to include in the apk.
1984 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1985 # will be added to java_files and be included in this apk.
1986 # apk_name: Name for final apk.
1987 # final_apk_path: Path to final built apk. Default is
1988 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1989 # native_libs: List paths of native libraries to include in this apk. If these
1990 # libraries depend on other shared_library targets, those dependencies will
1991 # also be included in the apk.
1992 # apk_under_test: The apk being tested.
1993 # isolate_file: Isolate file containing the list of test data dependencies.
1994 #
1995 # Example
1996 # instrumentation_test_apk("foo_test_apk") {
1997 # android_manifest = "AndroidManifest.xml"
1998 # apk_name = "FooTest"
1999 # apk_under_test = "Foo"
2000 # java_files = [
2001 # "android/org/chromium/foo/FooTestCase.java",
2002 # "android/org/chromium/foo/FooExampleTest.java",
2003 # ]
2004 # deps = [
2005 # ":foo_test_support_java"
2006 # ]
2007 # }
2008 template("instrumentation_test_apk") {
2009 testonly = true
2010 _apk_target_name = "${target_name}__apk"
2011 _test_runner_target_name = "${target_name}__test_runner_script"
2012 _install_script_name = "install_$target_name"
2013
2014 test_runner_script(_test_runner_target_name) {
2015 forward_variables_from(invoker,
2016 [
2017 "additional_apks",
2018 "apk_under_test",
2019 "isolate_file",
2020 ])
2021 test_name = invoker.target_name
2022 test_type = "instrumentation"
2023 apk_target = ":$_apk_target_name"
2024 }
2025
2026 test_runner_script("${_test_runner_target_name}_incremental") {
2027 forward_variables_from(invoker,
2028 [
2029 "additional_apks",
2030 "apk_under_test",
2031 "isolate_file",
2032 ])
2033 test_name = "${invoker.target_name}_incremental"
2034 test_type = "instrumentation"
2035 apk_target = ":$_apk_target_name"
2036 incremental_install = true
2037 }
2038
2039 android_apk(_apk_target_name) {
2040 deps = []
2041 data_deps = []
2042 forward_variables_from(invoker, "*")
2043 install_script_name = _install_script_name
2044 deps += [ "//testing/android/broker:broker_java" ]
2045 data_deps += [
2046 "//testing/android/driver:driver_apk",
2047 "//tools/android/forwarder2",
2048 "//tools/android/md5sum",
2049 ]
2050 if (defined(invoker.additional_apks)) {
2051 data_deps += invoker.additional_apks
2052 }
2053
2054 create_dist_ijar = true
2055 if (defined(invoker.run_findbugs_override)) {
2056 # Only allow findbugs when there are java files.
2057 run_findbugs_override =
2058 invoker.run_findbugs_override && defined(invoker.java_files)
2059 }
2060 }
2061
2062 group(target_name) {
2063 public_deps = [
2064 ":$_apk_target_name",
2065 ":$_test_runner_target_name",
2066
2067 # Required by test runner to enumerate test list.
2068 ":${_apk_target_name}_dist_ijar",
2069 ]
2070 if (defined(invoker.apk_under_test)) {
2071 public_deps += [ invoker.apk_under_test ]
2072 }
2073 if (defined(invoker.isolate_file)) {
2074 isolate_values = exec_script("//build/gypi_to_gn.py",
2075 [
2076 rebase_path(invoker.isolate_file),
2077 "--replace",
2078 "<(DEPTH)=/",
2079 ],
2080 "scope",
2081 [ invoker.isolate_file ])
2082 data = isolate_values.files
2083 }
2084 }
2085
2086 # TODO: Delete once recipes no longer use this target.
2087 group("${target_name}_run") {
2088 public_deps = [
2089 ":${invoker.target_name}",
2090 ]
2091 }
2092 group("${target_name}_incremental") {
2093 public_deps = [
2094 ":${_apk_target_name}_dist_ijar",
2095 ":${_apk_target_name}_incremental",
2096 ":${_test_runner_target_name}_incremental",
2097 ]
2098 if (defined(invoker.apk_under_test)) {
2099 public_deps += [ "${invoker.apk_under_test}_incremental" ]
2100 }
2101 }
2102 }
2103
2104 # Declare an Android gtest apk
2105 #
2106 # This target creates an Android apk for running gtest-based unittests.
2107 #
2108 # Variables
2109 # deps: Specifies the dependencies of this target. These will be passed to
2110 # the underlying android_apk invocation and should include the java and
2111 # resource dependencies of the apk.
2112 # unittests_dep: This should be the label of the gtest native target. This
2113 # target must be defined previously in the same file.
2114 # unittests_binary: The basename of the library produced by the unittests_dep
2115 # target. If unspecified, it assumes the name of the unittests_dep target
2116 # (which will be correct unless that target specifies an "output_name".
2117 # TODO(brettw) make this automatic by allowing get_target_outputs to
2118 # support executables.
2119 # apk_name: The name of the produced apk. If unspecified, it uses the name
2120 # of the unittests_dep target postfixed with "_apk"
2121 # use_default_launcher: Whether the default activity (NativeUnitTestActivity)
2122 # should be used for launching tests.
2123 # use_native_activity: Test implements ANativeActivity_onCreate().
2124 #
2125 # Example
2126 # unittest_apk("foo_unittests_apk") {
2127 # deps = [ ":foo_java", ":foo_resources" ]
2128 # unittests_dep = ":foo_unittests"
2129 # }
2130 template("unittest_apk") {
2131 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
2132
2133 test_suite_name = get_label_info(invoker.unittests_dep, "name")
2134
2135 # This trivial assert is needed in case both unittests_binary and apk_name
2136 # are defined, as otherwise test_suite_name would not be used.
2137 assert(test_suite_name != "")
2138
2139 _use_native_activity =
2140 defined(invoker.use_native_activity) && invoker.use_native_activity
2141 _android_manifest = "$target_gen_dir/$target_name/AndroidManifest.xml"
2142
2143 # This trivial assert is needed in case android_manifest is defined,
2144 # as otherwise _use_native_activity and _android_manifest would not be used.
2145 assert(_use_native_activity != "" && _android_manifest != "")
2146
2147 if (!defined(invoker.android_manifest)) {
2148 jinja_template("${target_name}_manifest") {
2149 if (!defined(invoker.unittests_binary)) {
2150 native_library_name = test_suite_name
2151 } else {
2152 native_library_name = invoker.unittests_binary
2153 }
2154 input = "//testing/android/native_test/java/AndroidManifest.xml.jinja2"
2155 output = _android_manifest
2156 variables = [
2157 "is_component_build=${is_component_build}",
2158 "native_library_name=${native_library_name}",
2159 "use_native_activity=${_use_native_activity}",
2160 ]
2161 }
2162 }
2163
2164 android_apk(target_name) {
2165 set_sources_assignment_filter([])
2166 data_deps = []
2167 deps = []
2168 forward_variables_from(invoker, "*")
2169 testonly = true
2170
2171 if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) {
2172 assert(invoker.proguard_configs != [])
2173 proguard_enabled = true
2174 proguard_configs = invoker.proguard_configs
2175 }
2176
2177 if (!defined(apk_name)) {
2178 apk_name = test_suite_name
2179 }
2180
2181 if (!defined(android_manifest)) {
2182 deps += [ ":${target_name}_manifest" ]
2183 android_manifest = _android_manifest
2184 }
2185
2186 if (!defined(unittests_binary)) {
2187 unittests_binary = "lib${test_suite_name}${shlib_extension}"
2188 }
2189
2190 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
2191
2192 if (!defined(use_default_launcher) || use_default_launcher) {
2193 deps += [ "//testing/android/native_test:native_test_java" ]
2194 }
2195 native_libs = [ unittests_binary ]
2196 deps += [
2197 "//base:base_java",
2198 "//testing/android/appurify_support:appurify_support_java",
2199 "//testing/android/reporter:reporter_java",
2200 ]
2201 data_deps += [
2202 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
2203 "//tools/android/md5sum",
2204 ]
2205 if (host_os == "linux") {
2206 data_deps += [ "//tools/android/forwarder2" ]
2207 }
2208 }
2209 }
2210
2211 # Generate .java files from .aidl files.
2212 #
2213 # This target will store the .java files in a srcjar and should be included in
2214 # an android_library or android_apk's srcjar_deps.
2215 #
2216 # Variables
2217 # sources: Paths to .aidl files to compile.
2218 # import_include: Path to directory containing .java files imported by the
2219 # .aidl files.
2220 # interface_file: Preprocessed aidl file to import.
2221 #
2222 # Example
2223 # android_aidl("foo_aidl") {
2224 # import_include = "java/src"
2225 # sources = [
2226 # "java/src/com/foo/bar/FooBarService.aidl",
2227 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
2228 # ]
2229 # }
2230 template("android_aidl") {
2231 set_sources_assignment_filter([])
2232 forward_variables_from(invoker, [ "testonly" ])
2233
2234 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
2235 aidl_path = "${android_sdk_build_tools}/aidl"
2236 framework_aidl = "$android_sdk/framework.aidl"
2237
2238 action(target_name) {
2239 script = "//build/android/gyp/aidl.py"
2240 sources = invoker.sources
2241
2242 imports = [ framework_aidl ]
2243 if (defined(invoker.interface_file)) {
2244 assert(invoker.interface_file != "")
2245 imports += [ invoker.interface_file ]
2246 }
2247
2248 inputs = [ aidl_path ] + imports
2249
2250 depfile = "${target_gen_dir}/${target_name}.d"
2251 outputs = [
2252 depfile,
2253 srcjar_path,
2254 ]
2255 rebased_imports = rebase_path(imports, root_build_dir)
2256 args = [
2257 "--depfile",
2258 rebase_path(depfile, root_build_dir),
2259 "--aidl-path",
2260 rebase_path(aidl_path, root_build_dir),
2261 "--imports=$rebased_imports",
2262 "--srcjar",
2263 rebase_path(srcjar_path, root_build_dir),
2264 ]
2265 if (defined(invoker.import_include) && invoker.import_include != "") {
2266 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
2267 # switch to constructing a depfile for the overall action from that
2268 # instead of having all the .java files in the include paths as inputs.
2269 rebased_import_includes =
2270 rebase_path([ invoker.import_include ], root_build_dir)
2271 args += [ "--includes=$rebased_import_includes" ]
2272
2273 _java_files_build_rel =
2274 exec_script("//build/android/gyp/find.py",
2275 rebase_path([ invoker.import_include ], root_build_dir),
2276 "list lines")
2277 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
2278 inputs += _java_files
2279 }
2280 args += rebase_path(sources, root_build_dir)
2281 }
2282 }
2283
2284 # Creates a dist directory for a native executable.
2285 #
2286 # Running a native executable on a device requires all the shared library
2287 # dependencies of that executable. To make it easier to install and run such an
2288 # executable, this will create a directory containing the native exe and all
2289 # it's library dependencies.
2290 #
2291 # Note: It's usually better to package things as an APK than as a native
2292 # executable.
2293 #
2294 # Variables
2295 # dist_dir: Directory for the exe and libraries. Everything in this directory
2296 # will be deleted before copying in the exe and libraries.
2297 # binary: Path to (stripped) executable.
2298 # extra_files: List of extra files to copy in (optional).
2299 #
2300 # Example
2301 # create_native_executable_dist("foo_dist") {
2302 # dist_dir = "$root_build_dir/foo_dist"
2303 # binary = "$root_build_dir/foo"
2304 # deps = [ ":the_thing_that_makes_foo" ]
2305 # }
2306 template("create_native_executable_dist") {
2307 forward_variables_from(invoker, [ "testonly" ])
2308
2309 _libraries_list = "${target_gen_dir}/${target_name}_library_dependencies.list"
2310
2311 _find_deps_target_name = "${target_name}__find_library_dependencies"
2312
2313 # TODO(agrieve): Extract dependent libs from GN rather than readelf.
2314 action(_find_deps_target_name) {
2315 forward_variables_from(invoker, [ "deps" ])
2316
2317 script = "//build/android/gyp/write_ordered_libraries.py"
2318 depfile = "$target_gen_dir/$target_name.d"
2319 inputs = [
2320 invoker.binary,
2321 android_readelf,
2322 ]
2323 outputs = [
2324 depfile,
2325 _libraries_list,
2326 ]
2327 rebased_binaries = rebase_path([ invoker.binary ], root_build_dir)
2328 args = [
2329 "--depfile",
2330 rebase_path(depfile, root_build_dir),
2331 "--input-libraries=$rebased_binaries",
2332 "--libraries-dir",
2333 rebase_path(root_shlib_dir, root_build_dir),
2334 "--output",
2335 rebase_path(_libraries_list, root_build_dir),
2336 "--readelf",
2337 rebase_path(android_readelf, root_build_dir),
2338 ]
2339 }
2340
2341 copy_ex(target_name) {
2342 clear_dir = true
2343
2344 inputs = [
2345 _libraries_list,
2346 invoker.binary,
2347 ]
2348
2349 dest = invoker.dist_dir
2350 data = [
2351 "${invoker.dist_dir}/",
2352 ]
2353
2354 _rebased_libraries_list = rebase_path(_libraries_list, root_build_dir)
2355 _rebased_binaries_list = rebase_path([ invoker.binary ], root_build_dir)
2356 args = [
2357 "--files=@FileArg($_rebased_libraries_list:lib_paths)",
2358 "--files=$_rebased_binaries_list",
2359 ]
2360 if (defined(invoker.extra_files)) {
2361 _rebased_extra_files = rebase_path(invoker.extra_files, root_build_dir)
2362 args += [ "--files=$_rebased_extra_files" ]
2363 }
2364
2365 deps = [
2366 ":$_find_deps_target_name",
2367 ]
2368 if (defined(invoker.deps)) {
2369 deps += invoker.deps
2370 }
2371 }
2372 }
2373
2374 # Compile a protocol buffer to java.
2375 #
2376 # This generates java files from protocol buffers and creates an Android library
2377 # containing the classes.
2378 #
2379 # Variables
2380 # sources: Paths to .proto files to compile.
2381 # proto_path: Root directory of .proto files.
2382 #
2383 # Example:
2384 # proto_java_library("foo_proto_java") {
2385 # proto_path = "src/foo"
2386 # sources = [ "$proto_path/foo.proto" ]
2387 # }
2388 template("proto_java_library") {
2389 set_sources_assignment_filter([])
2390 forward_variables_from(invoker, [ "testonly" ])
2391 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
2392 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
2393 _protoc_bin = "$_protoc_out_dir/android_protoc"
2394 _proto_path = invoker.proto_path
2395
2396 _template_name = target_name
2397
2398 action("${_template_name}__protoc_java") {
2399 srcjar_path = "$target_gen_dir/$target_name.srcjar"
2400 script = "//build/protoc_java.py"
2401
2402 deps = [
2403 _protoc_dep,
2404 ]
2405 if (defined(invoker.deps)) {
2406 deps += invoker.deps
2407 }
2408
2409 sources = invoker.sources
2410 depfile = "$target_gen_dir/$target_name.d"
2411 outputs = [
2412 depfile,
2413 srcjar_path,
2414 ]
2415 args = [
2416 "--depfile",
2417 rebase_path(depfile, root_build_dir),
2418 "--protoc",
2419 rebase_path(_protoc_bin, root_build_dir),
2420 "--proto-path",
2421 rebase_path(_proto_path, root_build_dir),
2422 "--srcjar",
2423 rebase_path(srcjar_path, root_build_dir),
2424 ] + rebase_path(sources, root_build_dir)
2425 }
2426
2427 android_library(target_name) {
2428 chromium_code = false
2429 java_files = []
2430 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2431 deps = [
2432 "//third_party/android_protobuf:protobuf_nano_javalib",
2433 ]
2434 }
2435 }
2436
2437 # Writes a script to root_out_dir/bin that passes --output-directory to the
2438 # wrapped script, in addition to forwarding arguments. Most / all of these
2439 # wrappers should be made deps of //tools/android:android_tools.
2440 #
2441 # Variables
2442 # target: Script to wrap.
2443 # flag_name: Default is "--output-directory"
2444 #
2445 # Example
2446 # wrapper_script("foo_wrapper") {
2447 # target = "//pkg/foo.py"
2448 # }
2449 template("wrapper_script") {
2450 action(target_name) {
2451 _name = get_path_info(invoker.target, "name")
2452 _output = "$root_out_dir/bin/$_name"
2453
2454 script = "//build/android/gyp/create_tool_wrapper.py"
2455 outputs = [
2456 _output,
2457 ]
2458
2459 # The target isn't actually used by the script, but it's nice to have GN
2460 # check that it exists.
2461 inputs = [
2462 invoker.target,
2463 ]
2464 args = [
2465 "--output",
2466 rebase_path(_output, root_build_dir),
2467 "--target",
2468 rebase_path(invoker.target, root_build_dir),
2469 "--output-directory",
2470 rebase_path(root_out_dir, root_build_dir),
2471 ]
2472 if (defined(invoker.flag_name)) {
2473 args += [ "--flag-name=${invoker.flag_name}" ]
2474 }
2475 }
2476 }
OLDNEW
« no previous file with comments | « build/config/android/internal_rules.gni ('k') | build/config/arm.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698