@@ -36,14 +36,12 @@ extension FileManager {
36
36
try createDirectory ( at: temporaryDirectory, withIntermediateDirectories: false )
37
37
defer {
38
38
// Best effort cleanup.
39
- do {
40
- if cleanup {
41
- try removeItem ( at: temporaryDirectory)
42
- logger. info ( " Removed temporary directory " )
43
- } else {
44
- logger. info ( " Keeping temporary directory " )
45
- }
46
- } catch { }
39
+ if cleanup {
40
+ try ? removeItem ( at: temporaryDirectory)
41
+ logger. info ( " Removed temporary directory " )
42
+ } else {
43
+ logger. info ( " Keeping temporary directory " )
44
+ }
47
45
}
48
46
49
47
logger. info ( " Created temporary directory " )
@@ -62,7 +60,7 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
62
60
logger [ metadataKey: " runArguments " ] = " \" \( runArguments) \" "
63
61
logger [ metadataKey: " scratchPath " ] = " \( scratchPath) "
64
62
65
- logger. info ( " Building SDK " )
63
+ logger. info ( " Building Swift SDK " )
66
64
67
65
var packageDirectory = FilePath ( #filePath)
68
66
packageDirectory. removeLastComponent ( )
@@ -71,7 +69,7 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
71
69
let generatorOutput = try await Shell . readStdout (
72
70
" cd \( packageDirectory) && swift run --scratch-path \" \( scratchPath) \" swift-sdk-generator make-linux-sdk \( runArguments) "
73
71
)
74
- logger. info ( " Finished building SDK " )
72
+ logger. info ( " Finished building Swift SDK " )
75
73
76
74
let installCommand = try XCTUnwrap (
77
75
generatorOutput. split ( separator: " \n " ) . first {
@@ -83,17 +81,17 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
83
81
) . stem
84
82
logger [ metadataKey: " bundleName " ] = " \( bundleName) "
85
83
86
- logger. info ( " Checking installed SDKs " )
84
+ logger. info ( " Checking installed Swift SDKs " )
87
85
let installedSDKs = try await Shell . readStdout ( " swift experimental-sdk list " ) . components (
88
86
separatedBy: " \n " )
89
87
90
88
// Make sure this bundle hasn't been installed already.
91
89
if installedSDKs. contains ( bundleName) {
92
- logger. info ( " Removing existing SDK " )
90
+ logger. info ( " Removing existing Swift SDK " )
93
91
try await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
94
92
}
95
93
96
- logger. info ( " Installing new SDK " )
94
+ logger. info ( " Installing new Swift SDK " )
97
95
let installOutput = try await Shell . readStdout ( String ( installCommand) )
98
96
XCTAssertTrue ( installOutput. contains ( " successfully installed " ) )
99
97
@@ -168,9 +166,11 @@ struct SDKConfiguration {
168
166
var linuxDistributionVersion : String
169
167
var architecture : String
170
168
var withDocker : Bool
169
+ var containerImageSuffix : String ?
171
170
172
171
var bundleName : String {
173
- " \( linuxDistributionName) _ \( linuxDistributionVersion) _ \( architecture) _ \( swiftVersion) -RELEASE \( withDocker ? " _with-docker " : " " ) "
172
+ let sdkPrefix = containerImageSuffix ?? " \( linuxDistributionName) _ \( linuxDistributionVersion) "
173
+ return " \( sdkPrefix) _ \( architecture) _ \( swiftVersion) -RELEASE \( withDocker ? " _with-docker " : " " ) "
174
174
}
175
175
176
176
func withDocker( _ enabled: Bool = true ) -> SDKConfiguration {
@@ -179,6 +179,12 @@ struct SDKConfiguration {
179
179
return res
180
180
}
181
181
182
+ func withContainerImageSuffix( _ containerImageSuffix: String ) -> SDKConfiguration {
183
+ var res = self
184
+ res. containerImageSuffix = containerImageSuffix
185
+ return res
186
+ }
187
+
182
188
func withArchitecture( _ arch: String ) -> SDKConfiguration {
183
189
var res = self
184
190
res. architecture = arch
@@ -191,14 +197,22 @@ struct SDKConfiguration {
191
197
}
192
198
193
199
var sdkGeneratorArguments : String {
200
+ // Build the container image tag
201
+ var containerImage : String ? = nil
202
+ if let containerImageSuffix {
203
+ containerImage = " swift: \( swiftVersion) - \( containerImageSuffix) "
204
+ }
205
+
194
206
return [
195
207
" --sdk-name \( bundleName) " ,
196
208
" --host-toolchain " ,
197
209
withDocker ? " --with-docker " : nil ,
210
+ containerImage != nil ? " --from-container-image " : nil , containerImage,
198
211
" --swift-version \( swiftVersion) -RELEASE " ,
199
212
testLinuxSwiftSDKs ? " --host \( hostArch!) -unknown-linux-gnu " : nil ,
200
213
" --target \( architecture) -unknown-linux-gnu " ,
201
214
" --linux-distribution-name \( linuxDistributionName) " ,
215
+ " --linux-distribution-version \( linuxDistributionVersion) " ,
202
216
] . compactMap { $0 } . joined ( separator: " " )
203
217
}
204
218
}
@@ -319,17 +333,28 @@ func buildTestcases(config: SDKConfiguration) async throws {
319
333
logger, scratchPath: tempDir. path, withArguments: config. sdkGeneratorArguments)
320
334
}
321
335
322
- logger. info ( " Built SDK " )
336
+ logger. info ( " Built Swift SDK " )
337
+
338
+ // Cleanup
339
+ func cleanupSDK( ) async {
340
+ logger. info ( " Removing Swift SDK to clean up... " )
341
+ try ? await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
342
+ }
323
343
324
344
for testcase in testcases {
325
- try await FileManager . default. withTemporaryDirectory ( logger: logger) { tempDir in
326
- try await buildTestcase ( logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir)
345
+ do {
346
+ try await FileManager . default. withTemporaryDirectory ( logger: logger) { tempDir in
347
+ try await buildTestcase (
348
+ logger, testcase: testcase, bundleName: bundleName, tempDir: tempDir
349
+ )
350
+ }
351
+ } catch {
352
+ await cleanupSDK ( )
353
+ throw error
327
354
}
328
355
}
329
356
330
- // Cleanup
331
- logger. info ( " Removing SDK to cleanup... " )
332
- try await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
357
+ await cleanupSDK ( )
333
358
}
334
359
335
360
final class Swift59_UbuntuEndToEndTests : XCTestCase {
@@ -433,12 +458,24 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
433
458
434
459
func testAarch64FromContainer( ) async throws {
435
460
try skipSlow ( )
436
- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
461
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
437
462
}
438
463
439
464
func testX86_64FromContainer( ) async throws {
440
465
try skipSlow ( )
441
- try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
466
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
467
+ }
468
+
469
+ func testAmazonLinux2Aarch64FromContainer( ) async throws {
470
+ try skipSlow ( )
471
+ try await buildTestcases (
472
+ config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
473
+ }
474
+
475
+ func testAmazonLinux2X86_64FromContainer( ) async throws {
476
+ try skipSlow ( )
477
+ try await buildTestcases (
478
+ config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
442
479
}
443
480
}
444
481
@@ -453,12 +490,36 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
453
490
454
491
func testAarch64FromContainer( ) async throws {
455
492
try skipSlow ( )
456
- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
493
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
457
494
}
458
495
459
496
func testX86_64FromContainer( ) async throws {
460
497
try skipSlow ( )
461
- try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
498
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
499
+ }
500
+
501
+ func testAmazonLinux2Aarch64FromContainer( ) async throws {
502
+ try skipSlow ( )
503
+ try await buildTestcases (
504
+ config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
505
+ }
506
+
507
+ func testAmazonLinux2X86_64FromContainer( ) async throws {
508
+ try skipSlow ( )
509
+ try await buildTestcases (
510
+ config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
511
+ }
512
+
513
+ func testFedora39Aarch64FromContainer( ) async throws {
514
+ try skipSlow ( )
515
+ try await buildTestcases (
516
+ config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " fedora39 " ) )
517
+ }
518
+
519
+ func testFedora39X86_64FromContainer( ) async throws {
520
+ try skipSlow ( )
521
+ try await buildTestcases (
522
+ config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " fedora39 " ) )
462
523
}
463
524
}
464
525
@@ -473,11 +534,35 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
473
534
474
535
func testAarch64FromContainer( ) async throws {
475
536
try skipSlow ( )
476
- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
537
+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
477
538
}
478
539
479
540
func testX86_64FromContainer( ) async throws {
480
541
try skipSlow ( )
481
- try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) . withDocker ( ) )
542
+ try await buildTestcases ( config: config. withArchitecture ( " x86_64 " ) )
543
+ }
544
+
545
+ func testAmazonLinux2Aarch64FromContainer( ) async throws {
546
+ try skipSlow ( )
547
+ try await buildTestcases (
548
+ config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
549
+ }
550
+
551
+ func testAmazonLinux2X86_64FromContainer( ) async throws {
552
+ try skipSlow ( )
553
+ try await buildTestcases (
554
+ config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " amazonlinux2 " ) )
555
+ }
556
+
557
+ func testFedora39Aarch64FromContainer( ) async throws {
558
+ try skipSlow ( )
559
+ try await buildTestcases (
560
+ config: config. withArchitecture ( " aarch64 " ) . withContainerImageSuffix ( " fedora39 " ) )
561
+ }
562
+
563
+ func testFedora39X86_64FromContainer( ) async throws {
564
+ try skipSlow ( )
565
+ try await buildTestcases (
566
+ config: config. withArchitecture ( " x86_64 " ) . withContainerImageSuffix ( " fedora39 " ) )
482
567
}
483
568
}
0 commit comments