@@ -36,14 +36,12 @@ extension FileManager {
3636 try createDirectory ( at: temporaryDirectory, withIntermediateDirectories: false )
3737 defer {
3838 // 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+ }
4745 }
4846
4947 logger. info ( " Created temporary directory " )
@@ -62,7 +60,7 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
6260 logger [ metadataKey: " runArguments " ] = " \" \( runArguments) \" "
6361 logger [ metadataKey: " scratchPath " ] = " \( scratchPath) "
6462
65- logger. info ( " Building SDK " )
63+ logger. info ( " Building Swift SDK " )
6664
6765 var packageDirectory = FilePath ( #filePath)
6866 packageDirectory. removeLastComponent ( )
@@ -71,7 +69,7 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
7169 let generatorOutput = try await Shell . readStdout (
7270 " cd \( packageDirectory) && swift run --scratch-path \" \( scratchPath) \" swift-sdk-generator make-linux-sdk \( runArguments) "
7371 )
74- logger. info ( " Finished building SDK " )
72+ logger. info ( " Finished building Swift SDK " )
7573
7674 let installCommand = try XCTUnwrap (
7775 generatorOutput. split ( separator: " \n " ) . first {
@@ -83,17 +81,17 @@ func buildSDK(_ logger: Logger, scratchPath: String, withArguments runArguments:
8381 ) . stem
8482 logger [ metadataKey: " bundleName " ] = " \( bundleName) "
8583
86- logger. info ( " Checking installed SDKs " )
84+ logger. info ( " Checking installed Swift SDKs " )
8785 let installedSDKs = try await Shell . readStdout ( " swift experimental-sdk list " ) . components (
8886 separatedBy: " \n " )
8987
9088 // Make sure this bundle hasn't been installed already.
9189 if installedSDKs. contains ( bundleName) {
92- logger. info ( " Removing existing SDK " )
90+ logger. info ( " Removing existing Swift SDK " )
9391 try await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
9492 }
9593
96- logger. info ( " Installing new SDK " )
94+ logger. info ( " Installing new Swift SDK " )
9795 let installOutput = try await Shell . readStdout ( String ( installCommand) )
9896 XCTAssertTrue ( installOutput. contains ( " successfully installed " ) )
9997
@@ -168,9 +166,11 @@ struct SDKConfiguration {
168166 var linuxDistributionVersion : String
169167 var architecture : String
170168 var withDocker : Bool
169+ var containerImageSuffix : String ?
171170
172171 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 " : " " ) "
174174 }
175175
176176 func withDocker( _ enabled: Bool = true ) -> SDKConfiguration {
@@ -179,6 +179,12 @@ struct SDKConfiguration {
179179 return res
180180 }
181181
182+ func withContainerImageSuffix( _ containerImageSuffix: String ) -> SDKConfiguration {
183+ var res = self
184+ res. containerImageSuffix = containerImageSuffix
185+ return res
186+ }
187+
182188 func withArchitecture( _ arch: String ) -> SDKConfiguration {
183189 var res = self
184190 res. architecture = arch
@@ -191,14 +197,22 @@ struct SDKConfiguration {
191197 }
192198
193199 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+
194206 return [
195207 " --sdk-name \( bundleName) " ,
196208 " --host-toolchain " ,
197209 withDocker ? " --with-docker " : nil ,
210+ containerImage != nil ? " --from-container-image " : nil , containerImage,
198211 " --swift-version \( swiftVersion) -RELEASE " ,
199212 testLinuxSwiftSDKs ? " --host \( hostArch!) -unknown-linux-gnu " : nil ,
200213 " --target \( architecture) -unknown-linux-gnu " ,
201214 " --linux-distribution-name \( linuxDistributionName) " ,
215+ " --linux-distribution-version \( linuxDistributionVersion) " ,
202216 ] . compactMap { $0 } . joined ( separator: " " )
203217 }
204218}
@@ -319,17 +333,28 @@ func buildTestcases(config: SDKConfiguration) async throws {
319333 logger, scratchPath: tempDir. path, withArguments: config. sdkGeneratorArguments)
320334 }
321335
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+ }
323343
324344 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
327354 }
328355 }
329356
330- // Cleanup
331- logger. info ( " Removing SDK to cleanup... " )
332- try await Shell . run ( " swift experimental-sdk remove \( bundleName) " )
357+ await cleanupSDK ( )
333358}
334359
335360final class Swift59_UbuntuEndToEndTests : XCTestCase {
@@ -433,12 +458,24 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
433458
434459 func testAarch64FromContainer( ) async throws {
435460 try skipSlow ( )
436- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
461+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
437462 }
438463
439464 func testX86_64FromContainer( ) async throws {
440465 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 " ) )
442479 }
443480}
444481
@@ -453,12 +490,36 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
453490
454491 func testAarch64FromContainer( ) async throws {
455492 try skipSlow ( )
456- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
493+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
457494 }
458495
459496 func testX86_64FromContainer( ) async throws {
460497 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 " ) )
462523 }
463524}
464525
@@ -473,11 +534,35 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
473534
474535 func testAarch64FromContainer( ) async throws {
475536 try skipSlow ( )
476- try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) . withDocker ( ) )
537+ try await buildTestcases ( config: config. withArchitecture ( " aarch64 " ) )
477538 }
478539
479540 func testX86_64FromContainer( ) async throws {
480541 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 " ) )
482567 }
483568}
0 commit comments