Skip to content

Commit 1581726

Browse files
committed
Merge pull request #185 from AquaGeek/release-configuration
Add release configuration
2 parents e8d650e + 4d0acf2 commit 1581726

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
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 testProductsGroupReference = "TestProducts_"
@@ -40,14 +41,15 @@ let sourceGroupFileRefPrefix = "__PBXFileRef_"
4041
let compilePhaseFileRefPrefix = "__src_cc_ref_"
4142

4243
extension Module {
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 configurationReference: String { return "___DebugConf_\(c99name)" }
49-
var compilePhaseReference: String { return "CompilePhase_\(c99name)" }
50-
var linkPhaseReference: String { return "___LinkPhase_\(c99name)" }
44+
var dependencyReference: String { return "__Dependency_\(c99name)" }
45+
var productReference: String { return "_____Product_\(c99name)" }
46+
var targetReference: String { return "______Target_\(c99name)" }
47+
var groupReference: String { return "_______Group_\(c99name)" }
48+
var configurationListReference: String { return "_______Confs_\(c99name)" }
49+
var debugConfigurationReference: String { return "___DebugConf_\(c99name)" }
50+
var releaseConfigurationReference: String { return "_ReleaseConf_\(c99name)" }
51+
var compilePhaseReference: String { return "CompilePhase_\(c99name)" }
52+
var linkPhaseReference: String { return "___LinkPhase_\(c99name)" }
5153
}
5254

5355
func fileRef(forLinkPhaseChild module: Module) -> String {
@@ -139,12 +141,23 @@ extension SwiftModule {
139141
}
140142
}
141143

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

149162
// prevents Xcode project upgrade warnings
150163
buildSettings["COMBINE_HIDPI_IMAGES"] = "YES"
@@ -176,7 +189,7 @@ extension SwiftModule {
176189
}
177190
}
178191

179-
return buildSettings.map{ "\($0) = \($1);" }.joined(separator: " ")
192+
return buildSettings
180193
}
181194
}
182195

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
@@ -119,15 +119,20 @@ public func pbxproj(srcroot srcroot: String, projectRoot: String, modules: [Swif
119119
// the target build configuration
120120
print(" \(module.configurationListReference) = {")
121121
print(" isa = XCConfigurationList;")
122-
print(" buildConfigurations = (\(module.configurationReference));")
122+
print(" buildConfigurations = (\(module.debugConfigurationReference), \(module.releaseConfigurationReference));")
123123
print(" defaultConfigurationIsVisible = 0;")
124124
print(" defaultConfigurationName = Debug;")
125125
print(" };")
126-
print(" \(module.configurationReference) = {")
126+
print(" \(module.debugConfigurationReference) = {")
127127
print(" isa = XCBuildConfiguration;")
128-
print(" buildSettings = { \(module.buildSettings) };")
128+
print(" buildSettings = { \(module.debugBuildSettings) };")
129129
print(" name = Debug;")
130130
print(" };")
131+
print(" \(module.releaseConfigurationReference) = {")
132+
print(" isa = XCBuildConfiguration;")
133+
print(" buildSettings = { \(module.releaseBuildSettings) };")
134+
print(" name = Release;")
135+
print(" };")
131136

132137
//TODO ^^ probably can consolidate this into the three kinds
133138
//TODO we use rather than have one per module
@@ -189,19 +194,24 @@ public func pbxproj(srcroot srcroot: String, projectRoot: String, modules: [Swif
189194
print(" };")
190195

191196
////// primary build configurations
192-
print(" \(rootBuildConfigurationReference) = {")
197+
print(" \(rootDebugBuildConfigurationReference) = {")
193198
print(" isa = XCBuildConfiguration;")
194199
print(" buildSettings = {};")
195200
print(" name = Debug;")
196201
print(" };")
202+
print(" \(rootReleaseBuildConfigurationReference) = {")
203+
print(" isa = XCBuildConfiguration;")
204+
print(" buildSettings = {};")
205+
print(" name = Release;")
206+
print(" };")
197207
print(" \(rootBuildConfigurationListReference) = {")
198208
print(" isa = XCConfigurationList;")
199-
print(" buildConfigurations = (\(rootBuildConfigurationReference));")
209+
print(" buildConfigurations = (\(rootDebugBuildConfigurationReference), \(rootReleaseBuildConfigurationReference));")
200210
print(" defaultConfigurationIsVisible = 0;")
201211
print(" defaultConfigurationName = Debug;")
202212
print(" };")
203213
print(" };")
204-
214+
205215
////// done!
206216
print("}")
207217
}

Tests/Xcodeproj/TestGeneration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TestGeneration: XCTestCase {
5858

5959
let output = try popen(["xcodebuild", "-list", "-project", outpath])
6060

61-
let expectedOutput = "Information about project \"DummyProjectName\":\n Targets:\n DummyModuleName\n\n Build Configurations:\n Debug\n\n If no build configuration is specified and -scheme is not passed then \"Debug\" is used.\n\n Schemes:\n DummyProjectName\n"
61+
let expectedOutput = "Information about project \"DummyProjectName\":\n Targets:\n DummyModuleName\n\n Build Configurations:\n Debug\n Release\n\n If no build configuration is specified and -scheme is not passed then \"Debug\" is used.\n\n Schemes:\n DummyProjectName\n"
6262

6363
XCTAssertEqual(output, expectedOutput)
6464
}

0 commit comments

Comments
 (0)