Skip to content

Commit

Permalink
Support visionOS by using -destination xros/xrsimulator. Make addit…
Browse files Browse the repository at this point in the history
…ive changes to XCBLD’s SDK.

• Move `selectAvailableSimulator` to a new query method `sdk.simulatorJsonKeyUnderDevicesDictQuery`

• Add knownIn2023Year APIs.

• Fix some whitespace that had spaces in a tabs-based file.
  • Loading branch information
klundberg authored and jdhealy committed Sep 11, 2023
1 parent 187a78c commit 2d62055
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Source/CarthageKit/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ extension SDK {
/// - Note: As last ditch effort, try inside `/Applications/Xcode.app`, which might not exist.
/// - Note: Mostly, `xcodebuild -showsdks -json`-based `XCDBLD.SDK`s will be grabbed instead of
/// this signal reaching completion.
/// - Note: Will, where possible, draw from `SDK.knownIn2019YearSDKs` for 2019-era captialization.
/// - Note: Will, where possible, draw from `SDK.knownIn2023YearSDKs` for 2023-era captialization.
static let setFromFallbackXcodeprojBuildSettings: SignalProducer<Set<SDK>?, NoError> =
Task("/usr/bin/xcrun", arguments: ["--find", "xcodebuild"], environment: Environment.withoutActiveXcodeXCConfigFile)
.launch()
Expand Down Expand Up @@ -405,13 +405,13 @@ extension SDK {
extension SDK {
/// - See: `SDK.setFromJSONShowSDKs`
/// - Note: Fallbacks are `SDK.setFromFallbackXcodeprojBuildSettings` and
/// hardcoded `SDK.knownIn2019YearSDKs`.
/// hardcoded `SDK.knownIn2023YearSDKs`.
static let setsFromJSONShowSDKsWithFallbacks: SignalProducer<Set<SDK>, NoError> =
SDK.setFromJSONShowSDKs
.concat(SDK.setFromFallbackXcodeprojBuildSettings)
.skip(while: { $0 == nil })
.take(first: 1)
.skipNil()
.reduce(into: SDK.knownIn2019YearSDKs) { $0 = $1 }
.reduce(into: SDK.knownIn2023YearSDKs) { $0 = $1 }
.replayLazily(upTo: 1)
}
4 changes: 2 additions & 2 deletions Source/CarthageKit/Simulator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ internal func selectAvailableSimulator(of sdk: SDK, from data: Data) -> Simulato
let devices = jsonObject["devices"] else {
return nil
}
let platformName = sdk.platformSimulatorlessFromHeuristic

func reducePlatformNames(_ result: inout [String: [Simulator]], _ entry: (key: String, value: [Simulator])) {
guard let platformVersion = parsePlatformVersion(for: platformName, from: entry.key) else { return }
guard let platformVersion = parsePlatformVersion(for: sdk.simulatorJsonKeyUnderDevicesDictQuery, from: entry.key) else { return }
guard entry.value.contains(where: { $0.isAvailable }) else { return }
result[platformVersion] = entry.value
}
Expand Down
2 changes: 1 addition & 1 deletion Source/CarthageKit/VersionFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public func createVersionFileForCommitish(
cachedFramework = CachedFramework(name: frameworkName, container: nil, libraryIdentifier: nil, hash: hash, linking: linking, swiftToolchainVersion: frameworkSwiftVersion)
case .xcframework(name: let container, libraryIdentifier: let identifier):
let targetOS = identifier.components(separatedBy: "-")[0]
platformName = SDK.associatedSetOfKnownIn2019YearSDKs(targetOS).first?.platformSimulatorlessFromHeuristic
platformName = SDK.associatedSetOfKnownIn2023YearSDKs(targetOS).first?.platformSimulatorlessFromHeuristic
cachedFramework = CachedFramework(name: frameworkName, container: container, libraryIdentifier: identifier, hash: hash, linking: nil, swiftToolchainVersion: frameworkSwiftVersion)
}
if let platformName = platformName, var frameworks = platformCaches[platformName] {
Expand Down
62 changes: 51 additions & 11 deletions Source/XCDBLD/SDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public struct SDK: Hashable {
return lhs.rawValue == rhs.rawValue
}

public var simulatorJsonKeyUnderDevicesDictQuery: String {
guard self.simulatorHeuristic != "Simulator - visionOS" else {
return "xros"
}

return self.platformSimulatorlessFromHeuristic
}

/// Take `simulatorHeuristic` and (best as possible) derive what used to be `XCDBLD.Platform` from it.
/// With data from `xcodebuild -showsdks -json`, should do solid job.
public var platformSimulatorlessFromHeuristic: String {
Expand Down Expand Up @@ -89,13 +97,31 @@ public struct SDK: Hashable {
$0[$1.0.lowercased()] = ($1.0, $1.1.0, $1.1.1)
}

private static let knownIn2023YearDictionary: [String: (String, [String], String)] = CollectionOfOne(
([
"XROS": (["visionOS"], "visionOS"),
"XRSimulator": (["visionOS Simulator", "xrsimulator"], "Simulator - visionOS"),
] as KeyValuePairs).reduce(into: [:]) {
$0[$1.0.lowercased()] = ($1.0, $1.1.0, $1.1.1)
}
)
.map { knownIn2019YearDictionary.merging($0, uniquingKeysWith: { x, y in y } ) }
.first!

public static let knownIn2019YearSDKs: Set<SDK> =
Set(
knownIn2019YearDictionary
.mapValues { $0.2 }
.map(SDK.init)
)

public static let knownIn2023YearSDKs: Set<SDK> =
Set(
knownIn2023YearDictionary
.mapValues { $0.2 }
.map(SDK.init)
)

/// - Warning:
public init?(rawValue: String) {
if rawValue.caseInsensitiveCompare("tvos") == .orderedSame {
Expand All @@ -104,17 +130,22 @@ public struct SDK: Hashable {
return
}

guard let index = SDK.knownIn2019YearDictionary.index(forKey: rawValue.lowercased()) else { return nil }
if rawValue.caseInsensitiveCompare("visionos") == .orderedSame {
self.name = "XROS"
self.simulatorHeuristic = ""
return
}

guard let index = SDK.knownIn2023YearDictionary.index(forKey: rawValue.lowercased()) else { return nil }

(self.name, _, self.simulatorHeuristic) = SDK.knownIn2019YearDictionary[index].value
(self.name, _, self.simulatorHeuristic) = SDK.knownIn2023YearDictionary[index].value
}

public static func associatedSetOfKnownIn2019YearSDKs(_ argumentSubstring: String) -> Set<SDK> {
let knownIn2019YearDictionary = SDK.knownIn2019YearDictionary
private static func associatedSetOfKnownSDKs(_ argumentSubstring: String, dictionary: [String: (String, [String], String)]) -> Set<SDK> {
let potentialSDK = argumentSubstring.lowercased()

let potentialIndex = knownIn2019YearDictionary.index(forKey: potentialSDK)
?? knownIn2019YearDictionary.firstIndex(
let potentialIndex = dictionary.index(forKey: potentialSDK)
?? dictionary.firstIndex(
where: { _, value in
value.1.contains { $0.caseInsensitiveCompare(potentialSDK) == .orderedSame }
}
Expand All @@ -123,14 +154,23 @@ public struct SDK: Hashable {
guard let index = potentialIndex else { return Set() }

return [
Optional(knownIn2019YearDictionary[index].value),
knownIn2019YearDictionary[knownIn2019YearDictionary[index].key.dropLast(2).appending("simulator")],
knownIn2019YearDictionary[knownIn2019YearDictionary[index].key.dropLast(9).appending("os")]
Optional(dictionary[index].value),
dictionary[dictionary[index].key.dropLast(2).appending("simulator")],
dictionary[dictionary[index].key.dropLast(9).appending("os")]
]
.reduce(into: [] as Set<SDK>) {
guard let value = $1 else { return }
$0.formUnion([SDK(name: value.0, simulatorHeuristic: value.2)])
}

}

public static func associatedSetOfKnownIn2023YearSDKs(_ argumentSubstring: String) -> Set<SDK> {
return associatedSetOfKnownSDKs(argumentSubstring, dictionary: SDK.knownIn2023YearDictionary)
}

public static func associatedSetOfKnownIn2019YearSDKs(_ argumentSubstring: String) -> Set<SDK> {
return associatedSetOfKnownSDKs(argumentSubstring, dictionary: SDK.knownIn2019YearDictionary)
}
}

Expand All @@ -146,7 +186,7 @@ extension SDK {
.materializeResults() // to map below and ignore errors
.filterMap { try? JSONSerialization.jsonObject(with: $0.value?.value ?? Data(bytes: []), options: JSONSerialization.ReadingOptions()) as? NSArray ?? NSArray() }
.map {
$0.compactMap { (nsobject: Any) -> SDK? in
$0.compactMap { (nsobject: Any) -> SDK? in
let platform = NSString.lowercased(
(nsobject as! NSObject).value(forKey: "platform") as? NSString ?? ""
)(with: Locale?.none)
Expand Down Expand Up @@ -183,7 +223,7 @@ extension SDK {
(nsobject as! NSObject).value(forKey: "platformPath") as? NSString ?? "", count: 1
).reduce(into: String?.none) { $0 = parseTitleCasePlatform($1.appending("")) }

return SDK(name: titleCasedPlatform ?? platform, simulatorHeuristic: simulatorHeuristic)
return SDK(name: titleCasedPlatform ?? platform, simulatorHeuristic: simulatorHeuristic)
}
}
.reduce(into: Set<SDK>?.none) {
Expand Down
2 changes: 1 addition & 1 deletion Source/carthage/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public struct ArchiveCommand: CommandProtocol {
return frameworks.flatMap(.merge) { frameworks -> SignalProducer<(), CarthageError> in
// TODO: Better warning/planning for compressing up archives with non-known-in-year-2019 platforms.
// NOTE: as of current, non-known-in-year-2019 platforms are not compressed and copied by this command.
return SignalProducer<SDK, CarthageError>(SDK.knownIn2019YearSDKs)
return SignalProducer<SDK, CarthageError>(SDK.knownIn2023YearSDKs)
.flatMap(.merge) { platform -> SignalProducer<String, CarthageError> in
return SignalProducer(frameworks).map { framework in
return (platform.relativePath as NSString).appendingPathComponent(framework)
Expand Down
2 changes: 1 addition & 1 deletion Source/carthage/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ extension BuildPlatform: ArgumentProtocol {

guard set.isDisjoint(with: ["all"]) else { throw CocoaError(.keyValueValidation) /* because not solely `all` */ }

let values = try set.lazy.map(SDK.associatedSetOfKnownIn2019YearSDKs).reduce(into: [] as Set<SDK>) {
let values = try set.lazy.map(SDK.associatedSetOfKnownIn2023YearSDKs).reduce(into: [] as Set<SDK>) {
guard $1.isEmpty == false else { throw CocoaError(.keyValueValidation) }
$0.formUnion($1)
}
Expand Down

0 comments on commit 2d62055

Please sign in to comment.