Skip to content

Commit

Permalink
Add new option for disabling validations
Browse files Browse the repository at this point in the history
This gives us an entry point for disabling specific project.yml
validations that sometimes shouldn't apply. The first example is
missingConfigs, which, if you use your .yml file in multiple projects,
can be too strict if the projects have different top level
configurations.
  • Loading branch information
keith committed Jan 4, 2018
1 parent 2fcf47c commit 774bbe8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Master

#### Added
- add `disabledValidations` to options to disable the `missingConfigs` project validation error [#220](https://github.com/yonaskolb/XcodeGen/pull/220) @keith

## 1.5.0

#### Added
Expand Down
2 changes: 2 additions & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Note that target names can also be changed by adding a `name` property to a targ
- [ ] **tabWidth**: **Int** - If this is specified, the Xcode project will override the user's setting for indent width in number of spaces.
- [ ] **xcodeVersion**: **String** - The version of Xcode. This defaults to the latest version periodically. You can specify it in the format `0910` or `9.1`
- [ ] **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

```yaml
options:
Expand Down
13 changes: 11 additions & 2 deletions Sources/ProjectSpec/ProjectSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public struct ProjectSpec {
public var createIntermediateGroups: Bool
public var bundleIdPrefix: String?
public var settingPresets: SettingPresets
public var disabledValidations: [DisabledValidations]
public var developmentLanguage: String?
public var usesTabs: Bool?
public var tabWidth: Int?
Expand Down Expand Up @@ -52,6 +53,10 @@ public struct ProjectSpec {
}
}

public enum DisabledValidations: String {
case missingConfigs
}

public init(
carthageBuildPath: String? = nil,
createIntermediateGroups: Bool = false,
Expand All @@ -62,7 +67,8 @@ public struct ProjectSpec {
tabWidth: Int? = nil,
usesTabs: Bool? = nil,
xcodeVersion: String? = nil,
deploymentTarget: DeploymentTarget = .init()
deploymentTarget: DeploymentTarget = .init(),
disabledValidations: [DisabledValidations] = []
) {
self.carthageBuildPath = carthageBuildPath
self.createIntermediateGroups = createIntermediateGroups
Expand All @@ -74,6 +80,7 @@ public struct ProjectSpec {
self.usesTabs = usesTabs
self.xcodeVersion = xcodeVersion
self.deploymentTarget = deploymentTarget
self.disabledValidations = disabledValidations
}

public static func == (lhs: ProjectSpec.Options, rhs: ProjectSpec.Options) -> Bool {
Expand All @@ -86,7 +93,8 @@ public struct ProjectSpec {
lhs.indentWidth == rhs.indentWidth &&
lhs.usesTabs == rhs.usesTabs &&
lhs.xcodeVersion == rhs.xcodeVersion &&
lhs.deploymentTarget == rhs.deploymentTarget
lhs.deploymentTarget == rhs.deploymentTarget &&
lhs.disabledValidations == rhs.disabledValidations
}
}

Expand Down Expand Up @@ -207,5 +215,6 @@ extension ProjectSpec.Options: JSONObjectConvertible {
indentWidth = jsonDictionary.json(atKeyPath: "indentWidth")
tabWidth = jsonDictionary.json(atKeyPath: "tabWidth")
deploymentTarget = jsonDictionary.json(atKeyPath: "deploymentTarget") ?? DeploymentTarget()
disabledValidations = jsonDictionary.json(atKeyPath: "disabledValidations") ?? []
}
}
4 changes: 2 additions & 2 deletions Sources/ProjectSpec/SpecValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension ProjectSpec {
if !(basePath + configFile).exists {
errors.append(.invalidConfigFile(configFile: configFile, config: config))
}
if getConfig(config) == nil {
if !options.disabledValidations.contains(.missingConfigs) && getConfig(config) == nil {
errors.append(.invalidConfigFileConfig(config))
}
}
Expand All @@ -56,7 +56,7 @@ extension ProjectSpec {
if !(basePath + configFile).exists {
errors.append(.invalidTargetConfigFile(target: target.name, configFile: configFile, config: config))
}
if getConfig(config) == nil {
if !options.disabledValidations.contains(.missingConfigs) && getConfig(config) == nil {
errors.append(.invalidConfigFileConfig(config))
}
}
Expand Down
Empty file added Tests/Fixtures/test.xcconfig
Empty file.
9 changes: 9 additions & 0 deletions Tests/XcodeGenKitTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Spectre
import XcodeGenKit
import xcproj
import PathKit
import ProjectSpec

func projectSpecTests() {
Expand Down Expand Up @@ -101,6 +102,14 @@ func projectSpecTests() {
try expectValidationError(spec, .invalidBuildSettingConfig("invalidSettingGroupConfig"))
}

$0.it("allows non-existent configurations") {
var spec = baseSpec
spec.options = ProjectSpec.Options(disabledValidations: [.missingConfigs])
let configPath = fixturePath + "test.xcconfig"
spec.configFiles = ["missingConfiguration": configPath.string]
try spec.validate()
}

$0.it("fails with invalid target") {
var spec = baseSpec
spec.targets = [Target(
Expand Down

0 comments on commit 774bbe8

Please sign in to comment.