Skip to content

Commit 5557de8

Browse files
nglevinswiple-rules-gardener
authored andcommitted
Add an analysis time check to avoid invoking actool when the asset catalog has no assets to compile.
PiperOrigin-RevId: 819717389
1 parent 0a04989 commit 5557de8

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

apple/internal/partials/support/resources_support.bzl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,34 @@ def _asset_catalogs(
174174
**_kwargs):
175175
"""Processes asset catalog files."""
176176

177+
asset_files = files.to_list()
178+
179+
# A list of all known asset catalog types besides Icon Composer icons can be found at this link
180+
# within the Apple legacy documentation archive:
181+
# https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_ref-Asset_Catalog_Format/AssetTypes.html#//apple_ref/doc/uid/TP40015170-CH30-SW1
182+
#
183+
# Check for empty asset catalogs; these will waste time and resources executing actool.
184+
contains_assets_to_compile = False
185+
for file in asset_files:
186+
# Skip directories and Contents.json files outside of .colorset folders.
187+
#
188+
# Contents.json files *inside* of .colorset folders are transformed into compiled asset
189+
# catalogs with color sets, and do not require any other files to generate these color sets.
190+
if (file.is_directory or (
191+
file.basename == "Contents.json" and not file.dirname.endswith(".colorset")
192+
)):
193+
continue
194+
contains_assets_to_compile = True
195+
break
196+
if not contains_assets_to_compile:
197+
# There is no other way to issue a warning, so print is the only way to message.
198+
# buildifier: disable=print
199+
print("""
200+
WARNING: No assets to compile for {rule_label} even though an asset catalog (.xcassets directory) \
201+
was declared. Skipping asset catalog compilation.
202+
""".format(rule_label = str(rule_label)))
203+
return struct(files = [], infoplists = [])
204+
177205
# Only merge the resulting plist for the top level bundle. For resource
178206
# bundles, skip generating the plist.
179207
assets_plist = None
@@ -197,7 +225,7 @@ def _asset_catalogs(
197225

198226
resource_actions.compile_asset_catalog(
199227
actions = actions,
200-
asset_files = files.to_list(),
228+
asset_files = asset_files,
201229
bundle_id = bundle_id,
202230
mac_exec_group = mac_exec_group,
203231
output_dir = assets_dir,

0 commit comments

Comments
 (0)