Skip to content

Commit

Permalink
Remove (depreciated immediately) XCDBLD.Platform and the non-dynami…
Browse files Browse the repository at this point in the history
…c SDK enum.

The non-dynamic SDK enum has replacement in commit 883f1c8.

Eliminate declaration of `XCDBLD.Platform` — we were using Platform wrong, twisting it into a simulatorless instance of the SDK.
 • instead, we just derive a method for that — `SDK.platformSimulatorlessFromHeuristic`
  • all the info needed for that gets parsed from -showsdks -json and stored in the SDK type

See `SDK.platformSimulatorlessFromHeuristic` from commit 883f1c8.
  • Loading branch information
jdhealy committed Jun 18, 2020
1 parent ade92cc commit d337254
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 208 deletions.
15 changes: 0 additions & 15 deletions Source/CarthageKit/XCDBLDExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,6 @@ extension ProjectLocator {
}
}

extension SD_K {
/// Attempts to parse an SDK name from a string returned from `xcodebuild`.
public static func from(string: String) -> Result<SD_K, CarthageError> {
return Result(self.init(rawValue: string.lowercased()), failWith: .parseError(description: "unexpected SDK key \"\(string)\""))
}

/// Split the given SDKs into simulator ones and device ones.
internal static func splitSDKs<S: Sequence>(_ sdks: S) -> (simulators: [SD_K], devices: [SD_K]) where S.Iterator.Element == SD_K {
return (
simulators: sdks.filter { $0.isSimulator },
devices: sdks.filter { !$0.isSimulator }
)
}
}

extension SDK {
/// Split the given SDKs into simulator ones and device ones.
internal static func splitSDKs<S: Sequence>(_ sdks: S) -> (simulators: [SDK], devices: [SDK]) where S.Iterator.Element == SDK {
Expand Down
40 changes: 8 additions & 32 deletions Source/XCDBLD/Platform.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
import Foundation

/// Represents a platform to build for.
internal enum Platform: String {
/// macOS.
case macOS = "Mac"
/*
Former file of `XCDBLD.Platform` — previously, platform functioned as somewhat of a
simulator-removed instance of an SDK.
/// iOS for device and simulator.
case iOS = "iOS"
This is dissimilar (in spirit and practice) to how Xcode Build Settings and
`xcodebuild -showsdks -json` employed the term `Platform`.
/// Apple Watch device and simulator.
case watchOS = "watchOS"

/// Apple TV device and simulator.
case tvOS = "tvOS"

/// All supported build platforms.
public static let supportedPlatforms: [Platform] = [ .macOS, .iOS, .watchOS, .tvOS ]

/// The SDKs that need to be built for this platform.
public var SDKs: [SD_K] {
switch self {
case .macOS:
return [ .macOSX ]

case .iOS:
return [ .iPhoneSimulator, .iPhoneOS ]

case .watchOS:
return [ .watchOS, .watchSimulator ]

case .tvOS:
return [ .tvOS, .tvSimulator ]
}
}
}
Functionality previously provided by this type is mostly now accomodated by
`SDK.platformSimulatorlessFromHeuristic`.
*/
111 changes: 0 additions & 111 deletions Source/XCDBLD/SDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,114 +198,3 @@ extension SDK: CustomStringConvertible {
?? self.platformSimulatorlessFromHeuristic.appending(self.isSimulator ? " Simulator" : "")
}
}

/// Represents an SDK buildable by Xcode.
public enum SD_K: String {
/// macOS.
case macOSX = "macosx"

/// iOS, for device.
case iPhoneOS = "iphoneos"

/// iOS, for the simulator.
case iPhoneSimulator = "iphonesimulator"

/// watchOS, for the Apple Watch device.
case watchOS = "watchos"

/// watchSimulator, for the Apple Watch simulator.
case watchSimulator = "watchsimulator"

/// tvOS, for the Apple TV device.
case tvOS = "appletvos"

/// tvSimulator, for the Apple TV simulator.
case tvSimulator = "appletvsimulator"

public static let allSDKs: Set<SD_K> = [.macOSX, .iPhoneOS, .iPhoneSimulator, .watchOS, .watchSimulator, .tvOS, .tvSimulator]

/// Returns whether this is a device SDK.
public var isDevice: Bool {
switch self {
case .macOSX, .iPhoneOS, .watchOS, .tvOS:
return true

case .iPhoneSimulator, .watchSimulator, .tvSimulator:
return false
}
}

/// Returns whether this is a simulator SDK.
public var isSimulator: Bool {
switch self {
case .iPhoneSimulator, .watchSimulator, .tvSimulator:
return true

case .macOSX, .iPhoneOS, .watchOS, .tvOS:
return false
}
}

/// The platform that this SDK targets.
/// - Note: `Platform` enum and concept removed in subsequent commit.
internal var platform: Platform {
switch self {
case .iPhoneOS, .iPhoneSimulator:
return .iOS

case .watchOS, .watchSimulator:
return .watchOS

case .tvOS, .tvSimulator:
return .tvOS

case .macOSX:
return .macOS
}
}

private static var aliases: [String: SD_K] {
return ["tvos": .tvOS]
}

public init?(rawValue: String) {
let lowerCasedRawValue = rawValue.lowercased()
let maybeSDK = SD_K
.allSDKs
.map { ($0, $0.rawValue) }
.first { _, stringValue in stringValue.lowercased() == lowerCasedRawValue }?
.0

guard let sdk = maybeSDK ?? SD_K.aliases[lowerCasedRawValue] else {
return nil
}
self = sdk
}
}

extension SD_K: CustomStringConvertible {
public var description: String {
switch self {
case .iPhoneOS:
return "iOS Device"

case .iPhoneSimulator:
return "iOS Simulator"

case .macOSX:
return "macOS"

case .watchOS:
return "watchOS"

case .watchSimulator:
return "watchOS Simulator"

case .tvOS:
return "tvOS"

case .tvSimulator:
return "tvOS Simulator"
}
}
}
50 changes: 0 additions & 50 deletions Tests/XCDBLDTests/SDKSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,53 +59,3 @@ class SDKEncompassingPlatformsSpec: QuickSpec {
}
}
}

