@@ -727,6 +727,9 @@ expected: {expected}\
727
727
728
728
# MARK: - Apple Resource Group
729
729
730
+ def _sanitized_bundle_file_name (bundle_path ):
731
+ return bundle_path .replace (" " , "_" ).replace ("." , "_" ).replace ("(" , "_" ).replace (")" , "_" )
732
+
730
733
def _apple_resource_bundle (target , package_name , default_localization , expose_build_targets ):
731
734
bzl_target_name = pkginfo_targets .bazel_label_name (target )
732
735
bundle_label_name = pkginfo_targets .resource_bundle_label_name (bzl_target_name )
@@ -735,10 +738,21 @@ def _apple_resource_bundle(target, package_name, default_localization, expose_bu
735
738
bzl_target_name ,
736
739
)
737
740
738
- resources = sorted ([
741
+ sorted_resources = sorted ([
739
742
r .path
740
743
for r in target .resources
741
744
])
745
+ resources = [
746
+ r
747
+ for r in sorted_resources
748
+ if not r .endswith (".bundle" )
749
+ ]
750
+ precompiled_bundles_and_labels = [
751
+ (r , "{}_{}" .format (bundle_label_name , _sanitized_bundle_file_name (r .split ("/" )[- 1 ])))
752
+ for r in sorted_resources
753
+ if r .endswith (".bundle" )
754
+ ]
755
+ precompiled_bundle_resource_labels = [bundle_pair [1 ] for bundle_pair in precompiled_bundles_and_labels ]
742
756
743
757
load_stmts = [
744
758
apple_resource_bundle_load_stmt ,
@@ -760,11 +774,28 @@ def _apple_resource_bundle(target, package_name, default_localization, expose_bu
760
774
"infoplists" : [":{}" .format (infoplist_name )],
761
775
# Based upon the code in SPM, it looks like they only support unstructured resources.
762
776
# https://github.com/apple/swift-package-manager/blob/main/Sources/PackageModel/Resource.swift#L25-L33
763
- "resources" : resources ,
777
+ "resources" : resources + [ ":{}" . format ( bundle_label ) for bundle_label in precompiled_bundle_resource_labels ] ,
764
778
"visibility" : _target_visibility (expose_build_targets ),
765
779
},
766
780
),
767
781
]
782
+
783
+ if len (precompiled_bundles_and_labels ) > 0 :
784
+ load_stmts .append (apple_resource_bundle_import_load_stmt )
785
+ for precompiled_bundle , precompiled_bundle_label_name in precompiled_bundles_and_labels :
786
+ decls .append (
787
+ build_decls .new (
788
+ kind = apple_kinds .apple_bundle_import ,
789
+ name = precompiled_bundle_label_name ,
790
+ attrs = {
791
+ "bundle_imports" : scg .new_fn_call (
792
+ "glob" ,
793
+ ["{precompiled_bundle}/**/*" .format (precompiled_bundle = precompiled_bundle )],
794
+ ),
795
+ },
796
+ ),
797
+ )
798
+
768
799
return struct (
769
800
bundle_name = bundle_name ,
770
801
bundle_label_name = bundle_label_name ,
@@ -1135,6 +1166,7 @@ apple_kinds = struct(
1135
1166
static_xcframework_import = "apple_static_xcframework_import" ,
1136
1167
dynamic_xcframework_import = "apple_dynamic_xcframework_import" ,
1137
1168
resource_bundle = "apple_resource_bundle" ,
1169
+ apple_bundle_import = "apple_bundle_import" ,
1138
1170
)
1139
1171
1140
1172
apple_apple_location = "@build_bazel_rules_apple//apple:apple.bzl"
@@ -1156,6 +1188,11 @@ apple_resource_bundle_load_stmt = load_statements.new(
1156
1188
apple_kinds .resource_bundle ,
1157
1189
)
1158
1190
1191
+ apple_resource_bundle_import_load_stmt = load_statements .new (
1192
+ apple_resources_location ,
1193
+ apple_kinds .apple_bundle_import ,
1194
+ )
1195
+
1159
1196
swiftpkg_kinds = struct (
1160
1197
generate_modulemap = "generate_modulemap" ,
1161
1198
objc_resource_bundle_accessor_hdr = "objc_resource_bundle_accessor_hdr" ,
0 commit comments