Fix xcdatamodel and xcassets files referenced by data attribute on objc_library.
Update integration tests inputs to use the data attribute instead (hey look! no changes to the output!)
Still needs updates for apple_resource_group handling, but this can at least unblock everything except structured_resources if it's referenced directly from the data attribute.
PiperOrigin-RevId: 236370438
diff --git a/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl b/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
index ad2c85b..8aff559 100644
--- a/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
+++ b/src/TulsiGenerator/Bazel/tulsi/tulsi_aspects.bzl
@@ -269,20 +269,38 @@
""""Converts a depset of files into a list of _file_metadata structs."""
return [_file_metadata(f) for f in a_depset.to_list()]
-def _collect_artifacts(obj, attr_path):
+def _collect_artifacts(obj, attr_path, exclude_xcdatamodel = False, exclude_xcassets = False):
"""Returns a list of Artifact objects for the attr_path in obj."""
return [
f
for src in _getattr_as_list(obj, attr_path)
for f in _get_opt_attr(src, "files").to_list()
+ if (not exclude_xcdatamodel or ".xcdatamodel" not in f.path) and
+ (not exclude_xcassets or ".xcassets" not in f.path) and
+ (not exclude_xcassets or ".xcstickers" not in f.path)
]
-def _collect_files(obj, attr_path, convert_to_metadata = True):
+def _collect_files(
+ obj,
+ attr_path,
+ convert_to_metadata = True,
+ exclude_xcdatamodel = False,
+ exclude_xcassets = False):
"""Returns a list of artifact_location's for the attr_path in obj."""
if convert_to_metadata:
- return [_file_metadata(f) for f in _collect_artifacts(obj, attr_path)]
+ return [_file_metadata(f) for f in _collect_artifacts(
+ obj,
+ attr_path,
+ exclude_xcdatamodel = exclude_xcdatamodel,
+ exclude_xcassets = exclude_xcassets,
+ )]
else:
- return _collect_artifacts(obj, attr_path)
+ return _collect_artifacts(
+ obj,
+ attr_path,
+ exclude_xcdatamodel = exclude_xcdatamodel,
+ exclude_xcassets = exclude_xcassets,
+ )
def _collect_first_file(obj, attr_path):
"""Returns a the first artifact_location for the attr_path in obj."""
@@ -299,6 +317,8 @@
rule_attr,
attr,
convert_to_metadata = convert_to_metadata,
+ exclude_xcdatamodel = True,
+ exclude_xcassets = True,
)
return all_files
@@ -334,7 +354,7 @@
def _collect_asset_catalogs(rule_attr):
"""Extracts xcassets directories from the given rule attributes."""
- attrs = ["app_asset_catalogs", "asset_catalogs"]
+ attrs = ["app_asset_catalogs", "asset_catalogs", "data"]
bundles = _collect_bundle_paths(rule_attr, attrs, ".xcassets")
bundles.extend(_collect_bundle_paths(rule_attr, attrs, ".xcstickers"))
@@ -707,12 +727,15 @@
copts_attr = _get_opt_attr(rule_attr, "copts")
is_swift_library = target_kind == "swift_library"
+ datamodels = _collect_xcdatamodeld_files(rule_attr, "datamodels")
+ datamodels.extend(_collect_xcdatamodeld_files(rule_attr, "data"))
+
# Keys for attribute and inheritable_attributes keys must be kept in sync
# with defines in Tulsi's RuleEntry.
attributes = _dict_omitting_none(
copts = None if is_swift_library else copts_attr,
swiftc_opts = copts_attr if is_swift_library else None,
- datamodels = _collect_xcdatamodeld_files(rule_attr, "datamodels"),
+ datamodels = datamodels,
supporting_files = supporting_files,
test_host = _get_label_attr(rule_attr, "test_host.label"),
test_bundle = _get_label_attr(rule_attr, "test_bundle.label"),
diff --git a/src/TulsiGeneratorIntegrationTests/Resources/ComplexSingle.BUILD b/src/TulsiGeneratorIntegrationTests/Resources/ComplexSingle.BUILD
index ff07dd6..b81a8f9 100644
--- a/src/TulsiGeneratorIntegrationTests/Resources/ComplexSingle.BUILD
+++ b/src/TulsiGeneratorIntegrationTests/Resources/ComplexSingle.BUILD
@@ -75,12 +75,20 @@
"Application/srcs/main.m",
":SrcGenerator",
],
- asset_catalogs = [
- "Application/AssetsOne.xcassets/test_file.ico",
- "Application/AssetsOne.xcassets/another_file.ico",
- "Application/AssetsTwo.xcassets/png_file.png",
- ],
bundles = [":ObjCBundle"],
+ data = [
+ "Application/AssetsOne.xcassets/another_file.ico",
+ "Application/AssetsOne.xcassets/test_file.ico",
+ "Application/AssetsTwo.xcassets/png_file.png",
+ "Application/Base.lproj/Localizable.strings",
+ "Application/Base.lproj/Localized.strings",
+ "Application/Base.lproj/One.storyboard",
+ "Application/NonLocalized.strings",
+ "Application/en.lproj/EN.strings",
+ "Application/en.lproj/Localized.strings",
+ "Application/es.lproj/Localized.strings",
+ ":StoryboardGenerator",
+ ],
defines = [
"A=BINARY_DEFINE",
],
@@ -91,18 +99,6 @@
non_arc_srcs = [
"Application/non_arc_srcs/NonARCFile.mm",
],
- storyboards = [
- "Application/Base.lproj/One.storyboard",
- ":StoryboardGenerator",
- ],
- strings = [
- "Application/Base.lproj/Localizable.strings",
- "Application/Base.lproj/Localized.strings",
- "Application/en.lproj/Localized.strings",
- "Application/en.lproj/EN.strings",
- "Application/es.lproj/Localized.strings",
- "Application/NonLocalized.strings",
- ],
deps = [
":CoreDataResources",
":Library",
diff --git a/src/TulsiGeneratorIntegrationTests/Resources/Mac.BUILD b/src/TulsiGeneratorIntegrationTests/Resources/Mac.BUILD
index 56e69d0..6dfc5ee 100644
--- a/src/TulsiGeneratorIntegrationTests/Resources/Mac.BUILD
+++ b/src/TulsiGeneratorIntegrationTests/Resources/Mac.BUILD
@@ -62,7 +62,7 @@
"src/AppDelegate.m",
"src/main.m",
],
- resources = [
+ data = [
"Resources/Main.storyboard",
],
)
@@ -106,7 +106,7 @@
"src/extensions/today/ExtSources/TodayViewController.m",
"src/extensions/today/TodayViewController.h",
],
- resources = [
+ data = [
"Resources/extensions/today/TodayViewController.xib",
],
sdk_frameworks = [
diff --git a/src/TulsiGeneratorIntegrationTests/Resources/PlatformDependent.BUILD b/src/TulsiGeneratorIntegrationTests/Resources/PlatformDependent.BUILD
index 60d8aa4..f2166e0 100644
--- a/src/TulsiGeneratorIntegrationTests/Resources/PlatformDependent.BUILD
+++ b/src/TulsiGeneratorIntegrationTests/Resources/PlatformDependent.BUILD
@@ -75,14 +75,15 @@
srcs = [
"App/srcs/main.m",
],
- asset_catalogs = ["App/Assets.xcassets/asset.png"],
- datamodels = glob(["SimpleTest.xcdatamodeld/**"]),
+ data = [
+ "App/Assets.xcassets/asset.png",
+ "App/Base.lproj/One.storyboard",
+ ] + glob(["SimpleTest.xcdatamodeld/**"]),
defines = [
"BINARY_ADDITIONAL_DEFINE",
"BINARY_ANOTHER_DEFINE=2",
],
includes = ["App/includes"],
- storyboards = ["App/Base.lproj/One.storyboard"],
deps = [
":Library",
],
@@ -105,12 +106,12 @@
"-I/Library/absolute/include/path",
"-Irelative/Library/include/path",
],
+ data = ["Library/xibs/xib.xib"],
defines = ["LIBRARY_DEFINES_DEFINE=1"],
pch = "Library/pch/PCHFile.pch",
textual_hdrs = [
"Library/textual_hdrs/TextualHdrsHeader.h",
],
- xibs = ["Library/xibs/xib.xib"],
deps = [
"J2ObjCLibrary",
":ObjcProtos",
diff --git a/src/TulsiGeneratorIntegrationTests/Resources/Simple.BUILD b/src/TulsiGeneratorIntegrationTests/Resources/Simple.BUILD
index ba0d3c6..b700e7a 100644
--- a/src/TulsiGeneratorIntegrationTests/Resources/Simple.BUILD
+++ b/src/TulsiGeneratorIntegrationTests/Resources/Simple.BUILD
@@ -61,9 +61,10 @@
srcs = [
"ApplicationLibrary/srcs/main.m",
],
- asset_catalogs = ["ApplicationLibrary/Assets.xcassets/asset.png"],
- data = ["ApplicationLibrary/Base.lproj/One.storyboard"],
- datamodels = glob(["SimpleTest.xcdatamodeld/**"]),
+ data = [
+ "ApplicationLibrary/Assets.xcassets/asset.png",
+ "ApplicationLibrary/Base.lproj/One.storyboard",
+ ] + glob(["SimpleTest.xcdatamodeld/**"]),
defines = [
"APPLIB_ADDITIONAL_DEFINE",
"APPLIB_ANOTHER_DEFINE=2",
diff --git a/src/TulsiGeneratorIntegrationTests/Resources/Watch.BUILD b/src/TulsiGeneratorIntegrationTests/Resources/Watch.BUILD
index e25b389..a9a8a31 100644
--- a/src/TulsiGeneratorIntegrationTests/Resources/Watch.BUILD
+++ b/src/TulsiGeneratorIntegrationTests/Resources/Watch.BUILD
@@ -49,7 +49,7 @@
srcs = [
"Library/srcs/main.m",
],
- asset_catalogs = [
+ data = [
"Library/AssetsOne.xcassets/test_file.ico",
"Library/AssetsTwo.xcassets/png_file.png",
],
@@ -71,8 +71,8 @@
objc_library(
name = "WatchApplicationResources",
- asset_catalogs = ["Watch2Extension/app_asset_catalogs.xcassets/app_asset_file.png"],
- resources = [
+ data = [
+ "Watch2Extension/app_asset_catalogs.xcassets/app_asset_file.png",
"Watch2Extension/ext_resources.file",
],
structured_resources = [
@@ -94,7 +94,7 @@
objc_library(
name = "WatchExtensionResources",
- resources = [
+ data = [
"Watch2Extension/ext_resources.file",
],
structured_resources = [