Skip to content

Add DriverKit as a supported platform #3293

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

Merged
merged 1 commit into from
Feb 20, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ extension PackageModel.Platform {
self = PackageModel.Platform.tvOS
case let name where name.contains("watchos"):
self = PackageModel.Platform.watchOS
case let name where name.contains("driverkit"):
self = PackageModel.Platform.driverKit
case let name where name.contains("linux"):
self = PackageModel.Platform.linux
case let name where name.contains("android"):
Expand Down
43 changes: 43 additions & 0 deletions Sources/PackageDescription/SupportedPlatforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public struct Platform: Encodable, Equatable {
/// The watchOS platform.
public static let watchOS: Platform = Platform(name: "watchos")

/// The DriverKit platform
public static let driverKit: Platform = Platform(name: "driverkit")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to deal with availability here since it seems like if #available does not work for _PackageDescription. That means if I add availability here, the static functions can't be compiled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just recently found out that _PackageDescription is a special thing — is it a bug that #ifavailable doesn't work for it, do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, that's what I was thinking. It seems we so far only added platform constants for platforms without versioning, so we may not have noticed that something is missing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not too bad to leave this without availability for now, but we will have to figure something out before we ship another release in the future.


/// The Linux platform.
public static let linux: Platform = Platform(name: "linux")

Expand Down Expand Up @@ -161,6 +164,25 @@ public struct SupportedPlatform: Encodable, Equatable {
public static func watchOS(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .watchOS, version: SupportedPlatform.WatchOSVersion(string: versionString).version)
}

/// Configures the minimum deployment target version for the DriverKit platform.
///
/// - Parameter version: The minimum deployment target that the package supports.
@available(_PackageDescription, introduced: 999.0)
public static func driverKit(_ version: SupportedPlatform.DriverKitVersion) -> SupportedPlatform {
return SupportedPlatform(platform: .driverKit, version: version.version)
}

/// Configures the minimum deployment target version for the DriverKit platform
/// using a custom version string.
///
/// The version string must be a series of two or three dot-separated integers, such as `19.0` or `19.0.1`.
///
/// - Parameter versionString: The minimum deployment target as a string representation of two or three dot-separated integers, such as `19.0.1`.
@available(_PackageDescription, introduced: 999.0)
public static func driverKit(_ versionString: String) -> SupportedPlatform {
return SupportedPlatform(platform: .driverKit, version: SupportedPlatform.DriverKitVersion(string: versionString).version)
}
}

/// An extension to the SupportedPlatform struct that defines major platform versions.
Expand Down Expand Up @@ -362,6 +384,27 @@ extension SupportedPlatform {
@available(_PackageDescription, introduced: 5.3)
public static let v7: WatchOSVersion = .init(string: "7.0")
}

/// The supported DriverKit version.
public struct DriverKitVersion: Encodable, AppleOSVersion {
fileprivate static let name = "DriverKit"
fileprivate static let minimumMajorVersion = 19

/// The underlying version representation.
let version: String

fileprivate init(uncheckedVersion version: String) {
self.version = version
}

/// The value that represents DriverKit 19.0.
@available(_PackageDescription, introduced: 999.0)
public static let v19: DriverKitVersion = .init(string: "19.0")

/// The value that represents DriverKit 20.0.
@available(_PackageDescription, introduced: 999.0)
public static let v20: DriverKitVersion = .init(string: "20.0")
}
}

