Skip to content

Commit

Permalink
infer url for Xcode 16+ runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomato committed Jun 15, 2024
1 parent aa795f8 commit 1f6a32a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
14 changes: 13 additions & 1 deletion Sources/XcodesKit/Models+Runtimes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct DownloadableRuntimesResponse: Decodable {
public struct DownloadableRuntime: Decodable {
let category: Category
let simulatorVersion: SimulatorVersion
let source: String
let source: String?
let dictionaryVersion: Int
let contentType: ContentType
let platform: Platform
Expand All @@ -36,6 +36,17 @@ public struct DownloadableRuntime: Decodable {
var visibleIdentifier: String {
return platform.shortName + " " + completeVersion
}

var sourceURL: URL {
source.flatMap(URL.init) ?? makeRuntimeURL(runtimeName: name)
}
}

let xcodeRuntimesFallbackURL = URL(string: "https://download.developer.apple.com/Developer_Tools/")!

func makeRuntimeURL(runtimeName: String) -> URL {
let baseName = runtimeName.replacingOccurrences(of: ".0 ", with: " ").replacingOccurrences(of: " ", with: "_")
return xcodeRuntimesFallbackURL.appendingPathComponent("\(baseName)/\(baseName).dmg")
}

func makeVersion(for osVersion: String, betaNumber: Int?) -> String {
Expand Down Expand Up @@ -79,6 +90,7 @@ extension DownloadableRuntime {
enum ContentType: String, Decodable {
case diskImage = "diskImage"
case package = "package"
case cryptexDiskImage = "cryptexDiskImage"
}

enum Platform: String, Decodable {
Expand Down
8 changes: 3 additions & 5 deletions Sources/XcodesKit/RuntimeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class RuntimeInstaller {
switch matchedRuntime.contentType {
case .package:
try await installFromPackage(dmgUrl: dmgUrl, runtime: matchedRuntime)
case .diskImage:
case .diskImage, .cryptexDiskImage:
try await installFromImage(dmgUrl: dmgUrl)
}
if shouldDelete {
Expand Down Expand Up @@ -183,7 +183,7 @@ public class RuntimeInstaller {

@MainActor
public func downloadOrUseExistingArchive(runtime: DownloadableRuntime, to destinationDirectory: Path, downloader: Downloader) async throws -> URL {
let url = URL(string: runtime.source)!
let url = runtime.sourceURL
let destination = destinationDirectory/url.lastPathComponent
let aria2DownloadMetadataPath = destination.parent/(destination.basename() + ".aria2")
var aria2DownloadIsIncomplete = false
Expand All @@ -202,9 +202,7 @@ public class RuntimeInstaller {
Current.logging.log("Found existing Runtime that will be used, at \(destination).")
return destination.url
}
if runtime.authentication == .virtual {
try await sessionService.validateADCSession(path: url.path).async()
}
try await sessionService.validateADCSession(path: url.path).async()
let formatter = NumberFormatter(numberStyle: .percent)
var observation: NSKeyValueObservation?
let result = try await downloader.download(url: url, to: destination, progressChanged: { progress in
Expand Down
6 changes: 3 additions & 3 deletions Tests/XcodesKitTests/RuntimeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ final class RuntimeTests: XCTestCase {
}

let url = try await runtimeInstaller.downloadOrUseExistingArchive(runtime: runtime, to: .xcodesCaches, downloader: .urlSession)
let fileName = URL(string: runtime.source)!.lastPathComponent
let fileName = runtime.sourceURL.lastPathComponent
XCTAssertEqual(url, Path.xcodesCaches.join(fileName).url)
XCTAssertNil(xcodeDownloadURL)
}
Expand All @@ -185,10 +185,10 @@ final class RuntimeTests: XCTestCase {
return (Progress(), Promise.value((destination, HTTPURLResponse(url: url.pmkRequest.url!, statusCode: 200, httpVersion: nil, headerFields: nil)!)))
}
let runtime = try await runtimeList.downloadableRuntimes().downloadables.first { $0.visibleIdentifier == "iOS 15.5" }!
let fileName = URL(string: runtime.source)!.lastPathComponent
let fileName = runtime.sourceURL.lastPathComponent
let url = try await runtimeInstaller.downloadOrUseExistingArchive(runtime: runtime, to: .xcodesCaches, downloader: .urlSession)
XCTAssertEqual(url, Path.xcodesCaches.join(fileName).url)
XCTAssertEqual(xcodeDownloadURL, URL(string: runtime.source)!)
XCTAssertEqual(xcodeDownloadURL, runtime.sourceURL)
}

func test_installStepsForPackage() async throws {
Expand Down

0 comments on commit 1f6a32a

Please sign in to comment.