diff --git a/apple/internal/environment_plist.bzl b/apple/internal/environment_plist.bzl index 8aa461168..9c8d428a2 100644 --- a/apple/internal/environment_plist.bzl +++ b/apple/internal/environment_plist.bzl @@ -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 diff --git a/apple/internal/platform_support.bzl b/apple/internal/platform_support.bzl index 3023a5509..7287ca8ce 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -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. @@ -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: @@ -88,6 +96,7 @@ 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. @@ -95,6 +104,29 @@ def _platform_prerequisites( platform_type_attr = getattr(apple_common.platform_type, platform_type_string) platform = apple_fragment.multi_arch_platform(platform_type_attr) + if environment == TARGET_ENVIROMENT.device: + if platform_type_attr == apple_common.platform_type.ios: + platform = apple_common.platform.ios_device + elif platform_type_attr == apple_common.platform_type.tvos: + platform = apple_common.platform.tvos_device + elif platform_type_attr == apple_common.platform_type.visionos: + platform = apple_common.platform.visionos_device + elif platform_type_attr == apple_common.platform_type.watchos: + platform = apple_common.platform.watchos_device + else: + platform = apple_common.platform.macos + elif 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.visionos_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: diff --git a/apple/internal/resource_rules/apple_core_data_model.bzl b/apple/internal/resource_rules/apple_core_data_model.bzl index be59130d5..6e2a1ff13 100644 --- a/apple/internal/resource_rules/apple_core_data_model.bzl +++ b/apple/internal/resource_rules/apple_core_data_model.bzl @@ -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( diff --git a/apple/internal/resource_rules/apple_core_ml_library.bzl b/apple/internal/resource_rules/apple_core_ml_library.bzl index d3d00fe66..3150f32fd 100644 --- a/apple/internal/resource_rules/apple_core_ml_library.bzl +++ b/apple/internal/resource_rules/apple_core_ml_library.bzl @@ -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] diff --git a/apple/internal/xcframework_rules.bzl b/apple/internal/xcframework_rules.bzl index fb71e321a..35b361705 100644 --- a/apple/internal/xcframework_rules.bzl +++ b/apple/internal/xcframework_rules.bzl @@ -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( @@ -1045,6 +1046,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"], diff --git a/test/starlark_tests/apple_xcframework_tests.bzl b/test/starlark_tests/apple_xcframework_tests.bzl index 837f15826..c0e6421e8 100644 --- a/test/starlark_tests/apple_xcframework_tests.bzl +++ b/test/starlark_tests/apple_xcframework_tests.bzl @@ -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),