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,13 @@ 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: FilePath ( " .build/x86_64-apple-macosx/release/swiftly " ) , FilePath ( " .build/arm64-apple-macosx/release/swiftly " ) )
416+ . create ( . output( swiftlyBinDir / " swiftly " ) )
417+ . run ( currentPlatform)
412418
413419 let swiftlyLicenseDir = FileManager . default. currentDirectoryPath + " /.build/release/.swiftly/license "
414420 try ? FileManager . default. createDirectory ( atPath: swiftlyLicenseDir, withIntermediateDirectories: true )
@@ -423,7 +429,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
423429 try runProgram (
424430 pkgbuild,
425431 " --root " ,
426- swiftlyBinDir + " /.. " ,
432+ " \( swiftlyBinDir . removingLastComponent ) " ,
427433 " --install-location " ,
428434 " .swiftly " ,
429435 " --version " ,
@@ -438,7 +444,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
438444 try runProgram (
439445 pkgbuild,
440446 " --root " ,
441- swiftlyBinDir + " /.. " ,
447+ " \( swiftlyBinDir . removingLastComponent ) " ,
442448 " --install-location " ,
443449 " .swiftly " ,
444450 " --version " ,
@@ -479,7 +485,11 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
479485
480486 let testArchive = releaseDir. appendingPathComponent ( " test-swiftly-macos.tar.gz " )
481487
482- try runProgram ( lipo, " .build/x86_64-apple-macosx/debug/test-swiftly " , " .build/arm64-apple-macosx/debug/test-swiftly " , " -create " , " -o " , " \( swiftlyBinDir) /swiftly " )
488+ try await sys. lipo (
489+ inputFiles: FilePath ( " .build/x86_64-apple-macosx/debug/test-swiftly " ) , FilePath ( " .build/arm64-apple-macosx/debug/test-swiftly " ) )
490+ . create ( . output( swiftlyBinDir / " swiftly " ) )
491+ . run ( currentPlatform)
492+
483493 try runProgram ( tar, " --directory=.build/x86_64-apple-macosx/debug " , " -czf " , testArchive. path, " test-swiftly " )
484494
485495 print ( testArchive. path)
0 commit comments