From b599933fbb5c69a4b118f090dc0547635d4839c5 Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Sat, 10 Feb 2024 14:44:09 -0600 Subject: [PATCH] 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 Co-authored-by: Chuck Grindel --- swiftpkg/internal/resource_files.bzl | 29 +++++++++++++------------ swiftpkg/tests/resource_files_tests.bzl | 10 ++++++--- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/swiftpkg/internal/resource_files.bzl b/swiftpkg/internal/resource_files.bzl index 1dd0cab34..431ed38a3 100644 --- a/swiftpkg/internal/resource_files.bzl +++ b/swiftpkg/internal/resource_files.bzl @@ -6,23 +6,24 @@ load("@bazel_skylib//lib:sets.bzl", "sets") # For a list of the auto-discovered resource types, see # https://github.com/apple/swift-package-manager/blob/main/Sources/PackageLoading/TargetSourcesBuilder.swift#L634-L677 _XIB_EXTS = ["nib", "xib", "storyboard"] -_ASSET_CATALOG_EXTS = ["xcassets"] _STRING_CATALOG_EXTS = ["xcstrings"] -_COREDATA_EXTS = ["xcdatamodeld", "xcdatamodel", "xcmappingmodel"] +_COREDATA_EXTS = ["xcmappingmodel"] _METAL_EXTS = ["metal"] -_ALL_AUTO_DISCOVERED_RES_EXTS = _XIB_EXTS + _ASSET_CATALOG_EXTS + \ - _STRING_CATALOG_EXTS + _COREDATA_EXTS + _METAL_EXTS -_ALL_AUTO_DISCOVERED_RES_EXTS_SET = sets.make(_ALL_AUTO_DISCOVERED_RES_EXTS) +_ALL_AUTO_DISCOVERED_RES_EXTS_SET = sets.make( + _XIB_EXTS + _STRING_CATALOG_EXTS + _COREDATA_EXTS + _METAL_EXTS, +) def _is_under_asset_catalog_dir(path): - for ext in _ASSET_CATALOG_EXTS: - # This won't work for Windows. It is unclear how to determine to proper - # separator to use. The bazel-skylib paths.bzl just uses forward slash - # (/) without checking. - pattern = ".{}/".format(ext) - if path.find(pattern) > 0: - return True - return False + # This won't work for Windows. It is unclear how to determine to proper + # separator to use. The bazel-skylib paths.bzl just uses forward slash + # (/) without checking. + return path.find(".xcassets/") > 0 + +def _is_under_xcdatamodeld_dir(path): + # This won't work for Windows. It is unclear how to determine to proper + # separator to use. The bazel-skylib paths.bzl just uses forward slash + # (/) without checking. + return path.find(".xcdatamodeld/") > 0 def _is_auto_discovered_resource(path): """Determines whether the specified path points to an auto-discoverable \ @@ -43,7 +44,7 @@ def _is_auto_discovered_resource(path): ext = ext_with_dot[1:] if ext_with_dot != "" else "" return sets.contains(_ALL_AUTO_DISCOVERED_RES_EXTS_SET, ext) or \ _is_under_asset_catalog_dir(path) or \ - False + _is_under_xcdatamodeld_dir(path) resource_files = struct( is_auto_discovered_resource = _is_auto_discovered_resource, diff --git a/swiftpkg/tests/resource_files_tests.bzl b/swiftpkg/tests/resource_files_tests.bzl index 9dc419314..ea1971f07 100644 --- a/swiftpkg/tests/resource_files_tests.bzl +++ b/swiftpkg/tests/resource_files_tests.bzl @@ -10,15 +10,19 @@ def _is_auto_discovered_resource_test(ctx): struct(msg = "nib", path = "foo.nib", exp = True), struct(msg = "xib", path = "foo.xib", exp = True), struct(msg = "storyboard", path = "foo.storyboard", exp = True), - struct(msg = "xcassets dir", path = "foo.xcassets", exp = True), + struct(msg = "xcassets dir", path = "foo.xcassets", exp = False), struct( msg = "file under xcassets dir", path = "foo.xcassets/bar.png", exp = True, ), struct(msg = "xcstrings", path = "foo.xcstrings", exp = True), - struct(msg = "xcdatamodeld", path = "foo.xcdatamodeld", exp = True), - struct(msg = "xcdatamodel", path = "foo.xcdatamodel", exp = True), + struct(msg = "xcdatamodeld", path = "foo.xcdatamodeld", exp = False), + struct( + msg = "content under .xcdatamodeld", + path = "foo.xcdatamodeld/bar.xcdatamodel/content", + exp = True, + ), struct(msg = "xcmappingmodel", path = "foo.xcmappingmodel", exp = True), struct(msg = "metal", path = "foo.metal", exp = True), struct(msg = "swift", path = "foo.swift", exp = False),