From 774bbe8632377ae4dfb77a74a67f93138d4d55bc Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 4 Jan 2018 13:48:41 -0800 Subject: [PATCH] Add new option for disabling validations 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. --- CHANGELOG.md | 3 +++ Docs/ProjectSpec.md | 2 ++ Sources/ProjectSpec/ProjectSpec.swift | 13 +++++++++++-- Sources/ProjectSpec/SpecValidation.swift | 4 ++-- Tests/Fixtures/test.xcconfig | 0 Tests/XcodeGenKitTests/ProjectSpecTests.swift | 9 +++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 Tests/Fixtures/test.xcconfig diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c093db8..d031c827 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index aadb8e59..8aadda6c 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -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: diff --git a/Sources/ProjectSpec/ProjectSpec.swift b/Sources/ProjectSpec/ProjectSpec.swift index 31a19691..ce9eac55 100644 --- a/Sources/ProjectSpec/ProjectSpec.swift +++ b/Sources/ProjectSpec/ProjectSpec.swift @@ -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? @@ -52,6 +53,10 @@ public struct ProjectSpec { } } + public enum DisabledValidations: String { + case missingConfigs + } + public init( carthageBuildPath: String? = nil, createIntermediateGroups: Bool = false, @@ -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 @@ -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 { @@ -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 } } @@ -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") ?? [] } } diff --git a/Sources/ProjectSpec/SpecValidation.swift b/Sources/ProjectSpec/SpecValidation.swift index ab8411b7..79440c83 100644 --- a/Sources/ProjectSpec/SpecValidation.swift +++ b/Sources/ProjectSpec/SpecValidation.swift @@ -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)) } } @@ -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)) } } diff --git a/Tests/Fixtures/test.xcconfig b/Tests/Fixtures/test.xcconfig new file mode 100644 index 00000000..e69de29b diff --git a/Tests/XcodeGenKitTests/ProjectSpecTests.swift b/Tests/XcodeGenKitTests/ProjectSpecTests.swift index fc02ce9e..fc6f2c93 100644 --- a/Tests/XcodeGenKitTests/ProjectSpecTests.swift +++ b/Tests/XcodeGenKitTests/ProjectSpecTests.swift @@ -1,6 +1,7 @@ import Spectre import XcodeGenKit import xcproj +import PathKit import ProjectSpec func projectSpecTests() { @@ -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(