Files
XcodeGen/Sources/ProjectSpec/DeploymentTarget.swift
T
Giovanni Amati 97d36fd1d2 Support for multiple deployment targets with xcode 14 (#1336)
* platformFilters on Dependecies

* platformFilters on sources

* fixed current unit tests

* renamed enum to SupportedPlatforms

* supportedPlatforms field for target

* errors

* renamed errors

* inferPlatformFiltersByPath flag

* changed priority to generate filter

* fixed parsing

* fixed init

* unit test supportedPlatforms

* unit tests for errors

* fixing build settings and unit tests

* added new settingsPresets

* new check errors and unit tests

* case insensitive match

* fixed skipping cross platform target

* json decode

* unit tests inferPlatformFiltersByPath and platformFilters for sources

* mocked files

* fixing unit tests

* first test on dependecies

* unit tests completed

* fixed unit tests

* changelog

* doc changes

* doc changes

* doc changes

* doc changes

* doc changes

* doc changes

* doc changes

* doc changes

* fixed doc

* fixed unti tests style

* fixed regex

* fixed doc

* addressing comments

* Added TestProject, moved unit tests resources in another folder

* Raising error if platform is an array

* unit test on new error

* fixed error enum

* Integrated in TestProject

* committed TestProject

* unit test error

* fixing spm deps in test project

* pushed testProject

* pushed testProject

* pushed testProject fix

* comment on isResolved property

* renameing supportedPlatforms to supportedDestinations

* renameing supportedPlatforms to supportedDestinations

* renameing test app

* checked out old file

* fixing test app

* working on auto baseSDK

* fixed deploymentTarget

* renamed errors

* fixed presets

* remamed index to priority

* small comments

* removed isResolved in target and fixed error check

* added unit tests

* fixed doc

* fixed doc

* fixed doc

* fixed doc

* fixed test app

* add visionOS and more error check and testing

* fixed supported destinations priority and tests

* fixed doc

* solved conflicts

* fixed conflicts

* renamed everything

---------

Co-authored-by: Giovanni Amati <giovanni.amati@sky.uk>
2023-10-31 20:55:38 +11:00

104 lines
2.8 KiB
Swift

import Foundation
import JSONUtilities
import Version
public struct DeploymentTarget: Equatable {
public var iOS: Version?
public var tvOS: Version?
public var watchOS: Version?
public var macOS: Version?
public var visionOS: Version?
public init(
iOS: Version? = nil,
tvOS: Version? = nil,
watchOS: Version? = nil,
macOS: Version? = nil,
visionOS: Version? = nil
) {
self.iOS = iOS
self.tvOS = tvOS
self.watchOS = watchOS
self.macOS = macOS
self.visionOS = visionOS
}
public func version(for platform: Platform) -> Version? {
switch platform {
case .auto: return nil
case .iOS: return iOS
case .tvOS: return tvOS
case .watchOS: return watchOS
case .macOS: return macOS
case .visionOS: return visionOS
}
}
}
extension Platform {
public var deploymentTargetSetting: String {
switch self {
case .auto: return ""
case .iOS: return "IPHONEOS_DEPLOYMENT_TARGET"
case .tvOS: return "TVOS_DEPLOYMENT_TARGET"
case .watchOS: return "WATCHOS_DEPLOYMENT_TARGET"
case .macOS: return "MACOSX_DEPLOYMENT_TARGET"
case .visionOS: return "XROS_DEPLOYMENT_TARGET"
}
}
public var sdkRoot: String {
switch self {
case .auto: return "auto"
case .iOS: return "iphoneos"
case .tvOS: return "appletvos"
case .watchOS: return "watchos"
case .macOS: return "macosx"
case .visionOS: return "xros"
}
}
}
extension Version {
/// doesn't print patch if 0
public var deploymentTarget: String {
"\(major).\(minor)\(patch > 0 ? ".\(patch)" : "")"
}
}
extension DeploymentTarget: JSONObjectConvertible {
public init(jsonDictionary: JSONDictionary) throws {
func parseVersion(_ platform: String) throws -> Version? {
if let string: String = jsonDictionary.json(atKeyPath: .key(platform)) {
return try Version.parse(string)
} else if let double: Double = jsonDictionary.json(atKeyPath: .key(platform)) {
return try Version.parse(double)
} else {
return nil
}
}
iOS = try parseVersion("iOS")
tvOS = try parseVersion("tvOS")
watchOS = try parseVersion("watchOS")
macOS = try parseVersion("macOS")
visionOS = try parseVersion("visionOS")
}
}
extension DeploymentTarget: JSONEncodable {
public func toJSONValue() -> Any {
[
"iOS": iOS?.description,
"tvOS": tvOS?.description,
"watchOS": watchOS?.description,
"macOS": macOS?.description,
"visionOS": visionOS?.description,
]
}
}