-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathincremental_input_files.bzl
More file actions
1004 lines (912 loc) · 34.9 KB
/
incremental_input_files.bzl
File metadata and controls
1004 lines (912 loc) · 34.9 KB
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
"""Module containing functions dealing with target input files."""
load(
"@build_bazel_rules_apple//apple:providers.bzl",
"AppleResourceInfo",
)
load(
"//xcodeproj/internal:memory_efficiency.bzl",
"EMPTY_DEPSET",
"EMPTY_LIST",
"memory_efficient_depset",
)
load("//xcodeproj/internal:xcodeprojinfo.bzl", "XcodeProjInfo")
load(":incremental_resources.bzl", resources_module = "incremental_resources")
load(":linker_input_files.bzl", "linker_input_files")
# Utility
_HEADER_EXTENSIONS = {
"def": None,
"h": None,
"hh": None,
"hpp": None,
"hxx": None,
"ilc": None,
"inc": None,
"ipp": None,
"tpp": None,
}
_IGNORE_ATTR = {
"to_json": None,
"to_proto": None,
}
def _collect_transitive_uncategorized(info):
if info.xcode_target:
return EMPTY_DEPSET
return info.inputs._uncategorized
def _inner_merge_input_files(
*,
framework_files,
resource_bundles,
transitive_infos,
xccurrentversions):
return struct(
_product_framework_files = memory_efficient_depset(
transitive = [
info.inputs._product_framework_files
for info in transitive_infos
] + [framework_files],
),
_resource_bundle_labels = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_labels
for info in transitive_infos
],
),
_resource_bundle_uncategorized_file_paths = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_uncategorized_file_paths
for info in transitive_infos
],
),
_resource_bundle_uncategorized_files = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_uncategorized_files
for info in transitive_infos
],
),
_resource_bundle_uncategorized_generated_file_paths = (
memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_uncategorized_generated_file_paths
for info in transitive_infos
],
)
),
resource_bundles = memory_efficient_depset(
resource_bundles,
transitive = [
info.inputs.resource_bundles
for info in transitive_infos
],
),
important_generated = memory_efficient_depset(
transitive = [
info.inputs.important_generated
for info in transitive_infos
],
),
_uncategorized = memory_efficient_depset(
transitive = [
info.inputs._uncategorized
for info in transitive_infos
],
),
unsupported_extra_files = memory_efficient_depset(
transitive = [
info.inputs.unsupported_extra_files
for info in transitive_infos
],
),
xccurrentversions = memory_efficient_depset(
xccurrentversions,
transitive = [
info.inputs.xccurrentversions
for info in transitive_infos
],
),
)
def _should_ignore_input_attr(attr):
return (
# We don't want to include implicit dependencies
attr[0] == "_" or
# These are actually Starklark methods, so ignore them
attr in _IGNORE_ATTR
)
def _process_files_and_deps(
*,
additional_src_files,
additional_src_file_handler,
attrs,
collect_uncategorized,
file_handlers,
rule_attr,
rule_file,
rule_files):
uncategorized = []
xccurrentversions = []
# buildifier: disable=uninitialized
def _handle_file(file, *, handler):
if file == None:
return
if handler:
handler(file)
categorized = True
else:
categorized = False
if file.is_source:
if not categorized:
if (file.basename == ".xccurrentversion" and
file.dirname.endswith(".xcdatamodeld")):
# rules_ios's `precompiled_apple_resource_bundle` rule
# exposes its resources as inputs, so we have to have the
# same check here for the `.xccurrentversion` file as we
# do in `resources.bzl`
xccurrentversions.append(file)
else:
uncategorized.append(file)
transitive_extra_files = []
# buildifier: disable=uninitialized
def _handle_dep(dep):
# This allows the transitive uncategorized files for target of a
# categorized attribute to be included in the project
if XcodeProjInfo not in dep:
return
transitive_extra_files.append(
dep[XcodeProjInfo].inputs._uncategorized,
)
for attr in dir(rule_files):
if _should_ignore_input_attr(attr):
continue
handler = file_handlers.get(attr, None)
if not collect_uncategorized and not handler:
continue
for file in getattr(rule_files, attr):
_handle_file(file, handler = handler)
for attr in dir(rule_file):
if _should_ignore_input_attr(attr):
continue
handler = file_handlers.get(attr, None)
if not collect_uncategorized and not handler:
continue
_handle_file(getattr(rule_file, attr), handler = handler)
for file in additional_src_files:
_handle_file(file, handler = additional_src_file_handler)
for attr in attrs:
if _should_ignore_input_attr(attr):
continue
if attr not in file_handlers:
# Only attributes in `file_handlers` are categorized
continue
dep = getattr(rule_attr, attr)
dep_type = type(dep)
if dep_type == "Target":
_handle_dep(dep)
elif dep_type == "list":
if not dep or type(dep[0]) != "Target":
continue
for list_dep in dep:
_handle_dep(list_dep)
return (
transitive_extra_files,
uncategorized,
xccurrentversions,
)
# API
C_EXTENSIONS = {
"c": None,
"m": None,
}
CXX_EXTENSIONS = {
"C": None,
"c++": None,
"cc": None,
"cl": None,
"cpp": None,
"cu": None,
"cxx": None,
"mm": None,
}
def _collect_incremental_input_files(
*,
ctx,
attrs,
automatic_target_info,
avoid_deps = EMPTY_LIST,
framework_files = EMPTY_DEPSET,
focused_labels = EMPTY_DEPSET,
infoplist = None,
label,
linker_inputs,
platform,
resource_info = None,
rule_attr,
swift_proto_info,
transitive_infos):
"""Collects all of the inputs of a target.
Args:
ctx: The aspect context.
attrs: `dir(ctx.rule.attr)` (as a performance optimization).
automatic_target_info: The `XcodeProjAutomaticTargetProcessingInfo` for
the target.
avoid_deps: A `list` of the targets that already consumed resources, and
their resources shouldn't be bundled with the target.
framework_files: A `depset` of framework files from
`AppleDynamicFrameworkInfo.framework_files`, if the target has the
`AppleDynamicFrameworkInfo` provider.
focused_labels: A `depset` of label strings of focused targets. This
will include the current target (if focused) and any focused
dependencies of the current target. This is only set for top-level
targets.
infoplist: A `File` for a rules_xcodeproj modified Info.plist file, or
None for non-top-level targets.
label: The effective label of the target.
linker_inputs: A value from `linker_file_inputs.collect`.
platform: A value from `platforms.collect`.
resource_info: If the target is a bundle and has the `AppleResourceInfo`
provider, this is the provider.
rule_attr: `ctx.rule.attr`.
swift_proto_info: The `SwiftProtoInfo` provider for the target, or
`None` if it doesn't have one.
transitive_infos: A `list` of `XcodeProjInfo`s for the transitive
dependencies of the target.
Returns:
A `tuple` with two elements:
* A `struct`, which will only be used within the aspect, with the
following fields:
* `c_sources`: A set `dict` (`None` values) of C source file path
strings.
* `cxx_sources`: A set `dict` (`None` values) of C++ source file
path strings.
* `entitlements`: A `File` for the entitlements file of `target`,
or `None` if it doesn't have one.
* `xcode_inputs`: A `struct`, which will be passed to
`xcode_targets.make`, with the following fields:
* `extra_file_paths`: A `depset` of file path strings that
aren't covered under the other attributes, but should be
included in the project navigator.
* `extra_files`: A `depset` of `File` that aren't covered
under the other attributes, but should be included in the
project navigator.
* `non_arc_srcs`: A `list` of `File`s that are inputs to
`target`'s `non_arc_srcs`-like attributes.
* `srcs`: A `list` of `File`s that are inputs to `target`'s
`srcs`-like attributes.
* A `struct`, which will end up in `XcodeProjInfo.inputs`, with the
following fields:
* `important_generated`: A `depset` of important generated `File`s
that are inputs to `target` or its transitive dependencies.
These differ from `generated` in that they will be generated as
part of project generation, to ensure they are created before
Xcode is opened. Entitlements are an example of this, as Xcode
won't even start a build if they are missing.
* `resource_bundles`: A `depset` of values from
`resources.collect().bundles`.
* `unsupported_extra_files`: A `depset` of `File`s that are inputs
of unsupported targets. These should be included in the project
navigator.
* `xccurrentversions`: A `depset` of `.xccurrentversion` `File`s
that are in `resources`.
"""
entitlements = []
c_sources = {}
cxx_sources = {}
non_arc_srcs = []
srcs = []
extra_files = [infoplist] if infoplist else []
# Include BUILD files for the project but not for external repos
build_file_paths = []
if not label.workspace_root:
build_file_paths.append(ctx.build_file_path)
# buildifier: disable=uninitialized
def _handle_srcs_file(file):
extension = file.extension
if extension in C_EXTENSIONS:
c_sources[file.path] = None
elif extension in CXX_EXTENSIONS:
cxx_sources[file.path] = None
if extension in _HEADER_EXTENSIONS:
extra_files.append(file)
else:
srcs.append(file)
# buildifier: disable=uninitialized
def _handle_non_arc_srcs_file(file):
extension = file.extension
if extension in C_EXTENSIONS:
c_sources[file.path] = None
elif extension in CXX_EXTENSIONS:
cxx_sources[file.path] = None
if extension in _HEADER_EXTENSIONS:
extra_files.append(file)
else:
non_arc_srcs.append(file)
# buildifier: disable=uninitialized
def _handle_entitlements_file(file):
# We use `append` instead of setting a single value because
# assigning to `entitlements` creates a new local variable instead
# of assigning to the existing variable
entitlements.append(file)
extra_files.append(file)
# buildifier: disable=uninitialized
def _handle_extrafiles_file(file):
extra_files.append(file)
file_handlers = {}
for attr in automatic_target_info.extra_files:
file_handlers[attr] = _handle_extrafiles_file
for attr in automatic_target_info.srcs:
file_handlers[attr] = _handle_srcs_file
for attr in automatic_target_info.non_arc_srcs:
file_handlers[attr] = _handle_non_arc_srcs_file
if automatic_target_info.entitlements:
file_handlers[automatic_target_info.entitlements] = (
_handle_entitlements_file
)
if swift_proto_info:
additional_src_files = swift_proto_info.pbswift_files.to_list()
else:
additional_src_files = EMPTY_LIST
(
transitive_extra_files,
uncategorized,
xccurrentversions,
) = _process_files_and_deps(
additional_src_files = additional_src_files,
additional_src_file_handler = _handle_srcs_file,
attrs = attrs,
collect_uncategorized = (
automatic_target_info.collect_uncategorized_files
),
file_handlers = file_handlers,
rule_attr = rule_attr,
rule_file = ctx.rule.file,
rule_files = ctx.rule.files,
)
product_framework_files = memory_efficient_depset(
transitive = [
info.inputs._product_framework_files
for info in transitive_infos
] + [framework_files],
)
linker_input_additional_files = linker_input_files.to_input_files(
linker_inputs,
)
if linker_input_additional_files:
framework_files = {f: None for f in product_framework_files.to_list()}
linker_input_additional_files = [
file
for file in linker_input_additional_files
if file not in framework_files
]
extra_files.extend(linker_input_additional_files)
if resource_info:
resources_result = resources_module.collect(
avoid_resource_infos = [
dep[AppleResourceInfo]
for dep in avoid_deps
if AppleResourceInfo in dep
],
label_str = str(label),
focused_labels = focused_labels,
platform = platform,
resource_info = resource_info,
)
extra_files.extend(resources_result.resources)
resource_bundles = resources_result.bundles
xccurrentversions.extend(resources_result.xccurrentversions)
resource_bundle_labels = memory_efficient_depset(
[
bundle.label
for bundle in resources_result.bundles
],
transitive = [
dep[XcodeProjInfo].inputs._resource_bundle_labels
for dep in avoid_deps
],
)
bundle_labels = {
label: None
for label in resource_bundle_labels.to_list()
}
resource_bundle_uncategorized_files = EMPTY_DEPSET
transitive_extra_files = [
d
for label, d in depset(
transitive = [
info.inputs._resource_bundle_uncategorized_files
for info in transitive_infos
],
).to_list()
if label not in bundle_labels
]
resource_bundle_uncategorized_file_paths = EMPTY_DEPSET
resource_bundle_uncategorized_generated_file_paths = EMPTY_DEPSET
extra_file_paths = memory_efficient_depset(
build_file_paths + resources_result.resource_file_paths,
transitive = [
d
for label, d in depset(
transitive = [
info.inputs._resource_bundle_uncategorized_file_paths
for info in transitive_infos
],
).to_list()
if label not in bundle_labels
],
)
extra_generated_file_paths = memory_efficient_depset(
resources_result.generated_resource_file_paths,
transitive = [
d
for label, d in depset(
transitive = [
info.inputs._resource_bundle_uncategorized_generated_file_paths
for info in transitive_infos
],
).to_list()
if label not in bundle_labels
],
)
else:
extra_file_paths = memory_efficient_depset(build_file_paths)
extra_generated_file_paths = EMPTY_DEPSET
resource_bundle_labels = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_labels
for info in transitive_infos
],
)
resource_bundle_uncategorized_files = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_uncategorized_files
for info in transitive_infos
],
)
resource_bundle_uncategorized_file_paths = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_uncategorized_file_paths
for info in transitive_infos
],
)
resource_bundle_uncategorized_generated_file_paths = (
memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_uncategorized_generated_file_paths
for info in transitive_infos
],
)
)
resource_bundles = None
important_generated = [
file
for file in entitlements
if not file.is_source
]
return (
struct(
c_sources = c_sources,
cxx_sources = cxx_sources,
entitlements = entitlements[0] if entitlements else None,
xcode_inputs = struct(
extra_file_paths = extra_file_paths,
extra_files = memory_efficient_depset(
extra_files,
transitive = transitive_extra_files,
),
extra_generated_file_paths = extra_generated_file_paths,
infoplist = infoplist,
non_arc_srcs = memory_efficient_depset(non_arc_srcs),
srcs = memory_efficient_depset(srcs),
),
),
struct(
_product_framework_files = product_framework_files,
_resource_bundle_labels = resource_bundle_labels,
_resource_bundle_uncategorized_files = (
resource_bundle_uncategorized_files
),
_resource_bundle_uncategorized_file_paths = (
resource_bundle_uncategorized_file_paths
),
_resource_bundle_uncategorized_generated_file_paths = (
resource_bundle_uncategorized_generated_file_paths
),
_uncategorized = memory_efficient_depset(
uncategorized,
transitive = [
_collect_transitive_uncategorized(info)
for info in transitive_infos
],
),
resource_bundles = memory_efficient_depset(
resource_bundles,
transitive = [
info.inputs.resource_bundles
for info in transitive_infos
],
),
important_generated = memory_efficient_depset(
important_generated,
transitive = [
info.inputs.important_generated
for info in transitive_infos
],
),
unsupported_extra_files = memory_efficient_depset(
transitive = [
info.inputs.unsupported_extra_files
for info in transitive_infos
],
),
xccurrentversions = memory_efficient_depset(
xccurrentversions,
transitive = [
info.inputs.xccurrentversions
for info in transitive_infos
],
),
),
)
def _collect_mixed_language_input_files(
*,
mergeable_info,
mixed_target_infos):
"""Collects all of the inputs of a target.
Args:
mergeable_info: A value from `mergeable_infos.calculate_mixed_language`.
mixed_target_infos: A `list` of `XcodeProjInfo`s for the underlying
Clang and Swift targets.
Returns:
A `tuple` with two elements:
* A `struct`, which will be passed to `xcode_targets.make`, with the
following fields:
* `extra_file_paths`: A `depset` of file path strings that aren't
covered under the other attributes, but should be included in
the project navigator.
* `extra_files`: A `depset` of `File` that aren't covered under
the other attributes, but should be included in the project
navigator.
* `non_arc_srcs`: A `list` of `File`s that are inputs to
`target`'s `non_arc_srcs`-like attributes.
* `srcs`: A `list` of `File`s that are inputs to `target`'s
`srcs`-like attributes.
* A `struct`, which will end up in `XcodeProjInfo.inputs`, with the
following fields:
* `important_generated`: A `depset` of important generated `File`s
that are inputs to `target` or its transitive dependencies.
These differ from `generated` in that they will be generated as
part of project generation, to ensure they are created before
Xcode is opened. Entitlements are an example of this, as Xcode
won't even start a build if they are missing.
* `resource_bundles`: A `depset` of values from
`resources.collect().bundles`.
* `unsupported_extra_files`: A `depset` of `File`s that are inputs
of unsupported targets. These should be included in the project
navigator.
* `xccurrentversions`: A `depset` of `.xccurrentversion` `File`s
that are in `resources`.
"""
if not mergeable_info:
return (
struct(
extra_file_paths = EMPTY_DEPSET,
extra_files = EMPTY_DEPSET,
extra_generated_file_paths = EMPTY_DEPSET,
infoplist = None,
non_arc_srcs = EMPTY_LIST,
srcs = EMPTY_LIST,
),
struct(
_product_framework_files = EMPTY_DEPSET,
_resource_bundle_labels = EMPTY_DEPSET,
_resource_bundle_uncategorized_files = EMPTY_DEPSET,
_resource_bundle_uncategorized_file_paths = EMPTY_DEPSET,
_resource_bundle_uncategorized_generated_file_paths = EMPTY_DEPSET,
_uncategorized = EMPTY_DEPSET,
resource_bundles = EMPTY_DEPSET,
important_generated = EMPTY_DEPSET,
unsupported_extra_files = EMPTY_DEPSET,
xccurrentversions = EMPTY_DEPSET,
),
)
return (
struct(
extra_file_paths = mergeable_info.extra_file_paths,
extra_files = mergeable_info.extra_files,
extra_generated_file_paths = EMPTY_DEPSET,
infoplist = None,
non_arc_srcs = mergeable_info.non_arc_srcs,
srcs = mergeable_info.srcs,
),
struct(
# Framework files only come from top-level targets, so no need to
# collect them from `mixed_target_infos`
_product_framework_files = EMPTY_DEPSET,
# Resources only come from top-level targets, so no need to collect
# them from `mixed_target_infos`
_resource_bundle_labels = EMPTY_DEPSET,
_resource_bundle_uncategorized_files = EMPTY_DEPSET,
_resource_bundle_uncategorized_file_paths = EMPTY_DEPSET,
_resource_bundle_uncategorized_generated_file_paths = EMPTY_DEPSET,
_uncategorized = memory_efficient_depset(
transitive = [
_collect_transitive_uncategorized(info)
for info in mixed_target_infos
],
),
resource_bundles = EMPTY_DEPSET,
# Only entitlements are currently considered important, but to
# prevent bugs if we add more files in the future, we will still
# merge here
important_generated = memory_efficient_depset(
transitive = [
info.inputs.important_generated
for info in mixed_target_infos
],
),
unsupported_extra_files = memory_efficient_depset(
transitive = [
info.inputs.unsupported_extra_files
for info in mixed_target_infos
],
),
# Same as resource collection, so no need to merge
xccurrentversions = EMPTY_DEPSET,
),
)
def _collect_unsupported_input_files(
*,
ctx,
attrs,
automatic_target_info,
include_extra_files,
is_resource_bundle,
label,
rule_attr,
transitive_infos):
"""Collects all of the inputs of a target.
Args:
ctx: The aspect context.
attrs: `dir(ctx.rule.attr)` (as a performance optimization).
automatic_target_info: The `XcodeProjAutomaticTargetProcessingInfo` for
`target`.
include_extra_files: Whether to include extra files in the inputs.
is_resource_bundle: Whether `target` is a resource bundle.
label: The effective label of the target.
rule_attr: `ctx.rule.attr`.
transitive_infos: A `list` of `XcodeProjInfo`s for the transitive
dependencies of `target`.
Returns:
A value similar to the second `struct` returned by `input_files.collect`.
"""
extra_file_paths = []
extra_files = []
if include_extra_files:
if not label.workspace_root:
# Include BUILD files for the project but not for external repos
extra_file_paths.append(ctx.build_file_path)
# buildifier: disable=uninitialized
def _handle_extrafiles_file(file):
extra_files.append(file)
else:
# buildifier: disable=uninitialized
def _handle_extrafiles_file(_file):
pass
# Turn source files into extra files for non-Xcode targets
file_handlers = {}
for attr in automatic_target_info.srcs:
file_handlers[attr] = _handle_extrafiles_file
for attr in automatic_target_info.non_arc_srcs:
file_handlers[attr] = _handle_extrafiles_file
for attr in automatic_target_info.extra_files:
file_handlers[attr] = _handle_extrafiles_file
(
transitive_extra_files,
uncategorized,
xccurrentversions,
) = _process_files_and_deps(
additional_src_files = EMPTY_LIST,
additional_src_file_handler = None,
attrs = attrs,
collect_uncategorized = (
include_extra_files and
automatic_target_info.collect_uncategorized_files
),
file_handlers = file_handlers,
rule_attr = rule_attr,
rule_file = ctx.rule.file,
rule_files = ctx.rule.files,
)
if is_resource_bundle:
uncategorized_files = []
uncategorized_file_paths = []
uncategorized_generated_file_paths = []
def _process_uncategorized_resource(resource):
# If a file is a child of a folder-type file, the parent
# folder-type file should be collected instead of the child file
folder_type_prefix = resources_module.folder_type_prefix(resource)
if folder_type_prefix:
if resource.is_source:
uncategorized_file_paths.append(folder_type_prefix)
else:
uncategorized_generated_file_paths.append(
struct(
owner = resource.owner,
path = folder_type_prefix,
),
)
return
uncategorized_files.append(resource)
for file in uncategorized:
_process_uncategorized_resource(file)
if uncategorized_files:
resource_bundle_uncategorized_files = [
(
label,
memory_efficient_depset(uncategorized_files),
),
]
else:
resource_bundle_uncategorized_files = None
if uncategorized_file_paths:
resource_bundle_uncategorized_file_paths = [
(
label,
memory_efficient_depset(uncategorized_file_paths),
),
]
else:
resource_bundle_uncategorized_file_paths = None
if uncategorized_generated_file_paths:
resource_bundle_uncategorized_generated_file_paths = [
(
label,
memory_efficient_depset(uncategorized_generated_file_paths),
),
]
else:
resource_bundle_uncategorized_generated_file_paths = None
uncategorized = None
else:
resource_bundle_uncategorized_files = None
resource_bundle_uncategorized_file_paths = None
resource_bundle_uncategorized_generated_file_paths = None
return struct(
_product_framework_files = memory_efficient_depset(
transitive = [
info.inputs._product_framework_files
for info in transitive_infos
],
),
_resource_bundle_labels = memory_efficient_depset(
transitive = [
info.inputs._resource_bundle_labels
for info in transitive_infos
],
),
_resource_bundle_uncategorized_files = memory_efficient_depset(
resource_bundle_uncategorized_files,
transitive = [
info.inputs._resource_bundle_uncategorized_files
for info in transitive_infos
],
),
_resource_bundle_uncategorized_file_paths = memory_efficient_depset(
resource_bundle_uncategorized_file_paths,
transitive = [
info.inputs._resource_bundle_uncategorized_file_paths
for info in transitive_infos
],
),
_resource_bundle_uncategorized_generated_file_paths = memory_efficient_depset(
resource_bundle_uncategorized_generated_file_paths,
transitive = [
info.inputs._resource_bundle_uncategorized_generated_file_paths
for info in transitive_infos
],
),
_uncategorized = memory_efficient_depset(
uncategorized,
transitive = [
_collect_transitive_uncategorized(info)
for info in transitive_infos
],
),
important_generated = memory_efficient_depset(
transitive = [
info.inputs.important_generated
for info in transitive_infos
],
),
resource_bundles = memory_efficient_depset(
transitive = [
info.inputs.resource_bundles
for info in transitive_infos
],
),
unsupported_extra_files = memory_efficient_depset(
extra_files,
transitive = [
info.inputs.unsupported_extra_files
for info in transitive_infos
] + (transitive_extra_files if include_extra_files else []),
),
xccurrentversions = memory_efficient_depset(
xccurrentversions,
transitive = [
info.inputs.xccurrentversions
for info in transitive_infos
],
),
)
def _merge_input_files(*, transitive_infos):
"""Creates merged inputs.
Args:
transitive_infos: A `list` of `XcodeProjInfo`s for the transitive
dependencies of the current target.
Returns:
A value similar to the one returned from `input_files.collect`. The
values potentially include the inputs of the transitive dependencies,
via `transitive_infos` (e.g. `extra_files`).
"""
return _inner_merge_input_files(
framework_files = EMPTY_DEPSET,
resource_bundles = None,
transitive_infos = transitive_infos,
xccurrentversions = None,
)
def _merge_top_level_input_files(
*,
avoid_deps,
focused_labels,
framework_files,
platform,
resource_info,
transitive_infos):
"""Creates merged inputs for an unfocused top-level target.
Args:
avoid_deps: A `list` of the targets that already consumed resources, and
their resources shouldn't be bundled with `target`.
focused_labels: A `depset` of label strings of focused targets. This
will include the current target (if focused) and any focused
dependencies of the current target.
framework_files: A `depset` of framework files from
`AppleDynamicFrameworkInfo.framework_files`, if the target has the
`AppleDynamicFrameworkInfo` provider.
platform: A value from `platforms.collect`.
resource_info: The `AppleResourceInfo` provider for the target if it is
resource bundle consuming.
transitive_infos: A `list` of `XcodeProjInfo`s for the transitive
dependencies of the current target.
Returns:
A value similar to the one returned from `input_files.collect`. The
values potentially include the inputs of the transitive dependencies,
via `transitive_infos` (e.g. `extra_files`).
"""
if resource_info:
resources_result = resources_module.collect(
avoid_resource_infos = [
dep[AppleResourceInfo]
for dep in avoid_deps
if AppleResourceInfo in dep
],
focused_labels = focused_labels,
label_str = None,
platform = platform,
resource_info = resource_info,
)
resource_bundles = resources_result.bundles
xccurrentversions = resources_result.xccurrentversions
else:
resource_bundles = None
xccurrentversions = None
return _inner_merge_input_files(
framework_files = framework_files,
resource_bundles = resource_bundles,
transitive_infos = transitive_infos,
xccurrentversions = xccurrentversions,
)
incremental_input_files = struct(
collect = _collect_incremental_input_files,
collect_mixed_language = _collect_mixed_language_input_files,