Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apple/internal/environment_plist.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _environment_plist_impl(ctx):
platform_type_string = str(ctx.fragments.apple.single_arch_platform.platform_type),
uses_swift = False,
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
environment = getattr(ctx.fragments.apple.single_arch_platform, "get_target_environment", None),
)
environment_plist_tool = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo].environment_plist_tool
platform = platform_prerequisites.platform
Expand Down
23 changes: 22 additions & 1 deletion apple/internal/platform_support.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ _DEVICE_FAMILY_VALUES = {
"mac": None,
}

# Align with migrated apple_common.platform to Starlark implementation
TARGET_ENVIROMENT = struct(
device = "device",
catalyst = "macabi",
simulator = "simulator",
)

def _ui_device_family_plist_value(*, platform_prerequisites):
"""Returns the value to use for `UIDeviceFamily` in an info.plist.

Expand Down Expand Up @@ -72,7 +79,8 @@ def _platform_prerequisites(
objc_fragment,
platform_type_string,
uses_swift,
xcode_version_config):
xcode_version_config,
environment = None):
"""Returns a struct containing information on the platform being targeted.

Args:
Expand All @@ -88,13 +96,26 @@ def _platform_prerequisites(
platform_type_string: The platform type for the current target as a string.
uses_swift: Boolean value to indicate if this target uses Swift.
xcode_version_config: The `apple_common.XcodeVersionConfig` provider from the current context.
environment: "device" or "simulator" environment of the current target. Optional.

Returns:
A struct representing the collected platform information.
"""
platform_type_attr = getattr(apple_common.platform_type, platform_type_string)
platform = apple_fragment.multi_arch_platform(platform_type_attr)
Copy link
Author

@themz themz Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[review-note]
Here, we don't have an option to determine the correct platform for the simulator, as platform_type can only be ios or tvos, whereas platform for ios can be both ios_simulator and ios_device.


if environment == TARGET_ENVIROMENT.simulator:
if platform_type_attr == apple_common.platform_type.ios:
platform = apple_common.platform.ios_simulator
elif platform_type_attr == apple_common.platform_type.tvos:
platform = apple_common.platform.tvos_simulator
elif platform_type_attr == apple_common.platform_type.visionos:
platform = apple_common.platform.tvos_simulator
elif platform_type_attr == apple_common.platform_type.watchos:
platform = apple_common.platform.watchos_simulator
else:
# no `macos_simulator` exists
fail("Simulator environment is not supported for platform type: %s" % platform_type_string)
if explicit_minimum_os:
minimum_os = explicit_minimum_os
else:
Expand Down
5 changes: 5 additions & 0 deletions apple/internal/resource_rules/apple_core_data_model.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def _apple_core_data_model_impl(ctx):
uses_swift = True,
xcode_version_config =
ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
environment = getattr(
ctx.fragments.apple.single_arch_platform,
"get_target_environment",
None,
),
)

datamodel_groups = group_files_by_directory(
Expand Down
1 change: 1 addition & 0 deletions apple/internal/resource_rules/apple_core_ml_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def _apple_core_ml_library_impl(ctx):
platform_type_string = str(ctx.fragments.apple.single_arch_platform.platform_type),
uses_swift = uses_swift,
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
environment = getattr(ctx.fragments.apple.single_arch_platform, "get_target_environment", None),
)

apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo]
Expand Down
2 changes: 2 additions & 0 deletions apple/internal/xcframework_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ def _apple_xcframework_impl(ctx):
platform_type_string = link_output.platform,
uses_swift = link_output.uses_swift,
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
environment = link_output.environment,
)

overridden_predeclared_outputs = struct(
Expand Down Expand Up @@ -1040,6 +1041,7 @@ def _apple_static_xcframework_impl(ctx):
platform_type_string = link_output.platform,
uses_swift = link_output.uses_swift,
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
environment = link_output.environment,
)
resource_deps = _unioned_attrs(
attr_names = ["deps"],
Expand Down
24 changes: 24 additions & 0 deletions test/starlark_tests/apple_xcframework_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,30 @@ def apple_xcframework_test_suite(name):
tags = [name],
)

# Test checks respect to platform name with ios build for iphonesimulator.
archive_contents_test(
name = "{}_multiple_infoplist_test_platform_name_iphonesimulator".format(name),
build_type = "device",
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_dynamic_xcframework_multiple_infoplists",
plist_test_file = "$BUNDLE_ROOT/ios-x86_64-simulator/ios_dynamic_xcframework_multiple_infoplists.framework/Info.plist",
plist_test_values = {
"DTPlatformName": "iphonesimulator",
},
tags = [name],
)

# Test checks respect to platform name with ios build for iphoneos.
archive_contents_test(
name = "{}_multiple_infoplist_test_platform_name_iphoneos".format(name),
build_type = "device",
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_dynamic_xcframework_multiple_infoplists",
plist_test_file = "$BUNDLE_ROOT/ios-arm64/ios_dynamic_xcframework_multiple_infoplists.framework/Info.plist",
plist_test_values = {
"DTPlatformName": "iphoneos",
},
tags = [name],
)

# Tests that resource bundles and files assigned through "data" are respected.
archive_contents_test(
name = "{}_dbg_resources_data_test".format(name),
Expand Down