Skip to content

Commit a6f4714

Browse files
committed
[Xcodeproj] Added Package.swift to the root of generated Xcode projects for easier access/editing
1 parent b354d67 commit a6f4714

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Sources/Xcodeproj/Module+PBXProj.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ private func fileRef(suffixForModuleSourceFile path: String, srcroot: String) ->
7070
}.joined(separator: "")
7171
}
7272

73+
func fileRef(inProjectRoot name: String, srcroot: String) -> (String, String, String) {
74+
let suffix = fileRef(suffixForModuleSourceFile: name, srcroot: srcroot)
75+
return ("'\(sourceGroupFileRefPrefix)\(suffix)'", name, Path.join(srcroot, name))
76+
}
77+
7378
func fileRefs(forModuleSources module: SwiftModule, srcroot: String) -> [(String, String)] {
7479
return module.sources.relativePaths.map { relativePath in
7580
let path = Path.join(module.sources.root, relativePath)

Sources/Xcodeproj/pbxproj().swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,20 @@ public func pbxproj(srcroot srcroot: String, projectRoot: String, modules: [Swif
4444
print(" targets = (" + modules.map{ $0.targetReference }.joined(separator: ", ") + ");")
4545
print(" };")
4646

47+
////// Package.swift file
48+
let packageSwift = fileRef(inProjectRoot: "Package.swift", srcroot: srcroot)
49+
print(" \(packageSwift.0) = {")
50+
print(" isa = PBXFileReference;")
51+
print(" lastKnownFileType = sourcecode.swift;")
52+
print(" name = '\(packageSwift.1)';")
53+
print(" path = '\(packageSwift.2)';")
54+
print(" sourceTree = '<group>';")
55+
print(" };")
56+
4757
////// root group
4858
print(" \(rootGroupReference) = {")
4959
print(" isa = PBXGroup;")
50-
print(" children = (\(sourcesGroupReference), \(testsGroupReference), \(productsGroupReference));")
60+
print(" children = (\(packageSwift.0), \(sourcesGroupReference), \(testsGroupReference), \(productsGroupReference));")
5161
print(" sourceTree = '<group>';")
5262
print(" };")
5363

@@ -143,7 +153,7 @@ public func pbxproj(srcroot srcroot: String, projectRoot: String, modules: [Swif
143153
print(" target = \(module.targetReference);")
144154
print(" };")
145155
}
146-
156+
147157
////// “Sources” group
148158
print(" \(sourcesGroupReference) = {")
149159
print(" isa = PBXGroup;")

0 commit comments

Comments
 (0)