@@ -65,6 +65,7 @@ This file provides methods to easily:
65
65
66
66
load (
67
67
"@build_bazel_rules_apple//apple:providers.bzl" ,
68
+ "AppleFrameworkBundleInfo" ,
68
69
"AppleResourceInfo" ,
69
70
)
70
71
load (
@@ -218,65 +219,74 @@ def _bucketize_data(
218
219
if allowed_buckets :
219
220
allowed_bucket_set = {k : None for k in allowed_buckets }
220
221
221
- for resource in resources :
222
- # Local cache of the resource short path since it gets used quite a bit below.
223
- resource_short_path = resource .short_path
222
+ for target , target_resources in resources .items ():
223
+ for resource in target_resources :
224
+ # Local cache of the resource short path since it gets used quite a bit below.
225
+ resource_short_path = resource .short_path
224
226
225
- if owner :
226
- owners .append ((resource_short_path , owner ))
227
- else :
228
- unowned_resources .append (resource_short_path )
227
+ if owner :
228
+ owners .append ((resource_short_path , owner ))
229
+ else :
230
+ unowned_resources .append (resource_short_path )
229
231
230
- if types .is_string (parent_dir_param ) or parent_dir_param == None :
231
- parent = parent_dir_param
232
- else :
233
- parent = partial .call (partial = parent_dir_param , resource = resource )
232
+ if types .is_string (parent_dir_param ) or parent_dir_param == None :
233
+ parent = parent_dir_param
234
+ else :
235
+ parent = partial .call (partial = parent_dir_param , resource = resource )
234
236
235
- # Special case for localized. If .lproj/ is in the path of the resource (and the parent
236
- # doesn't already have it) append the lproj component to the current parent.
237
- if ".lproj/" in resource_short_path and (not parent or ".lproj" not in parent ):
238
- lproj_path = bundle_paths .farthest_parent (resource_short_path , "lproj" )
239
- parent = paths .join (parent or "" , paths .basename (lproj_path ))
237
+ # Special case for localized. If .lproj/ is in the path of the resource (and the parent
238
+ # doesn't already have it) append the lproj component to the current parent.
239
+ if ".lproj/" in resource_short_path and (not parent or ".lproj" not in parent ):
240
+ lproj_path = bundle_paths .farthest_parent (resource_short_path , "lproj" )
241
+ parent = paths .join (parent or "" , paths .basename (lproj_path ))
240
242
241
- resource_swift_module = None
242
- resource_depset = depset ([resource ])
243
-
244
- # For each type of resource, place in the appropriate bucket.
245
- if resource_short_path .endswith (".strings" ) or resource_short_path .endswith (".stringsdict" ):
246
- bucket_name = "strings"
247
- elif resource_short_path .endswith (".storyboard" ):
248
- bucket_name = "storyboards"
249
- resource_swift_module = swift_module
250
- elif resource_short_path .endswith (".xib" ):
251
- bucket_name = "xibs"
252
- resource_swift_module = swift_module
253
- elif ".xcassets/" in resource_short_path or ".xcstickers/" in resource_short_path :
254
- bucket_name = "asset_catalogs"
255
- elif ".xcdatamodel" in resource_short_path or ".xcmappingmodel/" in resource_short_path :
256
- bucket_name = "datamodels"
257
- resource_swift_module = swift_module
258
- elif ".atlas" in resource_short_path :
259
- bucket_name = "texture_atlases"
260
- elif resource_short_path .endswith (".png" ):
261
- # Process standalone pngs after asset_catalogs and texture_atlases so the latter can
262
- # bucketed correctly.
263
- bucket_name = "pngs"
264
- elif resource_short_path .endswith (".plist" ):
265
- bucket_name = "plists"
266
- elif resource_short_path .endswith (".mlmodel" ):
267
- bucket_name = "mlmodels"
268
- else :
269
- bucket_name = "unprocessed"
270
-
271
- # If the allowed bucket list is not empty, and the bucket is not allowed, change the bucket
272
- # to unprocessed instead.
273
- if allowed_bucket_set and bucket_name not in allowed_bucket_set :
274
- bucket_name = "unprocessed"
275
243
resource_swift_module = None
244
+ resource_depset = depset ([resource ])
245
+
246
+ # For each type of resource, place in the appropriate bucket.
247
+ if AppleFrameworkBundleInfo in target :
248
+ if "framework.dSYM/" in resource_short_path or resource .extension == "linkmap" :
249
+ # TODO(b/271168739): Propagate AppleDebugSymbolsInfo and _AppleDebugInfo providers.
250
+ # Ignore dSYM bundle and linkmap since the debug symbols partial is
251
+ # responsible for propagating this up the dependency graph.
252
+ continue
253
+ bucket_name = "framework"
254
+ elif (resource_short_path .endswith (".strings" ) or
255
+ resource_short_path .endswith (".stringsdict" )):
256
+ bucket_name = "strings"
257
+ elif resource_short_path .endswith (".storyboard" ):
258
+ bucket_name = "storyboards"
259
+ resource_swift_module = swift_module
260
+ elif resource_short_path .endswith (".xib" ):
261
+ bucket_name = "xibs"
262
+ resource_swift_module = swift_module
263
+ elif ".xcassets/" in resource_short_path or ".xcstickers/" in resource_short_path :
264
+ bucket_name = "asset_catalogs"
265
+ elif ".xcdatamodel" in resource_short_path or ".xcmappingmodel/" in resource_short_path :
266
+ bucket_name = "datamodels"
267
+ resource_swift_module = swift_module
268
+ elif ".atlas" in resource_short_path :
269
+ bucket_name = "texture_atlases"
270
+ elif resource_short_path .endswith (".png" ):
271
+ # Process standalone pngs after asset_catalogs and texture_atlases so the latter can
272
+ # bucketed correctly.
273
+ bucket_name = "pngs"
274
+ elif resource_short_path .endswith (".plist" ):
275
+ bucket_name = "plists"
276
+ elif resource_short_path .endswith (".mlmodel" ):
277
+ bucket_name = "mlmodels"
278
+ else :
279
+ bucket_name = "unprocessed"
276
280
277
- buckets .setdefault (bucket_name , []).append (
278
- (parent , resource_swift_module , resource_depset ),
279
- )
281
+ # If the allowed bucket list is not empty, and the bucket is not allowed, change the
282
+ # bucket to unprocessed instead.
283
+ if allowed_bucket_set and bucket_name not in allowed_bucket_set :
284
+ bucket_name = "unprocessed"
285
+ resource_swift_module = None
286
+
287
+ buckets .setdefault (bucket_name , []).append (
288
+ (parent , resource_swift_module , resource_depset ),
289
+ )
280
290
281
291
return (
282
292
owners ,
@@ -338,7 +348,9 @@ def _bucketize_typed_data(*, bucket_type, owner = None, parent_dir_param = None,
338
348
parent_dir_param: Either a string/None or a struct used to calculate the value of
339
349
parent_dir for each resource. If it is a struct, it will be considered a partial
340
350
context, and will be invoked with partial.call().
341
- resources: List of resources to place in bucket_type.
351
+ resources: List of resources to place in bucket_type or Dictionary of resources keyed by
352
+ target to place in bucket_type. This dictionary is supported by the
353
+ `resources.collect()` API.
342
354
343
355
Returns:
344
356
A tuple with a list of owners, a list of "unowned" resources, and a dictionary with
@@ -348,7 +360,17 @@ def _bucketize_typed_data(*, bucket_type, owner = None, parent_dir_param = None,
348
360
owners = []
349
361
unowned_resources = []
350
362
351
- for resource in resources :
363
+ all_resources = []
364
+ if type (resources ) == "list" :
365
+ all_resources = resources
366
+ elif type (resources ) == "dict" :
367
+ for target_resources in resources .values ():
368
+ all_resources .extend (target_resources )
369
+ else :
370
+ fail ("Internal error: 'resources' should be either a list or dictionary.\n " +
371
+ "This is most likely a rules_apple bug, please file a bug with reproduction steps" )
372
+
373
+ for resource in all_resources :
352
374
resource_short_path = resource .short_path
353
375
if owner :
354
376
owners .append ((resource_short_path , owner ))
@@ -380,13 +402,15 @@ def _bucketize_typed(resources, bucket_type, *, owner = None, parent_dir_param =
380
402
parent_dir_param when available.
381
403
382
404
Args:
383
- resources: List of resources to place in bucket_type.
384
405
bucket_type: The AppleResourceInfo field under which to collect the resources.
385
406
owner: An optional string that has a unique identifier to the target that should own the
386
407
resources. If an owner should be passed, it's usually equal to `str(ctx.label)`.
387
408
parent_dir_param: Either a string/None or a struct used to calculate the value of
388
409
parent_dir for each resource. If it is a struct, it will be considered a partial
389
410
context, and will be invoked with partial.call().
411
+ resources: List of resources to place in bucket_type or Dictionary of resources keyed by
412
+ target to place in bucket_type. This dictionary is supported by the
413
+ `resources.collect()` API.
390
414
391
415
Returns:
392
416
An AppleResourceInfo provider with resources in the given bucket.
@@ -543,26 +567,28 @@ def _collect(*, attr, res_attrs = [], split_attr_keys = []):
543
567
split_attr_keys: If defined, a list of 1:2+ transition keys to merge values from.
544
568
545
569
Returns:
546
- A list with all the collected resources for the target represented by attr .
570
+ A dictionary keyed by target from the rule attr with the list of all collected resources .
547
571
"""
548
572
if not res_attrs :
549
573
return []
550
574
551
- files = []
575
+ files_by_target = {}
552
576
for res_attr in res_attrs :
553
- if hasattr (attr , res_attr ):
554
- file_groups = [
555
- x .files .to_list ()
556
- for x in _get_attr_as_list (
557
- attr = attr ,
558
- nested_attr = res_attr ,
559
- split_attr_keys = split_attr_keys ,
560
- )
561
- if x .files
562
- ]
563
- for file_group in file_groups :
564
- files .extend (file_group )
565
- return files
577
+ if not hasattr (attr , res_attr ):
578
+ continue
579
+
580
+ targets_for_attr = _get_attr_as_list (
581
+ attr = attr ,
582
+ nested_attr = res_attr ,
583
+ split_attr_keys = split_attr_keys ,
584
+ )
585
+ for target in targets_for_attr :
586
+ if not target .files :
587
+ # Target does not export any file, ignore.
588
+ continue
589
+ files_by_target .setdefault (target , []).extend (target .files .to_list ())
590
+
591
+ return files_by_target
566
592
567
593
def _merge_providers (* , default_owner = None , providers , validate_all_resources_owned = False ):
568
594
"""Merges multiple AppleResourceInfo providers into one.
0 commit comments