Skip to content

Commit 9b8a9c3

Browse files
authored
fix: skip expanding xcassets directories with no actual assets (#1940)
Fixes warning from rules_apple when an xcassets directory only contains `Contents.json` files with no actual asset content: > WARNING: No assets to compile for @@rules_swift_package_manager++swift_deps+swiftpkg_stripe_ios//:Stripe.rspm_resource_bundle > even though an asset catalog (.xcassets directory) was declared. > Skipping asset catalog compilation. Added `_xcassets_has_actual_assets()` function to check whether an xcassets directory contains files other than `Contents.json` before deciding to expand it into resources.
1 parent 3fa5721 commit 9b8a9c3

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

swiftpkg/internal/pkginfos.bzl

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,43 @@ def _new_target_from_json_maps(
461461
objc_src_info = objc_src_info,
462462
)
463463

464+
def _xcassets_has_actual_assets(repository_ctx, path):
465+
"""Checks if an xcassets directory contains actual asset files.
466+
467+
An xcassets directory that only contains Contents.json files has no
468+
compilable assets. rules_apple will warn about empty asset catalogs if
469+
we include such directories.
470+
471+
Args:
472+
repository_ctx: A `repository_ctx` instance.
473+
path: Path to the xcassets directory.
474+
475+
Returns:
476+
True if the directory contains files other than Contents.json.
477+
"""
478+
files = repository_files.list_files_under(
479+
repository_ctx,
480+
path,
481+
exclude_directories = True,
482+
)
483+
for f in files:
484+
if not f.endswith("/Contents.json") and not f.endswith("Contents.json"):
485+
return True
486+
return False
487+
464488
def _should_expand_resource(repository_ctx, resource):
465489
path = resource.path
466490

467491
if not repository_files.is_directory(repository_ctx, path):
468492
return False
469493

470-
# xcassets and xcdatamodeld folders should be expanded in-place rather than copied directly.
471-
if path.endswith(".xcassets") or path.endswith(".xcdatamodeld"):
494+
# xcassets folders should be expanded in-place rather than copied directly,
495+
# but only if they contain actual assets (not just Contents.json files).
496+
if path.endswith(".xcassets"):
497+
return _xcassets_has_actual_assets(repository_ctx, path)
498+
499+
# xcdatamodeld folders should be expanded in-place rather than copied directly.
500+
if path.endswith(".xcdatamodeld"):
472501
return True
473502

474503
return False

0 commit comments

Comments
 (0)