Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow the "watchOS" supported destination for multiplatform apps #1470

Merged
merged 4 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Next Version

### Fixed

- Fixed `supportedDestinations` validation when it contains watchOS for multiplatform apps. #1470 @tatsuky

## 2.40.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ targets:
destinationFilters: [iOS]
```

Note that the definition of supported destinations can be applied to every type of bundle making everything more easy to manage (app targets, unit tests, UI tests etc).
Note that the definition of supported destinations can be applied to almost every type of bundle making everything more easy to manage (app targets, unit tests, UI tests etc). App targets currently do not support the watchOS destination. Create a separate target using `platform` for watchOS apps. See Apple's [Configuring a multiplatform app](https://developer.apple.com/documentation/xcode/configuring-a-multiplatform-app-target) for details.

### Sources

Expand Down
6 changes: 6 additions & 0 deletions Sources/ProjectSpec/SpecValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ extension Project {
errors.append(.unexpectedTargetPlatformForSupportedDestinations(target: target.name, platform: target.platform))
}

if let supportedDestinations = target.supportedDestinations,
target.type.isApp,
supportedDestinations.contains(.watchOS) {
errors.append(.containsWatchOSDestinationForMultiplatformApp(target: target.name))
}

if target.supportedDestinations?.contains(.macOS) == true,
target.supportedDestinations?.contains(.macCatalyst) == true {

Expand Down
3 changes: 3 additions & 0 deletions Sources/ProjectSpec/SpecValidationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public struct SpecValidationError: Error, CustomStringConvertible {
case invalidTargetSchemeTest(target: String, testTarget: String)
case invalidTargetPlatformForSupportedDestinations(target: String)
case unexpectedTargetPlatformForSupportedDestinations(target: String, platform: Platform)
case containsWatchOSDestinationForMultiplatformApp(target: String)
case multipleMacPlatformsInSupportedDestinations(target: String)
case missingTargetPlatformInSupportedDestinations(target: String, platform: Platform)
case invalidSchemeTarget(scheme: String, target: String, action: String)
Expand Down Expand Up @@ -66,6 +67,8 @@ public struct SpecValidationError: Error, CustomStringConvertible {
return "Target \(target.quoted) has multiple definitions of mac platforms in supported destinations"
case let .missingTargetPlatformInSupportedDestinations(target, platform):
return "Target \(target.quoted) has platform \(platform.rawValue.quoted) that is missing in supported destinations"
case let .containsWatchOSDestinationForMultiplatformApp(target):
return "Multiplatform app \(target.quoted) cannot contain watchOS in \"supportedDestinations\". Create a separate target using \"platform\" for watchOS apps"
case let .invalidConfigFile(configFile, config):
return "Invalid config file \(configFile.quoted) for config \(config.quoted)"
case let .invalidSchemeTarget(scheme, target, action):
Expand Down
26 changes: 26 additions & 0 deletions Tests/ProjectSpecTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@ class ProjectSpecTests: XCTestCase {
try expectValidationError(project, .unexpectedTargetPlatformForSupportedDestinations(target: "target1", platform: .watchOS))
}

$0.it("watchOS in multiplatform app's supported destinations") {
var project = baseProject
project.targets = [
Target(
name: "target1",
type: .application,
platform: .auto,
supportedDestinations: [.watchOS]
)
]
try expectValidationError(project, .containsWatchOSDestinationForMultiplatformApp(target: "target1"))
}

$0.it("watchOS in non-app's supported destinations") {
var project = baseProject
project.targets = [
Target(
name: "target1",
type: .framework,
platform: .auto,
supportedDestinations: [.watchOS]
)
]
try expectNoValidationError(project, .containsWatchOSDestinationForMultiplatformApp(target: "target1"))
}

$0.it("multiple definitions of mac platform in supported destinations") {
var project = baseProject
project.targets = [
Expand Down
8 changes: 4 additions & 4 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ class ProjectGeneratorTests: XCTestCase {
try expect(targetConfig1.buildSettings["CODE_SIGN_IDENTITY"] as? String) == "iPhone Developer"
}

$0.it("supportedDestinations merges settings - iOS, watchOS") {
let target = Target(name: "Target", type: .application, platform: .auto, supportedDestinations: [.iOS, .watchOS])
$0.it("supportedDestinations merges settings - iOS, watchOS (framework)") {
let target = Target(name: "Target", type: .framework, platform: .auto, supportedDestinations: [.iOS, .watchOS])
let project = Project(name: "", targets: [target])

let pbxProject = try project.generatePbxProj()
Expand All @@ -499,8 +499,8 @@ class ProjectGeneratorTests: XCTestCase {
try expect(targetConfig1.buildSettings["SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD"] as? Bool) == true
}

$0.it("supportedDestinations merges settings - visionOS, watchOS") {
let target = Target(name: "Target", type: .application, platform: .auto, supportedDestinations: [.visionOS, .watchOS])
$0.it("supportedDestinations merges settings - visionOS, watchOS (framework)") {
let target = Target(name: "Target", type: .framework, platform: .auto, supportedDestinations: [.visionOS, .watchOS])
let project = Project(name: "", targets: [target])

let pbxProject = try project.generatePbxProj()
Expand Down