fileprivate protocol AppleOSVersion {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PackageLoading/MinimumDeploymentTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ private extension PackageModel.Platform {
return "appletvos"
case .watchOS:
return "watchos"
case .driverKit:
return nil // DriverKit does not support XCTest.
default:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageLoading/PlatformRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public final class PlatformRegistry {

/// The static list of known platforms.
private static var _knownPlatforms: [Platform] {
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi]
return [.macOS, .iOS, .tvOS, .watchOS, .linux, .windows, .android, .wasi, .driverKit]
}
}
3 changes: 3 additions & 0 deletions Sources/PackageModel/ManifestSourceGeneration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ fileprivate extension SourceCodeFragment {
self.init(enum: "tvOS", string: platform.version)
case "watchos":
self.init(enum: "watchOS", string: platform.version)
case "driverkit":
self.init(enum: "DriverKit", string: platform.version)
default:
self.init(enum: platform.platformName, string: platform.version)
}
Expand Down Expand Up @@ -296,6 +298,7 @@ fileprivate extension SourceCodeFragment {
case "ios": return SourceCodeFragment(enum: "iOS")
case "tvos": return SourceCodeFragment(enum: "tvOS")
case "watchos": return SourceCodeFragment(enum: "watchOS")
case "driverkit": return SourceCodeFragment(enum: "DriverKit")
default: return SourceCodeFragment(enum: platformName)
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/PackageModel/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public struct Platform: Equatable, Hashable, Codable {
public static let iOS: Platform = Platform(name: "ios", oldestSupportedVersion: "9.0")
public static let tvOS: Platform = Platform(name: "tvos", oldestSupportedVersion: "9.0")
public static let watchOS: Platform = Platform(name: "watchos", oldestSupportedVersion: "2.0")
public static let driverKit: Platform = Platform(name: "driverkit", oldestSupportedVersion: "19.0")
public static let linux: Platform = Platform(name: "linux", oldestSupportedVersion: .unknown)
public static let android: Platform = Platform(name: "android", oldestSupportedVersion: .unknown)
public static let windows: Platform = Platform(name: "windows", oldestSupportedVersion: .unknown)
Expand Down
6 changes: 5 additions & 1 deletion Sources/Workspace/InitPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ extension PackageModel.Platform {
return "tvOS"
case .watchOS:
return "watchOS"
case .driverKit:
return "DriverKit"
default:
fatalError("unexpected manifest name call for platform \(self)")
}
Expand All @@ -469,7 +471,7 @@ extension SupportedPlatform {
guard self.version.patch == 0 else {
return false
}
} else if [Platform.macOS, .iOS, .watchOS, .tvOS].contains(platform) {
} else if [Platform.macOS, .iOS, .watchOS, .tvOS, .driverKit].contains(platform) {
guard self.version.minor == 0, self.version.patch == 0 else {
return false
}
Expand All @@ -488,6 +490,8 @@ extension SupportedPlatform {
return (9...14).contains(version.major)
case .watchOS:
return (2...7).contains(version.major)
case .driverKit:
return (19...20).contains(version.major)

default:
return false
Expand Down
3 changes: 3 additions & 0 deletions Sources/XCBuildSupport/PIF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ public enum PIF {
case COPY_PHASE_STRIP
case DEBUG_INFORMATION_FORMAT
case DEFINES_MODULE
case DRIVERKIT_DEPLOYMENT_TARGET
case DYLIB_INSTALL_NAME_BASE
case EMBEDDED_CONTENT_CONTAINS_SWIFT
case ENABLE_NS_ASSERTIONS
Expand Down Expand Up @@ -959,6 +960,7 @@ public enum PIF {
case iOS = "ios"
case tvOS = "tvos"
case watchOS = "watchos"
case driverKit = "driverkit"
case linux

public var conditions: [String] {
Expand All @@ -967,6 +969,7 @@ public enum PIF {
case .iOS: return ["sdk=iphonesimulator*", "sdk=iphoneos*"]
case .tvOS: return ["sdk=appletvsimulator*", "sdk=appletvos*"]
case .watchOS: return ["sdk=watchsimulator*", "sdk=watchos*"]
case .driverKit: return ["sdk=driverkit*"]
case .linux: return ["sdk=linux*"]
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/XCBuildSupport/PIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
settings[.IPHONEOS_DEPLOYMENT_TARGET] = firstTarget?.deploymentTarget(for: .iOS)
settings[.TVOS_DEPLOYMENT_TARGET] = firstTarget?.deploymentTarget(for: .tvOS)
settings[.WATCHOS_DEPLOYMENT_TARGET] = firstTarget?.deploymentTarget(for: .watchOS)
settings[.DRIVERKIT_DEPLOYMENT_TARGET] = firstTarget?.deploymentTarget(for: .driverKit)
settings[.DYLIB_INSTALL_NAME_BASE] = "@rpath"
settings[.USE_HEADERMAP] = "NO"
settings[.SWIFT_ACTIVE_COMPILATION_CONDITIONS] = ["$(inherited)", "SWIFT_PACKAGE"]
Expand Down Expand Up @@ -1483,6 +1484,9 @@ extension Array where Element == PackageConditionProtocol {
case .windows:
result += PIF.PlatformFilter.windowsFilters

case .driverKit:
result += PIF.PlatformFilter.driverKitFilters

default:
assertionFailure("Unhandled platform condition: \(condition)")
break
Expand Down Expand Up @@ -1515,6 +1519,11 @@ extension PIF.PlatformFilter {
.init(platform: "watchos", environment: "simulator")
]

/// DriverKit platform filters.
public static let driverKitFilters: [PIF.PlatformFilter] = [
.init(platform: "driverkit"),
]

/// Windows platform filters.
public static let windowsFilters: [PIF.PlatformFilter] = [
.init(platform: "windows", environment: "msvc"),
Expand Down Expand Up @@ -1543,6 +1552,7 @@ private extension PIF.BuildSettings.Platform {
case .macOS: return .macOS
case .tvOS: return .tvOS
case .watchOS: return .watchOS
case .driverKit: return .driverKit
default: return nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/Xcodeproj/XcodeProjectModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ public struct Xcode {
public var IPHONEOS_DEPLOYMENT_TARGET: String?
public var TVOS_DEPLOYMENT_TARGET: String?
public var WATCHOS_DEPLOYMENT_TARGET: String?
public var DRIVERKIT_DEPLOYMENT_TARGET: String?
public var MODULEMAP_FILE: String?
public var ONLY_ACTIVE_ARCH: String?
public var OTHER_CFLAGS: [String]?
Expand Down Expand Up @@ -421,6 +422,7 @@ public struct Xcode {
IPHONEOS_DEPLOYMENT_TARGET: String? = nil,
TVOS_DEPLOYMENT_TARGET: String? = nil,
WATCHOS_DEPLOYMENT_TARGET: String? = nil,
DRIVERKIT_DEPLOYMENT_TARGET: String? = nil,
MODULEMAP_FILE: String? = nil,
ONLY_ACTIVE_ARCH: String? = nil,
OTHER_CFLAGS: [String]? = nil,
Expand Down Expand Up @@ -468,6 +470,7 @@ public struct Xcode {
self.IPHONEOS_DEPLOYMENT_TARGET = IPHONEOS_DEPLOYMENT_TARGET
self.TVOS_DEPLOYMENT_TARGET = TVOS_DEPLOYMENT_TARGET
self.WATCHOS_DEPLOYMENT_TARGET = WATCHOS_DEPLOYMENT_TARGET
self.DRIVERKIT_DEPLOYMENT_TARGET = DRIVERKIT_DEPLOYMENT_TARGET
self.MODULEMAP_FILE = MODULEMAP_FILE
self.ONLY_ACTIVE_ARCH = ONLY_ACTIVE_ARCH
self.OTHER_CFLAGS = OTHER_CFLAGS
Expand Down
2 changes: 2 additions & 0 deletions Sources/Xcodeproj/pbxproj.swift
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ public func xcodeProject(
targetSettings.common.TVOS_DEPLOYMENT_TARGET = version
case .watchOS:
targetSettings.common.WATCHOS_DEPLOYMENT_TARGET = version
case .driverKit:
targetSettings.common.DRIVERKIT_DEPLOYMENT_TARGET = version
default:
break
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/PackageLoadingTests/PackageBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,7 @@ class PackageBuilderTests: XCTestCase {
"macos": "10.12",
"ios": "9.0",
"tvos": "9.0",
"driverkit": "19.0",
"watchos": "2.0",
"android": "0.0",
"windows": "0.0",
Expand Down Expand Up @@ -1739,6 +1740,7 @@ class PackageBuilderTests: XCTestCase {
"linux": "0.0",
"ios": "9.0",
"watchos": "2.0",
"driverkit": "19.0",
"android": "0.0",
"windows": "0.0",
"wasi": "0.0",
Expand Down