class SD_KSpec: QuickSpec {
override func spec() {
describe("\(SD_K.self)") {
describe("initializer") {
it("should return nil for empty string") {
expect(SD_K(rawValue: "")).to(beNil())
}

it("should return nil for unexpected input") {
expect(SD_K(rawValue: "speakerOS")).to(beNil())
}

it("should return a valid value for expected input") {
let watchOS = SD_K(rawValue: "watchOS")
expect(watchOS).notTo(beNil())
expect(watchOS) == SD_K.watchOS

let watchOSSimulator = SD_K(rawValue: "wAtchsiMulator")
expect(watchOSSimulator).notTo(beNil())
expect(watchOSSimulator) == SD_K.watchSimulator

let tvOS1 = SD_K(rawValue: "tvOS")
expect(tvOS1).notTo(beNil())
expect(tvOS1) == SD_K.tvOS

let tvOS2 = SD_K(rawValue: "appletvos")
expect(tvOS2).notTo(beNil())
expect(tvOS2) == SD_K.tvOS

let tvOSSimulator = SD_K(rawValue: "appletvsimulator")
expect(tvOSSimulator).notTo(beNil())
expect(tvOSSimulator) == SD_K.tvSimulator

let macOS = SD_K(rawValue: "macosx")
expect(macOS).notTo(beNil())
expect(macOS) == SD_K.macOSX

let iOS = SD_K(rawValue: "iphoneos")
expect(iOS).notTo(beNil())
expect(iOS) == SD_K.iPhoneOS

let iOSimulator = SD_K(rawValue: "iphonesimulator")
expect(iOSimulator).notTo(beNil())
expect(iOSimulator) == SD_K.iPhoneSimulator
}
}
}
}
}

0 comments on commit d337254

Please sign in to comment.