Skip to content

Commit 4bc76e0

Browse files
authored
Use swiftCompilerTag for the swift compiler version (#8959)
The swiftCompilerTag field has been recently added to the swiftc -print-target-info JSON we use to determine the swift compiler version for prebuilts. Use this field as the default value, falling back to extracting the swift compiler version from the compilerVersion field using a regex. This gives us much better version numbers since it matches the tags for the toolchain. Also add in the redirect url, https://github.com/apple/swift-syntax.git, as a supported option.
1 parent f19d08c commit 4bc76e0

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

Sources/PackageModel/UserToolchain.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ public final class UserToolchain: Toolchain {
228228
}
229229

230230
private static func computeSwiftCompilerVersion(targetInfo: JSON) -> String? {
231-
// Get the compiler version from the target info
231+
// Use the new swiftCompilerTag if it's there
232+
if let swiftCompilerTag: String = targetInfo.get("swiftCompilerTag") {
233+
return swiftCompilerTag
234+
}
235+
236+
// Default to the swift portion of the compilerVersion
232237
let compilerVersion: String
233238
do {
234239
compilerVersion = try targetInfo.get("compilerVersion")

Sources/Workspace/Workspace+Prebuilts.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ extension Workspace {
221221
identity: .plain("swift-syntax"),
222222
kind: .remoteSourceControl("https://github.com/swiftlang/swift-syntax.git")
223223
),
224+
// The old site that's being redirected but still in use.
225+
.init(
226+
identity: .plain("swift-syntax"),
227+
kind: .remoteSourceControl("https://github.com/apple/swift-syntax.git")
228+
),
224229
.init(
225230
identity: .plain("swift-syntax"),
226231
kind: .remoteSourceControl("git@github.com:swiftlang/swift-syntax.git")

Tests/WorkspaceTests/PrebuiltsTests.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,67 @@ final class PrebuiltsTests: XCTestCase {
393393
}
394394
}
395395

396+
func testRedirectURL() async throws {
397+
let sandbox = AbsolutePath("/tmp/ws")
398+
let fs = InMemoryFileSystem()
399+
let artifact = Data()
400+
401+
try await with(fileSystem: fs, artifact: artifact, swiftSyntaxVersion: "600.0.1", swiftSyntaxURL: "https://github.com/apple/swift-syntax.git") {
402+
manifest, rootCertPath, rootPackage, swiftSyntax in
403+
404+
let manifestData = try JSONEncoder().encode(manifest)
405+
406+
let httpClient = HTTPClient { request, progressHandler in
407+
guard case .download(let fileSystem, let destination) = request.kind else {
408+
throw StringError("invalid request \(request.kind)")
409+
}
410+
411+
if request.url == "https://download.swift.org/prebuilts/swift-syntax/600.0.1/\(self.swiftVersion)-manifest.json" {
412+
try fileSystem.writeFileContents(destination, data: manifestData)
413+
return .okay()
414+
} else if request.url == "https://download.swift.org/prebuilts/swift-syntax/600.0.1/\(self.swiftVersion)-MacroSupport-macos_aarch64.zip" {
415+
try fileSystem.writeFileContents(destination, data: artifact)
416+
return .okay()
417+
} else {
418+
XCTFail("Unexpected URL \(request.url)")
419+
return .notFound()
420+
}
421+
}
422+
423+
let archiver = MockArchiver(handler: { _, archivePath, destination, completion in
424+
XCTAssertEqual(archivePath, sandbox.appending(components: ".build", "prebuilts", "swift-syntax", "600.0.1", "\(self.swiftVersion)-MacroSupport-macos_aarch64.zip"))
425+
XCTAssertEqual(destination, sandbox.appending(components: ".build", "prebuilts", "swift-syntax", "600.0.1", "\(self.swiftVersion)-MacroSupport-macos_aarch64"))
426+
completion(.success(()))
427+
})
428+
429+
let workspace = try await MockWorkspace(
430+
sandbox: sandbox,
431+
fileSystem: fs,
432+
roots: [
433+
rootPackage
434+
],
435+
packages: [
436+
swiftSyntax
437+
],
438+
prebuiltsManager: .init(
439+
swiftVersion: swiftVersion,
440+
httpClient: httpClient,
441+
archiver: archiver,
442+
hostPlatform: .macos_aarch64,
443+
rootCertPath: rootCertPath
444+
)
445+
)
446+
447+
try await workspace.checkPackageGraph(roots: ["Foo"]) { modulesGraph, diagnostics in
448+
XCTAssertTrue(diagnostics.filter({ $0.severity == .error }).isEmpty)
449+
let rootPackage = try XCTUnwrap(modulesGraph.rootPackages.first)
450+
try checkSettings(rootPackage, "FooMacros", usePrebuilt: true)
451+
try checkSettings(rootPackage, "FooTests", usePrebuilt: true)
452+
try checkSettings(rootPackage, "Foo", usePrebuilt: false)
453+
try checkSettings(rootPackage, "FooClient", usePrebuilt: false)
454+
}
455+
}
456+
}
396457
func testCachedArtifact() async throws {
397458
let sandbox = AbsolutePath("/tmp/ws")
398459
let fs = InMemoryFileSystem()

0 commit comments

Comments
 (0)