Skip to content

Commit

Permalink
Expand SUPPORTED_PLATFORMS for application extensions (#3012)
Browse files Browse the repository at this point in the history
Fixes #2979.

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.

---------

Signed-off-by: Brentley Jones <[email protected]>
  • Loading branch information
brentleyjones authored Apr 15, 2024
1 parent 12c4a59 commit 9b47a68
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ extension Generator {
func callAsFunction(
name: String,
label: BazelLabel,
platforms: OrderedSet<Platform>,
productType: PBXProductType,
productName: String,
platforms: OrderedSet<Platform>,
uiTestHostName: String?
) -> [BuildSetting] {
return callable(
/*name:*/ name,
/*label:*/ label,
/*platforms:*/ platforms,
/*productType:*/ productType,
/*productName:*/ productName,
/*platforms:*/ platforms,
/*uiTestHostName:*/ uiTestHostName
)
}
Expand All @@ -41,18 +41,18 @@ extension Generator.CalculateSharedBuildSettings {
typealias Callable = (
_ name: String,
_ label: BazelLabel,
_ platforms: OrderedSet<Platform>,
_ productType: PBXProductType,
_ productName: String,
_ platforms: OrderedSet<Platform>,
_ uiTestHostName: String?
) -> [BuildSetting]

static func defaultCallable(
name: String,
label: BazelLabel,
platforms: OrderedSet<Platform>,
productType: PBXProductType,
productName: String,
platforms: OrderedSet<Platform>,
uiTestHostName: String?
) -> [BuildSetting] {
var buildSettings: [BuildSetting] = []
Expand All @@ -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
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,42 @@ class CalculateSharedBuildSettingsTests: XCTestCase {
)
}

func test_platforms_appExtension() {
// Arrange

let platforms: OrderedSet<Platform> = [
.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

Expand Down Expand Up @@ -237,17 +273,17 @@ class CalculateSharedBuildSettingsTests: XCTestCase {
private func calculateSharedBuildSettingsWithDefaults(
name: String = "A",
label: BazelLabel = "@//A",
platforms: OrderedSet<Platform> = [.macOS],
productType: PBXProductType = .staticLibrary,
productName: String = "product_name",
platforms: OrderedSet<Platform> = [.macOS],
uiTestHostName: String? = nil
) -> [BuildSetting] {
return Generator.CalculateSharedBuildSettings.defaultCallable(
name: name,
label: label,
platforms: platforms,
productType: productType,
productName: productName,
platforms: platforms,
uiTestHostName: uiTestHostName
)
}
Expand Down

0 comments on commit 9b47a68

Please sign in to comment.