Skip to content

Commit bacbd74

Browse files
committed
Returns Xcode.Project from generate()
1 parent c75ee58 commit bacbd74

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

Sources/Commands/SwiftPackageTool.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public class SwiftPackageTool: SwiftTool<PackageToolOptions> {
162162
dstdir = try getPackageRoot()
163163
projectName = graph.rootPackages[0].name
164164
}
165-
let outpath = try Xcodeproj.generate(
165+
let project = try Xcodeproj.generate(
166166
outputDir: dstdir,
167167
projectName: projectName,
168168
graph: graph,
169169
options: options.xcodeprojOptions)
170170

171-
print("generated:", outpath.prettyPath(cwd: originalWorkingDirectory))
171+
print("generated:", project.path.prettyPath(cwd: originalWorkingDirectory))
172172

173173
case .describe:
174174
let graph = try loadPackageGraph()

Sources/Xcodeproj/XcodeProjectModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
main group; it needs to be added last in order to appear after the other
5454
references
5555
*/
56+
import Basic
5657

5758
public struct Xcode {
5859

@@ -65,7 +66,10 @@ public struct Xcode {
6566
var productGroup: Group?
6667
var projectDir: String
6768
var targets: [Target]
68-
init() {
69+
public let path: AbsolutePath
70+
71+
init(path: AbsolutePath) {
72+
self.path = path
6973
self.mainGroup = Group(path: "")
7074
self.buildSettings = BuildSettingsTable()
7175
self.productGroup = nil

Sources/Xcodeproj/generate().swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public func generate(
4848
projectName: String,
4949
graph: PackageGraph,
5050
options: XcodeprojOptions
51-
) throws -> AbsolutePath {
51+
) throws -> Xcode.Project {
5252
// Note that the output directory might be completely separate from the
5353
// path of the root package (which is where the sources live).
5454

@@ -70,10 +70,15 @@ public func generate(
7070
let extraDirs = try findDirectoryReferences(path: srcroot)
7171

7272
/// Generate the contents of project.xcodeproj (inside the .xcodeproj).
73+
var project: Xcode.Project!
7374
try open(xcodeprojPath.appending(component: "project.pbxproj")) { stream in
7475
// FIXME: This could be more efficient by directly writing to a stream
7576
// instead of first creating a string.
76-
let str = try pbxproj(xcodeprojPath: xcodeprojPath, graph: graph, extraDirs: extraDirs, options: options)
77+
project = try pbxproj(xcodeprojPath: xcodeprojPath, graph: graph, extraDirs: extraDirs, options: options)
78+
79+
// Serialize the project model we created to a plist, and return
80+
// its string description.
81+
let str = "// !$*UTF8*$!\n" + project.generatePlist().description
7782
stream(str)
7883
}
7984

@@ -144,7 +149,7 @@ public func generate(
144149
}
145150
}
146151

147-
return xcodeprojPath
152+
return project
148153
}
149154

150155
/// Writes the contents to the file specified.

Sources/Xcodeproj/pbxproj().swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func xcodeProject(
6262
) throws -> Xcode.Project {
6363

6464
// Create the project.
65-
let project = Xcode.Project()
65+
let project = Xcode.Project(path: xcodeprojPath)
6666

6767
// Generates a dummy target to provide autocompletion for the manifest file.
6868
func createPackageDescriptionTarget(for package: ResolvedPackage, manifestFileRef: Xcode.FileReference) {

0 commit comments

Comments
 (0)