Skip to content

Commit 8a88150

Browse files
committed
Fix wrong platfrom os in xcframework plist
1 parent b4a1d1e commit 8a88150

6 files changed

Lines changed: 54 additions & 1 deletion

File tree

apple/internal/environment_plist.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def _environment_plist_impl(ctx):
6161
platform_type_string = str(ctx.fragments.apple.single_arch_platform.platform_type),
6262
uses_swift = False,
6363
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
64+
environment = getattr(ctx.fragments.apple.single_arch_platform, "get_target_environment", None),
6465
)
6566
environment_plist_tool = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo].environment_plist_tool
6667
platform = platform_prerequisites.platform

apple/internal/platform_support.bzl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ _DEVICE_FAMILY_VALUES = {
2929
"mac": None,
3030
}
3131

32+
# Align with Migrate apple_common.platform to Starlark implimentaion
33+
TARGET_ENVIROMENT = struct(
34+
device = "device",
35+
catalyst = "macabi",
36+
simulator = "simulator",
37+
)
38+
3239
def _ui_device_family_plist_value(*, platform_prerequisites):
3340
"""Returns the value to use for `UIDeviceFamily` in an info.plist.
3441
@@ -72,7 +79,9 @@ def _platform_prerequisites(
7279
objc_fragment,
7380
platform_type_string,
7481
uses_swift,
75-
xcode_version_config):
82+
xcode_version_config,
83+
environment = None,
84+
):
7685
"""Returns a struct containing information on the platform being targeted.
7786
7887
Args:
@@ -88,13 +97,26 @@ def _platform_prerequisites(
8897
platform_type_string: The platform type for the current target as a string.
8998
uses_swift: Boolean value to indicate if this target uses Swift.
9099
xcode_version_config: The `apple_common.XcodeVersionConfig` provider from the current context.
100+
environment: "device" or "simulator" environment of the current target. Optional.
91101
92102
Returns:
93103
A struct representing the collected platform information.
94104
"""
95105
platform_type_attr = getattr(apple_common.platform_type, platform_type_string)
96106
platform = apple_fragment.multi_arch_platform(platform_type_attr)
97107

108+
if environment == TARGET_ENVIROMENT.simulator:
109+
if platform_type_attr == apple_common.platform_type.ios:
110+
platform = apple_common.platform.ios_simulator
111+
elif platform_type_attr == apple_common.platform_type.tvos:
112+
platform = apple_common.platform.tvos_simulator
113+
elif platform_type_attr == apple_common.platform_type.visionos:
114+
platform = apple_common.platform.tvos_simulator
115+
elif platform_type_attr == apple_common.platform_type.watchos:
116+
platform = apple_common.platform.watchos_simulator
117+
else:
118+
# no `macos_simulator` exists
119+
fail("Simulator environment is not supported for platform type: %s" % platform_type_string)
98120
if explicit_minimum_os:
99121
minimum_os = explicit_minimum_os
100122
else:

apple/internal/resource_rules/apple_core_data_model.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ def _apple_core_data_model_impl(ctx):
7878
uses_swift = True,
7979
xcode_version_config =
8080
ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
81+
environment = getattr(
82+
ctx.fragments.apple.single_arch_platform, "get_target_environment", None
83+
),
8184
)
8285

8386
datamodel_groups = group_files_by_directory(

apple/internal/resource_rules/apple_core_ml_library.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def _apple_core_ml_library_impl(ctx):
100100
platform_type_string = str(ctx.fragments.apple.single_arch_platform.platform_type),
101101
uses_swift = uses_swift,
102102
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
103+
environment = getattr(ctx.fragments.apple.single_arch_platform, "get_target_environment", None),
103104
)
104105

105106
apple_mac_toolchain_info = ctx.attr._mac_toolchain[AppleMacToolsToolchainInfo]

apple/internal/xcframework_rules.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ def _apple_xcframework_impl(ctx):
561561
platform_type_string = link_output.platform,
562562
uses_swift = link_output.uses_swift,
563563
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
564+
environment = link_output.environment,
564565
)
565566

566567
overridden_predeclared_outputs = struct(
@@ -1040,6 +1041,7 @@ def _apple_static_xcframework_impl(ctx):
10401041
platform_type_string = link_output.platform,
10411042
uses_swift = link_output.uses_swift,
10421043
xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig],
1044+
environment = link_output.environment,
10431045
)
10441046
resource_deps = _unioned_attrs(
10451047
attr_names = ["deps"],

test/starlark_tests/apple_xcframework_tests.bzl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,30 @@ def apple_xcframework_test_suite(name):
361361
tags = [name],
362362
)
363363

364+
# Tests checks respect to platfrom name with ios build for iphonesimulator.
365+
archive_contents_test(
366+
name = "{}_multiple_infoplist_test_platform_name_iphonesimulator".format(name),
367+
build_type = "device",
368+
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_dynamic_xcframework_multiple_infoplists",
369+
plist_test_file = "$BUNDLE_ROOT/ios-x86_64-simulator/ios_dynamic_xcframework_multiple_infoplists.framework/Info.plist",
370+
plist_test_values = {
371+
"DTPlatformName": "iphonesimulator",
372+
},
373+
tags = [name],
374+
)
375+
376+
# Tests checks respect to platfrom name with ios build for iphoneos.
377+
archive_contents_test(
378+
name = "{}_multiple_infoplist_test_platform_name_iphoneos".format(name),
379+
build_type = "device",
380+
target_under_test = "//test/starlark_tests/targets_under_test/apple:ios_dynamic_xcframework_multiple_infoplists",
381+
plist_test_file = "$BUNDLE_ROOT/ios-arm64/ios_dynamic_xcframework_multiple_infoplists.framework/Info.plist",
382+
plist_test_values = {
383+
"DTPlatformName": "iphoneos",
384+
},
385+
tags = [name],
386+
)
387+
364388
# Tests that resource bundles and files assigned through "data" are respected.
365389
archive_contents_test(
366390
name = "{}_dbg_resources_data_test".format(name),

0 commit comments

Comments
 (0)