11import ArgumentParser
22import Foundation
33import SwiftlyCore
4+ import SystemPackage
45
56#if os(macOS)
67import MacOSPlatform
@@ -14,6 +15,9 @@ let currentPlatform = MacOS()
1415let currentPlatform = Linux ( )
1516#endif
1617
18+ typealias fs = FileSystem
19+ typealias sys = SystemCommand
20+
1721public struct SwiftPlatform : Codable {
1822 public var name : String ?
1923 public var checksum : String ?
@@ -392,7 +396,6 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
392396
393397 try await self . checkGitRepoStatus ( git)
394398
395- let lipo = try await self . assertTool ( " lipo " , message: " In order to make a universal binary there needs to be the `lipo` tool that is installed on macOS. " )
396399 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. " )
397400 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. " )
398401
@@ -405,10 +408,14 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
405408 try runProgram ( strip, " .build/ \( arch) -apple-macosx/release/swiftly " )
406409 }
407410
408- let swiftlyBinDir = FileManager . default . currentDirectoryPath + " / .build/release/.swiftly/bin"
409- try ? FileManager . default . createDirectory ( atPath : swiftlyBinDir , withIntermediateDirectories : true )
411+ let swiftlyBinDir = fs . cwd / " .build/release/.swiftly/bin "
412+ try ? await fs . mkdir ( . parents , atPath : swiftlyBinDir )
410413
411- try runProgram ( lipo, " .build/x86_64-apple-macosx/release/swiftly " , " .build/arm64-apple-macosx/release/swiftly " , " -create " , " -o " , " \( swiftlyBinDir) /swiftly " )
414+ try await sys. lipo (
415+ inputFiles: " .build/x86_64-apple-macosx/release/swiftly " , " .build/arm64-apple-macosx/release/swiftly "
416+ )
417+ . create ( output: swiftlyBinDir / " swiftly " )
418+ . run ( currentPlatform)
412419
413420 let swiftlyLicenseDir = FileManager . default. currentDirectoryPath + " /.build/release/.swiftly/license "
414421 try ? FileManager . default. createDirectory ( atPath: swiftlyLicenseDir, withIntermediateDirectories: true )
@@ -423,7 +430,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
423430 try runProgram (
424431 pkgbuild,
425432 " --root " ,
426- swiftlyBinDir + " /.. " ,
433+ " \( swiftlyBinDir . parent ) " ,
427434 " --install-location " ,
428435 " .swiftly " ,
429436 " --version " ,
@@ -438,7 +445,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
438445 try runProgram (
439446 pkgbuild,
440447 " --root " ,
441- swiftlyBinDir + " /.. " ,
448+ " \( swiftlyBinDir . parent ) " ,
442449 " --install-location " ,
443450 " .swiftly " ,
444451 " --version " ,
@@ -479,7 +486,12 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
479486
480487 let testArchive = releaseDir. appendingPathComponent ( " test-swiftly-macos.tar.gz " )
481488
482- try runProgram ( lipo, " .build/x86_64-apple-macosx/debug/test-swiftly " , " .build/arm64-apple-macosx/debug/test-swiftly " , " -create " , " -o " , " \( swiftlyBinDir) /swiftly " )
489+ try await sys. lipo (
490+ inputFiles: " .build/x86_64-apple-macosx/debug/test-swiftly " , " .build/arm64-apple-macosx/debug/test-swiftly "
491+ )
492+ . create ( output: swiftlyBinDir / " swiftly " )
493+ . run ( currentPlatform)
494+
483495 try runProgram ( tar, " --directory=.build/x86_64-apple-macosx/debug " , " -czf " , testArchive. path, " test-swiftly " )
484496
485497 print ( testArchive. path)
0 commit comments