-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathandroid_rules.bzl
1532 lines (1417 loc) · 73.7 KB
/
android_rules.bzl
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 (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
# but should be manually edited going forward. There may be some errors in
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)
load("@prelude//:attrs_validators.bzl", "validation_common")
load("@prelude//decls:test_common.bzl", "test_common")
load("@prelude//utils:clear_platform.bzl", "clear_platform_transition")
load(":android_common.bzl", "android_common")
load(":common.bzl", "AbiGenerationMode", "AnnotationProcessingTool", "ForkMode", "LogLevel", "OnDuplicateEntry", "SourceAbiVerificationMode", "TestType", "UnusedDependenciesAction", "buck", "prelude_rule")
load(":core_rules.bzl", "TargetCpuType")
load(":genrule_common.bzl", "genrule_common")
load(":jvm_common.bzl", "jvm_common")
load(":re_test_common.bzl", "re_test_common")
CompressionAlgorithm = ["xz", "zstd"]
DexStore = ["raw", "jar", "xz", "xzs"]
DuplicateResourceBehaviour = ["allow_by_default", "ban_by_default"]
ExopackageMode = ["secondary_dex", "native_library", "resources", "modules", "arch64"]
JvmLanguage = ["java", "kotlin", "scala"]
PackageType = ["debug", "instrumented", "release", "test"]
RType = ["anim", "animator", "array", "attr", "bool", "color", "dimen", "drawable", "fraction", "font", "id", "integer", "interpolator", "layout", "menu", "navigation", "mipmap", "plurals", "raw", "string", "style", "styleable", "transition", "xml"]
ResourceCompressionMode = ["disabled", "enabled", "enabled_strings_only", "enabled_with_strings_as_assets"]
SdkProguardType = ["default", "optimized", "none"]
android_aar = prelude_rule(
name = "android_aar",
docs = """
An `android_aar()` rule is used to generate an Android AAR.
See the [official Android documentation](https://developer.android.com/studio/projects/android-library#aar-contents) for details about the `.aar` format.
""",
examples = """
```
android_resource(
name = 'res',
res = 'res',
assets = 'assets',
package = 'com.example',
)
android_library(
name = 'lib',
srcs = glob(['**/*.java']),
)
android_aar(
name = 'app',
manifest_skeleton = 'AndroidManifestSkeleton.xml',
deps = [
':res',
':lib',
],
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
{
"manifest_skeleton": attrs.source(doc = """
The skeleton manifest file used to generate the final `AndroidManifest.xml` . May either be a file or an `android_manifest()` target.
"""),
"build_config_values": attrs.list(attrs.string(), default = [], doc = """
See the documentation on the values argument for `android_build_config()`.
"""),
"include_build_config_class": attrs.bool(default = False, doc = """
Whether to include the `BuildConfig` class files in the final .aar file. Needs
to be set to `True` if any build\\_config\\_values are specified.
This is normally only needed if the build tool that is consuming the .aar file does not generate
`BuildConfig` classes.
Note: the AAR format does not specify a way to pass defaults that should be injected into
the final `BuildConfig` class, therefore that information might need to be replicated
manually in the build that's consuming the .aar file.
"""),
"deps": attrs.list(attrs.dep(), default = [], doc = """
List of build targets whose corresponding compiled Java code,
Android resources, and native libraries will be included in the AAR along with their transitive
dependencies. For compile time deps which should not be included in the final AAR,
use `provided_deps` instead.
* `android_library()` Will be included in the final `classes.jar`* `android_resource()` Will be included in the final `R.txt`,
`res/` and `assets/`* `android_build_config()` Will be included in the final `classes.jar`
if `include_build_config_class` is True
* `groovy_library()` Will be included in the final `classes.jar`* `java_library()` Will be included in the final `classes.jar`* `prebuilt_jar()` Will be included in the final `classes.jar`* `ndk_library()` Will be included in the final `jni/` or
`assets/` if `is_asset` is True
* `prebuilt_native_library()` Will be included in the final `jni/` or
`assets/` if `is_asset` is True
"""),
"remove_classes": attrs.list(attrs.regex(), default = [], doc = """
List of classes to remove from the output aar. It removes classes from the target's own sources,
and its dependencies.
"""),
"abi_generation_mode": attrs.option(attrs.enum(AbiGenerationMode), default = None),
"annotation_processing_tool": attrs.option(attrs.enum(AnnotationProcessingTool), default = None),
"annotation_processor_deps": attrs.list(attrs.dep(), default = []),
"annotation_processor_params": attrs.list(attrs.string(), default = []),
"annotation_processors": attrs.list(attrs.string(), default = []),
"build_config_values_file": attrs.option(attrs.source(), default = None),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"enable_relinker": attrs.bool(default = False),
"excluded_java_deps": attrs.list(attrs.dep(), default = []),
"extra_arguments": attrs.list(attrs.string(), default = []),
"extra_kotlinc_arguments": attrs.list(attrs.string(), default = []),
"friend_paths": attrs.list(attrs.dep(), default = []),
"java_version": attrs.option(attrs.string(), default = None),
"labels": attrs.list(attrs.string(), default = []),
"language": attrs.option(attrs.enum(JvmLanguage), default = None),
"licenses": attrs.list(attrs.source(), default = []),
"manifest": attrs.option(attrs.source(), default = None),
"manifest_entries": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
"manifest_file": attrs.option(attrs.source(), default = None),
"maven_coords": attrs.option(attrs.string(), default = None),
"native_library_bolt_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string())), default = None),
"native_library_merge_code_generator": attrs.option(attrs.exec_dep(), default = None),
"native_library_merge_glue": attrs.option(attrs.dep(), default = None),
"native_library_merge_map": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.regex()), sorted = False), default = None),
"native_library_merge_sequence": attrs.option(attrs.list(attrs.any()), default = None),
"native_library_merge_sequence_blocklist": attrs.option(attrs.list(attrs.regex()), default = None),
"native_library_merge_non_asset_libs": attrs.bool(default = False),
"never_mark_as_unused_dependency": attrs.option(attrs.bool(), default = None),
"on_unused_dependencies": attrs.option(attrs.enum(UnusedDependenciesAction), default = None),
"proguard_config": attrs.option(attrs.source(), default = None),
"relinker_extra_deps": attrs.list(attrs.dep(), default = [], doc = "Deps statically linked to every native lib by the relinker."),
"relinker_whitelist": attrs.list(attrs.regex(), default = []),
"required_for_source_only_abi": attrs.bool(default = False),
"resource_union_package": attrs.option(attrs.string(), default = None),
"resources": attrs.list(attrs.source(), default = []),
"resources_root": attrs.option(attrs.source(), default = None),
"runtime_deps": attrs.list(attrs.dep(), default = []),
"source": attrs.option(attrs.string(), default = None),
"source_abi_verification_mode": attrs.option(attrs.enum(SourceAbiVerificationMode), default = None),
"source_only_abi_deps": attrs.list(attrs.dep(), default = []),
"srcs": attrs.list(attrs.source(), default = []),
"target": attrs.option(attrs.string(), default = None),
"use_jvm_abi_gen": attrs.option(attrs.bool(), default = None),
}
) | jvm_common.plugins() | jvm_common.javac(),
)
android_app_modularity = prelude_rule(
name = "android_app_modularity",
docs = "",
examples = None,
further = None,
attrs = (
# @unsorted-dict-items
{
"application_module_blocklist": attrs.option(attrs.list(attrs.dep()), default = None),
"application_module_configs": attrs.dict(key = attrs.string(), value = attrs.list(attrs.dep()), sorted = False, default = {}),
"application_module_dependencies": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), sorted = False), default = None),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"deps": attrs.list(attrs.dep(), default = []),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
"no_dx": attrs.list(attrs.dep(), default = []),
"should_include_classes": attrs.bool(default = True),
"should_include_libraries": attrs.bool(default = False),
}
),
)
android_binary = prelude_rule(
name = "android_binary",
docs = "",
examples = None,
further = None,
attrs = (
# @unsorted-dict-items
{
"aapt2_keep_raw_values": attrs.bool(default = False),
"aapt2_locale_filtering": attrs.bool(default = False),
"aapt2_preferred_density": attrs.option(attrs.string(), default = None),
"additional_aapt_params": attrs.list(attrs.string(), default = []),
"allow_r_dot_java_in_secondary_dex": attrs.bool(default = False),
"allowed_duplicate_resource_types": attrs.list(attrs.enum(RType), default = []),
"android_sdk_proguard_config": attrs.option(attrs.enum(SdkProguardType), default = None),
"application_module_blocklist": attrs.option(attrs.list(attrs.dep()), default = None),
"application_module_configs": attrs.dict(key = attrs.string(), value = attrs.list(attrs.dep()), sorted = False, default = {}),
"application_module_dependencies": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), sorted = False), default = None),
"asset_compression_algorithm": attrs.option(attrs.enum(CompressionAlgorithm), default = None),
"banned_duplicate_resource_types": attrs.list(attrs.enum(RType), default = []),
"build_config_values": attrs.list(attrs.string(), default = []),
"build_config_values_file": attrs.option(attrs.source(), default = None),
"build_string_source_map": attrs.bool(default = False),
"compress_asset_libraries": attrs.bool(default = False),
"contacts": attrs.list(attrs.string(), default = []),
"cpu_filters": attrs.list(attrs.enum(TargetCpuType), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"deps": attrs.list(attrs.dep(), default = []),
"dex_compression": attrs.option(attrs.enum(DexStore), default = None),
"dex_group_lib_limit": attrs.int(default = 0),
"disable_pre_dex": attrs.bool(default = False),
"duplicate_resource_behavior": attrs.enum(DuplicateResourceBehaviour, default = "allow_by_default"),
"duplicate_resource_whitelist": attrs.option(attrs.source(), default = None),
"enable_bootstrap_dexes": attrs.bool(default = False),
"enable_relinker": attrs.bool(default = False),
"exopackage_modes": attrs.list(attrs.enum(ExopackageMode), default = []),
"extra_no_compress_asset_extensions": attrs.list(attrs.string(), default = []),
"extra_filtered_resources": attrs.list(attrs.string(), default = []),
"field_ref_count_buffer_space": attrs.int(default = 0),
"ignore_aapt_proguard_config": attrs.bool(default = False),
"includes_vector_drawables": attrs.bool(default = False),
"is_cacheable": attrs.bool(default = False),
"is_voltron_language_pack_enabled": attrs.bool(default = False),
"keystore": attrs.dep(),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
"linear_alloc_hard_limit": attrs.int(default = 4194304),
"locales": attrs.list(attrs.string(), default = []),
"manifest": attrs.option(attrs.source(), default = None),
"manifest_entries": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
"manifest_skeleton": attrs.option(attrs.source(), default = None),
"method_ref_count_buffer_space": attrs.int(default = 0),
"minimize_primary_dex_size": attrs.bool(default = False),
"module_manifest_skeleton": attrs.option(attrs.source(), default = None),
"native_library_bolt_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string())), default = None),
"native_library_merge_code_generator": attrs.option(attrs.dep(), default = None),
"native_library_merge_glue": attrs.option(attrs.dep(), default = None),
"native_library_merge_map": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.regex()), sorted = False), default = None),
"native_library_merge_sequence": attrs.option(attrs.list(attrs.any()), default = None),
"native_library_merge_sequence_blocklist": attrs.option(attrs.list(attrs.regex()), default = None),
"native_library_merge_non_asset_libs": attrs.bool(default = False),
"no_auto_add_overlay_resources": attrs.bool(default = False),
"no_auto_version_resources": attrs.bool(default = False),
"no_dx": attrs.list(attrs.dep(), default = []),
"no_version_transitions_resources": attrs.bool(default = False),
"optimization_passes": attrs.int(default = 1),
"package_asset_libraries": attrs.bool(default = False),
"package_type": attrs.enum(PackageType, default = "debug"),
"packaged_locales": attrs.list(attrs.string(), default = []),
"packaging_options": attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), default = {}),
"post_filter_resources_cmd": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_bash": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_cmd": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_deps": attrs.list(attrs.dep(), default = []),
"primary_dex_patterns": attrs.list(attrs.string(), default = []),
"proguard_config": attrs.option(attrs.source(), default = None),
"proguard_jvm_args": attrs.list(attrs.string(), default = []),
"relinker_extra_deps": attrs.list(attrs.dep(), default = [], doc = "Deps statically linked to every native lib by the relinker."),
"relinker_whitelist": attrs.list(attrs.regex(), default = []),
"resource_compression": attrs.enum(ResourceCompressionMode, default = "disabled"),
"resource_filter": attrs.list(attrs.string(), default = []),
"resource_stable_ids": attrs.option(attrs.source(), default = None),
"resource_union_package": attrs.option(attrs.string(), default = None),
"secondary_dex_weight_limit": attrs.option(attrs.int(), default = None),
"skip_crunch_pngs": attrs.option(attrs.bool(), default = None),
"skip_proguard": attrs.bool(default = False),
"strip_libraries": attrs.bool(default = True),
"trim_resource_ids": attrs.bool(default = False),
"use_split_dex": attrs.bool(default = False),
"xz_compression_level": attrs.int(default = 4),
}
),
)
android_build_config = prelude_rule(
name = "android_build_config",
docs = """
An `android_build_config()` rule is used to generate
a `BuildConfig` class with global configuration variables
that other `android_library()` rules can compile against.
Currently, the only variable exposed by `BuildConfig` is
a global `boolean` named `DEBUG`, much like
the `BuildConfig.java` generated by the official Android
build tools based on Gradle.
The fields in the generated `BuildConfig` class will
be non-constant-expressions (see [JLS 15.28](http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28)).
However, if `BuildConfig` is packaged into an APK, it will
be replaced with a new version where:
* The fields will be set to literal values (i.e., constant expressions).
* The `boolean BuildConfig.DEBUG` field will correspond to
that of the `package_type` argument to the `android_binary()` rule
that is packaging it.
This transformation is done before ProGuard is applied (if applicable), so
that it can propagate constants from `BuildConfig` and eliminate
dead code.
""",
examples = """
Here is an example of an `android_build_config()` rule that
is transitively included by both *debug* and *release* versions
of an `android_binary()` rule. The value
of `com.example.pkg.BuildConfig.DEBUG` will be different in each APK
even though they both transitively depend on the same `:build_config` rule.
```
android_build_config(
name = 'build_config',
package = 'com.example.pkg',
values = [
'String COMMIT_ID = "0000000000000000000000000000000000000000"',
],
)
# The .java files in this library may contain references to the boolean
# com.example.pkg.BuildConfig.DEBUG because :build_config is in the deps.
# It could also reference BuildConfig.COMMIT_ID.
android_library(
name = 'mylib',
srcs = glob(['src/**/*.java']),
deps = [
':build_config',
],
)
android_binary(
name = 'debug',
package_type = 'DEBUG',
keystore = '//keystores:debug',
manifest = 'AndroidManifest.xml',
target = 'Google Inc.:Google APIs:19',
deps = [
':mylib',
],
)
# The contents of the file generated by this rule might be:
#
# String COMMIT_ID = "7bf804bdf71fdbfc99cce3b155b3643f022c6fa4"
#
# Note that the output of :build_config_release_values will be cached by Buck.
# Assuming that generate_release_build_config.py depends on state that is not
# expressed by its deps (which violates a fundamental invariant in Buck!), a
# workaround is to ensure that the inputs to :build_config_release_values are
# changed in some way before :release is built to ensure that the output from
# :build_config_release_values is not pulled from cache. For example:
#
# $ buck build :release
# $ uuidgen > dummy_state_file.txt
# $ buck build :release
#
# This makes sure that generate_release_build_config.py is re-run before
# :release is rebuilt. This is much cheaper than deleting your build cache
# before rebuilding.
genrule(
name = 'build_config_release_values',
srcs = [ 'generate_release_build_config.py', 'dummy_state_file.txt' ],
bash = 'generate_release_build_config.py $OUT',
out = 'build_config_release_values.txt',
)
android_binary(
name = 'release',
package_type = 'RELEASE',
keystore = '//keystores:release',
manifest = 'AndroidManifest.xml',
target = 'Google Inc.:Google APIs:19',
build_config_values_file = ':build_config_release_values',
deps = [
':mylib',
],
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
{
"package": attrs.string(default = "", doc = """
Name of the Java package to use in the generated `BuildConfig.java` file.
Most developers set this to the application id declared in the manifest
via `<manifest package="APP_ID">`.
Example: `com.facebook.orca`.
"""),
"values": attrs.list(attrs.string(), default = [], doc = """
List of strings that defines additional fields (and values) that should be declared in the
generated `BuildConfig.java` file. Like `DEBUG`, the values will be
non-constant-expressions that evaluate to the value specified in the file at compilation
time.
To override the values in an APK, specify build\\_config\\_values or build\\_config\\_values\\_file in `android_binary()`.
"""),
"values_file": attrs.option(attrs.source(), default = None, doc = """
Optional path to a file that defines additional fields (and values) that should be declared in the
generated `BuildConfig.java` file. Like `DEBUG`, the values will be
non-constant-expressions that evaluate to the value specified in the file at compilation
time.
To override the values in an APK, specify build\\_config\\_values or build\\_config\\_values\\_file in `android_binary()`.
Note that values\\_file can be a generated file, as can build\\_config\\_values\\_file as
demonstrated in the example below.
"""),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
}
),
)
android_bundle = prelude_rule(
name = "android_bundle",
docs = "",
examples = None,
further = None,
attrs = (
# @unsorted-dict-items
{
"aapt2_keep_raw_values": attrs.bool(default = False),
"aapt2_locale_filtering": attrs.bool(default = False),
"aapt2_preferred_density": attrs.option(attrs.string(), default = None),
"additional_aapt_params": attrs.list(attrs.string(), default = []),
"allow_r_dot_java_in_secondary_dex": attrs.bool(default = False),
"allowed_duplicate_resource_types": attrs.list(attrs.enum(RType), default = []),
"android_sdk_proguard_config": attrs.option(attrs.enum(SdkProguardType), default = None),
"application_module_blocklist": attrs.option(attrs.list(attrs.dep()), default = None),
"application_module_configs": attrs.dict(key = attrs.string(), value = attrs.list(attrs.dep()), sorted = False, default = {}),
"application_module_dependencies": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), sorted = False), default = None),
"asset_compression_algorithm": attrs.option(attrs.enum(CompressionAlgorithm), default = None),
"banned_duplicate_resource_types": attrs.list(attrs.enum(RType), default = []),
"build_config_values": attrs.list(attrs.string(), default = []),
"build_config_values_file": attrs.option(attrs.source(), default = None),
"build_string_source_map": attrs.bool(default = False),
"bundle_config_file": attrs.option(attrs.source(), default = None),
"compress_asset_libraries": attrs.bool(default = False),
"contacts": attrs.list(attrs.string(), default = []),
"cpu_filters": attrs.list(attrs.enum(TargetCpuType), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"deps": attrs.list(attrs.dep(), default = []),
"dex_compression": attrs.option(attrs.enum(DexStore), default = None),
"dex_group_lib_limit": attrs.int(default = 0),
"disable_pre_dex": attrs.bool(default = False),
"duplicate_resource_behavior": attrs.enum(DuplicateResourceBehaviour, default = "allow_by_default"),
"duplicate_resource_whitelist": attrs.option(attrs.source(), default = None),
"enable_bootstrap_dexes": attrs.bool(default = False),
"enable_relinker": attrs.bool(default = False),
"exopackage_modes": attrs.list(attrs.enum(ExopackageMode), default = []),
"extra_no_compress_asset_extensions": attrs.list(attrs.string(), default = []),
"extra_filtered_resources": attrs.list(attrs.string(), default = []),
"field_ref_count_buffer_space": attrs.int(default = 0),
"ignore_aapt_proguard_config": attrs.bool(default = False),
"includes_vector_drawables": attrs.bool(default = False),
"is_cacheable": attrs.bool(default = False),
"is_voltron_language_pack_enabled": attrs.bool(default = False),
"keystore": attrs.dep(),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
"linear_alloc_hard_limit": attrs.int(default = 4194304),
"locales": attrs.list(attrs.string(), default = []),
"manifest": attrs.option(attrs.source(), default = None),
"manifest_entries": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
"manifest_skeleton": attrs.option(attrs.source(), default = None),
"method_ref_count_buffer_space": attrs.int(default = 0),
"minimize_primary_dex_size": attrs.bool(default = False),
"module_manifest_skeleton": attrs.option(attrs.source(), default = None),
"native_library_bolt_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string())), default = None),
"native_library_merge_code_generator": attrs.option(attrs.dep(), default = None),
"native_library_merge_glue": attrs.option(attrs.dep(), default = None),
"native_library_merge_map": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.regex()), sorted = False), default = None),
"native_library_merge_sequence": attrs.option(attrs.list(attrs.any()), default = None),
"native_library_merge_sequence_blocklist": attrs.option(attrs.list(attrs.regex()), default = None),
"native_library_merge_non_asset_libs": attrs.bool(default = False),
"no_auto_add_overlay_resources": attrs.bool(default = False),
"no_auto_version_resources": attrs.bool(default = False),
"no_dx": attrs.list(attrs.dep(), default = []),
"no_version_transitions_resources": attrs.bool(default = False),
"optimization_passes": attrs.int(default = 1),
"package_asset_libraries": attrs.bool(default = False),
"package_type": attrs.enum(PackageType, default = "debug"),
"packaged_locales": attrs.list(attrs.string(), default = []),
"packaging_options": attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), default = {}),
"post_filter_resources_cmd": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_bash": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_cmd": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_deps": attrs.list(attrs.dep(), default = []),
"primary_dex_patterns": attrs.list(attrs.string(), default = []),
"proguard_config": attrs.option(attrs.source(), default = None),
"proguard_jvm_args": attrs.list(attrs.string(), default = []),
"relinker_extra_deps": attrs.list(attrs.dep(), default = [], doc = "Deps statically linked to every native lib by the relinker."),
"relinker_whitelist": attrs.list(attrs.regex(), default = []),
"resource_compression": attrs.enum(ResourceCompressionMode, default = "disabled"),
"resource_filter": attrs.list(attrs.string(), default = []),
"resource_stable_ids": attrs.option(attrs.source(), default = None),
"resource_union_package": attrs.option(attrs.string(), default = None),
"secondary_dex_weight_limit": attrs.option(attrs.int(), default = None),
"skip_crunch_pngs": attrs.option(attrs.bool(), default = None),
"skip_proguard": attrs.bool(default = False),
"trim_resource_ids": attrs.bool(default = False),
"use_split_dex": attrs.bool(default = False),
"xz_compression_level": attrs.int(default = 4),
}
),
)
android_instrumentation_apk = prelude_rule(
name = "android_instrumentation_apk",
docs = """
An `android_instrumentation_apk()` rule is used to generate
an Android Instrumentation APK.
Android's [Testing Fundamentals](http://developer.android.com/tools/testing/testing_android.html) documentation includes a diagram that shows
the relationship between an "application package" and a "test package"
when running a test. This rule corresponds to a test package. Note
that a test package has an interesting quirk where it is *compiled
against* an application package, but *must not include* the
resources or Java classes of the application package. Therefore, this
class takes responsibility for making sure the appropriate bits are
excluded. Failing to do so will generate mysterious runtime errors
when running the test.
""",
examples = """
Here is an example of an `android_instrumentation_apk()` rule that tests an `android_binary()`, and depends on a test
package.
```
android_library(
name = 'test',
srcs = glob(['test/**/*.java']),
)
android_binary(
name = 'messenger',
manifest = 'AndroidManifest.xml',
keystore = '//keystores:prod',
package_type = 'release',
proguard_config = 'proguard.cfg',
deps = [
...
],
)
# Building this rule will produce a file named messenger_test.apk
android_instrumentation_apk(
name = 'messenger_test',
manifest = 'AndroidInstrumentationManifest.xml',
apk = ':messenger',
deps = [
':test',
],
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
android_common.manifest_apk_arg() |
{
"apk": attrs.dep(doc = """
APK build target, which should be used for the instrumentation APK.
Can be either an `android_binary()` or an `apk_genrule()`.
"""),
} |
android_common.deps_apk_arg() |
{
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"disable_pre_dex": attrs.bool(default = False),
"enable_bootstrap_dexes": attrs.bool(default = False),
"includes_vector_drawables": attrs.bool(default = False),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
"use_split_dex": attrs.option(attrs.bool(), default = None),
"primary_dex_patterns": attrs.list(attrs.string(), default = []),
"preprocess_java_classes_bash": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_cmd": attrs.option(attrs.arg(), default = None),
"preprocess_java_classes_deps": attrs.list(attrs.dep(), default = []),
}
),
)
android_instrumentation_test = prelude_rule(
name = "android_instrumentation_test",
docs = """
An `android_instrumentation_test()` rule is used to define
apks that should be used to run Android instrumentation tests.
""",
examples = """
Here is an example of an `android_instrumentation_test()`
rule that tests an `android_binary()`.
```
android_binary(
name = 'messenger',
manifest = 'AndroidManifest.xml',
keystore = '//keystores:prod',
package_type = 'release',
proguard_config = 'proguard.cfg',
deps = [
...
],
)
android_instrumentation_apk(
name = 'messenger_test',
manifest = 'AndroidInstrumentationManifest.xml',
apk = ':messenger',
deps = [
...
],
)
android_instrumentation_test(
name = 'messenger_instrumentation_test',
apk = ':messenger_test',
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
buck.inject_test_env_arg() |
{
"apk": attrs.dep(doc = """
The APK containing the tests. Can be an `android_binary()`,
an `apk_genrule()` or an `android_instrumentation_apk()`.
"""),
} |
buck.test_label_arg() |
buck.test_rule_timeout_ms() |
{
"clear_package_data": attrs.bool(default = False, doc = """
Runs `pm clear` on the app and test packages before the test run if set to True.
"""),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"disable_animations": attrs.bool(default = False, doc = """
Disables animations on the emulator if set to True.
"""),
"collect_tombstones": attrs.bool(default = False, doc = """
Checks whether the test generated any tombstones, and downloads them from the emulator if true.
"""),
"record_video": attrs.bool(default = False, doc = "Record video of test run and collect it as TRA"),
"log_extractors": attrs.dict(key = attrs.string(), value = attrs.string(), sorted = False, default = {}),
"env": attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}),
"licenses": attrs.list(attrs.source(), default = []),
"_android_emulators": attrs.option(attrs.transition_dep(cfg = clear_platform_transition, providers = [LocalResourceInfo]), default = None, doc = """
If provided, local resource of "android_emulators" type will be required to run this test locally and this target will be used to manage it. If omitted, local resource of "android_emulators" type will be ignored even if requested by the test runner.
"""),
} |
test_common.attributes()
),
)
android_library = prelude_rule(
name = "android_library",
docs = """
An `android_library()` rule is used to define a set of Java files
that can be compiled together against the Android SDK. The main output of an
`android_library()` rule is a single JAR file containing all of the
compiled class files and resources.
""",
examples = """
An `android_library` rule used in concert with an
`android_resource()` rule.
This would be a common arrangement for a standard Android Library project
as defined by
[http://developer.android.com/tools/projects/index.html](http://developer.android.com/tools/projects/index.html)
```
android_resource(
name = 'res',
res = 'res',
package = 'com.example',
)
android_library(
name = 'my_library',
srcs = glob(['src/**/*.java']),
deps = [
':res',
],
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
{
"srcs": attrs.list(attrs.source(), default = [], doc = """
The set of `.java` files to compile for this rule.
"""),
"resources": attrs.list(attrs.source(), default = [], doc = """
Static files to include among the compiled `.class`
files. These files can be loaded via [Class.getResource()](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String)).
**Note:** Buck uses the `src_roots` property in
`.buckconfig`
to help determine where resources should be placed within the generated JAR file.
"""),
} |
android_common.manifest_arg() |
{
"deps": attrs.list(attrs.dep(), default = [], doc = """
Rules (usually other `android_library` rules)
that are used to generate the classpath required to compile this
`android_library`.
"""),
"source": attrs.option(attrs.string(), default = None, doc = """
Specifies the version of Java (as a string) to interpret source
files as.
Overrides the value in "source\\_level" in the "java" section
of `.buckconfig`.
"""),
"target": attrs.option(attrs.string(), default = None, doc = """
Specifies the version of Java (as a string) for which to
generate code.
Overrides the value in "target\\_level" in the "java" section
of `.buckconfig`.
"""),
"extra_arguments": attrs.list(attrs.string(), default = [], doc = """
List of additional arguments to pass into the Java compiler. These
arguments follow the ones specified in `.buckconfig`.
"""),
"extra_kotlinc_arguments": attrs.list(attrs.string(), default = [], doc = """
List of additional arguments to pass into the Kotlin compiler.
"""),
"annotation_processing_tool": attrs.option(attrs.enum(AnnotationProcessingTool), default = None, doc = """
Specifies the tool to use for annotation processing. Possible values: "kapt" or "javac".
"kapt" allows running Java annotation processors against Kotlin sources while backporting
it for Java sources too.
"javac" works only against Java sources, Kotlin sources won't have access to generated
classes at compile time.
"""),
} |
jvm_common.exported_deps() |
jvm_common.provided_deps() |
jvm_common.exported_provided_deps() |
buck.provided_deps_query_arg() |
jvm_common.abi_generation_mode() |
jvm_common.source_only_abi_deps() |
jvm_common.required_for_source_only_abi() |
jvm_common.k2() |
jvm_common.kotlin_compiler_plugins() |
jvm_common.incremental() |
jvm_common.javac() |
jvm_common.enable_used_classes() |
{
"remove_classes": attrs.list(attrs.regex(), default = [], doc = """
List of classes to remove from the output jar. It only removes classes from the target's own
sources, not from any of its dependencies.
"""),
"annotation_processor_deps": attrs.list(attrs.dep(), default = []),
"annotation_processor_params": attrs.list(attrs.string(), default = []),
"annotation_processors": attrs.list(attrs.string(), default = []),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"friend_paths": attrs.list(attrs.dep(), default = []),
"java_version": attrs.option(attrs.string(), default = None),
"jar_postprocessor": attrs.option(attrs.exec_dep(), default = None),
"labels": attrs.list(attrs.string(), default = []),
"language": attrs.option(attrs.enum(JvmLanguage), default = None),
"licenses": attrs.list(attrs.source(), default = []),
"manifest_file": attrs.option(attrs.source(), default = None),
"maven_coords": attrs.option(attrs.string(), default = None),
"never_mark_as_unused_dependency": attrs.option(attrs.bool(), default = None),
"on_unused_dependencies": attrs.option(attrs.enum(UnusedDependenciesAction), default = None),
"proguard_config": attrs.option(attrs.source(), default = None),
"resource_union_package": attrs.option(attrs.string(), default = None),
"resources_root": attrs.option(attrs.source(), default = None),
"runtime_deps": attrs.list(attrs.dep(), default = []),
"source_abi_verification_mode": attrs.option(attrs.enum(SourceAbiVerificationMode), default = None),
"use_jvm_abi_gen": attrs.option(attrs.bool(), default = None),
}
) | jvm_common.plugins() | validation_common.attrs_validators_arg() | validation_common.validation_specs_arg(),
)
android_manifest = prelude_rule(
name = "android_manifest",
docs = """
An `android_manifest()` rule is used to generate an
[Android
Manifest](http://developer.android.com/guide/topics/manifest/manifest-intro.html) to be used by `android_binary()` and `android_aar()` rules. This
rule takes a skeleton manifest, and merges it with manifests found in any deps.
""",
examples = """
Here's an example of an `android_manifest()` that has no deps.
```
android_manifest(
name = 'my-manifest',
skeleton = 'AndroidManifestSkeleton.xml',
)
```
This is what `AndroidManifestSkeleton.xml` looks like.
```
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk targetSdkVersion="19" minSdkVersion="17"/>
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher">
<activity
android:name="MyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
```
You could also use a `genrule()` to generate the manifest file and reference the
`build target` in the `skeleton` argument.
""",
further = None,
attrs = (
# @unsorted-dict-items
{
"skeleton": attrs.source(doc = """
Either a `build target` or a path to a file representing the manifest that
will be merged with any manifests associated with this rule's `deps`.
"""),
"deps": attrs.list(attrs.dep(), default = [], doc = """
A collection of dependencies that includes android\\_library rules. The manifest files of the
`android_library()` rules will be filtered out to become dependent source files for
the manifest.
"""),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
}
),
)
android_platform = prelude_rule(
name = "android_platform",
docs = "",
examples = None,
further = None,
attrs = (
# @unsorted-dict-items
{
"base_platform": attrs.configuration_label(),
"native_platforms": attrs.dict(key = attrs.enum(TargetCpuType), value = attrs.configuration_label(), sorted = False, default = {}),
}
),
)
android_prebuilt_aar = prelude_rule(
name = "android_prebuilt_aar",
docs = """
An `android_prebuilt_aar()` rule takes an `.aar` file and
makes it available as an Android dependency. As expected,
an `android_binary()` that transitively depends on
an `android_prebuilt_aar()` will include its contents in the generated APK.
See the [official Android documentation](https://developer.android.com/studio/projects/android-library#aar-contents) for details about the `.aar` format.
""",
examples = """
```
android_prebuilt_aar(
name = 'play-services',
aar = 'play-services-4.0.30.aar',
source_jar = 'play-services-4.0.30-sources.jar',
javadoc_url = 'file:///opt/android-sdk/extras/google/google_play_services/docs/reference',
)
android_library(
name = 'lib',
# This Java code can compile against Play services and reference its resources.
srcs = glob(['*.java']),
deps = [ ':play-services' ],
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
{
"aar": attrs.source(doc = """
Path to the `.aar` file. This may also be a build target to
a rule (such as a `genrule()`) whose output is
an `.aar` file.
"""),
"source_jar": attrs.option(attrs.source(), default = None, doc = """
Path to a JAR file that contains the `.java` files to create
the `.class` in the `aar`. This is frequently
provided for debugging purposes.
"""),
"javadoc_url": attrs.option(attrs.string(), default = None, doc = """
URL to the Javadoc for the `.class` files in the
`aar`.
"""),
"use_system_library_loader": attrs.bool(default = False, doc = """
If this `.aar` file contains native prebuilt `.so` libraries and the
Java code uses these libraries via a call to `System.loadLibrary()`, then many
optimizations—such as exopackage, compression, or asset packaging—may not be compatible with these prebuilt libs.
Setting this parameter to `True` causes all of these optimizations to skip the prebuilt `.so`
files originating from this `.aar` file. The `.so` files will always be packaged directly into
the main `.apk`.
"""),
"contacts": attrs.list(attrs.string(), default = []),
"default_host_platform": attrs.option(attrs.configuration_label(), default = None),
"deps": attrs.list(attrs.dep(), default = []),
"desugar_deps": attrs.list(attrs.dep(), default = []),
"for_primary_apk": attrs.bool(default = False),
"labels": attrs.list(attrs.string(), default = []),
"licenses": attrs.list(attrs.source(), default = []),
"maven_coords": attrs.option(attrs.string(), default = None),
"required_for_source_only_abi": attrs.bool(default = False),
}
),
)
android_resource = prelude_rule(
name = "android_resource",
docs = """
An `android_resource()` rule is used to bundle Android resources
that are traditionally stored in `res` and `assets` directories.
The output of an `android_resource()` is an `R.txt` file
generated via `aapt --output-text-symbols`.
""",
examples = """
Most of the time, an `android_resource` rule defines only `name`, `res`, and `package`. By convention,
such simple rules are often named `res`:
```
android_resource(
name = 'res',
res = subdir_glob([('res', '**')]),
package = 'com.example',
)
```
""",
further = None,
attrs = (
# @unsorted-dict-items
{
"res": attrs.option(attrs.one_of(attrs.source(), attrs.dict(key = attrs.string(), value = attrs.source(), sorted = True)), default = None, doc = """
A dictionary mapping relative resource paths to either
the resource files or the build targets that generate them.
The `subdir_glob` function
can be used to generate dictionaries based on a directory structure of files checked
into the repository. Alternatively, this can be a path to a directory containing
Android resources, although this option is deprecated and might be removed in the future.
"""),
"package": attrs.option(attrs.string(), default = None, doc = """
Java package for the `R.java` file that will be generated for these
resources.
"""),
"assets": attrs.option(attrs.one_of(attrs.source(), attrs.dict(key = attrs.string(), value = attrs.source(), sorted = True)), default = None, doc = """
A dictionary mapping relative asset paths to either
the asset files or the build targets that generate them.
The `subdir_glob` function
can be used to generate dictionaries based on a directory structure of files checked
into the repository. Alternatively, this can be a path to a directory containing
Android assets, although this option is deprecated and might be removed in the future.
"""),
"project_res": attrs.option(attrs.source(), default = None, doc = """
A directory containing resources to be used for project generation.
If not provided, defaults to whatever the build uses.
"""),
"project_assets": attrs.option(attrs.source(), default = None, doc = """
A directory containing assets to be used for project generation.
If not provided, defaults to whatever the build uses.