Skip to content

Commit ceae881

Browse files
committed
show installed xcodes specific with architectures
1 parent debc41f commit ceae881

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

Xcodes/Backend/AppState.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,11 @@ class AppState: ObservableObject {
894894
}
895895
.map { availableXcode -> Xcode in
896896
let installedXcode = installedXcodes.first(where: { installedXcode in
897-
availableXcode.version.isEquivalent(to: installedXcode.version)
897+
if availableXcode.architectures == nil {
898+
return availableXcode.version.isEquivalent(to: installedXcode.version)
899+
} else {
900+
return availableXcode.xcodeID == installedXcode.xcodeID
901+
}
898902
})
899903

900904
let identicalBuilds: [XcodeID]
@@ -913,7 +917,7 @@ class AppState: ObservableObject {
913917
}
914918

915919
// If the existing install state is "installing", keep it
916-
let existingXcodeInstallState = allXcodes.first { $0.version == availableXcode.version && $0.installState.installing }?.installState
920+
let existingXcodeInstallState = allXcodes.first { $0.id == availableXcode.xcodeID && $0.installState.installing }?.installState
917921
// Otherwise, determine it from whether there's an installed Xcode
918922
let defaultXcodeInstallState: XcodeInstallState = installedXcode.map { .installed($0.path) } ?? .notInstalled
919923

Xcodes/Backend/InstalledXcode.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import Version
33
import Path
4+
import XcodesKit
45

56
/// A version of Xcode that's already installed
67
public struct InstalledXcode: Equatable {
@@ -36,16 +37,20 @@ public struct InstalledXcode: Equatable {
3637
prereleaseIdentifiers = ["beta"]
3738
}
3839

39-
// need:
40-
// lipo -archs /Applications/Xcode-26.0.0-Beta.3.app/Contents/MacOS/Xcode
41-
40+
let archsString = try? XcodesKit.Current.shell.archs(path.url.appending(path: "Contents/MacOS/Xcode")).out
41+
42+
let architectures = archsString?
43+
.trimmingCharacters(in: .whitespacesAndNewlines)
44+
.split(separator: " ")
45+
.compactMap { Architecture(rawValue: String($0)) }
46+
4247
let version = Version(major: bundleVersion.major,
4348
minor: bundleVersion.minor,
4449
patch: bundleVersion.patch,
4550
prereleaseIdentifiers: prereleaseIdentifiers,
4651
buildMetadataIdentifiers: [versionPlist.productBuildVersion].compactMap { $0 })
4752

48-
self.xcodeID = XcodeID(version: version, architectures: nil)
53+
self.xcodeID = XcodeID(version: version, architectures: architectures)
4954
}
5055
}
5156

Xcodes/Backend/Xcode.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,6 @@ public struct XcodeID: Codable, Hashable, Identifiable {
1717
self.version = version
1818
self.architectures = architectures
1919
}
20-
21-
public var architectureString: String {
22-
switch architectures {
23-
case .some(let architectures):
24-
if architectures.isAppleSilicon {
25-
return "Apple Silicon"
26-
} else {
27-
return "Universal"
28-
}
29-
default: return "Universal"
30-
}
31-
}
3220
}
3321

3422
struct Xcode: Identifiable, CustomStringConvertible {

Xcodes/XcodesKit/Sources/XcodesKit/Shell/Process.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ public typealias ProcessOutput = (status: Int32, out: String, err: String)
66

77
extension Process {
88
static func run(_ executable: Path, workingDirectory: URL? = nil, input: String? = nil, _ arguments: String...) async throws -> ProcessOutput {
9-
return try await run(executable.url, workingDirectory: workingDirectory, input: input, arguments)
9+
return try run(executable.url, workingDirectory: workingDirectory, input: input, arguments)
1010
}
1111

12-
static func run(_ executable: URL, workingDirectory: URL? = nil, input: String? = nil, _ arguments: [String]) async throws -> ProcessOutput {
12+
static func run(_ executable: Path, workingDirectory: URL? = nil, input: String? = nil, _ arguments: String...) throws -> ProcessOutput {
13+
return try run(executable.url, workingDirectory: workingDirectory, input: input, arguments)
14+
}
15+
16+
static func run(_ executable: URL, workingDirectory: URL? = nil, input: String? = nil, _ arguments: [String]) throws -> ProcessOutput {
1317

1418
let process = Process()
1519
process.currentDirectoryURL = workingDirectory ?? executable.deletingLastPathComponent()

Xcodes/XcodesKit/Sources/XcodesKit/Shell/XcodesShell.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ public struct XcodesShell {
2626
public var deleteRuntime: (String) async throws -> ProcessOutput = {
2727
try await Process.run(Path.root.usr.bin.join("xcrun"), "simctl", "runtime", "delete", $0)
2828
}
29+
30+
public var archs: (URL) throws -> ProcessOutput = {
31+
try Process.run(Path.root.usr.bin.join("lipo"), "-archs", $0.path)
32+
}
2933
}

0 commit comments

Comments
 (0)