Skip to content

Commit

Permalink
Merge pull request #431 from yonaskolb/config_setting_validation
Browse files Browse the repository at this point in the history
Validate incorrect config settings definitions
  • Loading branch information
yonaskolb committed Nov 2, 2018
2 parents b50a761 + 3eaed1e commit db616db
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -49,10 +49,11 @@ targets:
deploymentTarget: "10.0"
sources: [MyApp]
settings:
debug:
CUSTOM_BUILD_SETTING: my_debug_value
release:
CUSTOM_BUILD_SETTING: my_release_value
configs:
debug:
CUSTOM_BUILD_SETTING: my_debug_value
release:
CUSTOM_BUILD_SETTING: my_release_value
dependencies:
- target: MyFramework
- carthage: Alamofire
Expand Down
18 changes: 18 additions & 0 deletions Sources/ProjectSpec/SpecValidation.swift
Expand Up @@ -22,6 +22,24 @@ extension Project {
}
}
}

if settings.buildSettings.count == configs.count {
var allConfigs = true
for buildSetting in settings.buildSettings.keys {
var isConfig = false
for config in configs {
if config.name.lowercased().contains(buildSetting.lowercased()) {
isConfig = true
}
}
if !isConfig {
allConfigs = false
}
}
if allConfigs {
errors.append(.invalidPerConfigSettings)
}
}
return errors
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/ProjectSpec/SpecValidationError.swift
Expand Up @@ -21,6 +21,7 @@ public struct SpecValidationError: Error, CustomStringConvertible {
case invalidConfigFileConfig(String)
case missingConfigForTargetScheme(target: String, configType: ConfigType)
case missingDefaultConfig(configName: String)
case invalidPerConfigSettings

public var description: String {
switch self {
Expand Down Expand Up @@ -56,6 +57,8 @@ public struct SpecValidationError: Error, CustomStringConvertible {
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"
case .invalidPerConfigSettings:
return "Settings that are for a specific config must go in \"configs\". \"base\" can be used for common settings"
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/XcodeGenKitTests/ProjectSpecTests.swift
Expand Up @@ -205,6 +205,14 @@ class ProjectSpecTests: XCTestCase {
try expectValidationError(project, .missingDefaultConfig(configName: "foo"))
}

$0.it("validates config settings format") {
var project = baseProject
project.configs = Config.defaultConfigs
project.settings.buildSettings = ["Debug": ["SETTING": "VALUE"], "Release": ["SETTING": "VALUE"]]

try expectValidationError(project, .invalidPerConfigSettings)
}

$0.it("allows custom scheme for aggregated target") {
var project = baseProject
let buildScript = BuildScript(script: .path(#file), name: "buildScript1")
Expand Down

0 comments on commit db616db

Please sign in to comment.