@@ -68,21 +68,23 @@ struct XcodeBuilder {
6868 // MARK: - Build
6969
7070 func build ( targets: [ String ] , sdk: TargetPlatform . SDK ) throws -> [ String : Foundation . URL ] {
71- let process = TSCBasic . Process (
72- arguments: try self . buildCommand ( targets: targets, sdk: sdk) ,
73- outputRedirection: . none
74- )
75-
76- try process. launch ( )
77- let result = try process. waitUntilExit ( )
78-
79- switch result. exitStatus {
80- case let . terminated( code: code) :
81- if code != 0 {
82- throw Error . nonZeroExit ( code)
71+ for target in targets {
72+ let process = TSCBasic . Process (
73+ arguments: try self . buildCommand ( target: target, sdk: sdk) ,
74+ outputRedirection: . none
75+ )
76+
77+ try process. launch ( )
78+ let result = try process. waitUntilExit ( )
79+
80+ switch result. exitStatus {
81+ case let . terminated( code: code) :
82+ if code != 0 {
83+ throw Error . nonZeroExit ( code)
84+ }
85+ case let . signalled( signal: signal) :
86+ throw Error . signalExit ( signal)
8387 }
84- case let . signalled( signal: signal) :
85- throw Error . signalExit ( signal)
8688 }
8789
8890 return targets
@@ -91,29 +93,40 @@ struct XcodeBuilder {
9193 }
9294 }
9395
94- private func buildCommand ( targets : [ String ] , sdk: TargetPlatform . SDK ) throws -> [ String ] {
96+ private func buildCommand ( target : String , sdk: TargetPlatform . SDK ) throws -> [ String ] {
9597 var command : [ String ] = [
9698 " xcrun " ,
9799 " xcodebuild " ,
98100 " -project " , self . path. pathString,
99101 " -configuration " , self . options. configuration. xcodeConfigurationName,
100- " -sdk " , sdk. sdkName,
101- " BUILD_DIR= \( self . buildDirectory. path) "
102+ " -archivePath " , self . buildDirectory. appendingPathComponent ( self . productName ( target: target) ) . appendingPathComponent ( sdk. archiveName) . path,
103+ " -destination " , sdk. destination,
104+ " BUILD_DIR= \( self . buildDirectory. path) " ,
105+ " SKIP_INSTALL=NO "
102106 ]
103107
108+ // add any build settings
109+ if let settings = sdk. buildSettings {
110+ for setting in settings {
111+ command. append ( " \( setting. key) = \( setting. value) " )
112+ }
113+ }
114+
104115 // add our targets
105- command += targets . flatMap { [ " -target " , $0 ] }
116+ command += [ " -scheme " , target ]
106117
107118 // and the command
108- command += [ " build " ]
119+ command += [ " archive " ]
109120
110121 return command
111122 }
112123
113124 // we should probably pull this from the build output but we just make assumptions here
114125 private func frameworkPath ( target: String , sdk: TargetPlatform . SDK ) -> Foundation . URL {
115126 return self . buildDirectory
116- . appendingPathComponent ( self . options. configuration. xcodeConfigurationName + sdk. directorySuffix)
127+ . appendingPathComponent ( self . productName ( target: target) )
128+ . appendingPathComponent ( sdk. archiveName)
129+ . appendingPathComponent ( " Products/Library/Frameworks " )
117130 . appendingPathComponent ( " \( self . productName ( target: target) ) .framework " )
118131 . absoluteURL
119132 }
@@ -124,6 +137,9 @@ struct XcodeBuilder {
124137 func merge ( target: String , frameworks: [ Foundation . URL ] ) throws -> Foundation . URL {
125138 let outputPath = self . xcframeworkPath ( target: target)
126139
140+ // try to remove it if its already there, otherwise we're going to get errors
141+ try ? FileManager . default. removeItem ( at: outputPath)
142+
127143 let process = TSCBasic . Process (
128144 arguments: self . mergeCommand ( outputPath: outputPath, frameworks: frameworks) ,
129145 outputRedirection: . none
@@ -156,7 +172,6 @@ struct XcodeBuilder {
156172
157173 // and the output
158174 command += [ " -output " , outputPath. path ]
159-
160175 return command
161176 }
162177
0 commit comments