Skip to content

Commit b599933

Browse files
fix: handling of .xcdatamodeld resources (#875)
Similar to asset catalogs, we want to include all of the files under `.xcdatamodeld` directories. --------- Signed-off-by: Brentley Jones <[email protected]> Co-authored-by: Chuck Grindel <[email protected]>
1 parent 9bbd940 commit b599933

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

swiftpkg/internal/resource_files.bzl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ load("@bazel_skylib//lib:sets.bzl", "sets")
66
# For a list of the auto-discovered resource types, see
77
# https://github.com/apple/swift-package-manager/blob/main/Sources/PackageLoading/TargetSourcesBuilder.swift#L634-L677
88
_XIB_EXTS = ["nib", "xib", "storyboard"]
9-
_ASSET_CATALOG_EXTS = ["xcassets"]
109
_STRING_CATALOG_EXTS = ["xcstrings"]
11-
_COREDATA_EXTS = ["xcdatamodeld", "xcdatamodel", "xcmappingmodel"]
10+
_COREDATA_EXTS = ["xcmappingmodel"]
1211
_METAL_EXTS = ["metal"]
13-
_ALL_AUTO_DISCOVERED_RES_EXTS = _XIB_EXTS + _ASSET_CATALOG_EXTS + \
14-
_STRING_CATALOG_EXTS + _COREDATA_EXTS + _METAL_EXTS
15-
_ALL_AUTO_DISCOVERED_RES_EXTS_SET = sets.make(_ALL_AUTO_DISCOVERED_RES_EXTS)
12+
_ALL_AUTO_DISCOVERED_RES_EXTS_SET = sets.make(
13+
_XIB_EXTS + _STRING_CATALOG_EXTS + _COREDATA_EXTS + _METAL_EXTS,
14+
)
1615

1716
def _is_under_asset_catalog_dir(path):
18-
for ext in _ASSET_CATALOG_EXTS:
19-
# This won't work for Windows. It is unclear how to determine to proper
20-
# separator to use. The bazel-skylib paths.bzl just uses forward slash
21-
# (/) without checking.
22-
pattern = ".{}/".format(ext)
23-
if path.find(pattern) > 0:
24-
return True
25-
return False
17+
# This won't work for Windows. It is unclear how to determine to proper
18+
# separator to use. The bazel-skylib paths.bzl just uses forward slash
19+
# (/) without checking.
20+
return path.find(".xcassets/") > 0
21+
22+
def _is_under_xcdatamodeld_dir(path):
23+
# This won't work for Windows. It is unclear how to determine to proper
24+
# separator to use. The bazel-skylib paths.bzl just uses forward slash
25+
# (/) without checking.
26+
return path.find(".xcdatamodeld/") > 0
2627

2728
def _is_auto_discovered_resource(path):
2829
"""Determines whether the specified path points to an auto-discoverable \
@@ -43,7 +44,7 @@ def _is_auto_discovered_resource(path):
4344
ext = ext_with_dot[1:] if ext_with_dot != "" else ""
4445
return sets.contains(_ALL_AUTO_DISCOVERED_RES_EXTS_SET, ext) or \
4546
_is_under_asset_catalog_dir(path) or \
46-
False
47+
_is_under_xcdatamodeld_dir(path)
4748

4849
resource_files = struct(
4950
is_auto_discovered_resource = _is_auto_discovered_resource,

swiftpkg/tests/resource_files_tests.bzl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ def _is_auto_discovered_resource_test(ctx):
1010
struct(msg = "nib", path = "foo.nib", exp = True),
1111
struct(msg = "xib", path = "foo.xib", exp = True),
1212
struct(msg = "storyboard", path = "foo.storyboard", exp = True),
13-
struct(msg = "xcassets dir", path = "foo.xcassets", exp = True),
13+
struct(msg = "xcassets dir", path = "foo.xcassets", exp = False),
1414
struct(
1515
msg = "file under xcassets dir",
1616
path = "foo.xcassets/bar.png",
1717
exp = True,
1818
),
1919
struct(msg = "xcstrings", path = "foo.xcstrings", exp = True),
20-
struct(msg = "xcdatamodeld", path = "foo.xcdatamodeld", exp = True),
21-
struct(msg = "xcdatamodel", path = "foo.xcdatamodel", exp = True),
20+
struct(msg = "xcdatamodeld", path = "foo.xcdatamodeld", exp = False),
21+
struct(
22+
msg = "content under .xcdatamodeld",
23+
path = "foo.xcdatamodeld/bar.xcdatamodel/content",
24+
exp = True,
25+
),
2226
struct(msg = "xcmappingmodel", path = "foo.xcmappingmodel", exp = True),
2327
struct(msg = "metal", path = "foo.metal", exp = True),
2428
struct(msg = "swift", path = "foo.swift", exp = False),

0 commit comments

Comments
 (0)