@@ -155,7 +155,7 @@ extension Module {
155
155
}
156
156
}
157
157
158
- var headerSearchPaths : ( key: String , value: String ) ? {
158
+ var headerSearchPaths : ( key: String , value: Any ) ? {
159
159
let headerPathKey = " HEADER_SEARCH_PATHS "
160
160
var headerPaths = dependencies. flatMap { module -> AbsolutePath ? in
161
161
switch module {
@@ -174,36 +174,48 @@ extension Module {
174
174
}
175
175
176
176
guard !headerPaths. isEmpty else { return nil }
177
-
178
- if headerPaths. count == 1 , let first = headerPaths. first {
179
- return ( headerPathKey, first. asString)
180
- }
181
-
182
- let headerPathValue = headerPaths. map { $0. asString } . joined ( separator: " " )
183
177
184
- return ( headerPathKey, headerPathValue )
178
+ return ( headerPathKey, headerPaths . map { $0 . asString } )
185
179
}
186
180
187
181
func getDebugBuildSettings( _ options: XcodeprojOptions , xcodeProjectPath: AbsolutePath ) throws -> String {
188
182
var buildSettings = try getCommonBuildSettings ( options, xcodeProjectPath: xcodeProjectPath)
189
183
if let headerSearchPaths = headerSearchPaths {
190
184
buildSettings [ headerSearchPaths. key] = headerSearchPaths. value
191
185
}
192
- // FIXME: Need to honor actual quoting rules here.
193
- return buildSettings. map { " \( $0) = ' \( $1) '; " } . joined ( separator: " " )
186
+ return toPlist ( buildSettings) . serialize ( )
194
187
}
195
188
196
189
func getReleaseBuildSettings( _ options: XcodeprojOptions , xcodeProjectPath: AbsolutePath ) throws -> String {
197
190
var buildSettings = try getCommonBuildSettings ( options, xcodeProjectPath: xcodeProjectPath)
198
191
if let headerSearchPaths = headerSearchPaths {
199
192
buildSettings [ headerSearchPaths. key] = headerSearchPaths. value
200
193
}
201
- // FIXME: Need to honor actual quoting rules here.
202
- return buildSettings. map { " \( $0) = ' \( $1) '; " } . joined ( separator: " " )
194
+ return toPlist ( buildSettings) . serialize ( )
195
+ }
196
+
197
+ /// Converts build settings dictionary to a Plist object.
198
+ ///
199
+ /// Adds string values in dictionaries as is and array values are quoted and then converted
200
+ /// to a string joined by whitespace.
201
+ private func toPlist( _ buildSettings: [ String : Any ] ) -> Plist {
202
+ var buildSettingsPlist = [ String: Plist] ( )
203
+ for (k, v) in buildSettings {
204
+ switch v {
205
+ case let value as String :
206
+ buildSettingsPlist [ k] = . string( value)
207
+ case let value as [ String ] :
208
+ let escaped = value. map { " \" " + Plist. escape ( string: $0) + " \" " } . joined ( separator: " " )
209
+ buildSettingsPlist [ k] = . string( escaped)
210
+ default :
211
+ fatalError ( " build setting dictionary should only contain String or [String] " )
212
+ }
213
+ }
214
+ return . dictionary( buildSettingsPlist)
203
215
}
204
216
205
- private func getCommonBuildSettings( _ options: XcodeprojOptions , xcodeProjectPath: AbsolutePath ) throws -> [ String : String ] {
206
- var buildSettings = [ String: String ] ( )
217
+ private func getCommonBuildSettings( _ options: XcodeprojOptions , xcodeProjectPath: AbsolutePath ) throws -> [ String : Any ] {
218
+ var buildSettings = [ String: Any ] ( )
207
219
let plistPath = xcodeProjectPath. appending ( component: infoPlistFileName)
208
220
209
221
if isTest {
@@ -220,7 +232,7 @@ extension Module {
220
232
//
221
233
// This means the built binaries are not suitable for distribution,
222
234
// among other things.
223
- buildSettings [ " LD_RUNPATH_SEARCH_PATHS " ] = " $(TOOLCHAIN_DIR)/usr/lib/swift/macosx "
235
+ buildSettings [ " LD_RUNPATH_SEARCH_PATHS " ] = [ " $(TOOLCHAIN_DIR)/usr/lib/swift/macosx " ]
224
236
if isLibrary {
225
237
buildSettings [ " ENABLE_TESTABILITY " ] = " YES "
226
238
@@ -259,13 +271,13 @@ extension Module {
259
271
// example would be `@executable_path/../lib` but there are
260
272
// other problems to solve first, e.g. how to deal with the
261
273
// Swift standard library paths).
262
- buildSettings [ " LD_RUNPATH_SEARCH_PATHS " ] = buildSettings [ " LD_RUNPATH_SEARCH_PATHS " ] ! + " @executable_path"
274
+ buildSettings [ " LD_RUNPATH_SEARCH_PATHS " ] = buildSettings [ " LD_RUNPATH_SEARCH_PATHS " ] as! [ String ] + [ " @executable_path " ]
263
275
}
264
276
}
265
277
266
278
if let pkgArgs = try ? self . pkgConfigArgs ( ) {
267
- buildSettings [ " OTHER_LDFLAGS " ] = ( [ " $(inherited) " ] + pkgArgs. libs) . joined ( separator : " " )
268
- buildSettings [ " OTHER_SWIFT_FLAGS " ] = ( [ " $(inherited) " ] + pkgArgs. cFlags) . joined ( separator : " " )
279
+ buildSettings [ " OTHER_LDFLAGS " ] = [ " $(inherited) " ] + pkgArgs. libs
280
+ buildSettings [ " OTHER_SWIFT_FLAGS " ] = [ " $(inherited) " ] + pkgArgs. cFlags
269
281
}
270
282
271
283
// Add framework search path to build settings.
0 commit comments