Skip to content

Commit dce4d12

Browse files
committed
Move discoveredLdLinkerSpecInfo_Windows to platform tests.
* Move discoveredLdLinkerSpecInfo_Windows to the windows platform tests. * Use the helper functions to make linker tests conditional on the presence of specific host SDK components.
1 parent c872bc6 commit dce4d12

File tree

3 files changed

+75
-57
lines changed

3 files changed

+75
-57
lines changed

Sources/SWBWindowsPlatform/Plugin.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ struct WindowsPlatformSpecsExtension: SpecificationsExtension {
7373
}
7474

7575
@_spi(Testing)public func findLatestInstallDirectory(fs: any FSProxy) async throws -> Path? {
76-
let plugin: WindowsPlugin
77-
let installations = try await plugin.cachedVSInstallations()
78-
.sorted(by: { $0.installationVersion > $1.installationVersion })
79-
if let latest = installations.first {
80-
let msvcDir = latest.installationPath.join("VC").join("Tools").join("MSVC")
81-
if fs.exists(msvcDir) {
82-
let versions = try fs.listdir(msvcDir).map { try Version($0) }.sorted { $0 > $1 }
83-
if let latestVersion = versions.first {
84-
return msvcDir.join(latestVersion.description)
76+
let installations = try await plugin.cachedVSInstallations()
77+
.sorted(by: { $0.installationVersion > $1.installationVersion })
78+
if let latest = installations.first {
79+
let msvcDir = latest.installationPath.join("VC").join("Tools").join("MSVC")
80+
if fs.exists(msvcDir) {
81+
let versions = try fs.listdir(msvcDir).map { try Version($0) }.sorted { $0 > $1 }
82+
if let latestVersion = versions.first {
83+
return msvcDir.join(latestVersion.description)
84+
}
8585
}
8686
}
87+
return nil
8788
}
88-
return nil
8989
}
9090

9191
struct WindowsPlatformExtension: PlatformInfoExtension {

Tests/SWBCoreTests/CommandLineToolSpecDiscoveredInfoTests.swift

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -234,53 +234,6 @@ import SWBMacro
234234
}
235235
}
236236

237-
@Test(.requireSDKs(.windows))
238-
func discoveredLdLinkerSpecInfo_Windows() async throws {
239-
var table = try await ldMacroTable()
240-
table.push(BuiltinMacros._LD_MULTIARCH, literal: true)
241-
try await withSpec(LdLinkerSpec.self, .deferred, platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
242-
#expect(!info.toolPath.isEmpty)
243-
#expect(info.toolVersion != nil)
244-
if let toolVersion = info.toolVersion {
245-
#expect(toolVersion > Version(0, 0, 0))
246-
}
247-
#expect(info.linker == .lld)
248-
}
249-
try await withSpec(LdLinkerSpec.self, .result(status: .exit(0), stdout: Data("Microsoft (R) Incremental Linker Version 14.41.34120.0\n".utf8), stderr: Data()), platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
250-
#expect(!info.toolPath.isEmpty)
251-
#expect(info.toolVersion == Version(14, 41, 34120))
252-
#expect(info.architectures == Set())
253-
}
254-
255-
// link.exe cannot be used for multipler architectures and requires a distinct link.exe for each target architecture
256-
table.push(BuiltinMacros.ALTERNATE_LINKER, literal: "link")
257-
table.push(BuiltinMacros._LD_MULTIARCH, literal: false)
258-
table.push(BuiltinMacros._LD_MULTIARCH_PREFIX_MAP, literal: ["x86_64:x64", "aarch64:arm64", "i386:x86", "thumbv7:arm"])
259-
260-
// x86_64
261-
table.push(BuiltinMacros.ARCHS, literal: ["x86_64"])
262-
try await withSpec(LdLinkerSpec.self, .deferred, platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
263-
#expect(!info.toolPath.isEmpty)
264-
#expect(info.toolVersion != nil)
265-
if let toolVersion = info.toolVersion {
266-
#expect(toolVersion > Version(0, 0, 0))
267-
}
268-
#expect(info.linker == .linkExe)
269-
}
270-
271-
// FIXME: Fails in swift-ci missing arm64 toolchain on x86_64 host.
272-
// // link aarch64
273-
// table.push(BuiltinMacros.ARCHS, literal: ["aarch64"])
274-
// try await withSpec(LdLinkerSpec.self, .deferred, platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
275-
// #expect(!info.toolPath.isEmpty)
276-
// #expect(info.toolVersion != nil)
277-
// if let toolVersion = info.toolVersion {
278-
// #expect(toolVersion > Version(0, 0, 0))
279-
// }
280-
// #expect(info.linker == .linkExe)
281-
// }
282-
}
283-
284237
@Test(.skipHostOS(.windows), .requireSystemPackages(apt: "libtool", yum: "libtool"))
285238
func discoveredLibtoolSpecInfo() async throws {
286239
try await withSpec(LibtoolLinkerSpec.self, .deferred) { (info: DiscoveredLibtoolLinkerToolSpecInfo) in

Tests/SWBWindowsPlatformTests/SWBWindowsPlatformTests.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,69 @@
99
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12+
import Foundation
13+
@_spi(Testing) import SWBCore
14+
import SWBProtocol
15+
import SWBTestSupport
16+
import SWBUtil
17+
import Testing
18+
import SWBMacro
1219

20+
@Suite fileprivate struct CommandLineToolSpecDiscoveredInfoTests: CoreBasedTests {
21+
// Linker tool discovery is a bit more complex as it afffected by the ALTERNATE_LINKER build setting.
22+
func ldMacroTable() async throws -> MacroValueAssignmentTable {
23+
let core = try await getCore()
24+
return MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
25+
}
26+
27+
@Test(.requireSDKs(.windows))
28+
func discoveredLdLinkerSpecInfo_Windows() async throws {
29+
var table = try await ldMacroTable()
30+
let core = try await getCore()
31+
table.push(BuiltinMacros._LD_MULTIARCH, literal: true)
32+
try await withSpec(LdLinkerSpec.self, .deferred, platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
33+
#expect(!info.toolPath.isEmpty)
34+
#expect(info.toolVersion != nil)
35+
if let toolVersion = info.toolVersion {
36+
#expect(toolVersion > Version(0, 0, 0))
37+
}
38+
#expect(info.linker == .lld)
39+
}
40+
try await withSpec(LdLinkerSpec.self, .result(status: .exit(0), stdout: Data("Microsoft (R) Incremental Linker Version 14.41.34120.0\n".utf8), stderr: Data()), platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
41+
#expect(!info.toolPath.isEmpty)
42+
#expect(info.toolVersion == Version(14, 41, 34120))
43+
#expect(info.architectures == Set())
44+
}
45+
46+
// link.exe cannot be used for multipler architectures and requires a distinct link.exe for each target architecture
47+
table.push(BuiltinMacros.ALTERNATE_LINKER, literal: "link")
48+
table.push(BuiltinMacros._LD_MULTIARCH, literal: false)
49+
table.push(BuiltinMacros._LD_MULTIARCH_PREFIX_MAP, literal: ["x86_64:x64", "aarch64:arm64", "i386:x86", "thumbv7:arm"])
50+
51+
// x86_64
52+
if try await core.hasVisualStudioComponent(.visualCppBuildTools_x86_x64) {
53+
table.push(BuiltinMacros.ARCHS, literal: ["x86_64"])
54+
try await withSpec(LdLinkerSpec.self, .deferred, platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
55+
#expect(!info.toolPath.isEmpty)
56+
#expect(info.toolVersion != nil)
57+
if let toolVersion = info.toolVersion {
58+
#expect(toolVersion > Version(0, 0, 0))
59+
}
60+
#expect(info.linker == .linkExe)
61+
}
62+
}
63+
64+
// link aarch64
65+
if try await core.hasVisualStudioComponent(.visualCppBuildTools_arm64) {
66+
table.push(BuiltinMacros.ARCHS, literal: ["aarch64"])
67+
try await withSpec(LdLinkerSpec.self, .deferred, platform: "windows", additionalTable: table) { (info: DiscoveredLdLinkerToolSpecInfo) in
68+
#expect(!info.toolPath.isEmpty)
69+
#expect(info.toolVersion != nil)
70+
if let toolVersion = info.toolVersion {
71+
#expect(toolVersion > Version(0, 0, 0))
72+
}
73+
#expect(info.linker == .linkExe)
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)