Skip to content

Commit

Permalink
Merge pull request #269 from yonaskolb/ks/defaultConfigurationName
Browse files Browse the repository at this point in the history
Add defaultConfigurationName to options
  • Loading branch information
yonaskolb authored Mar 19, 2018
2 parents ad3aaaa + 6f95e57 commit 9ebb927
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Note that target names can also be changed by adding a `name` property to a targ
- [ ] **deploymentTarget**: **[[Platform](#platform): String]** - A project wide deployment target can be specified for each platform otherwise the default SDK version in Xcode will be used. This will be overridden by any custom build settings that set the deployment target eg `IPHONEOS_DEPLOYMENT_TARGET`. Target specific deployment targets can also be set with [Target](#target).deploymentTarget.
- [ ] **disabledValidations**: **[String]** - A list of validations that can be disabled if they're too strict for your use case. By default this is set to an empty array. Currently these are the available options:
- `missingConfigs`: Disable errors for configurations in yaml files that don't exist in the project itself. This can be useful if you include the same yaml file in different projects
- [ ] **defaultConfig**: **String** - The default configuration for command line builds from Xcode. If the configuration provided here doesn't match one in your [configs](#configs) key, XcodeGen will fail. If you don't set this, the first configuration alphabetically will be chosen.

```yaml
options:
Expand Down
6 changes: 5 additions & 1 deletion Sources/ProjectSpec/ProjectSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public struct ProjectSpec {
public var indentWidth: UInt?
public var xcodeVersion: String?
public var deploymentTarget: DeploymentTarget
public var defaultConfig: String?

public enum SettingPresets: String {
case all
Expand Down Expand Up @@ -66,7 +67,8 @@ public struct ProjectSpec {
usesTabs: Bool? = nil,
xcodeVersion: String? = nil,
deploymentTarget: DeploymentTarget = .init(),
disabledValidations: [ValidationType] = []
disabledValidations: [ValidationType] = [],
defaultConfig: String? = nil
) {
self.carthageBuildPath = carthageBuildPath
self.carthageExecutablePath = carthageExecutablePath
Expand All @@ -80,6 +82,7 @@ public struct ProjectSpec {
self.xcodeVersion = xcodeVersion
self.deploymentTarget = deploymentTarget
self.disabledValidations = disabledValidations
self.defaultConfig = defaultConfig
}

public static func == (lhs: ProjectSpec.Options, rhs: ProjectSpec.Options) -> Bool {
Expand Down Expand Up @@ -217,5 +220,6 @@ extension ProjectSpec.Options: JSONObjectConvertible {
tabWidth = (jsonDictionary.json(atKeyPath: "tabWidth") as Int?).flatMap(UInt.init)
deploymentTarget = jsonDictionary.json(atKeyPath: "deploymentTarget") ?? DeploymentTarget()
disabledValidations = jsonDictionary.json(atKeyPath: "disabledValidations") ?? []
defaultConfig = jsonDictionary.json(atKeyPath: "defaultConfig")
}
}
6 changes: 6 additions & 0 deletions Sources/ProjectSpec/SpecValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ extension ProjectSpec {
}
}

if let configName = options.defaultConfig {
if !configs.contains(where: { $0.name == configName }) {
errors.append(.missingDefaultConfig(configName: configName))
}
}

for settings in settingGroups.values {
errors += validateSettings(settings)
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/ProjectSpec/SpecValidationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public struct SpecValidationError: Error, CustomStringConvertible {
case invalidFileGroup(String)
case invalidConfigFileConfig(String)
case missingConfigForTargetScheme(target: String, configType: ConfigType)
case missingDefaultConfig(configName: String)

public var description: String {
switch self {
Expand Down Expand Up @@ -50,6 +51,8 @@ public struct SpecValidationError: Error, CustomStringConvertible {
return "Config file has invalid config \(config.quoted)"
case let .missingConfigForTargetScheme(target, configType):
return "Target \(target.quoted) is missing a config of type \(configType.rawValue) to generate its scheme"
case let .missingDefaultConfig(name):
return "Default configuration \(name) doesn't exist"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ public class PBXProjGenerator {
)
}

let configName = spec.options.defaultConfig ?? buildConfigs.first?.object.name ?? ""
let buildConfigList = createObject(
id: spec.name,
XCConfigurationList(
buildConfigurations: buildConfigs.map { $0.reference },
defaultConfigurationName: buildConfigs.first?.object.name ?? ""
defaultConfigurationName: configName
)
)

Expand Down
14 changes: 14 additions & 0 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ func projectGeneratorTests() {
try expect(XCodeVersion.parse(version)) == expected
}
}

$0.it("uses the default configuration name") {
let options = ProjectSpec.Options(defaultConfig: "Bconfig")
let spec = ProjectSpec(basePath: "", name: "test", configs: [Config(name: "Aconfig"), Config(name: "Bconfig")], targets: [framework], options: options)
let pbxProject = try getPbxProj(spec)

guard let projectConfigListReference = pbxProject.objects.projects.values.first?.buildConfigurationList,
let defaultConfigurationName = pbxProject.objects.configurationLists[projectConfigListReference]?.defaultConfigurationName
else {
throw failure("Default configuration name not found")
}

try expect(defaultConfigurationName) == "Bconfig"
}
}

$0.describe("Config") {
Expand Down
6 changes: 6 additions & 0 deletions Tests/XcodeGenKitTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ func projectSpecTests() {
)]
try spec.validate()
}

$0.it("validates missing default configurations") {
var spec = baseSpec
spec.options = ProjectSpec.Options(defaultConfig: "foo")
try expectValidationError(spec, .missingDefaultConfig(configName: "foo"))
}
}
}
}

0 comments on commit 9ebb927

Please sign in to comment.