From d0c257e938a31237c315d0f8ffcc6cb18ea9f2af Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Mon, 28 Jan 2019 14:49:17 +1100 Subject: [PATCH] don't partial apply exact config matches --- Docs/ProjectSpec.md | 2 +- Sources/XcodeGenKit/SettingsBuilder.swift | 9 +++++++-- Tests/XcodeGenKitTests/ProjectGeneratorTests.swift | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 3dbfbf4b..08ca7cd6 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -155,7 +155,7 @@ settingGroups: Settings can either be a simple map of build settings `[String:String]`, or can be more advanced with the following properties: - [ ] **groups**: **[String]** - List of setting groups to include and merge -- [ ] **configs**: **[String:[Settings](#settings)]** - Mapping of config name to a settings spec. These settings will only be applied for that config. Each key will be matched to any configs that contain the key and is case insensitive. So if you had `Staging Debug` and `Staging Release`, you could apply settings to both of them using `staging`. +- [ ] **configs**: **[String:[Settings](#settings)]** - Mapping of config name to a settings spec. These settings will only be applied for that config. Each key will be matched to any configs that contain the key and is case insensitive. So if you had `Staging Debug` and `Staging Release`, you could apply settings to both of them using `staging`. However if a config name is an exact match to a config it won't be applied to any others. eg `Release` will be applied to config `Release` but not `Staging Release` - [ ] **base**: **[String:String]** - Used to specify default settings that apply to any config ```yaml diff --git a/Sources/XcodeGenKit/SettingsBuilder.swift b/Sources/XcodeGenKit/SettingsBuilder.swift index 5415d839..a8ad7abb 100644 --- a/Sources/XcodeGenKit/SettingsBuilder.swift +++ b/Sources/XcodeGenKit/SettingsBuilder.swift @@ -81,8 +81,13 @@ extension Project { buildSettings += settings.buildSettings for (configVariant, settings) in settings.configSettings { - if config.name.lowercased().contains(configVariant.lowercased()) { - buildSettings += getBuildSettings(settings: settings, config: config) + let isPartialMatch = config.name.lowercased().contains(configVariant.lowercased()) + if isPartialMatch { + let exactConfig = getConfig(configVariant) + let matchesExactlyToOtherConfig = exactConfig != nil && exactConfig?.name != config.name + if !matchesExactlyToOtherConfig { + buildSettings += getBuildSettings(settings: settings, config: config) + } } } diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index 89b523d1..9738379d 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -179,15 +179,25 @@ class ProjectGeneratorTests: XCTestCase { basePath: "", name: "test", configs: [ + Config(name: "Release", type: .release), Config(name: "Staging Debug", type: .debug), Config(name: "Staging Release", type: .release), ], - settings: Settings(configSettings: ["staging": ["SETTING1": "VALUE1"], "debug": ["SETTING2": "VALUE2"]]) + settings: Settings(configSettings: [ + "staging": ["SETTING1": "VALUE1"], + "debug": ["SETTING2": "VALUE2"], + "Release": ["SETTING3": "VALUE3"], + ] + ) ) - var buildSettings = project.getProjectBuildSettings(config: project.configs.first!) + var buildSettings = project.getProjectBuildSettings(config: project.configs[1]) try expect(buildSettings["SETTING1"] as? String) == "VALUE1" try expect(buildSettings["SETTING2"] as? String) == "VALUE2" + + // don't apply partial when exact match + buildSettings = project.getProjectBuildSettings(config: project.configs[2]) + try expect(buildSettings["SETTING3"]).beNil() } $0.it("sets project SDKROOT if there is only a single platform") {