forked from otcshare/chromium-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.gni
5581 lines (5155 loc) · 208 KB
/
rules.gni
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Do not add any imports to non-//build directories here.
# Some projects (e.g. V8) do not have non-build directories DEPS'ed in.
import("//build/config/android/channel.gni")
import("//build/config/android/config.gni")
import("//build/config/android/copy_ex.gni")
import("//build/config/clang/clang.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/coverage/coverage.gni")
import("//build/config/python.gni")
import("//build/config/rts.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/zip.gni")
import("//build/toolchain/toolchain.gni")
assert(is_android || is_robolectric)
declare_args() {
enable_jni_tracing = false
}
# Use a dedicated include dir so that files can #include headers from other
# toolchains without affecting non-JNI #includes.
if (target_os == "android") {
jni_headers_dir = "$root_build_dir/gen/jni_headers"
} else {
# Chrome OS builds cannot share gen/ directories because is_android=false
# within default_toolchain.
jni_headers_dir = "$root_gen_dir/jni_headers"
}
if (target_cpu == "arm") {
_sanitizer_arch = "arm"
} else if (target_cpu == "arm64") {
_sanitizer_arch = "aarch64"
} else if (target_cpu == "x86") {
_sanitizer_arch = "i686"
}
_sanitizer_runtimes = []
if (use_cfi_diag || is_ubsan || is_ubsan_security || is_ubsan_vptr) {
_sanitizer_runtimes = [ "$clang_base_path/lib/clang/$clang_version/lib/linux/libclang_rt.ubsan_standalone-$_sanitizer_arch-android.so" ]
}
_BUNDLETOOL_JAR_PATH =
"//third_party/android_build_tools/bundletool/bundletool.jar"
# Creates a dist directory for a native executable.
#
# Running a native executable on a device requires all the shared library
# dependencies of that executable. To make it easier to install and run such an
# executable, this will create a directory containing the native exe and all
# it's library dependencies.
#
# Note: It's usually better to package things as an APK than as a native
# executable.
#
# Variables
# dist_dir: Directory for the exe and libraries. Everything in this directory
# will be deleted before copying in the exe and libraries.
# binary: Path to (stripped) executable.
# extra_files: List of extra files to copy in (optional).
#
# Example
# create_native_executable_dist("foo_dist") {
# dist_dir = "$root_build_dir/foo_dist"
# binary = "$root_build_dir/foo"
# deps = [ ":the_thing_that_makes_foo" ]
# }
template("create_native_executable_dist") {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
_libraries_list = "${target_gen_dir}/${target_name}_library_dependencies.list"
_sanitizer_runtimes_target_name = "${target_name}__sanitizer_runtimes"
group(_sanitizer_runtimes_target_name) {
metadata = {
shared_libraries = _sanitizer_runtimes
}
}
generated_file("${target_name}__library_list") {
forward_variables_from(invoker, [ "deps" ])
if (!defined(deps)) {
deps = []
}
deps += [ ":${_sanitizer_runtimes_target_name}" ]
output_conversion = "json"
outputs = [ _libraries_list ]
data_keys = [ "shared_libraries" ]
walk_keys = [ "shared_libraries_barrier" ]
rebase = root_build_dir
}
copy_ex(target_name) {
inputs = [
_libraries_list,
invoker.binary,
]
dest = invoker.dist_dir
data = [ "${invoker.dist_dir}/" ]
_rebased_libraries_list = rebase_path(_libraries_list, root_build_dir)
_rebased_binaries_list = rebase_path([ invoker.binary ], root_build_dir)
args = [
"--clear",
"--files=@FileArg($_rebased_libraries_list)",
"--files=$_rebased_binaries_list",
]
if (defined(invoker.extra_files)) {
_rebased_extra_files = rebase_path(invoker.extra_files, root_build_dir)
args += [ "--files=$_rebased_extra_files" ]
}
_depfile = "$target_gen_dir/$target_name.d"
_stamp_file = "$target_gen_dir/$target_name.stamp"
outputs = [ _stamp_file ]
args += [
"--depfile",
rebase_path(_depfile, root_build_dir),
"--stamp",
rebase_path(_stamp_file, root_build_dir),
]
deps = [ ":${target_name}__library_list" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}
if (enable_java_templates) {
if (is_android) {
import("//build/config/android/internal_rules.gni")
}
# JNI target implementation. See generate_jni or generate_jar_jni for usage.
template("generate_jni_impl") {
_prev_jni_output_dir = "$target_gen_dir/$target_name"
_subdir = rebase_path(target_gen_dir, root_gen_dir)
_jni_output_dir = "$jni_headers_dir/$_subdir/$target_name"
if (defined(invoker.jni_generator_include)) {
_jni_generator_include = invoker.jni_generator_include
_jni_generator_include_deps = []
} else {
_jni_generator_include =
"//base/android/jni_generator/jni_generator_helper.h"
_jni_generator_include_deps = [
# Using //base/android/jni_generator/jni_generator_helper.h introduces
# a dependency on buildflags targets indirectly through
# base/android/jni_android.h, which is part of the //base target.
# This can't depend directly on //base without causing a dependency
# cycle, though.
"//base:debugging_buildflags",
"//base:logging_buildflags",
"//build:chromeos_buildflags",
]
}
action_with_pydeps(target_name) {
# The sources aren't compiled so don't check their dependencies.
check_includes = false
script = "//base/android/jni_generator/jni_generator.py"
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"deps",
"public_deps",
])
if (!defined(public_deps)) {
public_deps = []
}
public_deps += _jni_generator_include_deps
inputs = []
args = [
"--ptr_type=long",
# TODO(agrieve): --prev_output_dir used only to make incremental builds
# work. Remove --prev_output_dir at some point after 2022.
"--prev_output_dir",
rebase_path(_prev_jni_output_dir, root_build_dir),
"--output_dir",
rebase_path(_jni_output_dir, root_build_dir),
"--includes",
rebase_path(_jni_generator_include, _jni_output_dir),
]
if (defined(invoker.classes)) {
if (is_robolectric) {
not_needed(invoker, [ "jar_file" ])
} else {
if (defined(invoker.jar_file)) {
_jar_file = invoker.jar_file
} else {
_jar_file = android_sdk_jar
}
inputs += [ _jar_file ]
args += [
"--jar_file",
rebase_path(_jar_file, root_build_dir),
]
}
_input_args = invoker.classes
_input_names = invoker.classes
if (defined(invoker.always_mangle) && invoker.always_mangle) {
args += [ "--always_mangle" ]
}
if (defined(invoker.unchecked_exceptions) &&
invoker.unchecked_exceptions) {
args += [ "--unchecked_exceptions" ]
}
} else {
assert(defined(invoker.sources))
inputs += invoker.sources
_input_args = rebase_path(invoker.sources, root_build_dir)
_input_names = invoker.sources
if (!is_robolectric && use_hashed_jni_names) {
args += [ "--use_proxy_hash" ]
}
if (!is_robolectric && enable_jni_multiplexing) {
args += [ "--enable_jni_multiplexing" ]
}
if (defined(invoker.namespace)) {
args += [ "-n ${invoker.namespace}" ]
}
}
if (defined(invoker.split_name)) {
args += [ "--split_name=${invoker.split_name}" ]
}
outputs = []
foreach(_name, _input_names) {
_name = get_path_info(_name, "name") + "_jni.h"
outputs += [ "$_jni_output_dir/$_name" ]
# Avoid passing GN lists because not all webrtc embedders use //build.
args += [
"--output_name",
_name,
]
}
foreach(_input, _input_args) {
args += [ "--input_file=$_input" ]
}
if (enable_profiling) {
args += [ "--enable_profiling" ]
}
if (enable_jni_tracing) {
args += [ "--enable_tracing" ]
}
if (current_toolchain != default_toolchain && target_os == "android") {
# Rather than regenerating .h files in secondary toolchains, re-use the
# ones from the primary toolchain by depending on it and adding the
# root gen directory to the include paths.
# https://crbug.com/1369398
inputs = []
outputs = []
_stamp = "$target_gen_dir/$target_name.stamp"
outputs = [ _stamp ]
# Since we used to generate the .h files rather than delegate, the
# script will delete all .h files it finds in --prev_output_dir.
# TODO(agrieve): --prev_output_dir used only to make incremental builds
# work. Convert to group() target at some point after 2022.
args += [
"--stamp",
rebase_path(_stamp, root_build_dir),
]
deps = []
public_deps = []
public_deps = [ ":$target_name($default_toolchain)" ]
public_configs =
[ "//build/config/android:jni_include_dir($default_toolchain)" ]
} else {
public_configs = [ "//build/config/android:jni_include_dir" ]
if (defined(visibility)) {
# Allow dependency on ourselves from secondary toolchain.
visibility += [ ":$target_name" ]
}
}
}
}
# Declare a jni target
#
# This target generates the native jni bindings for a set of .java files.
#
# See base/android/jni_generator/jni_generator.py for more info about the
# format of generating JNI bindings.
#
# Variables
# sources: list of .java files to generate jni for
# namespace: Specify the namespace for the generated header file.
# deps, public_deps: As normal
#
# Example
# # Target located in base/BUILD.gn.
# generate_jni("foo_jni") {
# # Generates gen/base/foo_jni/Foo_jni.h
# # To use: #include "base/foo_jni/Foo_jni.h"
# sources = [
# "android/java/src/org/chromium/foo/Foo.java",
# ...,
# ]
# }
template("generate_jni") {
generate_jni_impl(target_name) {
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
}
}
# Declare a jni target for a prebuilt jar
#
# This target generates the native jni bindings for a set of classes in a .jar.
#
# See base/android/jni_generator/jni_generator.py for more info about the
# format of generating JNI bindings.
#
# Variables
# classes: list of .class files in the jar to generate jni for. These should
# include the full path to the .class file.
# jar_file: the path to the .jar. If not provided, will default to the sdk's
# android.jar
# always_mangle: Mangle all generated method names. By default, the script
# only mangles methods that cause ambiguity due to method overload.
# unchecked_exceptions: Don't CHECK() for exceptions in generated stubs.
# This behaves as if every method had @CalledByNativeUnchecked.
# deps, public_deps: As normal
#
# Example
# # Target located in base/BUILD.gn.
# generate_jar_jni("foo_jni") {
# # Generates gen/base/foo_jni/Runnable_jni.h
# # To use: #include "base/foo_jni/Runnable_jni.h"
# classes = [
# "android/view/Foo.class",
# ]
# }
template("generate_jar_jni") {
generate_jni_impl(target_name) {
forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY)
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
}
}
} # enable_java_templates
# non-robolectric things
if (enable_java_templates && is_android) {
# Declare a jni registration target.
#
# This target generates a srcjar containing a copy of GEN_JNI.java, which has
# the native methods of all dependent java files. It can also create a .h file
# for use with manual JNI registration.
#
# The script does not scan any generated sources (those within .srcjars, or
# within root_build_dir). This could be fixed by adding deps & logic to scan
# .srcjars, but isn't currently needed.
#
# See base/android/jni_generator/jni_registration_generator.py for more info
# about the format of the header file.
#
# Variables
# targets: List of .build_config.json supported targets to provide java sources.
# manual_jni_registration: Manually do JNI registration - required for feature
# splits which provide their own native library. (optional)
# file_exclusions: List of .java files that should be skipped. (optional)
# namespace: Registration functions will be wrapped into this. (optional)
# require_native_mocks: Enforce that any native calls using
# org.chromium.base.annotations.NativeMethods must have a mock set
# (optional).
# enable_native_mocks: Allow native calls using
# org.chromium.base.annotations.NativeMethods to be mocked in tests
# (optional).
# no_transitive_deps: Generate registration for only the Java source in the
# specified target(s). This is useful for generating registration for
# feature modules, without including base module dependencies.
#
# Example
# generate_jni_registration("chrome_jni_registration") {
# targets = [ ":chrome_public_apk" ]
# manual_jni_registration = false
# file_exclusions = [
# "//path/to/Exception.java",
# ]
# }
template("generate_jni_registration") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
script = "//base/android/jni_generator/jni_registration_generator.py"
inputs = []
deps = []
_srcjar_output = "$target_gen_dir/$target_name.srcjar"
outputs = [ _srcjar_output ]
depfile = "$target_gen_dir/$target_name.d"
args = [
"--srcjar-path",
rebase_path(_srcjar_output, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
foreach(_target, invoker.targets) {
deps += [ "${_target}$build_config_target_suffix($default_toolchain)" ]
_build_config =
get_label_info("${_target}($default_toolchain)", "target_gen_dir") +
"/" + get_label_info("${_target}($default_toolchain)", "name") +
".build_config.json"
_rebased_build_config = rebase_path(_build_config, root_build_dir)
inputs += [ _build_config ]
if (defined(invoker.no_transitive_deps) && invoker.no_transitive_deps) {
args += [ "--sources-files=@FileArg($_rebased_build_config:deps_info:target_sources_file)" ]
} else {
args += [
# This is a list of .sources files.
"--sources-files=@FileArg($_rebased_build_config:deps_info:jni_all_source)",
]
}
}
if (defined(invoker.include_testonly)) {
_include_testonly = invoker.include_testonly
} else {
_include_testonly = defined(testonly) && testonly
}
if (_include_testonly) {
args += [ "--include-test-only" ]
}
if (use_hashed_jni_names) {
args += [ "--use-proxy-hash" ]
}
if (defined(invoker.enable_native_mocks) && invoker.enable_native_mocks) {
args += [ "--enable-proxy-mocks" ]
if (defined(invoker.require_native_mocks) &&
invoker.require_native_mocks) {
args += [ "--require-mocks" ]
}
}
_manual_jni_registration = defined(invoker.manual_jni_registration) &&
invoker.manual_jni_registration
if (_manual_jni_registration || enable_jni_multiplexing) {
assert(current_toolchain == default_toolchain,
"We do not need >1 toolchain copies of the same header.")
if (_manual_jni_registration) {
args += [ "--manual-jni-registration" ]
}
if (enable_jni_multiplexing) {
args += [ "--enable-jni-multiplexing" ]
}
_subdir = rebase_path(target_gen_dir, root_gen_dir)
_jni_header_output =
"$jni_headers_dir/$_subdir/${target_name}_generated.h"
outputs += [ _jni_header_output ]
args += [
"--header-path",
rebase_path(_jni_header_output, root_build_dir),
]
# This gives targets depending on this registration access to our generated header.
public_configs = [ "//build/config/android:jni_include_dir" ]
}
if (defined(invoker.file_exclusions)) {
_rebase_file_exclusions =
rebase_path(invoker.file_exclusions, root_build_dir)
args += [ "--file-exclusions=$_rebase_file_exclusions" ]
}
if (defined(invoker.namespace)) {
args += [ "--namespace=${invoker.namespace}" ]
}
}
}
# Declare a target for c-preprocessor-generated java files
#
# NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum
# rule instead.
#
# This target generates java files using the host C pre-processor. Each file in
# sources will be compiled using the C pre-processor. If include_path is
# specified, it will be passed (with --I) to the pre-processor.
#
# This target will create a single .srcjar. Adding this target to an
# android_library target's srcjar_deps will make the generated java files be
# included in that library's final outputs.
#
# Variables
# sources: list of files to be processed by the C pre-processor. For each
# file in sources, there will be one .java file in the final .srcjar. For a
# file named FooBar.template, a java file will be created with name
# FooBar.java.
# inputs: additional compile-time dependencies. Any files
# `#include`-ed in the templates should be listed here.
# defines: List of -D arguments for the preprocessor.
#
# Example
# java_cpp_template("foo_generated_enum") {
# sources = [
# "android/java/templates/Foo.template",
# ]
# inputs = [
# "android/java/templates/native_foo_header.h",
# ]
# }
template("java_cpp_template") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"inputs",
"public_deps",
"sources",
"testonly",
"visibility",
])
script = "//build/android/gyp/gcc_preprocess.py"
outputs = [ "$target_gen_dir/$target_name.srcjar" ]
_include_dirs = [
"//",
root_gen_dir,
]
_rebased_include_dirs = rebase_path(_include_dirs, root_build_dir)
args = [
"--include-dirs=$_rebased_include_dirs",
"--output",
rebase_path(outputs[0], root_build_dir),
]
if (defined(invoker.defines)) {
foreach(_define, invoker.defines) {
args += [
"--define",
_define,
]
}
}
args += rebase_path(sources, root_build_dir)
}
}
# Declare a target for generating Java classes from C++ enums.
#
# This target generates Java files from C++ enums using a script.
#
# This target will create a single .srcjar. Adding this target to an
# android_library target's srcjar_deps will make the generated java files be
# included in that library's final outputs.
#
# Variables
# sources: list of files to be processed by the script. For each annotated
# enum contained in the sources files the script will generate a .java
# file with the same name as the name of the enum.
#
# Example
# java_cpp_enum("foo_generated_enum") {
# sources = [
# "src/native_foo_header.h",
# ]
# }
template("java_cpp_enum") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "sources" ])
# The sources aren't compiled so don't check their dependencies.
check_includes = false
script = "//build/android/gyp/java_cpp_enum.py"
_srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
_rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir)
_rebased_sources = rebase_path(invoker.sources, root_build_dir)
args = [ "--srcjar=$_rebased_srcjar_path" ] + _rebased_sources
outputs = [ _srcjar_path ]
}
}
# Declare a target for generating Java classes with string constants matching
# those found in C++ files using a python script.
#
# This target will create a single .srcjar. Adding this target to an
# android_library target's srcjar_deps will make the generated java files be
# included in that library's final outputs.
#
# Variables
# sources: list of files to be processed by the script. For each string
# constant in the source files, the script will add a corresponding
# Java string to the specified template file.
# Example
# java_cpp_strings("foo_switches") {
# sources = [
# "src/foo_switches.cc",
# ]
# template = "src/templates/FooSwitches.java.tmpl
# }
#
# foo_switches.cc:
#
# // A switch.
# const char kASwitch = "a-switch";
#
# FooSwitches.java.tmpl
#
# // Copyright {YEAR} The Chromium Authors. All rights reserved.
# // Use of this source code is governed by a BSD-style license that can be
# // found in the LICENSE file.
#
# // This file is autogenerated by
# // {SCRIPT_NAME}
# // From
# // {SOURCE_PATH}, and
# // {TEMPLATE_PATH}
#
# package my.java.package;
#
# public abstract class FooSwitches {{
# // ...snip...
# {NATIVE_STRINGS}
# // ...snip...
# }}
#
# result:
# A FooSwitches.java file, defining a class named FooSwitches in the package
# my.java.package.
template("java_cpp_strings") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "sources" ])
# The sources aren't compiled so don't check their dependencies.
check_includes = false
script = "//build/android/gyp/java_cpp_strings.py"
_srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
_rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir)
_rebased_sources = rebase_path(invoker.sources, root_build_dir)
_rebased_template = rebase_path(invoker.template, root_build_dir)
args = [
"--srcjar=$_rebased_srcjar_path",
"--template=$_rebased_template",
]
args += _rebased_sources
sources += [ invoker.template ]
outputs = [ _srcjar_path ]
}
}
# Declare a target for generating Java classes with string constants matching
# those found in C++ base::Feature declarations, using a python script.
#
# This target will create a single .srcjar. Adding this target to an
# android_library target's srcjar_deps will make the generated java files be
# included in that library's final outputs.
#
# Variables
# sources: list of files to be processed by the script. For each
# base::Feature in the source files, the script will add a
# corresponding Java string for that feature's name to the
# specified template file.
# Example
# java_cpp_features("foo_features") {
# sources = [
# "src/foo_features.cc",
# ]
# template = "src/templates/FooFeatures.java.tmpl
# }
#
# foo_features.cc:
#
# // A feature.
# BASE_FEATURE(kSomeFeature, "SomeFeature",
# base::FEATURE_DISABLED_BY_DEFAULT);
#
# FooFeatures.java.tmpl
#
# // Copyright $YEAR The Chromium Authors. All rights reserved.
# // Use of this source code is governed by a BSD-style license that can be
# // found in the LICENSE file.
#
# package my.java.package;
#
# public final class FooFeatures {{
# // ...snip...
# {NATIVE_STRINGS}
# // ...snip...
# // Do not instantiate this class.
# private FooFeatures() {{}}
# }}
#
# result:
# A FooFeatures.java file, defining a class named FooFeatures in the package
# my.java.package.
template("java_cpp_features") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"deps",
"sources",
])
# The sources aren't compiled so don't check their dependencies.
check_includes = false
script = "//build/android/gyp/java_cpp_features.py"
_srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
_rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir)
_rebased_sources = rebase_path(invoker.sources, root_build_dir)
_rebased_template = rebase_path(invoker.template, root_build_dir)
args = [
"--srcjar=$_rebased_srcjar_path",
"--template=$_rebased_template",
]
args += _rebased_sources
sources += [ invoker.template ]
outputs = [ _srcjar_path ]
}
}
# Declare a target for processing a Jinja template.
#
# Variables
# input: The template file to be processed.
# includes: List of files {% include %}'ed by input.
# output: Where to save the result.
# variables: (Optional) A list of variables to make available to the template
# processing environment, e.g. ["name=foo", "color=red"].
#
# Example
# jinja_template("chrome_public_manifest") {
# input = "java/AndroidManifest.xml"
# output = "$target_gen_dir/AndroidManifest.xml"
# }
template("jinja_template") {
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
inputs = [ invoker.input ]
if (defined(invoker.includes)) {
inputs += invoker.includes
}
script = "//build/android/gyp/jinja_template.py"
outputs = [ invoker.output ]
args = [
"--loader-base-dir",
rebase_path("//", root_build_dir),
"--inputs",
rebase_path(invoker.input, root_build_dir),
"--output",
rebase_path(invoker.output, root_build_dir),
"--check-includes",
]
if (defined(invoker.includes)) {
_rebased_includes = rebase_path(invoker.includes, root_build_dir)
args += [ "--includes=$_rebased_includes" ]
}
if (defined(invoker.variables)) {
args += [ "--variables=${invoker.variables}" ]
}
}
}
# Writes native libraries to a NativeLibaries.java file.
#
# This target will create a single .srcjar. Adding this target to an
# android_library target's srcjar_deps will make the generated java files be
# included in that library's final outputs.
#
# Variables:
# native_libraries_list_file: (Optional) Path to file listing all native
# libraries to write.
# version_number: (Optional) String of expected version of 'main' native
# library.
# enable_chromium_linker: (Optional) Whether to use the Chromium linker.
# use_final_fields: True to use final fields. When false, all other
# variables must not be set.
template("write_native_libraries_java") {
_native_libraries_file = "$target_gen_dir/$target_name.srcjar"
if (current_cpu == "arm" || current_cpu == "arm64") {
_cpu_family = "CPU_FAMILY_ARM"
} else if (current_cpu == "x86" || current_cpu == "x64") {
_cpu_family = "CPU_FAMILY_X86"
} else if (current_cpu == "mipsel" || current_cpu == "mips64el") {
_cpu_family = "CPU_FAMILY_MIPS"
} else {
assert(false, "Unsupported CPU family")
}
action_with_pydeps(target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
script = "//build/android/gyp/write_native_libraries_java.py"
outputs = [ _native_libraries_file ]
args = [
"--output",
rebase_path(_native_libraries_file, root_build_dir),
"--cpu-family",
_cpu_family,
]
if (invoker.use_final_fields) {
# Write native_libraries_list_file via depfile rather than specifyin it
# as a dep in order allow R8 to run in parallel with native compilation.
args += [ "--final" ]
if (defined(invoker.native_libraries_list_file)) {
depfile = "$target_gen_dir/$target_name.d"
args += [
"--native-libraries-list",
rebase_path(invoker.native_libraries_list_file, root_build_dir),
"--depfile",
rebase_path(depfile, root_build_dir),
]
}
if (defined(invoker.main_component_library)) {
args += [
"--main-component-library",
invoker.main_component_library,
]
}
if (defined(invoker.enable_chromium_linker) &&
invoker.enable_chromium_linker) {
args += [ "--enable-chromium-linker" ]
}
}
}
}
# Declare a target for a set of Android resources generated at build
# time and stored in a single zip archive. The content of the archive
# should match the layout of a regular Android res/ folder (but the
# archive should not include a top-level res/ directory).
#
# Note that there is no associated .srcjar, R.txt or package name
# associated with this target.
#
# Variables:
# generated_resources_zip: Generated zip archive path.
# generating_target: Name of the target generating
# generated_resources_zip. This rule will check that it is part
# of its outputs.
# deps: Specifies the dependencies of this target. Any Android resources
# listed here will be also be included *after* this one when compiling
# all resources for a final apk or junit binary. This is useful to
# ensure that the resources of the current target override those of the
# dependency as well (and would not work if you have these deps to the
# generating target's dependencies).
#
# Example
# _zip_archive = "$target_gen_dir/${target_name}.resources_zip"
#
# action("my_resources__create_zip") {
# _depfile = "$target_gen_dir/${target_name}.d"
# script = "//build/path/to/create_my_resources_zip.py"
# args = [
# "--depfile", rebase_path(_depfile, root_build_dir),
# "--output-zip", rebase_path(_zip_archive, root_build_dir),
# ]
# inputs = []
# outputs = _zip_archive
# depfile = _depfile
# }
#
# android_generated_resources("my_resources") {
# generated_resources_zip = _zip_archive
# generating_target = ":my_resources__create_zip"
# }
#
template("android_generated_resources") {
forward_variables_from(invoker, [ "testonly" ])
_build_config = "$target_gen_dir/${target_name}.build_config.json"
_rtxt_out_path = "$target_gen_dir/${target_name}.R.txt"
write_build_config("$target_name$build_config_target_suffix") {
forward_variables_from(invoker, [ "resource_overlay" ])
build_config = _build_config
resources_zip = invoker.generated_resources_zip
type = "android_resources"
if (defined(invoker.deps)) {
possible_config_deps = invoker.deps
}
r_text = _rtxt_out_path
}
action_with_pydeps(target_name) {
forward_variables_from(invoker, [ "visibility" ])
public_deps = [
":$target_name$build_config_target_suffix",
invoker.generating_target,
]
inputs = [ invoker.generated_resources_zip ]
outputs = [ _rtxt_out_path ]
script = "//build/android/gyp/create_r_txt.py"
args = [
"--resources-zip-path",
rebase_path(invoker.generated_resources_zip, root_build_dir),
"--rtxt-path",
rebase_path(_rtxt_out_path, root_build_dir),
]
}
}
# Declare a target for processing Android resources as Jinja templates.
#
# This takes an Android resource directory where each resource is a Jinja
# template, processes each template, then packages the results in a zip file
# which can be consumed by an android resources, library, or apk target.
#
# If this target is included in the deps of an android resources/library/apk,
# the resources will be included with that target.
#
# Variables
# resources: The list of resources files to process.
# res_dir: The resource directory containing the resources.
# variables: (Optional) A list of variables to make available to the template
# processing environment, e.g. ["name=foo", "color=red"].
#
# Example
# jinja_template_resources("chrome_public_template_resources") {
# res_dir = "res_template"
# resources = ["res_template/xml/syncable.xml"]
# variables = ["color=red"]
# }
template("jinja_template_resources") {
_resources_zip = "$target_out_dir/${target_name}.resources.zip"
_generating_target_name = "${target_name}__template"
action_with_pydeps(_generating_target_name) {
forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "deps" ])
inputs = invoker.resources
script = "//build/android/gyp/jinja_template.py"
outputs = [ _resources_zip ]
_rebased_resources = rebase_path(invoker.resources, root_build_dir)
args = [
"--inputs=${_rebased_resources}",
"--inputs-base-dir",
rebase_path(invoker.res_dir, root_build_dir),
"--outputs-zip",
rebase_path(_resources_zip, root_build_dir),
"--check-includes",
]
if (defined(invoker.variables)) {
variables = invoker.variables
args += [ "--variables=${variables}" ]
}
}
android_generated_resources(target_name) {
forward_variables_from(invoker,
TESTONLY_AND_VISIBILITY + [
"deps",
"resource_overlay",
])
generating_target = ":$_generating_target_name"
generated_resources_zip = _resources_zip
}
}
# Declare a prebuilt android native library.
#
# This takes a base directory and library name and then looks for the library
# in <base dir>/$android_app_abi/<library name>.
#
# If you depend on this target, the library is stripped and output to the
# same locations non-prebuilt libraries are output.
#
# Variables
# base_dir: Directory where all ABIs of the library live.
# library_name: Name of the library .so file.
#
# Example
# android_native_prebuilt("elements_native") {
# base_dir = "//third_party/elements"
# lib_name = "elements.so"
# }
template("android_native_prebuilt") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
[
"deps",
"testonly",
])
script = "//build/android/gyp/process_native_prebuilt.py"
_lib_path = "${invoker.base_dir}/$android_app_abi/${invoker.lib_name}"