Skip to content
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
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
.package(url: "https://github.com/xcodereleases/data", revision: "fcf527b187817f67c05223676341f3ab69d4214d"),
.package(url: "https://github.com/onevcat/Rainbow.git", .upToNextMinor(from: "3.2.0")),
.package(url: "https://github.com/XcodesOrg/XcodesLoginKit.git", branch: "main"),
.package(url: "https://github.com/XcodesOrg/XcodesKit.git", .upToNextMinor(from: "1.1.0"))
.package(url: "https://github.com/XcodesOrg/XcodesKit.git", .upToNextMinor(from: "1.2.0"))
],
targets: [
.executableTarget(
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ xcodes install 10.2.1
xcodes install 11 Beta 7
xcodes install 11.2 GM seed
xcodes install 9.0 --path ~/Archive/Xcode_9.xip
xcodes install 27.3 Beta --path ~/Archive/Xcode_27.3_beta.aea
xcodes install --latest-prerelease
xcodes install --latest --directory "/Volumes/Bag Of Holding/"
xcodes install --latest --experimental-unxip
```

Installing an `.aea` archive requires macOS with `archiveutil extractXcodeAEA`. If Xcode Releases has an outdated link, try installing with `--data-source apple`.

You'll then be prompted to enter your Apple ID username and password. You can also provide these with the `XCODES_USERNAME` and `XCODES_PASSWORD` environment variables.

After successfully authenticating, xcodes will save your Apple ID password into the keychain and will remember your Apple ID for future use. If you need to use a different Apple ID than the one that's remembered, set the `XCODES_USERNAME` environment variable.
Expand Down
9 changes: 7 additions & 2 deletions Sources/XcodesKit/XcodeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public final class XcodeInstaller: Sendable {
enum InstallationStep: CustomStringConvertible {
case downloading(version: String, progress: String?, willInstall: Bool)
case unarchiving(experimentalUnxip: Bool)
case extractingAEA
case moving(destination: String)
case cleaningArchive(archiveName: String, shouldDelete: Bool)
case checkingSecurity
Expand Down Expand Up @@ -118,6 +119,8 @@ public final class XcodeInstaller: Sendable {
Unarchiving Xcode (This can take a while)
\(hint)
"""
case .extractingAEA:
return "Extracting Xcode with archiveutil (This can take a while)"
case .moving(let destination):
return "Moving Xcode to \(destination)"
case .cleaningArchive(let archiveName, let shouldDelete):
Expand All @@ -135,7 +138,7 @@ public final class XcodeInstaller: Sendable {
var stepNumber: Int {
switch self {
case .downloading: return 1
case .unarchiving: return 2
case .unarchiving, .extractingAEA: return 2
case .moving: return 3
case .cleaningArchive: return 4
case .checkingSecurity: return 5
Expand Down Expand Up @@ -421,7 +424,9 @@ public final class XcodeInstaller: Sendable {
) { step in
switch step {
case .unarchive(.unarchiving):
Current.logging.log(InstallationStep.unarchiving(experimentalUnxip: experimentalUnxip).description)
let installationStep: InstallationStep = archiveURL.pathExtension.lowercased() == "aea"
? .extractingAEA : .unarchiving(experimentalUnxip: experimentalUnxip)
Current.logging.log(installationStep.description)
case let .unarchive(.moving(destination)):
Current.logging.log(InstallationStep.moving(destination: destination).description)
case let .cleaningArchive(archiveName):
Expand Down
10 changes: 5 additions & 5 deletions Sources/xcodes/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct Xcodes: AsyncParsableCommand {
let versionString = version.joined(separator: " ")

let installation: XcodeInstaller.InstallationType
// Deliberately not using InstallationType.path here as it doesn't make sense to download an Xcode from a .xip that's already on disk
// A local archive is already downloaded.
if latest {
installation = .latest
} else if latestPrerelease {
Expand Down Expand Up @@ -214,8 +214,8 @@ struct Xcodes: AsyncParsableCommand {
var version: [String] = []

@Option(name: .customLong("path"),
help: "Local path to Xcode .xip",
completion: .file(extensions: ["xip"]))
help: "Local path to an Xcode .xip or .aea archive",
completion: .file(extensions: ["xip", "aea"]))
var pathString: String?

@Flag(help: "Update and then install the latest release version available.")
Expand All @@ -240,13 +240,13 @@ struct Xcodes: AsyncParsableCommand {
@ArgumentParser.Flag(name: [.customShort("p"), .customLong("print-path")], help: "Print the path of the selected Xcode")
var print: Bool = false

@Flag(help: "Use the experimental unxip functionality. May speed up unarchiving by up to 2-3x.")
@Flag(help: "Use experimental unxip for .xip archives. May speed up unarchiving by up to 2-3x.")
var experimentalUnxip: Bool = false

@Flag(help: "Don't ask for superuser (root) permission. Some optional steps of the installation will be skipped.")
var noSuperuser: Bool = false

@Flag(help: "Completely delete Xcode .xip after installation, instead of keeping it on the user's Trash.")
@Flag(help: "Permanently delete the Xcode archive after installation instead of moving it to the Trash.")
var emptyTrash: Bool = false

@Option(help: "The directory to install Xcode into. Defaults to /Applications.",
Expand Down
83 changes: 83 additions & 0 deletions Tests/XcodesKitTests/XcodesKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,89 @@ final class XcodesKitTests: XCTestCase {
XCTAssertEqual(info.bundleIdentifier, "com.apple.dt.Xcode")
}

func test_InstallDownloadedAEAUsingAria2() async throws {
let environment = ProcessInfo.processInfo.environment
guard let aria2 = environment["XCODES_ARCHIVE_SMOKE_ARIA2"].flatMap(Path.init) else {
throw XCTSkip("Set XCODES_ARCHIVE_SMOKE_ARIA2 to the aria2c executable for this smoke test.")
}
try await installFromArchiveSmokeServer(
format: "aea", downloader: .aria2(aria2), experimentalUnxip: true
)
}

func test_InstallDownloadedXIPUsingURLSession() async throws {
try await installFromArchiveSmokeServer(
format: "xip", downloader: .urlSession, experimentalUnxip: false
)
}

private func installFromArchiveSmokeServer(
format: String, downloader: Downloader, experimentalUnxip: Bool
) async throws {
let environment = ProcessInfo.processInfo.environment
guard let server = environment["XCODES_ARCHIVE_SMOKE_URL"].flatMap(URL.init(string:)),
server.scheme == "http", server.host == "127.0.0.1",
let home = environment["XCODES_ARCHIVE_SMOKE_HOME"].flatMap(Path.init),
home == Path.environmentHome, home.basename().hasPrefix("xcodes-cli-smoke.") else {
throw XCTSkip("Set XCODES_ARCHIVE_SMOKE_URL to the loopback fixture server and HOME and XCODES_ARCHIVE_SMOKE_HOME to a temporary xcodes-cli-smoke.* directory.")
}
let url = server.appendingPathComponent("cli/Xcode_27.3_beta.\(format)")
let version = try XCTUnwrap(Version("27.3.0-Beta"))
let destination = home/"Installed-\(format)"
let archive = Path.xcodesApplicationSupport/"Xcode-\(version).\(format)"
try FileManager.default.createDirectory(at: destination.url, withIntermediateDirectories: true)
try FileManager.default.createDirectory(at: Path.xcodesApplicationSupport.url, withIntermediateDirectories: true)
XCTAssertFalse(FileManager.default.fileExists(atPath: archive.string))

let metadata = Data("""
[{
"name": "Xcode",
"version": {"number": "27.3", "release": {"beta": 1}},
"date": {"year": 2026, "month": 11, "day": 3},
"requires": "15.0",
"links": {"download": {"url": "\(url.absoluteString)"}}
}]
""".utf8)
Current.files = Files()
Current.network = Network(
session: URLSession(configuration: .ephemeral),
loadData: { request in
let requestURL = try XCTUnwrap(request.url)
let data = requestURL == URLRequest.xcodeReleasesData.url ? metadata : Data()
return (data, try XCTUnwrap(HTTPURLResponse(url: requestURL, statusCode: 200, httpVersion: nil, headerFields: nil)))
},
validateSession: {}
)
Current.shell.spctlAssess = XcodesShell().spctlAssess
Current.shell.codesignVerify = XcodesShell().codesignVerify
if url.pathExtension == "xip" {
Current.shell.unxip = XcodesShell().unxip
} else {
Current.shell.unxip = { _ in throw XcodesKitError("AEA must bypass xip") }
}
Current.shell.isatty = { false }
let list = XcodeList()
// Both fixtures report the same version, so replace any cached URL from the other format.
_ = try await list.updateAvailableXcodes(dataSource: .xcodeReleases)
let installer = XcodeInstaller(xcodeList: list, sessionService: AppleSessionService(configuration: Configuration()))
let expectedApp = destination/"Xcode-\(version.descriptionWithoutBuildMetadata).app"
let expectDamagedXIP = url.pathExtension == "xip" && environment["XCODES_ARCHIVE_SMOKE_EXPECT_DAMAGED_XIP"] == "1"
do {
let installed = try await installer.install(
.version("27.3 Beta"), dataSource: .xcodeReleases, downloader: downloader,
destination: destination, experimentalUnxip: experimentalUnxip, emptyTrash: true, noSuperuser: true
)
XCTAssertFalse(expectDamagedXIP, "Expected the damaged XIP to be rejected")
XCTAssertEqual(installed.path, expectedApp)
XCTAssertEqual(installed.version.buildMetadataIdentifiers, ["27C5020n"])
XCTAssertFalse(FileManager.default.fileExists(atPath: archive.string))
} catch let error as XcodeInstaller.Error {
guard expectDamagedXIP, case let .damagedXIP(rejectedArchive) = error else { throw error }
XCTAssertEqual(rejectedArchive.path, archive.string)
XCTAssertFalse(FileManager.default.fileExists(atPath: expectedApp.string))
}
}

func test_DownloadOrUseExistingArchive_ReturnsExistingArchive() async throws {
Current.files.fileExistsAtPath = { _ in return true }
let xcodeDownloadURL = LockedBox<URL?>(nil)
Expand Down
Loading