@@ -34,14 +34,12 @@ extension FileManager {
34
34
try createDirectory ( at: temporaryDirectory, withIntermediateDirectories: false )
35
35
defer {
36
36
// Best effort cleanup.
37
- do {
38
- if cleanup {
39
- try removeItem ( at: temporaryDirectory)
40
- logger. info ( " Removed temporary directory " )
41
- } else {
42
- logger. info ( " Keeping temporary directory " )
43
- }
44
- } catch { }
37
+ if cleanup {
38
+ try ? removeItem ( at: temporaryDirectory)
39
+ logger. info ( " Removed temporary directory " )
40
+ } else {
41
+ logger. info ( " Keeping temporary directory " )
42
+ }
45
43
}
46
44
47
45
logger. info ( " Created temporary directory " )
@@ -58,7 +56,7 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
58
56
logger [ metadataKey: " runArguments " ] = " \" \( runArguments) \" "
59
57
logger [ metadataKey: " scratchPath " ] = " \( scratchPath) "
60
58
61
- logger. info ( " Building SDK " )
59
+ logger. info ( " Building Swift SDK " )
62
60
63
61
var packageDirectory = FilePath ( #filePath)
64
62
packageDirectory. removeLastComponent ( )
@@ -67,7 +65,7 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
67
65
let generatorOutput = try await Shell . readStdout (
68
66
" cd \( packageDirectory) && swift run --scratch-path \" \( scratchPath) \" swift-sdk-generator make-linux-sdk \( runArguments) "
69
67
)
70
- logger. info ( " Finished building SDK " )
68
+ logger. info ( " Finished building Swift SDK " )
71
69
72
70
let installCommand = try XCTUnwrap ( generatorOutput. split ( separator: " \n " ) . first {
73
71
$0. contains ( " swift experimental-sdk install " )
@@ -78,16 +76,16 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
78
76
) . stem
79
77
logger [ metadataKey: " bundleName " ] = " \( bundleName) "
80
78
81
- logger. info ( " Checking installed SDKs " )
79
+ logger. info ( " Checking installed Swift SDKs " )
82
80
let installedSDKs = try await Shell . readStdout ( " swift experimental-sdk list " ) . components ( separatedBy: " \n " )
83
81
84
82
// Make sure this bundle hasn't been installed already.
85
83
if installedSDKs. contains ( bundleName) {
86
- logger. info ( " Removing existing SDK " )
84
+ logger. info ( " Removing existing Swift SDK " )
87
85
try await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
88
86
}
89
87
90
- logger. info ( " Installing new SDK " )
88
+ logger. info ( " Installing new Swift SDK " )
91
89
let installOutput = try await Shell . readStdout ( String ( installCommand) )
92
90
XCTAssertTrue ( installOutput. contains ( " successfully installed " ) )
93
91
@@ -154,15 +152,25 @@ struct SDKConfiguration {
154
152
var linuxDistributionVersion : String
155
153
var architecture : String
156
154
var withDocker : Bool
155
+ var containerImageSuffix : String ?
157
156
158
- var bundleName : String { " \( linuxDistributionName) _ \( linuxDistributionVersion) _ \( architecture) _ \( swiftVersion) -RELEASE \( withDocker ? " _with-docker " : " " ) " }
157
+ var bundleName : String {
158
+ let sdkPrefix = containerImageSuffix ?? " \( linuxDistributionName) _ \( linuxDistributionVersion) "
159
+ return " \( sdkPrefix) _ \( architecture) _ \( swiftVersion) -RELEASE \( withDocker ? " _with-docker " : " " ) "
160
+ }
159
161
160
162
func withDocker( _ enabled: Bool = true ) -> SDKConfiguration {
161
163
var res = self
162
164
res. withDocker = enabled
163
165
return res
164
166
}
165
167
168
+ func withContainerImageSuffix( _ containerImageSuffix: String ) -> SDKConfiguration {
169
+ var res = self
170
+ res. containerImageSuffix = containerImageSuffix
171
+ return res
172
+ }
173
+
166
174
func withArchitecture( _ arch: String ) -> SDKConfiguration {
167
175
var res = self
168
176
res. architecture = arch
@@ -175,14 +183,22 @@ struct SDKConfiguration {
175
183
}
176
184
177
185
var sdkGeneratorArguments : String {
186
+ // Build the container image tag
187
+ var containerImage : String ? = nil
188
+ if let containerImageSuffix {
189
+ containerImage = " swift: \( swiftVersion) - \( containerImageSuffix) "
190
+ }
191
+
178
192
return [
179
193
" --sdk-name \( bundleName) " ,
180
194
" --host-toolchain " ,
181
195
withDocker ? " --with-docker " : nil ,
196
+ containerImage != nil ? " --from-container-image " : nil , containerImage,
182
197
" --swift-version \( swiftVersion) -RELEASE " ,
183
198
testLinuxSwiftSDKs ? " --host \( hostArch!) -unknown-linux-gnu " : nil ,
184
199
" --target \( architecture) -unknown-linux-gnu " ,
185
- " --linux-distribution-name \( linuxDistributionName) "
200
+ " --linux-distribution-name \( linuxDistributionName) " ,
201
+ " --linux-distribution-version \( linuxDistributionVersion) "
186
202
] . compactMap { $0 } . joined ( separator: " " )
187
203
}
188
204
}
@@ -273,6 +289,8 @@ func buildTestcase(_ logger: Logger, testcase: String, bundleName: String, tempD
273
289
}
274
290
275
291
func buildTestcases( config: SDKConfiguration ) async throws {
292
+ try skipSlow ( )
293
+
276
294
var logger = Logger ( label: " EndToEndTests " )
277
295
logger [ metadataKey: " testcase " ] = " testPackageInitExecutable "
278
296
@@ -292,17 +310,26 @@ func buildTestcases(config: SDKConfiguration) async throws {
292
310
try await buildSDK ( logger, scratchPath: tempDir. path, withArguments: config. sdkGeneratorArguments)
293
311
}
294
312
295
- logger. info ( " Built SDK " )
313
+ logger. info ( " Built Swift SDK " )
314
+
315
+ // Cleanup
316
+ let cleanupSdk : ( ) async -> Void = {
317
+ logger. info ( " Removing Swift SDK to cleanup... " )
318
+ try ? await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
319
+ }
296
320
297
321
for testcase in testcases {
298
- try await FileManager . default. withTemporaryDirectory ( logger: logger) { tempDir in
299
- try await buildTestcase ( logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir)
322
+ do {
323
+ try await FileManager . default. withTemporaryDirectory ( logger: logger) { tempDir in
324
+ try await buildTestcase ( logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir)
325
+ }
326
+ } catch {
327
+ await cleanupSdk ( )
328
+ throw error
300
329
}
301
330
}
302
331
303
- // Cleanup
304
- logger. info ( " Removing SDK to cleanup... " )
305
- try await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
332
+ await cleanupSdk ( )
306
333
}
307
334
308
335
final class Swift59_UbuntuEndToEndTests : XCTestCase {
@@ -315,22 +342,18 @@ final class Swift59_UbuntuEndToEndTests: XCTestCase {
315
342
)
316
343
317
344
func testAarch64Direct( ) async throws {
318
- try skipSlow ( )
319
345
try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
320
346
}
321
347
322
348
func testX86_64Direct( ) async throws {
323
- try skipSlow ( )
324
349
try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
325
350
}
326
351
327
352
func testAarch64FromContainer( ) async throws {
328
- try skipSlow ( )
329
353
try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
330
354
}
331
355
332
356
func testX86_64FromContainer( ) async throws {
333
- try skipSlow ( )
334
357
try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
335
358
}
336
359
}
@@ -345,22 +368,18 @@ final class Swift510_UbuntuEndToEndTests: XCTestCase {
345
368
)
346
369
347
370
func testAarch64Direct( ) async throws {
348
- try skipSlow ( )
349
371
try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
350
372
}
351
373
352
374
func testX86_64Direct( ) async throws {
353
- try skipSlow ( )
354
375
try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
355
376
}
356
377
357
378
func testAarch64FromContainer( ) async throws {
358
- try skipSlow ( )
359
379
try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
360
380
}
361
381
362
382
func testX86_64FromContainer( ) async throws {
363
- try skipSlow ( )
364
383
try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
365
384
}
366
385
}
@@ -375,22 +394,18 @@ final class Swift60_UbuntuEndToEndTests: XCTestCase {
375
394
)
376
395
377
396
func testAarch64Direct( ) async throws {
378
- try skipSlow ( )
379
397
try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
380
398
}
381
399
382
400
func testX86_64Direct( ) async throws {
383
- try skipSlow ( )
384
401
try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
385
402
}
386
403
387
404
func testAarch64FromContainer( ) async throws {
388
- try skipSlow ( )
389
405
try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
390
406
}
391
407
392
408
func testX86_64FromContainer( ) async throws {
393
- try skipSlow ( )
394
409
try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
395
410
}
396
411
}
@@ -405,13 +420,19 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
405
420
)
406
421
407
422
func testAarch64FromContainer( ) async throws {
408
- try skipSlow ( )
409
- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
423
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
410
424
}
411
425
412
426
func testX86_64FromContainer( ) async throws {
413
- try skipSlow ( )
414
- try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
427
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
428
+ }
429
+
430
+ func testAmazonLinux2Aarch64FromContainer( ) async throws {
431
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
432
+ }
433
+
434
+ func testAmazonLinux2X86_64FromContainer( ) async throws {
435
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
415
436
}
416
437
}
417
438
@@ -425,13 +446,27 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
425
446
)
426
447
427
448
func testAarch64FromContainer( ) async throws {
428
- try skipSlow ( )
429
- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
449
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
430
450
}
431
451
432
452
func testX86_64FromContainer( ) async throws {
433
- try skipSlow ( )
434
- try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
453
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
454
+ }
455
+
456
+ func testAmazonLinux2Aarch64FromContainer( ) async throws {
457
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
458
+ }
459
+
460
+ func testAmazonLinux2X86_64FromContainer( ) async throws {
461
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
462
+ }
463
+
464
+ func testFedora39Aarch64FromContainer( ) async throws {
465
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " fedora39 " ) )
466
+ }
467
+
468
+ func testFedora39X86_64FromContainer( ) async throws {
469
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " fedora39 " ) )
435
470
}
436
471
}
437
472
@@ -445,12 +480,26 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
445
480
)
446
481
447
482
func testAarch64FromContainer( ) async throws {
448
- try skipSlow ( )
449
- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
483
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
450
484
}
451
485
452
486
func testX86_64FromContainer( ) async throws {
453
- try skipSlow ( )
454
- try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
487
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
488
+ }
489
+
490
+ func testAmazonLinux2Aarch64FromContainer( ) async throws {
491
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
492
+ }
493
+
494
+ func testAmazonLinux2X86_64FromContainer( ) async throws {
495
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
496
+ }
497
+
498
+ func testFedora39Aarch64FromContainer( ) async throws {
499
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " fedora39 " ) )
500
+ }
501
+
502
+ func testFedora39X86_64FromContainer( ) async throws {
503
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " fedora39 " ) )
455
504
}
456
505
}
0 commit comments