@@ -164,6 +164,9 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
164164 var useRhelUbi9 : Bool = false
165165#endif
166166
167+ @Flag ( help: " Produce a swiftly-test.tar.gz that has a standalone test suite to test the released bundle. " )
168+ var test : Bool = false
169+
167170 @Argument ( help: " Version of swiftly to build the release. " )
168171 var version : String
169172
@@ -365,7 +368,6 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
365368 FileManager . default. changeCurrentDirectoryPath ( cwd)
366369
367370 try runProgram ( swift, " build " , " --swift-sdk " , " \( arch) -swift-linux-musl " , " --product=swiftly " , " --pkg-config-path= \( pkgConfigPath) /lib/pkgconfig " , " --static-swift-stdlib " , " --configuration=release " )
368- try runProgram ( swift, " sdk " , " remove " , sdkName)
369371
370372 let releaseDir = cwd + " /.build/release "
371373
@@ -383,6 +385,21 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
383385 try runProgram ( tar, " --directory= \( releaseDir) " , " -czf " , releaseArchive, " swiftly " , " LICENSE.txt " )
384386
385387 print ( releaseArchive)
388+
389+ if self . test {
390+ #if arch(arm64)
391+ let testArchive = " \( releaseDir) /test-swiftly-linux-aarch64.tar.gz "
392+ #else
393+ let testArchive = " \( releaseDir) /test-swiftly-linux-x86_64.tar.gz "
394+ #endif
395+
396+ try runProgram ( swift, " build " , " --swift-sdk " , " \( arch) -swift-linux-musl " , " --product=test-swiftly " , " --pkg-config-path= \( pkgConfigPath) /lib/pkgconfig " , " --static-swift-stdlib " , " --configuration=release " )
397+ try runProgram ( tar, " --directory= \( releaseDir) " , " -czf " , testArchive, " test-swiftly " )
398+
399+ print ( testArchive)
400+ }
401+
402+ try runProgram ( swift, " sdk " , " remove " , sdkName)
386403 }
387404
388405 func buildMacOSRelease( cert: String ? , identifier: String ) async throws {
@@ -397,6 +414,8 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
397414 let pkgbuild = try await self . assertTool ( " pkgbuild " , message: " In order to make pkg installers there needs to be the `pkgbuild` tool that is installed on macOS. " )
398415 let strip = try await self . assertTool ( " strip " , message: " In order to strip binaries there needs to be the `strip` tool that is installed on macOS. " )
399416
417+ let tar = try await self . assertTool ( " tar " , message: " In order to produce archives there needs to be the `tar` tool that is installed on macOS. " )
418+
400419 try runProgram ( swift, " package " , " clean " )
401420
402421 for arch in [ " x86_64 " , " arm64 " ] {
@@ -415,7 +434,8 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
415434
416435 let cwd = FileManager . default. currentDirectoryPath
417436
418- let pkgFile = URL ( fileURLWithPath: cwd + " /.build/release/swiftly- \( self . version) .pkg " )
437+ let releaseDir = URL ( fileURLWithPath: cwd + " /.build/release " )
438+ let pkgFile = releaseDir. appendingPathComponent ( " /swiftly- \( self . version) .pkg " )
419439
420440 if let cert {
421441 try runProgram (
@@ -450,8 +470,8 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
450470 // Re-configure the pkg to prefer installs into the current user's home directory with the help of productbuild.
451471 // Note that command-line installs can override this preference, but the GUI install will limit the choices.
452472
453- let pkgFileReconfigured = URL ( fileURLWithPath : cwd + " /.build/release/ swiftly-\( self . version) -reconfigured.pkg " )
454- let distFile = URL ( fileURLWithPath : cwd + " /.build/release/ distribution.plist" )
473+ let pkgFileReconfigured = releaseDir . appendingPathComponent ( " swiftly- \( self . version) -reconfigured.pkg " )
474+ let distFile = releaseDir . appendingPathComponent ( " distribution.plist " )
455475
456476 try runProgram ( " productbuild " , " --synthesize " , " --package " , pkgFile. path, distFile. path)
457477
@@ -466,5 +486,19 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
466486 }
467487 try FileManager . default. removeItem ( at: pkgFile)
468488 try FileManager . default. copyItem ( atPath: pkgFileReconfigured. path, toPath: pkgFile. path)
489+
490+ print ( pkgFile. path)
491+
492+ if self . test {
493+ for arch in [ " x86_64 " , " arm64 " ] {
494+ try runProgram ( swift, " build " , " --product=test-swiftly " , " --configuration=release " , " --arch= \( arch) " )
495+ try runProgram ( strip, " .build/ \( arch) -apple-macosx/release/swiftly " )
496+ }
497+
498+ let testArchive = releaseDir. appendingPathComponent ( " test-swiftly-macos.tar.gz " )
499+
500+ try runProgram ( lipo, " .build/x86_64-apple-macosx/release/test-swiftly " , " .build/arm64-apple-macosx/release/test-swiftly " , " -create " , " -o " , " \( swiftlyBinDir) /swiftly " )
501+ try runProgram ( tar, " --directory= \( swiftlyBinDir) " , " -czf " , testArchive. path, " test-swiftly " )
502+ }
469503 }
470504}
0 commit comments