1616 and serialization to .xcodeproj plists. There is no consistency checking to
1717 ensure, for example, that build settings have valid values, dependency cycles
1818 are not created, etc.
19-
19+
2020 Everything here is geared toward supporting project generation. The intended
2121 usage model is for custom logic to build up a project using Xcode terminology
2222 (e.g. "group", "reference", "target", "build phase"), but there is almost no
2323 provision for modifying the model after it has been built up. The intent is
2424 to create it as desired from the start.
25-
25+
2626 Rather than try to represent everything that Xcode's project model supports,
2727 the approach is to start small and to add functionality as needed.
28-
28+
2929 Note that this API represents only the project model — there is no notion of
3030 workspaces, schemes, etc (although schemes are represented individually in a
3131 separate API). The notion of build settings is also somewhat different from
3737 configuration of the settings, since most values are the same between Debug
3838 and Release. Also, the build settings themselves are represented as structs
3939 of named fields, instead of dictionaries with arbitrary name strings as keys.
40-
40+
4141 It is expected that some of these simplifications will need to be lifted over
4242 time, based on need. That should be done carefully, however, to avoid ending
4343 up with an overly complicated model.
44-
44+
4545 Some things that are incomplete in even this first model:
4646 - copy files build phases are incomplete
4747 - shell script build phases are incomplete
5757 */
5858
5959public struct Xcode {
60-
60+
6161 /// An Xcode project, consisting of a tree of groups and file references,
6262 /// a list of targets, and some additional information. Note that schemes
6363 /// are outside of the project data model.
@@ -74,7 +74,7 @@ public struct Xcode {
7474 self . projectDir = " "
7575 self . targets = [ ]
7676 }
77-
77+
7878 /// Creates and adds a new target (which does not initially have any
7979 /// build phases).
8080 public func addTarget( objectID: String ? = nil , productType: Target . ProductType ? = nil , name: String ) -> Target {
@@ -94,7 +94,7 @@ public struct Xcode {
9494 /// Name of the reference, if different from the last path component
9595 /// (if not set, Xcode will use the last path component as the name).
9696 public var name : String ?
97-
97+
9898 /// Determines the base path for a reference's relative path (this is
9999 /// what for some reason is called a "source tree" in Xcode).
100100 public enum RefPathBase : String {
@@ -111,13 +111,13 @@ public struct Xcode {
111111 /// destination, or even an overridden build setting.
112112 case buildDir = " BUILT_PRODUCTS_DIR "
113113 }
114-
114+
115115 init ( path: String , pathBase: RefPathBase = . groupDir, name: String ? = nil ) {
116116 self . path = path
117117 self . pathBase = pathBase
118118 self . name = name
119119 }
120-
120+
121121 /// Whether this is either a group or directory reference (blue folder).
122122 public var isDirectoryLike : Bool {
123123 if self is Xcode . Group {
@@ -129,7 +129,7 @@ public struct Xcode {
129129 return false
130130 }
131131 }
132-
132+
133133 /// A reference to a file system entity (a file, folder, etc).
134134 public final class FileReference : Reference {
135135 public var objectID : String ?
@@ -153,7 +153,7 @@ public struct Xcode {
153153 /// references whose source tree type is GroupRelative.
154154 public final class Group : Reference {
155155 public var subitems = [ Reference] ( )
156-
156+
157157 /// Creates and appends a new Group to the list of subitems.
158158 /// The new group is returned so that it can be configured.
159159 @discardableResult
@@ -166,7 +166,7 @@ public struct Xcode {
166166 subitems. append ( group)
167167 return group
168168 }
169-
169+
170170 /// Creates and appends a new FileReference to the list of subitems.
171171 @discardableResult
172172 public func addFileReference(
@@ -212,11 +212,11 @@ public struct Xcode {
212212 self . dependencies = [ ]
213213 self . buildableFolders = [ ]
214214 }
215-
215+
216216 // FIXME: There's a lot repetition in these methods; using generics to
217217 // try to avoid that raised other issues in terms of requirements on
218218 // the Reference class, though.
219-
219+
220220 /// Adds a "headers" build phase, i.e. one that copies headers into a
221221 /// directory of the product, after suitable processing.
222222 @discardableResult
@@ -225,7 +225,7 @@ public struct Xcode {
225225 buildPhases. append ( phase)
226226 return phase
227227 }
228-
228+
229229 /// Adds a "sources" build phase, i.e. one that compiles sources and
230230 /// provides them to be linked into the executable code of the product.
231231 @discardableResult
@@ -234,7 +234,7 @@ public struct Xcode {
234234 buildPhases. append ( phase)
235235 return phase
236236 }
237-
237+
238238 /// Adds a "frameworks" build phase, i.e. one that links compiled code
239239 /// and libraries into the executable of the product.
240240 @discardableResult
@@ -243,7 +243,7 @@ public struct Xcode {
243243 buildPhases. append ( phase)
244244 return phase
245245 }
246-
246+
247247 /// Adds a "copy files" build phase, i.e. one that copies files to an
248248 /// arbitrary location relative to the product.
249249 @discardableResult
@@ -252,7 +252,7 @@ public struct Xcode {
252252 buildPhases. append ( phase)
253253 return phase
254254 }
255-
255+
256256 /// Adds a "shell script" build phase, i.e. one that runs a custom
257257 /// shell script as part of the build.
258258 @discardableResult
@@ -265,7 +265,7 @@ public struct Xcode {
265265 buildPhases. append ( phase)
266266 return phase
267267 }
268-
268+
269269 /// Adds a dependency on another target.
270270 /// FIXME: We do not check for cycles. Should we? This is an extremely
271271 /// minimal API so it's not clear that we should.
@@ -286,11 +286,11 @@ public struct Xcode {
286286 public unowned var target : Target
287287 }
288288 }
289-
289+
290290 /// Abstract base class for all build phases in a target.
291291 public class BuildPhase {
292292 public var files : [ BuildFile ] = [ ]
293-
293+
294294 /// Adds a new build file that refers to `fileRef`.
295295 @discardableResult
296296 public func addBuildFile( fileRef: FileReference ) -> BuildFile {
@@ -299,25 +299,25 @@ public struct Xcode {
299299 return buildFile
300300 }
301301 }
302-
302+
303303 /// A "headers" build phase, i.e. one that copies headers into a directory
304304 /// of the product, after suitable processing.
305305 public final class HeadersBuildPhase : BuildPhase {
306306 // Nothing extra yet.
307307 }
308-
308+
309309 /// A "sources" build phase, i.e. one that compiles sources and provides
310310 /// them to be linked into the executable code of the product.
311311 public final class SourcesBuildPhase : BuildPhase {
312312 // Nothing extra yet.
313313 }
314-
314+
315315 /// A "frameworks" build phase, i.e. one that links compiled code and
316316 /// libraries into the executable of the product.
317317 public final class FrameworksBuildPhase : BuildPhase {
318318 // Nothing extra yet.
319319 }
320-
320+
321321 /// A "copy files" build phase, i.e. one that copies files to an arbitrary
322322 /// location relative to the product.
323323 public final class CopyFilesBuildPhase : BuildPhase {
@@ -326,7 +326,7 @@ public struct Xcode {
326326 self . dstDir = dstDir
327327 }
328328 }
329-
329+
330330 /// A "shell script" build phase, i.e. one that runs a custom shell script.
331331 public final class ShellScriptBuildPhase : BuildPhase {
332332 public var script : String
@@ -340,27 +340,27 @@ public struct Xcode {
340340 self . alwaysRun = alwaysRun
341341 }
342342 }
343-
343+
344344 /// A build file, representing the membership of a file reference in a
345345 /// build phase of a target.
346346 public final class BuildFile {
347347 public var fileRef : FileReference ?
348348 init ( fileRef: FileReference ) {
349349 self . fileRef = fileRef
350350 }
351-
351+
352352 public var settings = Settings ( )
353-
353+
354354 /// A set of file settings.
355355 public struct Settings : Encodable {
356356 public var ATTRIBUTES : [ String ] ?
357357 public var COMPILER_FLAGS : String ?
358-
358+
359359 public init ( ) {
360360 }
361361 }
362362 }
363-
363+
364364 /// A table of build settings, which for the sake of simplicity consists
365365 /// (in this simplified model) of a set of common settings, and a set of
366366 /// overlay settings for Debug and Release builds. There can also be a
@@ -369,21 +369,21 @@ public struct Xcode {
369369 /// Common build settings are in both generated configurations (Debug
370370 /// and Release).
371371 public var common = BuildSettings ( )
372-
372+
373373 /// Debug build settings are overlaid over the common settings in the
374374 /// generated Debug configuration.
375375 public var debug = BuildSettings ( )
376-
376+
377377 /// Release build settings are overlaid over the common settings in the
378378 /// generated Release configuration.
379379 public var release = BuildSettings ( )
380-
380+
381381 /// An optional file reference to an .xcconfig file.
382382 public var xcconfigFileRef : FileReference ?
383-
383+
384384 public init ( ) {
385385 }
386-
386+
387387 /// A set of build settings, which is represented as a struct of optional
388388 /// build settings. This is not optimally efficient, but it is great for
389389 /// code completion and type-checking.
0 commit comments