@@ -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,23 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
383385 try runProgram ( tar, " --directory= \( releaseDir) " , " -czf " , releaseArchive, " swiftly " , " LICENSE.txt " )
384386
385387 print ( releaseArchive)
388+
389+ if self . test {
390+ let debugDir = cwd + " /.build/debug "
391+
392+ #if arch(arm64)
393+ let testArchive = " \( debugDir) /test-swiftly-linux-aarch64.tar.gz "
394+ #else
395+ let testArchive = " \( debugDir) /test-swiftly-linux-x86_64.tar.gz "
396+ #endif
397+
398+ try runProgram ( swift, " build " , " --swift-sdk " , " \( arch) -swift-linux-musl " , " --product=test-swiftly " , " --pkg-config-path= \( pkgConfigPath) /lib/pkgconfig " , " --static-swift-stdlib " , " --configuration=debug " )
399+ try runProgram ( tar, " --directory= \( debugDir) " , " -czf " , testArchive, " test-swiftly " )
400+
401+ print ( testArchive)
402+ }
403+
404+ try runProgram ( swift, " sdk " , " remove " , sdkName)
386405 }
387406
388407 func buildMacOSRelease( cert: String ? , identifier: String ) async throws {
@@ -397,6 +416,8 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
397416 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. " )
398417 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. " )
399418
419+ 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. " )
420+
400421 try runProgram ( swift, " package " , " clean " )
401422
402423 for arch in [ " x86_64 " , " arm64 " ] {
@@ -415,7 +436,8 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
415436
416437 let cwd = FileManager . default. currentDirectoryPath
417438
418- let pkgFile = URL ( fileURLWithPath: cwd + " /.build/release/swiftly- \( self . version) .pkg " )
439+ let releaseDir = URL ( fileURLWithPath: cwd + " /.build/release " )
440+ let pkgFile = releaseDir. appendingPathComponent ( " /swiftly- \( self . version) .pkg " )
419441
420442 if let cert {
421443 try runProgram (
@@ -450,8 +472,8 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
450472 // Re-configure the pkg to prefer installs into the current user's home directory with the help of productbuild.
451473 // Note that command-line installs can override this preference, but the GUI install will limit the choices.
452474
453- let pkgFileReconfigured = URL ( fileURLWithPath : cwd + " /.build/release/ swiftly-\( self . version) -reconfigured.pkg " )
454- let distFile = URL ( fileURLWithPath : cwd + " /.build/release/ distribution.plist" )
475+ let pkgFileReconfigured = releaseDir . appendingPathComponent ( " swiftly- \( self . version) -reconfigured.pkg " )
476+ let distFile = releaseDir . appendingPathComponent ( " distribution.plist " )
455477
456478 try runProgram ( " productbuild " , " --synthesize " , " --package " , pkgFile. path, distFile. path)
457479
@@ -466,5 +488,21 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
466488 }
467489 try FileManager . default. removeItem ( at: pkgFile)
468490 try FileManager . default. copyItem ( atPath: pkgFileReconfigured. path, toPath: pkgFile. path)
491+
492+ print ( pkgFile. path)
493+
494+ if self . test {
495+ for arch in [ " x86_64 " , " arm64 " ] {
496+ try runProgram ( swift, " build " , " --product=test-swiftly " , " --configuration=debug " , " --arch= \( arch) " )
497+ try runProgram ( strip, " .build/ \( arch) -apple-macosx/release/swiftly " )
498+ }
499+
500+ let testArchive = releaseDir. appendingPathComponent ( " test-swiftly-macos.tar.gz " )
501+
502+ try runProgram ( lipo, " .build/x86_64-apple-macosx/debug/test-swiftly " , " .build/arm64-apple-macosx/debug/test-swiftly " , " -create " , " -o " , " \( swiftlyBinDir) /swiftly " )
503+ try runProgram ( tar, " --directory=.build/x86_64-apple-macosx/debug " , " -czf " , testArchive. path, " test-swiftly " )
504+
505+ print ( testArchive. path)
506+ }
469507 }
470508}
0 commit comments