Skip to content

Commit 5462ab0

Browse files
Add tests for downloading Ubuntu toolchains when Debian targets are selected
1 parent f4d0922 commit 5462ab0

File tree

1 file changed

+111
-9
lines changed

1 file changed

+111
-9
lines changed

Tests/SwiftSDKGeneratorTests/SwiftSDKRecipes/LinuxRecipeTests.swift

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class LinuxRecipeTests: XCTestCase {
2020

2121
func createRecipe(
2222
hostTriple: Triple = Triple("x86_64-unknown-linux-gnu"),
23+
linuxDistribution: LinuxDistribution,
2324
swiftVersion: String = "6.0",
2425
withDocker: Bool = false,
2526
fromContainerImage: String? = nil,
@@ -30,7 +31,7 @@ final class LinuxRecipeTests: XCTestCase {
3031
try LinuxRecipe(
3132
targetTriple: Triple("aarch64-unknown-linux-gnu"),
3233
hostTriple: hostTriple,
33-
linuxDistribution: .init(name: .ubuntu, version: "22.04"),
34+
linuxDistribution: linuxDistribution,
3435
swiftVersion: swiftVersion,
3536
swiftBranch: nil, lldVersion: "",
3637
withDocker: withDocker, fromContainerImage: fromContainerImage,
@@ -73,8 +74,10 @@ final class LinuxRecipeTests: XCTestCase {
7374
),
7475
]
7576

77+
let linuxDistribution = try LinuxDistribution(name: .ubuntu, version: "22.04")
7678
for testCase in testCases {
77-
let recipe = try self.createRecipe(swiftVersion: testCase.swiftVersion)
79+
let recipe = try self.createRecipe(
80+
linuxDistribution: linuxDistribution, swiftVersion: testCase.swiftVersion)
7881
var toolset = Toolset(rootPath: nil)
7982
recipe.applyPlatformOptions(
8083
toolset: &toolset, targetTriple: testCase.targetTriple
@@ -87,7 +90,9 @@ final class LinuxRecipeTests: XCTestCase {
8790
}
8891

8992
func testToolOptionsForPreinstalledSdk() throws {
90-
let recipe = try self.createRecipe(includeHostToolchain: false)
93+
let linuxDistribution = try LinuxDistribution(name: .ubuntu, version: "22.04")
94+
let recipe = try self.createRecipe(
95+
linuxDistribution: linuxDistribution, includeHostToolchain: false)
9196
var toolset = Toolset(rootPath: "swift.xctoolchain")
9297
recipe.applyPlatformOptions(
9398
toolset: &toolset, targetTriple: Triple("x86_64-unknown-linux-gnu")
@@ -137,29 +142,33 @@ final class LinuxRecipeTests: XCTestCase {
137142

138143
func testItemsToDownloadForMacOSHost() throws {
139144
let hostTriple = Triple("x86_64-apple-macos")
145+
let linuxDistribution = try LinuxDistribution(name: .ubuntu, version: "22.04")
140146
let testCases:
141147
[(
142148
recipe: LinuxRecipe, includesHostLLVM: Bool, includesTargetSwift: Bool,
143149
includesHostSwift: Bool
144150
)] = [
145151
(
146152
// Remote tarballs on Swift < 6.0
147-
recipe: try createRecipe(hostTriple: hostTriple, swiftVersion: "5.10"),
153+
recipe: try createRecipe(
154+
hostTriple: hostTriple, linuxDistribution: linuxDistribution, swiftVersion: "5.10"),
148155
includesHostLLVM: true,
149156
includesTargetSwift: true,
150157
includesHostSwift: true
151158
),
152159
(
153160
// Remote tarballs on Swift >= 6.0
154-
recipe: try createRecipe(hostTriple: hostTriple, swiftVersion: "6.0"),
161+
recipe: try createRecipe(
162+
hostTriple: hostTriple, linuxDistribution: linuxDistribution, swiftVersion: "6.0"),
155163
includesHostLLVM: false,
156164
includesTargetSwift: true,
157165
includesHostSwift: true
158166
),
159167
(
160168
// Remote target tarball with preinstalled toolchain
161169
recipe: try createRecipe(
162-
hostTriple: hostTriple, swiftVersion: "5.9", includeHostToolchain: false),
170+
hostTriple: hostTriple, linuxDistribution: linuxDistribution, swiftVersion: "5.9",
171+
includeHostToolchain: false),
163172
includesHostLLVM: false,
164173
includesTargetSwift: true,
165174
includesHostSwift: false
@@ -168,6 +177,7 @@ final class LinuxRecipeTests: XCTestCase {
168177
// Local packages with Swift < 6.0
169178
recipe: try createRecipe(
170179
hostTriple: hostTriple,
180+
linuxDistribution: linuxDistribution,
171181
swiftVersion: "5.10",
172182
hostSwiftPackagePath: "/path/to/host/swift",
173183
targetSwiftPackagePath: "/path/to/target/swift"
@@ -180,6 +190,7 @@ final class LinuxRecipeTests: XCTestCase {
180190
// Local packages with Swift >= 6.0
181191
recipe: try createRecipe(
182192
hostTriple: hostTriple,
193+
linuxDistribution: linuxDistribution,
183194
swiftVersion: "6.0",
184195
hostSwiftPackagePath: "/path/to/host/swift",
185196
targetSwiftPackagePath: "/path/to/target/swift"
@@ -202,30 +213,35 @@ final class LinuxRecipeTests: XCTestCase {
202213

203214
func testItemsToDownloadForLinuxHost() throws {
204215
let hostTriple = Triple("x86_64-unknown-linux-gnu")
216+
let linuxDistribution = try LinuxDistribution(name: .ubuntu, version: "22.04")
205217
let testCases = [
206218
(
207219
// Remote tarballs on Swift < 6.0
208-
recipe: try createRecipe(hostTriple: hostTriple, swiftVersion: "5.10"),
220+
recipe: try createRecipe(
221+
hostTriple: hostTriple, linuxDistribution: linuxDistribution, swiftVersion: "5.10"),
209222
includesTargetSwift: true,
210223
includesHostSwift: true
211224
),
212225
(
213226
// Remote tarballs on Swift >= 6.0
214-
recipe: try createRecipe(hostTriple: hostTriple, swiftVersion: "6.0"),
227+
recipe: try createRecipe(
228+
hostTriple: hostTriple, linuxDistribution: linuxDistribution, swiftVersion: "6.0"),
215229
includesTargetSwift: true,
216230
includesHostSwift: true
217231
),
218232
(
219233
// Remote target tarball with preinstalled toolchain
220234
recipe: try createRecipe(
221-
hostTriple: hostTriple, swiftVersion: "5.9", includeHostToolchain: false),
235+
hostTriple: hostTriple, linuxDistribution: linuxDistribution, swiftVersion: "5.9",
236+
includeHostToolchain: false),
222237
includesTargetSwift: true,
223238
includesHostSwift: false
224239
),
225240
(
226241
// Local packages with Swift < 6.0
227242
recipe: try createRecipe(
228243
hostTriple: hostTriple,
244+
linuxDistribution: linuxDistribution,
229245
swiftVersion: "5.10",
230246
hostSwiftPackagePath: "/path/to/host/swift",
231247
targetSwiftPackagePath: "/path/to/target/swift"
@@ -237,6 +253,7 @@ final class LinuxRecipeTests: XCTestCase {
237253
// Local packages with Swift >= 6.0
238254
recipe: try createRecipe(
239255
hostTriple: hostTriple,
256+
linuxDistribution: linuxDistribution,
240257
swiftVersion: "6.0",
241258
hostSwiftPackagePath: "/path/to/host/swift",
242259
targetSwiftPackagePath: "/path/to/target/swift"
@@ -256,6 +273,89 @@ final class LinuxRecipeTests: XCTestCase {
256273
}
257274
}
258275

276+
// Ubuntu toolchains will be selected for Debian 11 and 12 depending on the Swift version
277+
func testItemsToDownloadForDebianTargets() throws {
278+
let hostTriple = Triple("x86_64-unknown-linux-gnu")
279+
let testCases = [
280+
(
281+
// Debian 11 -> ubuntu20.04
282+
recipe: try createRecipe(
283+
hostTriple: hostTriple,
284+
linuxDistribution: try LinuxDistribution(name: .debian, version: "11"),
285+
swiftVersion: "5.9"
286+
),
287+
expectedTargetSwift: "ubuntu20.04"
288+
),
289+
(
290+
// Debian 12 with Swift 5.9 -> ubuntu22.04
291+
recipe: try createRecipe(
292+
hostTriple: hostTriple,
293+
linuxDistribution: try LinuxDistribution(name: .debian, version: "12"),
294+
swiftVersion: "5.9"
295+
),
296+
expectedTargetSwift: "ubuntu22.04"
297+
),
298+
(
299+
// Debian 12 with Swift 5.10 -> ubuntu22.04
300+
recipe: try createRecipe(
301+
hostTriple: hostTriple,
302+
linuxDistribution: try LinuxDistribution(name: .debian, version: "12"),
303+
swiftVersion: "5.10"
304+
),
305+
expectedTargetSwift: "ubuntu22.04"
306+
),
307+
(
308+
// Debian 11 with Swift 6.0 -> ubuntu20.04
309+
recipe: try createRecipe(
310+
hostTriple: hostTriple,
311+
linuxDistribution: try LinuxDistribution(name: .debian, version: "11"),
312+
swiftVersion: "6.0"
313+
),
314+
expectedTargetSwift: "ubuntu20.04"
315+
),
316+
(
317+
// Debian 12 with Swift 5.10.1 -> debian12
318+
recipe: try createRecipe(
319+
hostTriple: hostTriple,
320+
linuxDistribution: try LinuxDistribution(name: .debian, version: "12"),
321+
swiftVersion: "5.10.1"
322+
),
323+
expectedTargetSwift: "debian12"
324+
),
325+
(
326+
// Debian 12 with Swift 6.0 -> debian12
327+
recipe: try createRecipe(
328+
hostTriple: hostTriple,
329+
linuxDistribution: try LinuxDistribution(name: .debian, version: "12"),
330+
swiftVersion: "6.0"
331+
),
332+
expectedTargetSwift: "debian12"
333+
),
334+
]
335+
336+
for testCase in testCases {
337+
338+
let pathsConfiguration = PathsConfiguration(
339+
sourceRoot: ".",
340+
artifactID: "my-sdk",
341+
targetTriple: testCase.recipe.mainTargetTriple
342+
)
343+
let downloadableArtifacts = try DownloadableArtifacts(
344+
hostTriple: testCase.recipe.mainHostTriple,
345+
targetTriple: testCase.recipe.mainTargetTriple,
346+
testCase.recipe.versionsConfiguration,
347+
pathsConfiguration
348+
)
349+
let itemsToDownload = testCase.recipe.itemsToDownload(from: downloadableArtifacts)
350+
let targetSwiftRemoteURL = itemsToDownload.first(where: {
351+
$0.remoteURL == downloadableArtifacts.targetSwift.remoteURL
352+
})?.remoteURL.absoluteString
353+
354+
// If this is a Linux host, we do not download LLVM
355+
XCTAssert(targetSwiftRemoteURL!.contains(testCase.expectedTargetSwift))
356+
}
357+
}
358+
259359
func testHostTriples() throws {
260360
let allHostTriples = [
261361
Triple("x86_64-unknown-linux-gnu"),
@@ -273,8 +373,10 @@ final class LinuxRecipeTests: XCTestCase {
273373
),
274374
]
275375

376+
let linuxDistribution = try LinuxDistribution(name: .ubuntu, version: "22.04")
276377
for testCase in testCases {
277378
let recipe = try createRecipe(
379+
linuxDistribution: linuxDistribution,
278380
swiftVersion: testCase.swiftVersion,
279381
includeHostToolchain: testCase.includeHostToolchain
280382
)

0 commit comments

Comments
 (0)