diff --git a/tools/generators/pbxnativetargets/src/Generator/CalculateSharedBuildSettings.swift b/tools/generators/pbxnativetargets/src/Generator/CalculateSharedBuildSettings.swift index 90ded277d5..1a3506406c 100644 --- a/tools/generators/pbxnativetargets/src/Generator/CalculateSharedBuildSettings.swift +++ b/tools/generators/pbxnativetargets/src/Generator/CalculateSharedBuildSettings.swift @@ -18,17 +18,17 @@ extension Generator { func callAsFunction( name: String, label: BazelLabel, + platforms: OrderedSet, productType: PBXProductType, productName: String, - platforms: OrderedSet, uiTestHostName: String? ) -> [BuildSetting] { return callable( /*name:*/ name, /*label:*/ label, + /*platforms:*/ platforms, /*productType:*/ productType, /*productName:*/ productName, - /*platforms:*/ platforms, /*uiTestHostName:*/ uiTestHostName ) } @@ -41,18 +41,18 @@ extension Generator.CalculateSharedBuildSettings { typealias Callable = ( _ name: String, _ label: BazelLabel, + _ platforms: OrderedSet, _ productType: PBXProductType, _ productName: String, - _ platforms: OrderedSet, _ uiTestHostName: String? ) -> [BuildSetting] static func defaultCallable( name: String, label: BazelLabel, + platforms: OrderedSet, productType: PBXProductType, productName: String, - platforms: OrderedSet, uiTestHostName: String? ) -> [BuildSetting] { var buildSettings: [BuildSetting] = [] @@ -73,10 +73,33 @@ extension Generator.CalculateSharedBuildSettings { buildSettings.append( .init(key: "SDKROOT", value: platforms.first!.os.sdkRoot) ) + + var supportedPlatforms = platforms + if productType == .appExtension { + // Xcode has a bug where if we don't include device platforms in + // app extension targets, then it will fail to install the hosting + // application + if let index = supportedPlatforms.firstIndex(of: .iOSSimulator) { + supportedPlatforms.insert(.iOSDevice, at: index + 1) + } + if let index = supportedPlatforms.firstIndex(of: .tvOSSimulator) { + supportedPlatforms.insert(.tvOSDevice, at: index + 1) + } + if let index = supportedPlatforms.firstIndex( + of: .watchOSSimulator + ) { + supportedPlatforms.insert(.watchOSDevice, at: index + 1) + } + if let index = supportedPlatforms.firstIndex( + of: .visionOSSimulator + ) { + supportedPlatforms.insert(.visionOSDevice, at: index + 1) + } + } buildSettings.append( .init( key: "SUPPORTED_PLATFORMS", - value: platforms.map(\.rawValue).joined(separator: " ") + value: supportedPlatforms.map(\.rawValue).joined(separator: " ") .pbxProjEscaped ) ) diff --git a/tools/generators/pbxnativetargets/src/Generator/CreateXcodeConfigurations.swift b/tools/generators/pbxnativetargets/src/Generator/CreateXcodeConfigurations.swift index 49e33e852b..00b8d8c82b 100644 --- a/tools/generators/pbxnativetargets/src/Generator/CreateXcodeConfigurations.swift +++ b/tools/generators/pbxnativetargets/src/Generator/CreateXcodeConfigurations.swift @@ -155,11 +155,11 @@ extension Generator.CreateXcodeConfigurations { let sharedBuildSettings = calculateSharedBuildSettings( name: name, label: label, - productType: productType, - productName: productName, platforms: OrderedSet( platformVariants.map(\.platform).sorted() ), + productType: productType, + productName: productName, uiTestHostName: uiTestHostName ) diff --git a/tools/generators/pbxnativetargets/test/Generator/CalculateSharedBuildSettingsTests.swift b/tools/generators/pbxnativetargets/test/Generator/CalculateSharedBuildSettingsTests.swift index 3a0a35541d..f134876637 100644 --- a/tools/generators/pbxnativetargets/test/Generator/CalculateSharedBuildSettingsTests.swift +++ b/tools/generators/pbxnativetargets/test/Generator/CalculateSharedBuildSettingsTests.swift @@ -152,6 +152,42 @@ class CalculateSharedBuildSettingsTests: XCTestCase { ) } + func test_platforms_appExtension() { + // Arrange + + let platforms: OrderedSet = [ + .tvOSSimulator, + .visionOSDevice, + .visionOSSimulator, + .macOS, + .watchOSDevice, + .iOSSimulator, + ] + let productType = PBXProductType.appExtension + + // Order is wrong, but it shows that we don't do sorting in this + // function + let expectedBuildSettings = baseBuildSettings.updating([ + "SDKROOT": "appletvos", + "SUPPORTED_PLATFORMS": #""appletvsimulator appletvos xros xrsimulator macosx watchos iphonesimulator iphoneos""#, + "SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD": "NO", + ]) + + // Act + + let buildSettings = calculateSharedBuildSettingsWithDefaults( + platforms: platforms, + productType: productType + ) + + // Assert + + XCTAssertNoDifference( + buildSettings.asDictionary, + expectedBuildSettings + ) + } + func test_staticFramework() { // Arrange @@ -237,17 +273,17 @@ class CalculateSharedBuildSettingsTests: XCTestCase { private func calculateSharedBuildSettingsWithDefaults( name: String = "A", label: BazelLabel = "@//A", + platforms: OrderedSet = [.macOS], productType: PBXProductType = .staticLibrary, productName: String = "product_name", - platforms: OrderedSet = [.macOS], uiTestHostName: String? = nil ) -> [BuildSetting] { return Generator.CalculateSharedBuildSettings.defaultCallable( name: name, label: label, + platforms: platforms, productType: productType, productName: productName, - platforms: platforms, uiTestHostName: uiTestHostName ) }