Skip to content

Commit 82a5185

Browse files
committed
Add release configuration
1 parent 5040f9e commit 82a5185

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

Sources/Xcodeproj/Module+PBXProj.swift

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
1. Unique reference identifiers
1515
2. Human readable reference identifiers
1616
3. Stable reference identifiers
17-
17+
1818
(as opposed to the generated UUIDs Xcode typically generates)
19-
19+
2020
We create identifiers with a constant-length unique prefix and
2121
a unique suffix where the suffix is the filename or module name
2222
and since we guarantee uniqueness at the PackageDescription
@@ -29,7 +29,8 @@ import PackageType
2929

3030
let rootObjectReference = "__RootObject_"
3131
let rootBuildConfigurationListReference = "___RootConfs_"
32-
let rootBuildConfigurationReference = "_______Debug_"
32+
let rootDebugBuildConfigurationReference = "_______Debug_"
33+
let rootReleaseBuildConfigurationReference = "_____Release_"
3334
let rootGroupReference = "___RootGroup_"
3435
let productsGroupReference = "____Products_"
3536
let sourcesGroupReference = "_____Sources_"
@@ -39,14 +40,15 @@ let sourceGroupFileRefPrefix = "__PBXFileRef_"
3940
let compilePhaseFileRefPrefix = "__src_cc_ref_"
4041

4142
extension Module {
42-
var dependencyReference: String { return "__Dependency_\(c99name)" }
43-
var productReference: String { return "_____Product_\(c99name)" }
44-
var targetReference: String { return "______Target_\(c99name)" }
45-
var groupReference: String { return "_______Group_\(c99name)" }
46-
var configurationListReference: String { return "_______Confs_\(c99name)" }
47-
var configurationReference: String { return "___DebugConf_\(c99name)" }
48-
var compilePhaseReference: String { return "CompilePhase_\(c99name)" }
49-
var linkPhaseReference: String { return "___LinkPhase_\(c99name)" }
43+
var dependencyReference: String { return "__Dependency_\(c99name)" }
44+
var productReference: String { return "_____Product_\(c99name)" }
45+
var targetReference: String { return "______Target_\(c99name)" }
46+
var groupReference: String { return "_______Group_\(c99name)" }
47+
var configurationListReference: String { return "_______Confs_\(c99name)" }
48+
var debugConfigurationReference: String { return "___DebugConf_\(c99name)" }
49+
var releaseConfigurationReference: String { return "_ReleaseConf_\(c99name)" }
50+
var compilePhaseReference: String { return "CompilePhase_\(c99name)" }
51+
var linkPhaseReference: String { return "___LinkPhase_\(c99name)" }
5052
}
5153

5254
func fileRef(forLinkPhaseChild module: Module) -> String {
@@ -138,12 +140,23 @@ extension SwiftModule {
138140
}
139141
}
140142

141-
var buildSettings: String {
143+
var debugBuildSettings: String {
144+
var buildSettings = commonBuildSettings
145+
buildSettings["SWIFT_OPTIMIZATION_LEVEL"] = "-Onone"
146+
147+
return buildSettings.map{ "\($0) = \($1);" }.joinWithSeparator(" ")
148+
}
149+
150+
var releaseBuildSettings: String {
151+
let buildSettings = commonBuildSettings
152+
return buildSettings.map{ "\($0) = \($1);" }.joinWithSeparator(" ")
153+
}
154+
155+
private var commonBuildSettings: [String: String] {
142156
var buildSettings = ["PRODUCT_NAME": productName]
143157
buildSettings["PRODUCT_MODULE_NAME"] = c99name
144158
buildSettings["OTHER_SWIFT_FLAGS"] = "-DXcode"
145159
buildSettings["MACOSX_DEPLOYMENT_TARGET"] = "'10.10'"
146-
buildSettings["SWIFT_OPTIMIZATION_LEVEL"] = "-Onone"
147160

148161
// prevents Xcode project upgrade warnings
149162
buildSettings["COMBINE_HIDPI_IMAGES"] = "YES"
@@ -175,7 +188,7 @@ extension SwiftModule {
175188
}
176189
}
177190

178-
return buildSettings.map{ "\($0) = \($1);" }.joinWithSeparator(" ")
191+
return buildSettings
179192
}
180193
}
181194

Sources/Xcodeproj/TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ The following features are welcome, please submit a PR:
55
* Split out tests and non-tests in Products group
66
* Enable code coverage
77
* Allow frameworks instead of dylibs and add a command line toggle
8-
* Release configuration
98
* Nest Groups for module sources, eg. Sources/Bar/Foo/Baz.swift would be in Xcode groups: Source -> Bar -> Foo -> Baz.swift
109
* Put dependencies in Package-named sub groups of a group called "Dependencies"

Sources/Xcodeproj/pbxproj().swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,20 @@ public func pbxproj(package package: Package, modules: [SwiftModule], products _
121121
// the target build configuration
122122
print(" \(module.configurationListReference) = {")
123123
print(" isa = XCConfigurationList;")
124-
print(" buildConfigurations = (\(module.configurationReference));")
124+
print(" buildConfigurations = (\(module.debugConfigurationReference), \(module.releaseConfigurationReference));")
125125
print(" defaultConfigurationIsVisible = 0;")
126126
print(" defaultConfigurationName = Debug;")
127127
print(" };")
128-
print(" \(module.configurationReference) = {")
128+
print(" \(module.debugConfigurationReference) = {")
129129
print(" isa = XCBuildConfiguration;")
130-
print(" buildSettings = { \(module.buildSettings) };")
130+
print(" buildSettings = { \(module.debugBuildSettings) };")
131131
print(" name = Debug;")
132132
print(" };")
133+
print(" \(module.releaseConfigurationReference) = {")
134+
print(" isa = XCBuildConfiguration;")
135+
print(" buildSettings = { \(module.releaseBuildSettings) };")
136+
print(" name = Release;")
137+
print(" };")
133138

134139
//TODO ^^ probably can consolidate this into the three kinds
135140
//TODO we use rather than have one per module
@@ -166,19 +171,24 @@ public func pbxproj(package package: Package, modules: [SwiftModule], products _
166171
print(" };")
167172

168173
////// primary build configurations
169-
print(" \(rootBuildConfigurationReference) = {")
174+
print(" \(rootDebugBuildConfigurationReference) = {")
170175
print(" isa = XCBuildConfiguration;")
171176
print(" buildSettings = {};")
172177
print(" name = Debug;")
173178
print(" };")
179+
print(" \(rootReleaseBuildConfigurationReference) = {")
180+
print(" isa = XCBuildConfiguration;")
181+
print(" buildSettings = {};")
182+
print(" name = Release;")
183+
print(" };")
174184
print(" \(rootBuildConfigurationListReference) = {")
175185
print(" isa = XCConfigurationList;")
176-
print(" buildConfigurations = (\(rootBuildConfigurationReference));")
186+
print(" buildConfigurations = (\(rootDebugBuildConfigurationReference), \(rootReleaseBuildConfigurationReference));")
177187
print(" defaultConfigurationIsVisible = 0;")
178188
print(" defaultConfigurationName = Debug;")
179189
print(" };")
180190
print(" };")
181-
191+
182192
////// done!
183193
print("}")
184194
}

0 commit comments

Comments
 (0)