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

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

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 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("//third_party/android_platform/config.gni")
9 import("//tools/grit/grit_rule.gni")
10
11 assert(is_android)
12
13 # Declare a jni target
14 #
15 # This target generates the native jni bindings for a set of .java files.
16 #
17 # See base/android/jni_generator/jni_generator.py for more info about the
18 # format of generating JNI bindings.
19 #
20 # Variables
21 # sources: list of .java files to generate jni for
22 # jni_package: subdirectory path for generated bindings
23 #
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 }
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 if (defined(invoker.jni_generator_jarjar_file)) {
70 args += [
71 "--jarjar",
72 rebase_path(jni_generator_jarjar_file, root_build_dir),
73 ]
74 }
75 }
76
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 }
86
87 group(target_name) {
88 deps = [
89 ":$foreach_target_name",
90 ]
91 public_configs = [ ":jni_includes_${target_name}" ]
92
93 if (defined(invoker.deps)) {
94 deps += invoker.deps
95 }
96 if (defined(invoker.public_deps)) {
97 public_deps = invoker.public_deps
98 }
99
100 if (defined(invoker.visibility)) {
101 visibility = invoker.visibility
102 }
103 }
104 }
105
106 # Declare a jni target for a prebuilt jar
107 #
108 # This target generates the native jni bindings for a set of classes in a .jar.
109 #
110 # See base/android/jni_generator/jni_generator.py for more info about the
111 # format of generating JNI bindings.
112 #
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
119 #
120 # deps, public_deps: As normal
121 #
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 }
134
135 assert(defined(invoker.classes))
136 assert(defined(invoker.jni_package))
137
138 if (defined(invoker.jar_file)) {
139 jar_file = invoker.jar_file
140 } else {
141 jar_file = android_sdk_jar
142 }
143
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"
147
148 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h"
149
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 ]
171
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 }
189
190 config("jni_includes_${target_name}") {
191 include_dirs = [ base_output_dir ]
192 }
193
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 }
204 }
205
206 # Declare a target for c-preprocessor-generated java files
207 #
208 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
209 # rule instead.
210 #
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.
214 #
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.
218 #
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.
228 #
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 # ]
237 #
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 }
246
247 assert(defined(invoker.sources))
248 package_name = invoker.package_name + ""
249
250 if (defined(invoker.include_path)) {
251 include_path = invoker.include_path + ""
252 } else {
253 include_path = "//"
254 }
255
256 apply_gcc_target_name = "${target_name}__apply_gcc"
257 zip_srcjar_target_name = "${target_name}__zip_srcjar"
258 final_target_name = target_name
259
260 action_foreach(apply_gcc_target_name) {
261 visibility = [ ":$zip_srcjar_target_name" ]
262 script = "//build/android/gyp/gcc_preprocess.py"
263 if (defined(invoker.inputs)) {
264 inputs = invoker.inputs + []
265 }
266 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d"
267
268 sources = invoker.sources
269
270 if (defined(invoker.deps)) {
271 deps = invoker.deps
272 }
273 if (defined(invoker.public_deps)) {
274 public_deps = invoker.public_deps
275 }
276 if (defined(invoker.data_deps)) {
277 data_deps = invoker.data_deps
278 }
279
280 gen_dir =
281 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}"
282 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
283
284 outputs = [
285 depfile,
286 gcc_template_output_pattern,
287 ]
288
289 args = [
290 "--depfile",
291 rebase_path(depfile, root_build_dir),
292 "--include-path",
293 rebase_path(include_path, root_build_dir),
294 "--output",
295 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java",
296 "--template={{source}}",
297 ]
298
299 if (defined(invoker.defines)) {
300 foreach(def, invoker.defines) {
301 args += [
302 "--defines",
303 def,
304 ]
305 }
306 }
307 }
308
309 apply_gcc_outputs = get_target_outputs(":$apply_gcc_target_name")
310 base_gen_dir = get_label_info(":$apply_gcc_target_name", "target_gen_dir")
311
312 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
313 zip(zip_srcjar_target_name) {
314 visibility = [ ":$final_target_name" ]
315 inputs = apply_gcc_outputs
316 output = srcjar_path
317 base_dir = base_gen_dir
318 deps = [
319 ":$apply_gcc_target_name",
320 ]
321 }
322
323 group(final_target_name) {
324 if (defined(invoker.visibility)) {
325 visibility = invoker.visibility
326 }
327 public_deps = [
328 ":$zip_srcjar_target_name",
329 ]
330 }
331 }
332
333 # Declare a target for generating Java classes from C++ enums.
334 #
335 # This target generates Java files from C++ enums using a script.
336 #
337 # This target will create a single .srcjar. Adding this target to an
338 # android_library target's srcjar_deps will make the generated java files be
339 # included in that library's final outputs.
340 #
341 # Variables
342 # sources: list of files to be processed by the script. For each annotated
343 # enum contained in the sources files the script will generate a .java
344 # file with the same name as the name of the enum.
345 #
346 # outputs: list of outputs, relative to the output_dir. These paths are
347 # verified at build time by the script. To get the list programatically run:
348 # python build/android/gyp/java_cpp_enum.py \
349 # --print_output_only . path/to/header/file.h
350 #
351 # Example
352 # java_cpp_enum("foo_generated_enum") {
353 # sources = [
354 # "src/native_foo_header.h",
355 # ]
356 # outputs = [
357 # "org/chromium/FooEnum.java",
358 # ]
359 # }
360 template("java_cpp_enum") {
361 set_sources_assignment_filter([])
362 if (defined(invoker.testonly)) {
363 testonly = invoker.testonly
364 }
365
366 assert(defined(invoker.sources))
367 assert(defined(invoker.outputs))
368
369 generate_enum_target_name = "${target_name}__generate_enum"
370 zip_srcjar_target_name = "${target_name}__zip_srcjar"
371 final_target_name = target_name
372
373 action(generate_enum_target_name) {
374 visibility = [ ":$zip_srcjar_target_name" ]
375
376 # The sources aren't compiled so don't check their dependencies.
377 check_includes = false
378
379 sources = invoker.sources
380 script = "//build/android/gyp/java_cpp_enum.py"
381 gen_dir = "${target_gen_dir}/${target_name}/enums"
382 outputs =
383 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath")
384
385 args = []
386 foreach(output, rebase_path(outputs, root_build_dir)) {
387 args += [
388 "--assert_file",
389 output,
390 ]
391 }
392 args += [ rebase_path(gen_dir, root_build_dir) ]
393 args += rebase_path(invoker.sources, root_build_dir)
394 }
395
396 generate_enum_outputs = get_target_outputs(":$generate_enum_target_name")
397 base_gen_dir = get_label_info(":$generate_enum_target_name", "target_gen_dir")
398
399 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
400 zip(zip_srcjar_target_name) {
401 visibility = [ ":$final_target_name" ]
402 inputs = generate_enum_outputs
403 output = srcjar_path
404 base_dir = base_gen_dir
405 deps = [
406 ":$generate_enum_target_name",
407 ]
408 }
409
410 group(final_target_name) {
411 if (defined(invoker.visibility)) {
412 visibility = invoker.visibility
413 }
414 public_deps = [
415 ":$zip_srcjar_target_name",
416 ]
417 }
418 }
419
420 # Declare a target for processing a Jinja template.
421 #
422 # Variables
423 # input: The template file to be processed.
424 # output: Where to save the result.
425 # variables: (Optional) A list of variables to make available to the template
426 # processing environment, e.g. ["name=foo", "color=red"].
427 #
428 # Example
429 # jinja_template("chrome_shell_manifest") {
430 # input = "shell/java/AndroidManifest.xml"
431 # output = "$target_gen_dir/AndroidManifest.xml"
432 # }
433 template("jinja_template") {
434 set_sources_assignment_filter([])
435 if (defined(invoker.testonly)) {
436 testonly = invoker.testonly
437 }
438
439 assert(defined(invoker.input))
440 assert(defined(invoker.output))
441
442 action(target_name) {
443 if (defined(invoker.visibility)) {
444 visibility = invoker.visibility
445 }
446
447 sources = [
448 invoker.input,
449 ]
450 script = "//build/android/gyp/jinja_template.py"
451 depfile = "$target_gen_dir/$target_name.d"
452
453 outputs = [
454 depfile,
455 invoker.output,
456 ]
457
458 args = [
459 "--inputs",
460 rebase_path(invoker.input, root_build_dir),
461 "--output",
462 rebase_path(invoker.output, root_build_dir),
463 "--depfile",
464 rebase_path(depfile, root_build_dir),
465 ]
466 if (defined(invoker.variables)) {
467 variables = invoker.variables
468 args += [ "--variables=${variables}" ]
469 }
470 }
471 }
472
473 # Declare a target for processing Android resources as Jinja templates.
474 #
475 # This takes an Android resource directory where each resource is a Jinja
476 # template, processes each template, then packages the results in a zip file
477 # which can be consumed by an android resources, library, or apk target.
478 #
479 # If this target is included in the deps of an android resources/library/apk,
480 # the resources will be included with that target.
481 #
482 # Variables
483 # resources: The list of resources files to process.
484 # res_dir: The resource directory containing the resources.
485 # variables: (Optional) A list of variables to make available to the template
486 # processing environment, e.g. ["name=foo", "color=red"].
487 #
488 # Example
489 # jinja_template_resources("chrome_shell_template_resources") {
490 # res_dir = "shell/res_template"
491 # resources = ["shell/res_template/xml/syncable.xml"]
492 # variables = ["color=red"]
493 # }
494 template("jinja_template_resources") {
495 set_sources_assignment_filter([])
496 if (defined(invoker.testonly)) {
497 testonly = invoker.testonly
498 }
499
500 assert(defined(invoker.resources))
501 assert(defined(invoker.res_dir))
502
503 _base_path = "$target_gen_dir/$target_name"
504 _resources_zip = _base_path + ".resources.zip"
505 _build_config = _base_path + ".build_config"
506
507 write_build_config("${target_name}__build_config") {
508 build_config = _build_config
509 resources_zip = _resources_zip
510 type = "android_resources"
511 }
512
513 action("${target_name}__template") {
514 sources = invoker.resources
515 script = "//build/android/gyp/jinja_template.py"
516 depfile = "$target_gen_dir/$target_name.d"
517
518 outputs = [
519 depfile,
520 _resources_zip,
521 ]
522
523 rebased_resources = rebase_path(invoker.resources, root_build_dir)
524 args = [
525 "--inputs=${rebased_resources}",
526 "--inputs-base-dir",
527 rebase_path(invoker.res_dir, root_build_dir),
528 "--outputs-zip",
529 rebase_path(_resources_zip, root_build_dir),
530 "--depfile",
531 rebase_path(depfile, root_build_dir),
532 ]
533 if (defined(invoker.variables)) {
534 variables = invoker.variables
535 args += [ "--variables=${variables}" ]
536 }
537 }
538
539 group(target_name) {
540 deps = [
541 ":${target_name}__build_config",
542 ":${target_name}__template",
543 ]
544 }
545 }
546
547 # Declare an Android resources target
548 #
549 # This creates a resources zip file that will be used when building an Android
550 # library or apk and included into a final apk.
551 #
552 # To include these resources in a library/apk, this target should be listed in
553 # the library's deps. A library/apk will also include any resources used by its
554 # own dependencies.
555 #
556 # Variables
557 # deps: Specifies the dependencies of this target. Any Android resources
558 # listed in deps will be included by libraries/apks that depend on this
559 # target.
560 # resource_dirs: List of directories containing resources for this target.
561 # android_manifest: AndroidManifest.xml for this target. Defaults to
562 # //build/android/AndroidManifest.xml.
563 # custom_package: java package for generated .java files.
564 # v14_skip: If true, don't run v14 resource generator on this. Defaults to
565 # false. (see build/android/gyp/generate_v14_compatible_resources.py)
566 #
567 # shared_resources: If true make a resource package that can be loaded by a
568 # different application at runtime to access the package's resources.
569 #
570
571 # Example
572 # android_resources("foo_resources") {
573 # deps = [":foo_strings_grd"]
574 # resource_dirs = ["res"]
575 # custom_package = "org.chromium.foo"
576 # }
577 template("android_resources") {
578 set_sources_assignment_filter([])
579 if (defined(invoker.testonly)) {
580 testonly = invoker.testonly
581 }
582
583 assert(defined(invoker.resource_dirs))
584 assert(defined(invoker.android_manifest) || defined(invoker.custom_package))
585
586 base_path = "$target_gen_dir/$target_name"
587 zip_path = base_path + ".resources.zip"
588 srcjar_path = base_path + ".srcjar"
589 r_text_path = base_path + "_R.txt"
590 build_config = base_path + ".build_config"
591
592 build_config_target_name = "${target_name}__build_config"
593 process_resources_target_name = "${target_name}__process_resources"
594 final_target_name = target_name
595
596 write_build_config(build_config_target_name) {
597 visibility = [ ":$process_resources_target_name" ]
598
599 type = "android_resources"
600 resources_zip = zip_path
601 srcjar = srcjar_path
602 r_text = r_text_path
603 if (defined(invoker.deps)) {
604 deps = invoker.deps
605 }
606 if (defined(invoker.android_manifest)) {
607 android_manifest = invoker.android_manifest
608 }
609 if (defined(invoker.custom_package)) {
610 custom_package = invoker.custom_package
611 }
612 }
613
614 android_manifest = "//build/android/AndroidManifest.xml"
615 if (defined(invoker.android_manifest)) {
616 android_manifest = invoker.android_manifest
617 }
618
619 process_resources(process_resources_target_name) {
620 visibility = [ ":$final_target_name" ]
621
622 resource_dirs = invoker.resource_dirs
623 if (defined(invoker.custom_package)) {
624 custom_package = invoker.custom_package
625 }
626
627 if (defined(invoker.v14_skip)) {
628 v14_skip = invoker.v14_skip
629 }
630
631 if (defined(invoker.shared_resources)) {
632 shared_resources = invoker.shared_resources
633 }
634
635 deps = [
636 ":$build_config_target_name",
637 ]
638 if (defined(invoker.deps)) {
639 # Invoker may have added deps that generate the input resources.
640 deps += invoker.deps
641 }
642 }
643
644 group(final_target_name) {
645 if (defined(invoker.visibility)) {
646 visibility = invoker.visibility
647 }
648 deps = [
649 ":${target_name}__process_resources",
650 ]
651 }
652 }
653
654 # Declare a target that generates localized strings.xml from a .grd file.
655 #
656 # If this target is included in the deps of an android resources/library/apk,
657 # the strings.xml will be included with that target.
658 #
659 # Variables
660 # deps: Specifies the dependencies of this target.
661 # grd_file: Path to the .grd file to generate strings.xml from.
662 # outputs: Expected grit outputs (see grit rule).
663 #
664 # Example
665 # java_strings_grd("foo_strings_grd") {
666 # grd_file = "foo_strings.grd"
667 # }
668 template("java_strings_grd") {
669 set_sources_assignment_filter([])
670 if (defined(invoker.testonly)) {
671 testonly = invoker.testonly
672 }
673
674 base_path = "$target_gen_dir/$target_name"
675 resources_zip = base_path + ".resources.zip"
676 build_config = base_path + ".build_config"
677
678 write_build_config("${target_name}__build_config") {
679 type = "android_resources"
680 if (defined(invoker.deps)) {
681 deps = invoker.deps
682 }
683 }
684
685 # Put grit files into this subdirectory of target_gen_dir.
686 extra_output_path = target_name + "_grit_output"
687
688 grit_target_name = "${target_name}__grit"
689 grit_output_dir = "$target_gen_dir/$extra_output_path"
690 grit(grit_target_name) {
691 grit_flags = [
692 "-E",
693 "ANDROID_JAVA_TAGGED_ONLY=false",
694 ]
695 output_dir = grit_output_dir
696 resource_ids = ""
697 source = invoker.grd_file
698 outputs = invoker.outputs
699 }
700
701 # This needs to get outputs from grit's internal target, not the final
702 # source_set.
703 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
704
705 zip("${target_name}__zip") {
706 base_dir = grit_output_dir
707 inputs = generate_strings_outputs
708 output = resources_zip
709 deps = [
710 ":$grit_target_name",
711 ]
712 }
713
714 group(target_name) {
715 deps = [
716 ":${target_name}__build_config",
717 ":${target_name}__zip",
718 ]
719 }
720 }
721
722 # Declare a target that packages strings.xml generated from a grd file.
723 #
724 # If this target is included in the deps of an android resources/library/apk,
725 # the strings.xml will be included with that target.
726 #
727 # Variables
728 # grit_output_dir: directory containing grit-generated files.
729 # generated_files: list of android resource files to package.
730 #
731 # Example
732 # java_strings_grd_prebuilt("foo_strings_grd") {
733 # grit_output_dir = "$root_gen_dir/foo/grit"
734 # generated_files = [
735 # "values/strings.xml"
736 # ]
737 # }
738 template("java_strings_grd_prebuilt") {
739 set_sources_assignment_filter([])
740 if (defined(invoker.testonly)) {
741 testonly = invoker.testonly
742 }
743
744 base_path = "$target_gen_dir/$target_name"
745 resources_zip = base_path + ".resources.zip"
746 build_config = base_path + ".build_config"
747
748 build_config_target_name = "${target_name}__build_config"
749 zip_target_name = "${target_name}__zip"
750 final_target_name = target_name
751
752 write_build_config(build_config_target_name) {
753 visibility = [ ":$zip_target_name" ]
754 type = "android_resources"
755 }
756
757 zip(zip_target_name) {
758 visibility = [ ":$final_target_name" ]
759
760 base_dir = invoker.grit_output_dir
761 inputs = rebase_path(invoker.generated_files, ".", base_dir)
762 output = resources_zip
763 deps = [
764 ":$build_config_target_name",
765 ]
766 if (defined(invoker.deps)) {
767 deps += invoker.deps
768 }
769 }
770
771 group(final_target_name) {
772 if (defined(invoker.visibility)) {
773 visibility = invoker.visibility
774 }
775 deps = [
776 ":$zip_target_name",
777 ]
778 }
779 }
780
781 # Declare a Java executable target
782 #
783 # This target creates an executable from java code and libraries. The executable
784 # will be in the output folder's /bin/ directory.
785 #
786 # Variables
787 # deps: Specifies the dependencies of this target. Java targets in this list
788 # will be included in the executable (and the javac classpath).
789 #
790 # java_files: List of .java files included in this library.
791 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
792 # will be added to java_files and be included in this library.
793 # srcjars: List of srcjars to be included in this library, together with the
794 # ones obtained from srcjar_deps.
795 #
796 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
797 # dependencies for this target. This will allow depending on an
798 # android_library target, for example.
799 #
800 # chromium_code: If true, extra analysis warning/errors will be enabled.
801 #
802 # data_deps, testonly
803 #
804 # Example
805 # java_binary("foo") {
806 # java_files = [ "org/chromium/foo/FooMain.java" ]
807 # deps = [ ":bar_java" ]
808 # main_class = "org.chromium.foo.FooMain"
809 # }
810 template("java_binary") {
811 set_sources_assignment_filter([])
812
813 # TODO(cjhopman): This should not act like a java_library for dependents (i.e.
814 # dependents shouldn't get the jar in their classpath, etc.).
815 java_library_impl(target_name) {
816 if (defined(invoker.DEPRECATED_java_in_dir)) {
817 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
818 }
819 if (defined(invoker.chromium_code)) {
820 chromium_code = invoker.chromium_code
821 }
822 if (defined(invoker.data_deps)) {
823 deps = invoker.data_deps
824 }
825 if (defined(invoker.deps)) {
826 deps = invoker.deps
827 }
828 if (defined(invoker.java_files)) {
829 java_files = invoker.java_files
830 }
831 if (defined(invoker.srcjar_deps)) {
832 srcjar_deps = invoker.srcjar_deps
833 }
834 if (defined(invoker.srcjars)) {
835 srcjars = invoker.srcjars
836 }
837 if (defined(invoker.bypass_platform_checks)) {
838 bypass_platform_checks = invoker.bypass_platform_checks
839 }
840 if (defined(invoker.testonly)) {
841 testonly = invoker.testonly
842 }
843
844 main_class = invoker.main_class
845 }
846 }
847
848 # Declare a Junit executable target
849 #
850 # This target creates an executable from java code for running as a junit test
851 # suite. The executable will be in the output folder's /bin/ directory.
852 #
853 # Variables
854 # deps: Specifies the dependencies of this target. Java targets in this list
855 # will be included in the executable (and the javac classpath).
856 #
857 # java_files: List of .java files included in this library.
858 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
859 # will be added to java_files and be included in this library.
860 # srcjars: List of srcjars to be included in this library, together with the
861 # ones obtained from srcjar_deps.
862 #
863 # chromium_code: If true, extra analysis warning/errors will be enabled.
864 #
865 # Example
866 # junit_binary("foo") {
867 # java_files = [ "org/chromium/foo/FooTest.java" ]
868 # deps = [ ":bar_java" ]
869 # }
870 template("junit_binary") {
871 set_sources_assignment_filter([])
872
873 java_binary(target_name) {
874 bypass_platform_checks = true
875 main_class = "org.chromium.testing.local.JunitTestMain"
876 testonly = true
877
878 if (defined(invoker.DEPRECATED_java_in_dir)) {
879 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
880 }
881 if (defined(invoker.chromium_code)) {
882 chromium_code = invoker.chromium_code
883 }
884 deps = [
885 "//testing/android/junit:junit_test_support",
886 "//third_party/junit",
887 "//third_party/mockito:mockito_java",
888 "//third_party/robolectric:robolectric_java",
889 "//third_party/robolectric:android-all-4.3_r2-robolectric-0",
890 ]
891 if (defined(invoker.deps)) {
892 deps += invoker.deps
893 }
894 if (defined(invoker.java_files)) {
895 java_files = invoker.java_files
896 }
897 if (defined(invoker.srcjar_deps)) {
898 srcjar_deps = invoker.srcjar_deps
899 }
900 if (defined(invoker.srcjars)) {
901 srcjars = invoker.srcjars
902 }
903 }
904 }
905
906 # Declare a java library target
907 #
908 # Variables
909 # deps: Specifies the dependencies of this target. Java targets in this list
910 # will be added to the javac classpath.
911 #
912 # java_files: List of .java files included in this library.
913 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
914 # will be added to java_files and be included in this library.
915 # srcjars: List of srcjars to be included in this library, together with the
916 # ones obtained from srcjar_deps.
917 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
918 # this directory will be included in the library. This is only supported to
919 # ease the gyp->gn conversion and will be removed in the future.
920 #
921 # chromium_code: If true, extra analysis warning/errors will be enabled.
922 # jar_excluded_patterns: List of patterns of .class files to exclude from the
923 # final jar.
924 #
925 # proguard_preprocess: If true, proguard preprocessing will be run. This can
926 # be used to remove unwanted parts of the library.
927 # proguard_config: Path to the proguard config for preprocessing.
928 #
929 # supports_android: If true, Android targets (android_library, android_apk)
930 # may depend on this target. Note: if true, this target must only use the
931 # subset of Java available on Android.
932 # bypass_platform_checks: Disables checks about cross-platform (Java/Android)
933 # dependencies for this target. This will allow depending on an
934 # android_library target, for example.
935 #
936 # data_deps, testonly
937 #
938 # Example
939 # java_library("foo_java") {
940 # java_files = [
941 # "org/chromium/foo/Foo.java",
942 # "org/chromium/foo/FooInterface.java",
943 # "org/chromium/foo/FooService.java",
944 # ]
945 # deps = [
946 # ":bar_java"
947 # ]
948 # srcjar_deps = [
949 # ":foo_generated_enum"
950 # ]
951 # jar_excluded_patterns = [
952 # "*/FooService.class", "*/FooService##*.class"
953 # ]
954 # }
955 template("java_library") {
956 set_sources_assignment_filter([])
957 java_library_impl(target_name) {
958 if (defined(invoker.DEPRECATED_java_in_dir)) {
959 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
960 }
961 if (defined(invoker.chromium_code)) {
962 chromium_code = invoker.chromium_code
963 }
964 if (defined(invoker.data_deps)) {
965 deps = invoker.data_deps
966 }
967 if (defined(invoker.deps)) {
968 deps = invoker.deps
969 }
970 if (defined(invoker.jar_excluded_patterns)) {
971 jar_excluded_patterns = invoker.jar_excluded_patterns
972 }
973 if (defined(invoker.java_files)) {
974 java_files = invoker.java_files
975 }
976 if (defined(invoker.proguard_config)) {
977 proguard_config = invoker.proguard_config
978 }
979 if (defined(invoker.proguard_preprocess)) {
980 proguard_preprocess = invoker.proguard_preprocess
981 }
982 if (defined(invoker.srcjar_deps)) {
983 srcjar_deps = invoker.srcjar_deps
984 }
985 if (defined(invoker.srcjars)) {
986 srcjars = invoker.srcjars
987 }
988 if (defined(invoker.bypass_platform_checks)) {
989 bypass_platform_checks = invoker.bypass_platform_checks
990 }
991 if (defined(invoker.testonly)) {
992 testonly = invoker.testonly
993 }
994 if (defined(invoker.jar_path)) {
995 jar_path = invoker.jar_path
996 }
997
998 if (defined(invoker.supports_android) && invoker.supports_android) {
999 supports_android = true
1000 }
1001 }
1002 }
1003
1004 # Declare a java library target for a prebuilt jar
1005 #
1006 # Variables
1007 # deps: Specifies the dependencies of this target. Java targets in this list
1008 # will be added to the javac classpath.
1009 # jar_path: Path to the prebuilt jar.
1010 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1011 # be used to remove unwanted parts of the library.
1012 # proguard_config: Path to the proguard config for preprocessing.
1013 #
1014 # Example
1015 # java_prebuilt("foo_java") {
1016 # jar_path = "foo.jar"
1017 # deps = [
1018 # ":foo_resources",
1019 # ":bar_java"
1020 # ]
1021 # }
1022 template("java_prebuilt") {
1023 set_sources_assignment_filter([])
1024 java_prebuilt_impl(target_name) {
1025 jar_path = invoker.jar_path
1026 if (defined(invoker.testonly)) {
1027 testonly = invoker.testonly
1028 }
1029 if (defined(invoker.deps)) {
1030 deps = invoker.deps
1031 }
1032 if (defined(invoker.proguard_config)) {
1033 proguard_config = invoker.proguard_config
1034 }
1035 if (defined(invoker.proguard_preprocess)) {
1036 proguard_preprocess = invoker.proguard_preprocess
1037 }
1038 }
1039 }
1040
1041 # Declare an Android library target
1042 #
1043 # This target creates an Android library containing java code and Android
1044 # resources.
1045 #
1046 # Variables
1047 # deps: Specifies the dependencies of this target. Java targets in this list
1048 # will be added to the javac classpath. Android resources in dependencies
1049 # will be used when building this library.
1050 #
1051 # java_files: List of .java files included in this library.
1052 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1053 # will be added to java_files and be included in this library.
1054 # srcjars: List of srcjars to be included in this library, together with the
1055 # ones obtained from srcjar_deps.
1056 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1057 # this directory will be included in the library. This is only supported to
1058 # ease the gyp->gn conversion and will be removed in the future.
1059 #
1060 # chromium_code: If true, extra analysis warning/errors will be enabled.
1061 # jar_excluded_patterns: List of patterns of .class files to exclude from the
1062 # final jar.
1063 #
1064 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1065 # be used to remove unwanted parts of the library.
1066 # proguard_config: Path to the proguard config for preprocessing.
1067 #
1068 # dex_path: If set, the resulting .dex.jar file will be placed under this
1069 # path.
1070 #
1071 #
1072 # Example
1073 # android_library("foo_java") {
1074 # java_files = [
1075 # "android/org/chromium/foo/Foo.java",
1076 # "android/org/chromium/foo/FooInterface.java",
1077 # "android/org/chromium/foo/FooService.java",
1078 # ]
1079 # deps = [
1080 # ":bar_java"
1081 # ]
1082 # srcjar_deps = [
1083 # ":foo_generated_enum"
1084 # ]
1085 # jar_excluded_patterns = [
1086 # "*/FooService.class", "*/FooService##*.class"
1087 # ]
1088 # }
1089 template("android_library") {
1090 set_sources_assignment_filter([])
1091 assert(!defined(invoker.jar_path),
1092 "android_library does not support a custom jar path")
1093 java_library_impl(target_name) {
1094 if (defined(invoker.DEPRECATED_java_in_dir)) {
1095 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1096 }
1097 if (defined(invoker.chromium_code)) {
1098 chromium_code = invoker.chromium_code
1099 }
1100 if (defined(invoker.data_deps)) {
1101 deps = invoker.data_deps
1102 }
1103 if (defined(invoker.deps)) {
1104 deps = invoker.deps
1105 }
1106 if (defined(invoker.jar_excluded_patterns)) {
1107 jar_excluded_patterns = invoker.jar_excluded_patterns
1108 }
1109 if (defined(invoker.java_files)) {
1110 java_files = invoker.java_files
1111 }
1112 if (defined(invoker.proguard_config)) {
1113 proguard_config = invoker.proguard_config
1114 }
1115 if (defined(invoker.proguard_preprocess)) {
1116 proguard_preprocess = invoker.proguard_preprocess
1117 }
1118 if (defined(invoker.srcjar_deps)) {
1119 srcjar_deps = invoker.srcjar_deps
1120 }
1121 if (defined(invoker.srcjars)) {
1122 srcjars = invoker.srcjars
1123 }
1124 if (defined(invoker.testonly)) {
1125 testonly = invoker.testonly
1126 }
1127 if (defined(invoker.visibility)) {
1128 visibility = invoker.visibility
1129 }
1130 if (defined(invoker.dex_path)) {
1131 dex_path = invoker.dex_path
1132 }
1133 if (defined(invoker.manifest_entries)) {
1134 manifest_entries = invoker.manifest_entries
1135 }
1136
1137 supports_android = true
1138 requires_android = true
1139
1140 if (!defined(jar_excluded_patterns)) {
1141 jar_excluded_patterns = []
1142 }
1143 jar_excluded_patterns += [
1144 "*/R.class",
1145 "*/R##*.class",
1146 "*/Manifest.class",
1147 "*/Manifest##*.class",
1148 ]
1149 }
1150 }
1151
1152 # Declare a target that packages a set of Java dependencies into a standalone
1153 # .dex.jar.
1154 #
1155 # Variables
1156 # deps: specifies the dependencies of this target. Android libraries in deps
1157 # will be packaged into the resulting .dex.jar file.
1158 # dex_path: location at which the output file will be put
1159 template("android_standalone_library") {
1160 set_sources_assignment_filter([])
1161 deps_dex(target_name) {
1162 deps = invoker.deps
1163 dex_path = invoker.dex_path
1164 if (defined(invoker.excluded_jars)) {
1165 excluded_jars = invoker.excluded_jars
1166 }
1167 }
1168 }
1169
1170 # Declare an Android library target for a prebuilt jar
1171 #
1172 # This target creates an Android library containing java code and Android
1173 # resources.
1174 #
1175 # Variables
1176 # deps: Specifies the dependencies of this target. Java targets in this list
1177 # will be added to the javac classpath. Android resources in dependencies
1178 # will be used when building this library.
1179 # jar_path: Path to the prebuilt jar.
1180 # proguard_preprocess: If true, proguard preprocessing will be run. This can
1181 # be used to remove unwanted parts of the library.
1182 # proguard_config: Path to the proguard config for preprocessing.
1183 #
1184 # Example
1185 # android_java_prebuilt("foo_java") {
1186 # jar_path = "foo.jar"
1187 # deps = [
1188 # ":foo_resources",
1189 # ":bar_java"
1190 # ]
1191 # }
1192 template("android_java_prebuilt") {
1193 set_sources_assignment_filter([])
1194 java_prebuilt_impl(target_name) {
1195 jar_path = invoker.jar_path
1196 supports_android = true
1197 requires_android = true
1198 if (defined(invoker.testonly)) {
1199 testonly = invoker.testonly
1200 }
1201 if (defined(invoker.deps)) {
1202 deps = invoker.deps
1203 }
1204 if (defined(invoker.proguard_config)) {
1205 proguard_config = invoker.proguard_config
1206 }
1207 if (defined(invoker.proguard_preprocess)) {
1208 proguard_preprocess = invoker.proguard_preprocess
1209 }
1210 }
1211 }
1212
1213 # Declare an Android apk target
1214 #
1215 # This target creates an Android APK containing java code, resources, assets,
1216 # and (possibly) native libraries.
1217 #
1218 # Variables
1219 # android_manifest: Path to AndroidManifest.xml.
1220 # data_deps: List of dependencies needed at runtime. These will be built but
1221 # won't change the generated .apk in any way (in fact they may be built
1222 # after the .apk is).
1223 # deps: List of dependencies. All Android java resources and libraries in the
1224 # "transitive closure" of these dependencies will be included in the apk.
1225 # Note: this "transitive closure" actually only includes such targets if
1226 # they are depended on through android_library or android_resources targets
1227 # (and so not through builtin targets like 'action', 'group', etc).
1228 # java_files: List of .java files to include in the apk.
1229 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1230 # will be added to java_files and be included in this apk.
1231 # apk_name: Name for final apk.
1232 # final_apk_path: Path to final built apk. Default is
1233 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1234 # native_libs: List paths of native libraries to include in this apk. If these
1235 # libraries depend on other shared_library targets, those dependencies will
1236 # also be included in the apk.
1237 # apk_under_test: For an instrumentation test apk, this is the target of the
1238 # tested apk.
1239 # include_all_resources - If true include all resource IDs in all generated
1240 # R.java files.
1241 # testonly: Marks this target as "test-only".
1242 #
1243 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1244 # this directory will be included in the library. This is only supported to
1245 # ease the gyp->gn conversion and will be removed in the future.
1246 #
1247 # Example
1248 # android_apk("foo_apk") {
1249 # android_manifest = "AndroidManifest.xml"
1250 # java_files = [
1251 # "android/org/chromium/foo/FooApplication.java",
1252 # "android/org/chromium/foo/FooActivity.java",
1253 # ]
1254 # deps = [
1255 # ":foo_support_java"
1256 # ":foo_resources"
1257 # ]
1258 # srcjar_deps = [
1259 # ":foo_generated_enum"
1260 # ]
1261 # native_libs = [
1262 # native_lib_path
1263 # ]
1264 # }
1265 template("android_apk") {
1266 set_sources_assignment_filter([])
1267 if (defined(invoker.testonly)) {
1268 testonly = invoker.testonly
1269 }
1270
1271 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name))
1272 assert(defined(invoker.android_manifest))
1273 gen_dir = "$target_gen_dir/$target_name"
1274 base_path = "$gen_dir/$target_name"
1275 _build_config = "$target_gen_dir/$target_name.build_config"
1276 resources_zip_path = "$base_path.resources.zip"
1277 _all_resources_zip_path = "$base_path.resources.all.zip"
1278 jar_path = "$base_path.jar"
1279 _template_name = target_name
1280
1281 final_dex_path = "$gen_dir/classes.dex"
1282 final_dex_target_name = "${_template_name}__final_dex"
1283
1284 _final_apk_path = ""
1285 if (defined(invoker.final_apk_path)) {
1286 _final_apk_path = invoker.final_apk_path
1287 } else if (defined(invoker.apk_name)) {
1288 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk"
1289 }
1290 _dist_jar_path_list =
1291 process_file_template(
1292 [ _final_apk_path ],
1293 "$root_build_dir/test.lib.java/{{source_name_part}}.jar")
1294 _dist_jar_path = _dist_jar_path_list[0]
1295
1296 _native_libs = []
1297
1298 _version_code = "1"
1299 if (defined(invoker.version_code)) {
1300 _version_code = invoker.version_code
1301 }
1302
1303 _version_name = "Developer Build"
1304 if (defined(invoker.version_name)) {
1305 _version_name = invoker.version_name
1306 }
1307 _keystore_path = android_default_keystore_path
1308 _keystore_name = android_default_keystore_name
1309 _keystore_password = android_default_keystore_password
1310
1311 if (defined(invoker.keystore_path)) {
1312 _keystore_path = invoker.keystore_path
1313 _keystore_name = invoker.keystore_name
1314 _keystore_password = invoker.keystore_password
1315 }
1316
1317 _srcjar_deps = []
1318 if (defined(invoker.srcjar_deps)) {
1319 _srcjar_deps += invoker.srcjar_deps
1320 }
1321
1322 _load_library_from_apk = false
1323
1324 # The dependency that makes the chromium linker, if any is needed.
1325 _chromium_linker_dep = []
1326
1327 if (defined(invoker.native_libs)) {
1328 _use_chromium_linker = false
1329 if (defined(invoker.use_chromium_linker)) {
1330 _use_chromium_linker =
1331 invoker.use_chromium_linker && chromium_linker_supported
1332 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ]
1333 }
1334
1335 if (defined(invoker.load_library_from_apk) &&
1336 invoker.load_library_from_apk) {
1337 _load_library_from_apk = true
1338 assert(_use_chromium_linker,
1339 "Loading library from the apk requires use" +
1340 " of the Chromium linker.")
1341 }
1342
1343 _enable_relocation_packing = false
1344 if (defined(invoker.enable_relocation_packing) &&
1345 invoker.enable_relocation_packing) {
1346 _enable_relocation_packing = relocation_packing_supported
1347 assert(_use_chromium_linker,
1348 "Relocation packing requires use of the" + " Chromium linker.")
1349 }
1350
1351 _native_libs = process_file_template(
1352 invoker.native_libs,
1353 "$root_build_dir/lib.stripped/{{source_file_part}}")
1354
1355 _native_libs_dir = base_path + "/libs"
1356
1357 if (_use_chromium_linker) {
1358 _native_libs +=
1359 [ "$root_build_dir/lib.stripped/libchromium_android_linker.so" ]
1360 }
1361
1362 _enable_relocation_packing = false
1363 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) &&
1364 invoker.enable_relocation_packing) {
1365 _enable_relocation_packing = true
1366 }
1367
1368 _native_lib_version_name = ""
1369 if (defined(invoker.native_lib_version_name)) {
1370 _native_lib_version_name = invoker.native_lib_version_name
1371 }
1372 }
1373
1374 _android_manifest = invoker.android_manifest
1375 _rebased_build_config = rebase_path(_build_config, root_build_dir)
1376 _create_abi_split =
1377 defined(invoker.create_abi_split) && invoker.create_abi_split
1378 _create_density_splits =
1379 defined(invoker.create_density_splits) && invoker.create_density_splits
1380
1381 # Help GN understand that _create_abi_split is not unused (bug in GN).
1382 assert(_create_abi_split || true)
1383
1384 build_config_target = "${_template_name}__build_config"
1385 write_build_config(build_config_target) {
1386 type = "android_apk"
1387 dex_path = final_dex_path
1388 resources_zip = resources_zip_path
1389 build_config = _build_config
1390 android_manifest = _android_manifest
1391
1392 deps = _chromium_linker_dep
1393 if (defined(invoker.deps)) {
1394 deps += invoker.deps
1395 }
1396
1397 if (defined(invoker.apk_under_test)) {
1398 apk_under_test = invoker.apk_under_test
1399 }
1400
1401 native_libs = _native_libs
1402 }
1403
1404 final_deps = []
1405
1406 process_resources_target = "${_template_name}__process_resources"
1407 final_deps += [ ":$process_resources_target" ]
1408 process_resources(process_resources_target) {
1409 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1410 r_text_path = "${target_gen_dir}/${target_name}_R.txt"
1411 android_manifest = _android_manifest
1412 resource_dirs = [ "//build/android/ant/empty/res" ]
1413 zip_path = resources_zip_path
1414 all_resources_zip_path = _all_resources_zip_path
1415 generate_constant_ids = true
1416
1417 if (defined(invoker.include_all_resources)) {
1418 include_all_resources = invoker.include_all_resources
1419 }
1420
1421 build_config = _build_config
1422 deps = [
1423 ":$build_config_target",
1424 ]
1425 if (defined(invoker.deps)) {
1426 deps += invoker.deps
1427 }
1428 }
1429 _srcjar_deps += [ ":$process_resources_target" ]
1430
1431 if (_native_libs != []) {
1432 _enable_chromium_linker_tests = false
1433 if (defined(invoker.enable_chromium_linker_tests)) {
1434 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests
1435 }
1436
1437 java_cpp_template("${_template_name}__native_libraries_java") {
1438 package_name = "org/chromium/base/library_loader"
1439 sources = [
1440 "//base/android/java/templates/NativeLibraries.template",
1441 ]
1442 inputs = [
1443 _build_config,
1444 ]
1445 deps = [
1446 ":$build_config_target",
1447 ]
1448
1449 defines = [
1450 "NATIVE_LIBRARIES_LIST=" +
1451 "@FileArg($_rebased_build_config:native:java_libraries_list)",
1452 "NATIVE_LIBRARIES_VERSION_NUMBER=\"$_native_lib_version_name\"",
1453 ]
1454 if (_use_chromium_linker) {
1455 defines += [ "ENABLE_CHROMIUM_LINKER" ]
1456 }
1457 if (_load_library_from_apk) {
1458 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ]
1459 }
1460 if (_enable_chromium_linker_tests) {
1461 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ]
1462 }
1463 }
1464 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ]
1465 }
1466
1467 java_target = "${_template_name}__java"
1468 final_deps += [ ":$java_target" ]
1469 java_library_impl(java_target) {
1470 supports_android = true
1471 requires_android = true
1472 override_build_config = _build_config
1473 deps = [
1474 ":$build_config_target",
1475 ]
1476
1477 android_manifest = _android_manifest
1478 chromium_code = true
1479 if (defined(invoker.java_files)) {
1480 java_files = invoker.java_files
1481 } else if (defined(invoker.DEPRECATED_java_in_dir)) {
1482 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1483 } else {
1484 java_files = []
1485 }
1486 srcjar_deps = _srcjar_deps
1487 dex_path = base_path + ".dex.jar"
1488
1489 if (defined(invoker.deps)) {
1490 deps += invoker.deps
1491 }
1492 }
1493
1494 if (_dist_jar_path != "") {
1495 create_dist_target = "${_template_name}__create_dist_jar"
1496 final_deps += [ ":$create_dist_target" ]
1497
1498 # TODO(cjhopman): This is only ever needed to calculate the list of tests to
1499 # run. See build/android/pylib/instrumentation/test_jar.py. We should be
1500 # able to just do that calculation at build time instead.
1501 action(create_dist_target) {
1502 script = "//build/android/gyp/create_dist_jar.py"
1503 depfile = "$target_gen_dir/$target_name.d"
1504 inputs = [
1505 _build_config,
1506 ]
1507 outputs = [
1508 depfile,
1509 _dist_jar_path,
1510 ]
1511 args = [
1512 "--depfile",
1513 rebase_path(depfile, root_build_dir),
1514 "--output",
1515 rebase_path(_dist_jar_path, root_build_dir),
1516 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)",
1517 ]
1518 inputs += [ jar_path ]
1519 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir)
1520 args += [ "--inputs=$_rebased_jar_path" ]
1521 deps = [
1522 ":$build_config_target", # Generates the build config file.
1523 ":$java_target", # Generates the jar file.
1524 ]
1525 }
1526 }
1527
1528 final_deps += [ ":$final_dex_target_name" ]
1529 dex("$final_dex_target_name") {
1530 deps = [
1531 ":$build_config_target",
1532 ":$java_target",
1533 ]
1534 sources = [
1535 jar_path,
1536 ]
1537 inputs = [
1538 _build_config,
1539 ]
1540 output = final_dex_path
1541 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files"
1542 args = [ "--inputs=@FileArg($dex_arg_key)" ]
1543 }
1544
1545 if (_native_libs != []) {
1546 action("${_template_name}__prepare_native") {
1547 script = "//build/android/gyp/pack_arm_relocations.py"
1548 packed_libraries_dir = "$_native_libs_dir/$android_app_abi"
1549 depfile = "$target_gen_dir/$target_name.d"
1550 outputs = [
1551 depfile,
1552 ]
1553
1554 inputs = _native_libs
1555 deps = _chromium_linker_dep
1556
1557 inputs += [ _build_config ]
1558 deps += [ ":$build_config_target" ]
1559
1560 skip_packing_list = [
1561 "gdbserver",
1562 "libchromium_android_linker.so",
1563 ]
1564
1565 enable_packing_arg = 0
1566 if (_enable_relocation_packing) {
1567 enable_packing_arg = 1
1568 deps += [ relocation_packer_target ]
1569 }
1570
1571 args = [
1572 "--depfile",
1573 rebase_path(depfile, root_build_dir),
1574 "--enable-packing=$enable_packing_arg",
1575 "--exclude-packing-list=$skip_packing_list",
1576 "--android-pack-relocations",
1577 rebase_path(relocation_packer_exe, root_build_dir),
1578 "--stripped-libraries-dir",
1579 rebase_path(root_build_dir, root_build_dir),
1580 "--packed-libraries-dir",
1581 rebase_path(packed_libraries_dir, root_build_dir),
1582 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)",
1583 "--clear-dir",
1584 ]
1585
1586 if (defined(invoker.deps)) {
1587 deps += invoker.deps
1588 }
1589 if (defined(invoker.public_deps)) {
1590 public_deps = invoker.public_deps
1591 }
1592 if (defined(invoker.data_deps)) {
1593 data_deps = invoker.data_deps
1594 }
1595
1596 if (is_debug) {
1597 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir)
1598 inputs += [ android_gdbserver ]
1599 args += [ "--libraries=$rebased_gdbserver" ]
1600 }
1601 }
1602 }
1603
1604 final_deps += [ ":${_template_name}__create" ]
1605 create_apk("${_template_name}__create") {
1606 apk_path = _final_apk_path
1607 android_manifest = _android_manifest
1608 resources_zip = _all_resources_zip_path
1609 dex_path = final_dex_path
1610 load_library_from_apk = _load_library_from_apk
1611 create_density_splits = _create_density_splits
1612
1613 version_code = _version_code
1614 version_name = _version_name
1615
1616 keystore_name = _keystore_name
1617 keystore_path = _keystore_path
1618 keystore_password = _keystore_password
1619
1620 # This target generates the input file _all_resources_zip_path.
1621 deps = [
1622 ":$process_resources_target",
1623 ":$final_dex_target_name",
1624 ]
1625 if (defined(invoker.deps)) {
1626 deps += invoker.deps
1627 }
1628
1629 if (defined(invoker.asset_location)) {
1630 asset_location = invoker.asset_location
1631
1632 # We don't know the exact dependencies that create the assets in
1633 # |asset_location|; we depend on all caller deps until a better solution
1634 # is figured out (http://crbug.com/433330).
1635 if (defined(invoker.deps)) {
1636 deps += invoker.deps
1637 }
1638 }
1639
1640 if (_native_libs != [] && !_create_abi_split) {
1641 native_libs_dir = _native_libs_dir
1642 deps += [ ":${_template_name}__prepare_native" ]
1643 }
1644 }
1645
1646 if (_native_libs != [] && _create_abi_split) {
1647 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}"
1648 generate_split_manifest(_manifest_rule) {
1649 main_manifest = _android_manifest
1650 out_manifest =
1651 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml"
1652 split_name = "abi_${android_app_abi}"
1653 }
1654
1655 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}"
1656 final_deps += [ ":$_apk_rule" ]
1657 create_apk(_apk_rule) {
1658 _split_paths = process_file_template(
1659 [ _final_apk_path ],
1660 "{{source_dir}}/{{source_name_part}}-abi-${android_app_abi}.apk")
1661 apk_path = _split_paths[0]
1662 base_path = "$gen_dir/$_apk_rule"
1663
1664 manifest_outputs = get_target_outputs(":${_manifest_rule}")
1665 android_manifest = manifest_outputs[1]
1666 load_library_from_apk = _load_library_from_apk
1667
1668 version_code = _version_code
1669 version_name = _version_name
1670
1671 keystore_name = _keystore_name
1672 keystore_path = _keystore_path
1673 keystore_password = _keystore_password
1674
1675 native_libs_dir = _native_libs_dir
1676 deps = [
1677 ":${_template_name}__prepare_native",
1678 ]
1679 }
1680 }
1681
1682 group(target_name) {
1683 deps = final_deps
1684 if (defined(invoker.data_deps)) {
1685 data_deps = invoker.data_deps
1686 }
1687 }
1688 }
1689
1690 # Declare an Android instrumentation test apk
1691 #
1692 # This target creates an Android instrumentation test apk.
1693 #
1694 # Variables
1695 # android_manifest: Path to AndroidManifest.xml.
1696 # data_deps: List of dependencies needed at runtime. These will be built but
1697 # won't change the generated .apk in any way (in fact they may be built
1698 # after the .apk is).
1699 # deps: List of dependencies. All Android java resources and libraries in the
1700 # "transitive closure" of these dependencies will be included in the apk.
1701 # Note: this "transitive closure" actually only includes such targets if
1702 # they are depended on through android_library or android_resources targets
1703 # (and so not through builtin targets like 'action', 'group', etc).
1704 # java_files: List of .java files to include in the apk.
1705 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
1706 # will be added to java_files and be included in this apk.
1707 # apk_name: Name for final apk.
1708 # final_apk_path: Path to final built apk. Default is
1709 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name.
1710 # native_libs: List paths of native libraries to include in this apk. If these
1711 # libraries depend on other shared_library targets, those dependencies will
1712 # also be included in the apk.
1713 # apk_under_test: The apk being tested.
1714 # isolate_file: Isolate file containing the list of test data dependencies.
1715 #
1716 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in
1717 # this directory will be included in the library. This is only supported to
1718 # ease the gyp->gn conversion and will be removed in the future.
1719 #
1720 # Example
1721 # instrumentation_test_apk("foo_test_apk") {
1722 # android_manifest = "AndroidManifest.xml"
1723 # apk_name = "FooTest"
1724 # apk_under_test = "Foo"
1725 # java_files = [
1726 # "android/org/chromium/foo/FooTestCase.java",
1727 # "android/org/chromium/foo/FooExampleTest.java",
1728 # ]
1729 # deps = [
1730 # ":foo_test_support_java"
1731 # ]
1732 # }
1733 template("instrumentation_test_apk") {
1734 set_sources_assignment_filter([])
1735 testonly = true
1736 _template_name = target_name
1737
1738 if (defined(invoker.apk_name)) {
1739 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ]
1740 test_runner_script("${_template_name}__test_runner_script") {
1741 test_name = invoker.target_name
1742 test_type = "instrumentation"
1743 test_apk = invoker.apk_name
1744 if (defined(invoker.isolate_file)) {
1745 isolate_file = invoker.isolate_file
1746 }
1747 }
1748 }
1749
1750 android_apk(target_name) {
1751 if (defined(invoker.android_manifest)) {
1752 android_manifest = invoker.android_manifest
1753 }
1754 data_deps = [
1755 "//testing/android/driver:driver_apk",
1756 "//tools/android/forwarder2",
1757 "//tools/android/md5sum",
1758 ]
1759 if (defined(test_runner_data_dep)) {
1760 data_deps += test_runner_data_dep
1761 }
1762 if (defined(invoker.data_deps)) {
1763 data_deps += invoker.data_deps
1764 }
1765 deps = [
1766 "//testing/android/broker:broker_java",
1767 ]
1768 if (defined(invoker.deps)) {
1769 deps += invoker.deps
1770 }
1771 if (defined(invoker.java_files)) {
1772 java_files = invoker.java_files
1773 }
1774 if (defined(invoker.srcjar_deps)) {
1775 srcjar_deps = invoker.srcjar_deps
1776 }
1777 if (defined(invoker.apk_name)) {
1778 apk_name = invoker.apk_name
1779 }
1780 if (defined(invoker.final_apk_path)) {
1781 final_apk_path = invoker.final_apk_path
1782 }
1783 if (defined(invoker.native_libs)) {
1784 native_libs = invoker.native_libs
1785 }
1786 if (defined(invoker.apk_under_test)) {
1787 apk_under_test = invoker.apk_under_test
1788 }
1789 if (defined(invoker.DEPRECATED_java_in_dir)) {
1790 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir
1791 }
1792 }
1793 }
1794
1795 # Declare an Android gtest apk
1796 #
1797 # This target creates an Android apk for running gtest-based unittests.
1798 #
1799 # Variables
1800 # deps: Specifies the dependencies of this target. These will be passed to
1801 # the underlying android_apk invocation and should include the java and
1802 # resource dependencies of the apk.
1803 # unittests_dep: This should be the label of the gtest native target. This
1804 # target must be defined previously in the same file.
1805 # unittests_binary: The basename of the library produced by the unittests_dep
1806 # target. If unspecified, it assumes the name of the unittests_dep target
1807 # (which will be correct unless that target specifies an "output_name".
1808 # TODO(brettw) make this automatic by allowing get_target_outputs to
1809 # support executables.
1810 # apk_name: The name of the produced apk. If unspecified, it uses the name
1811 # of the unittests_dep target postfixed with "_apk"
1812 #
1813 # Example
1814 # unittest_apk("foo_unittests_apk") {
1815 # deps = [ ":foo_java", ":foo_resources" ]
1816 # unittests_dep = ":foo_unittests"
1817 # }
1818 template("unittest_apk") {
1819 set_sources_assignment_filter([])
1820 testonly = true
1821
1822 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name")
1823
1824 test_suite_name = get_label_info(invoker.unittests_dep, "name")
1825
1826 # This trivial assert is needed in case both unittests_binary and apk_name
1827 # are defined, as otherwise test_suite_name would not be used.
1828 assert(test_suite_name != "")
1829
1830 if (defined(invoker.unittests_binary)) {
1831 unittests_binary = invoker.unittests_binary
1832 } else {
1833 unittests_binary = "lib" + test_suite_name + ".so"
1834 }
1835
1836 if (defined(invoker.apk_name)) {
1837 apk_name = invoker.apk_name
1838 } else {
1839 apk_name = test_suite_name
1840 }
1841
1842 android_apk(target_name) {
1843 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk"
1844 java_files = [
1845 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBro wserTestActivity.java",
1846 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTes tActivity.java",
1847 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUni tTestActivity.java",
1848 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTes tInstrumentationTestRunner.java",
1849 ]
1850 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml"
1851 native_libs = [ unittests_binary ]
1852 if (defined(invoker.asset_location)) {
1853 asset_location = invoker.asset_location
1854 }
1855 deps = [
1856 "//base:base_java",
1857 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk",
1858 "//testing/android/appurify_support:appurify_support_java",
1859 ]
1860 if (defined(invoker.deps)) {
1861 deps += invoker.deps
1862 }
1863 data_deps = [
1864 "//tools/android/md5sum",
1865 ]
1866 if (host_os == "linux") {
1867 data_deps += [ "//tools/android/forwarder2" ]
1868 }
1869 if (defined(invoker.data_deps)) {
1870 data_deps += invoker.data_deps
1871 }
1872 }
1873 }
1874
1875 # Generate .java files from .aidl files.
1876 #
1877 # This target will store the .java files in a srcjar and should be included in
1878 # an android_library or android_apk's srcjar_deps.
1879 #
1880 # Variables
1881 # sources: Paths to .aidl files to compile.
1882 # import_include: Path to directory containing .java files imported by the
1883 # .aidl files.
1884 # interface_file: Preprocessed aidl file to import.
1885 #
1886 # Example
1887 # android_aidl("foo_aidl") {
1888 # import_include = "java/src"
1889 # sources = [
1890 # "java/src/com/foo/bar/FooBarService.aidl",
1891 # "java/src/com/foo/bar/FooBarServiceCallback.aidl",
1892 # ]
1893 # }
1894 template("android_aidl") {
1895 set_sources_assignment_filter([])
1896 if (defined(invoker.testonly)) {
1897 testonly = invoker.testonly
1898 }
1899
1900 srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
1901 aidl_path = "${android_sdk_build_tools}/aidl"
1902 framework_aidl = "$android_sdk/framework.aidl"
1903
1904 action(target_name) {
1905 script = "//build/android/gyp/aidl.py"
1906 sources = invoker.sources
1907
1908 imports = [ framework_aidl ]
1909 if (defined(invoker.interface_file)) {
1910 assert(invoker.interface_file != "")
1911 imports += [ invoker.interface_file ]
1912 }
1913
1914 inputs = [ aidl_path ] + imports
1915
1916 depfile = "${target_gen_dir}/${target_name}.d"
1917 outputs = [
1918 depfile,
1919 srcjar_path,
1920 ]
1921 rebased_imports = rebase_path(imports, root_build_dir)
1922 args = [
1923 "--depfile",
1924 rebase_path(depfile, root_build_dir),
1925 "--aidl-path",
1926 rebase_path(aidl_path, root_build_dir),
1927 "--imports=$rebased_imports",
1928 "--srcjar",
1929 rebase_path(srcjar_path, root_build_dir),
1930 ]
1931 if (defined(invoker.import_include) && invoker.import_include != "") {
1932 # TODO(cjhopman): aidl supports creating a depfile. We should be able to
1933 # switch to constructing a depfile for the overall action from that
1934 # instead of having all the .java files in the include paths as inputs.
1935 rebased_import_includes =
1936 rebase_path([ invoker.import_include ], root_build_dir)
1937 args += [ "--includes=$rebased_import_includes" ]
1938
1939 _java_files_build_rel =
1940 exec_script("//build/android/gyp/find.py",
1941 rebase_path([ invoker.import_include ], root_build_dir),
1942 "list lines")
1943 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir)
1944 inputs += _java_files
1945 }
1946 args += rebase_path(sources, root_build_dir)
1947 }
1948 }
1949
1950 # Creates a dist directory for a native executable.
1951 #
1952 # Running a native executable on a device requires all the shared library
1953 # dependencies of that executable. To make it easier to install and run such an
1954 # executable, this will create a directory containing the native exe and all
1955 # it's library dependencies.
1956 #
1957 # Note: It's usually better to package things as an APK than as a native
1958 # executable.
1959 #
1960 # Variables
1961 # dist_dir: Directory for the exe and libraries. Everything in this directory
1962 # will be deleted before copying in the exe and libraries.
1963 # binary: Path to (stripped) executable.
1964 #
1965 # Example
1966 # create_native_executable_dist("foo_dist") {
1967 # dist_dir = "$root_build_dir/foo_dist"
1968 # binary = "$root_build_dir/exe.stripped/foo"
1969 # deps = [ ":the_thing_that_makes_foo" ]
1970 # }
1971 template("create_native_executable_dist") {
1972 set_sources_assignment_filter([])
1973 if (defined(invoker.testonly)) {
1974 testonly = invoker.testonly
1975 }
1976
1977 dist_dir = invoker.dist_dir
1978 binary = invoker.binary
1979 template_name = target_name
1980
1981 libraries_list =
1982 "${target_gen_dir}/${template_name}_library_dependencies.list"
1983
1984 # TODO(gyp)
1985 #'dependencies': [
1986 #'<(DEPTH)/build/android/setup.gyp:copy_system_libraries',
1987 #],
1988
1989 find_deps_target_name = "${template_name}__find_library_dependencies"
1990 copy_target_name = "${template_name}__copy_libraries_and_exe"
1991
1992 stripped_libraries_dir = "$root_build_dir/lib.stripped"
1993 action(find_deps_target_name) {
1994 visibility = [ ":$copy_target_name" ]
1995
1996 script = "//build/android/gyp/write_ordered_libraries.py"
1997 depfile = "$target_gen_dir/$target_name.d"
1998 inputs = [
1999 binary,
2000 android_readelf,
2001 ]
2002 outputs = [
2003 depfile,
2004 libraries_list,
2005 ]
2006 rebased_binaries = rebase_path([ binary ], root_build_dir)
2007 args = [
2008 "--depfile",
2009 rebase_path(depfile, root_build_dir),
2010 "--input-libraries=$rebased_binaries",
2011 "--libraries-dir",
2012 rebase_path(stripped_libraries_dir, root_build_dir),
2013 "--output",
2014 rebase_path(libraries_list, root_build_dir),
2015 "--readelf",
2016 rebase_path(android_readelf, root_build_dir),
2017 ]
2018 if (defined(invoker.deps)) {
2019 deps = invoker.deps
2020 }
2021 }
2022
2023 copy_ex(copy_target_name) {
2024 visibility = [ ":$template_name" ]
2025
2026 clear_dir = true
2027 inputs = [
2028 binary,
2029 libraries_list,
2030 ]
2031 dest = dist_dir
2032 rebased_binaries_list = rebase_path([ binary ], root_build_dir)
2033 rebased_libraries_list = rebase_path(libraries_list, root_build_dir)
2034 args = [
2035 "--files=$rebased_binaries_list",
2036 "--files=@FileArg($rebased_libraries_list:libraries)",
2037 ]
2038
2039 deps = [
2040 ":$find_deps_target_name",
2041 ]
2042 if (defined(invoker.deps)) {
2043 deps += invoker.deps
2044 }
2045 }
2046
2047 group(template_name) {
2048 if (defined(invoker.visibility)) {
2049 visibility = invoker.visibility
2050 }
2051 deps = [
2052 ":$copy_target_name",
2053 ]
2054 }
2055 }
2056
2057 # Compile a protocol buffer to java.
2058 #
2059 # This generates java files from protocol buffers and creates an Android library
2060 # containing the classes.
2061 #
2062 # Variables
2063 # sources: Paths to .proto files to compile.
2064 # proto_path: Root directory of .proto files.
2065 #
2066 # Example:
2067 # proto_java_library("foo_proto_java") {
2068 # proto_path = [ "src/foo" ]
2069 # sources = [ "$proto_path/foo.proto" ]
2070 # }
2071 template("proto_java_library") {
2072 set_sources_assignment_filter([])
2073 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)"
2074 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir")
2075 _protoc_bin = "$_protoc_out_dir/android_protoc"
2076 _proto_path = invoker.proto_path
2077
2078 _template_name = target_name
2079
2080 action("${_template_name}__protoc_java") {
2081 srcjar_path = "$target_gen_dir/$target_name.srcjar"
2082 script = "//build/protoc_java.py"
2083 deps = [
2084 _protoc_dep,
2085 ]
2086 sources = invoker.sources
2087 depfile = "$target_gen_dir/$target_name.d"
2088 outputs = [
2089 depfile,
2090 srcjar_path,
2091 ]
2092 args = [
2093 "--depfile",
2094 rebase_path(depfile, root_build_dir),
2095 "--protoc",
2096 rebase_path(_protoc_bin, root_build_dir),
2097 "--proto-path",
2098 rebase_path(_proto_path, root_build_dir),
2099 "--srcjar",
2100 rebase_path(srcjar_path, root_build_dir),
2101 ] + rebase_path(sources, root_build_dir)
2102 }
2103
2104 android_library(target_name) {
2105 java_files = []
2106 srcjar_deps = [ ":${_template_name}__protoc_java" ]
2107 deps = [
2108 "//third_party/android_protobuf:protobuf_nano_javalib",
2109 ]
2110 }
2111 }
2112
2113 # TODO(GYP): implement this.
2114 template("uiautomator_test") {
2115 set_sources_assignment_filter([])
2116 if (defined(invoker.testonly)) {
2117 testonly = invoker.testonly
2118 }
2119 assert(target_name != "")
2120 assert(invoker.deps != [] || true)
2121 group(target_name) {
2122 }
2123 }
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