From 8a88150d2a71426723c14159fde32d1a410e5354 Mon Sep 17 00:00:00 2001 From: Mikhail Zinov Date: Fri, 4 Oct 2024 17:23:45 +0900 Subject: [PATCH 1/6] Fix wrong platfrom os in xcframework plist --- apple/internal/environment_plist.bzl | 1 + apple/internal/platform_support.bzl | 24 ++++++++++++++++++- .../resource_rules/apple_core_data_model.bzl | 3 +++ .../resource_rules/apple_core_ml_library.bzl | 1 + apple/internal/xcframework_rules.bzl | 2 ++ .../apple_xcframework_tests.bzl | 24 +++++++++++++++++++ 6 files changed, 54 insertions(+), 1 deletion(-) diff --git a/apple/internal/environment_plist.bzl b/apple/internal/environment_plist.bzl index 13a8e1ba1a..2e48d8ec31 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 3023a5509d..57f9a2b3eb 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -29,6 +29,13 @@ _DEVICE_FAMILY_VALUES = { "mac": None, } +# Align with Migrate apple_common.platform to Starlark implimentaion +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,9 @@ 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 +97,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 +105,18 @@ 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.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: diff --git a/apple/internal/resource_rules/apple_core_data_model.bzl b/apple/internal/resource_rules/apple_core_data_model.bzl index c72248dfdd..732bd21a0c 100644 --- a/apple/internal/resource_rules/apple_core_data_model.bzl +++ b/apple/internal/resource_rules/apple_core_data_model.bzl @@ -78,6 +78,9 @@ 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 d4c68a4d83..c498f31a8b 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 e862c1e220..f32641cd1d 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( @@ -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"], diff --git a/test/starlark_tests/apple_xcframework_tests.bzl b/test/starlark_tests/apple_xcframework_tests.bzl index 837f158263..fa8b82ee91 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], ) + # Tests checks respect to platfrom 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], + ) + + # Tests checks respect to platfrom 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), From ec8d9b3c469d896d53e99c466068de241713344d Mon Sep 17 00:00:00 2001 From: Mikhail Zinov Date: Fri, 4 Oct 2024 17:41:55 +0900 Subject: [PATCH 2/6] fix typos --- apple/internal/platform_support.bzl | 2 +- test/starlark_tests/apple_xcframework_tests.bzl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apple/internal/platform_support.bzl b/apple/internal/platform_support.bzl index 57f9a2b3eb..5db4d67b3c 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -29,7 +29,7 @@ _DEVICE_FAMILY_VALUES = { "mac": None, } -# Align with Migrate apple_common.platform to Starlark implimentaion +# Align with migrated apple_common.platform to Starlark implementation TARGET_ENVIROMENT = struct( device = "device", catalyst = "macabi", diff --git a/test/starlark_tests/apple_xcframework_tests.bzl b/test/starlark_tests/apple_xcframework_tests.bzl index fa8b82ee91..bc9408b2ee 100644 --- a/test/starlark_tests/apple_xcframework_tests.bzl +++ b/test/starlark_tests/apple_xcframework_tests.bzl @@ -361,7 +361,7 @@ def apple_xcframework_test_suite(name): tags = [name], ) - # Tests checks respect to platfrom name with ios build for iphonesimulator. + # 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", @@ -373,7 +373,7 @@ def apple_xcframework_test_suite(name): tags = [name], ) - # Tests checks respect to platfrom name with ios build for iphoneos. + # 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", From 9c502023ce69c174594fd1d666b8c2b4b8f51005 Mon Sep 17 00:00:00 2001 From: Mikhail Zinov Date: Fri, 4 Oct 2024 17:44:31 +0900 Subject: [PATCH 3/6] fix formatting --- apple/internal/platform_support.bzl | 7 +++---- apple/internal/resource_rules/apple_core_data_model.bzl | 4 +++- test/starlark_tests/apple_xcframework_tests.bzl | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apple/internal/platform_support.bzl b/apple/internal/platform_support.bzl index 5db4d67b3c..13b26bc74b 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -80,8 +80,7 @@ def _platform_prerequisites( platform_type_string, uses_swift, xcode_version_config, - environment = None, - ): + environment = None): """Returns a struct containing information on the platform being targeted. Args: @@ -115,8 +114,8 @@ def _platform_prerequisites( 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) + # 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 732bd21a0c..b7fc038445 100644 --- a/apple/internal/resource_rules/apple_core_data_model.bzl +++ b/apple/internal/resource_rules/apple_core_data_model.bzl @@ -79,7 +79,9 @@ def _apple_core_data_model_impl(ctx): xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig], environment = getattr( - ctx.fragments.apple.single_arch_platform, "get_target_environment", None + ctx.fragments.apple.single_arch_platform, + "get_target_environment", + None, ), ) diff --git a/test/starlark_tests/apple_xcframework_tests.bzl b/test/starlark_tests/apple_xcframework_tests.bzl index bc9408b2ee..c0e6421e80 100644 --- a/test/starlark_tests/apple_xcframework_tests.bzl +++ b/test/starlark_tests/apple_xcframework_tests.bzl @@ -373,7 +373,7 @@ def apple_xcframework_test_suite(name): tags = [name], ) - # Test checks respect to platform name with ios build for iphoneos. + # 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", From 259247999d787bced914ef18493f73ae52e116b1 Mon Sep 17 00:00:00 2001 From: Mikhail Zinov Date: Mon, 7 Oct 2024 11:51:45 +0900 Subject: [PATCH 4/6] fix visionos_simulator case --- apple/internal/platform_support.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/platform_support.bzl b/apple/internal/platform_support.bzl index 13b26bc74b..54d65efb5c 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -110,7 +110,7 @@ def _platform_prerequisites( 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 + platform = apple_common.platform.visionos_simulator elif platform_type_attr == apple_common.platform_type.watchos: platform = apple_common.platform.watchos_simulator else: From 6f312444628f803faf5e9ea760e1acb6ee94d89d Mon Sep 17 00:00:00 2001 From: Mikhail Zinov Date: Mon, 7 Oct 2024 22:02:02 +0900 Subject: [PATCH 5/6] drop selection --- apple/internal/platform_support.bzl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apple/internal/platform_support.bzl b/apple/internal/platform_support.bzl index 54d65efb5c..0b26236024 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -103,8 +103,19 @@ 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.simulator: + + 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: From 1a109a03d4b2d0107c450b0e9f93237a679c650e Mon Sep 17 00:00:00 2001 From: Mikhail Zinov Date: Tue, 8 Oct 2024 16:58:11 +0900 Subject: [PATCH 6/6] fix formatting --- apple/internal/platform_support.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple/internal/platform_support.bzl b/apple/internal/platform_support.bzl index 0b26236024..7287ca8ce0 100644 --- a/apple/internal/platform_support.bzl +++ b/apple/internal/platform_support.bzl @@ -103,7 +103,7 @@ 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