From d8ffafe4cf9a64557d9d4e8dee9c0326aad378cc Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Sat, 26 Aug 2017 18:32:43 +0200 Subject: [PATCH] rename setting presets to setting groups --- Fixtures/TestProject/environment_test.yml | 2 +- Fixtures/settings_test.yml | 16 ++++----- README.md | 2 +- Sources/ProjectSpec/ProjectSpec.swift | 10 +++--- Sources/ProjectSpec/Settings.swift | 22 ++++++------ Sources/ProjectSpec/Target.swift | 2 +- Sources/XcodeGenKit/ProjectGenerator.swift | 6 ++-- Sources/XcodeGenKit/SettingsBuilder.swift | 4 +-- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 34 +++++++++---------- docs/ProjectSpec.md | 24 ++++++------- 10 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Fixtures/TestProject/environment_test.yml b/Fixtures/TestProject/environment_test.yml index 511946f1..b9e69021 100644 --- a/Fixtures/TestProject/environment_test.yml +++ b/Fixtures/TestProject/environment_test.yml @@ -1,5 +1,5 @@ name: EnvironmentTest -settingPresets: +settingGroups: app: PRODUCT_BUNDLE_IDENTIFIER: com.app$(BUNDLE_ID_SUFFIX)$(BUNDLE_ID_EXTENSION_SUFFIX) test: diff --git a/Fixtures/settings_test.yml b/Fixtures/settings_test.yml index dd460812..5b07f38f 100644 --- a/Fixtures/settings_test.yml +++ b/Fixtures/settings_test.yml @@ -8,11 +8,11 @@ settings: configs: my_config: BUILD_SETTING_2: value 2 - presets: + groups: - my_settings name: SettingsTest -settingPresets: +settingGroups: preset1: SETTING: value preset2: @@ -29,12 +29,12 @@ settingPresets: base: SETTING: value preset5: - presets: + groups: - preset1 base: SETTING: value preset6: - presets: + groups: - preset1 base: SETTING: value @@ -46,7 +46,7 @@ settingPresets: SETTING: value configs: config1: - presets: + groups: - preset1 base: SETTING: value @@ -59,7 +59,7 @@ settingPresets: settings: base: SETTING 5: value 5 - presets: + groups: - preset7 configs: config1: @@ -72,13 +72,13 @@ targets: type: application platform: iOS settings: - presets: + groups: - preset7 base: SETTING 2: value 2 configs: config1: - presets: + groups: - preset1 base: SETTING 3: value 3 diff --git a/README.md b/README.md index 76d7aa36..150bc232 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The project spec is a YAML or JSON file that defines your targets, configuration - ✅ Groups in Xcode are always **synced** to your directories on disk - ✅ Create projects on demand and remove your `.xcodeproj` file from git, which means **no merge conflicts**! - ✅ Easily **copy and paste** files and directories without having to edit anything in xcode -- ✅ Share build settings across multiple targets with **build setting presets** +- ✅ Share build settings across multiple targets with **build setting groups** - ✅ Automatically generate Schemes for **different environments** like test and production - ✅ Easily **create new projects** with complicated setups on demand without messing around with Xcode - ✅ Generate from anywhere including **Continuous Delivery** servers diff --git a/Sources/ProjectSpec/ProjectSpec.swift b/Sources/ProjectSpec/ProjectSpec.swift index 6c1b50bc..f6204268 100644 --- a/Sources/ProjectSpec/ProjectSpec.swift +++ b/Sources/ProjectSpec/ProjectSpec.swift @@ -17,7 +17,7 @@ public struct ProjectSpec { public var name: String public var targets: [Target] public var settings: Settings - public var settingPresets: [String: Settings] + public var settingGroups: [String: Settings] public var configs: [Config] public var schemes: [Scheme] public var options: Options @@ -30,12 +30,12 @@ public struct ProjectSpec { } } - public init(name: String, configs: [Config] = [], targets: [Target] = [], settings: Settings = .empty, settingPresets: [String: Settings] = [:], schemes: [Scheme] = [], options: Options = Options()) { + public init(name: String, configs: [Config] = [], targets: [Target] = [], settings: Settings = .empty, settingGroups: [String: Settings] = [:], schemes: [Scheme] = [], options: Options = Options()) { self.name = name self.targets = targets self.configs = configs self.settings = settings - self.settingPresets = settingPresets + self.settingGroups = settingGroups self.schemes = schemes self.options = options } @@ -55,7 +55,7 @@ extension ProjectSpec: Equatable { return lhs.name == rhs.name && lhs.targets == rhs.targets && lhs.settings == rhs.settings && - lhs.settingPresets == rhs.settingPresets && + lhs.settingGroups == rhs.settingGroups && lhs.configs == rhs.configs && lhs.schemes == rhs.schemes && lhs.options == rhs.options @@ -86,7 +86,7 @@ extension ProjectSpec { public init(jsonDictionary: JSONDictionary) throws { name = try jsonDictionary.json(atKeyPath: "name") settings = jsonDictionary.json(atKeyPath: "settings") ?? .empty - settingPresets = jsonDictionary.json(atKeyPath: "settingPresets") ?? [:] + settingGroups = jsonDictionary.json(atKeyPath: "settingGroups") ?? jsonDictionary.json(atKeyPath: "settingPresets") ?? [:] let configs: [String: String] = jsonDictionary.json(atKeyPath: "configs") ?? [:] self.configs = configs.map { Config(name: $0, type: ConfigType(rawValue: $1)) } self.targets = try Target.decodeTargets(jsonDictionary: jsonDictionary) diff --git a/Sources/ProjectSpec/Settings.swift b/Sources/ProjectSpec/Settings.swift index 2e6e9846..e1c719d3 100644 --- a/Sources/ProjectSpec/Settings.swift +++ b/Sources/ProjectSpec/Settings.swift @@ -15,46 +15,46 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl public let buildSettings: BuildSettings public let configSettings: [String: Settings] - public let presets: [String] + public let groups: [String] - public init(buildSettings: BuildSettings = [:], configSettings: [String: Settings] = [:], presets: [String] = []) { + public init(buildSettings: BuildSettings = [:], configSettings: [String: Settings] = [:], groups: [String] = []) { self.buildSettings = buildSettings self.configSettings = configSettings - self.presets = presets + self.groups = groups } public init(dictionary: [String: Any]) { buildSettings = dictionary configSettings = [:] - presets = [] + groups = [] } static let empty: Settings = Settings(dictionary: [:]) public init(jsonDictionary: JSONDictionary) throws { - if jsonDictionary["configs"] != nil || jsonDictionary["presets"] != nil || jsonDictionary["base"] != nil { - presets = jsonDictionary.json(atKeyPath: "presets") ?? [] + if jsonDictionary["configs"] != nil || jsonDictionary["groups"] != nil || jsonDictionary["base"] != nil { + groups = jsonDictionary.json(atKeyPath: "groups") ?? jsonDictionary.json(atKeyPath: "presets") ?? [] let buildSettingsDictionary: JSONDictionary = jsonDictionary.json(atKeyPath: "base") ?? [:] buildSettings = buildSettingsDictionary configSettings = jsonDictionary.json(atKeyPath: "configs") ?? [:] } else { buildSettings = jsonDictionary configSettings = [:] - presets = [] + groups = [] } } public static func ==(lhs: Settings, rhs: Settings) -> Bool { return NSDictionary(dictionary: lhs.buildSettings).isEqual(to: rhs.buildSettings) && lhs.configSettings == rhs.configSettings && - lhs.presets == rhs.presets + lhs.groups == rhs.groups } public var description: String { var string: String = "" if !buildSettings.isEmpty { let buildSettingDescription = buildSettings.map { "\($0) = \($1)" }.joined(separator: "\n") - if !configSettings.isEmpty || !presets.isEmpty { + if !configSettings.isEmpty || !groups.isEmpty { string += "base:\n " + buildSettingDescription.replacingOccurrences(of: "(.)\n", with: "$1\n ", options: .regularExpression, range: nil) } else { string += buildSettingDescription @@ -71,11 +71,11 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl } } } - if !presets.isEmpty { + if !groups.isEmpty { if !string.isEmpty { string += "\n" } - string += "presets:\n \(presets.joined(separator: "\n "))" + string += "groups:\n \(groups.joined(separator: "\n "))" } return string } diff --git a/Sources/ProjectSpec/Target.swift b/Sources/ProjectSpec/Target.swift index ae502280..740c7c5f 100644 --- a/Sources/ProjectSpec/Target.swift +++ b/Sources/ProjectSpec/Target.swift @@ -92,7 +92,7 @@ extension Target { platformTarget["name"] = platformPrefix + name + platformSuffix var settings = platformTarget["settings"] as? JSONDictionary ?? [:] - if settings["configs"] != nil || settings["presets"] != nil || settings["base"] != nil { + if settings["configs"] != nil || settings["groups"] != nil || settings["base"] != nil { var base = settings["base"] as? JSONDictionary ?? [:] if base["PRODUCT_NAME"] == nil { base["PRODUCT_NAME"] = name diff --git a/Sources/XcodeGenKit/ProjectGenerator.swift b/Sources/XcodeGenKit/ProjectGenerator.swift index 28489873..fba22efc 100644 --- a/Sources/XcodeGenKit/ProjectGenerator.swift +++ b/Sources/XcodeGenKit/ProjectGenerator.swift @@ -42,8 +42,8 @@ public class ProjectGenerator { func validateSettings(_ settings: Settings) -> [SpecValidationError.Error] { var errors: [SpecValidationError.Error] = [] - for preset in settings.presets { - if let settings = spec.settingPresets[preset] { + for preset in settings.groups { + if let settings = spec.settingGroups[preset] { errors += validateSettings(settings) } else { errors.append(.invalidSettingsPreset(preset)) @@ -52,7 +52,7 @@ public class ProjectGenerator { return errors } - for settings in spec.settingPresets.values { + for settings in spec.settingGroups.values { errors += validateSettings(settings) } diff --git a/Sources/XcodeGenKit/SettingsBuilder.swift b/Sources/XcodeGenKit/SettingsBuilder.swift index fbc7cbc7..c579665a 100644 --- a/Sources/XcodeGenKit/SettingsBuilder.swift +++ b/Sources/XcodeGenKit/SettingsBuilder.swift @@ -42,8 +42,8 @@ extension ProjectSpec { public func getBuildSettings(settings: Settings, config: Config) -> BuildSettings { var buildSettings: BuildSettings = [:] - for preset in settings.presets { - let presetSettings = settingPresets[preset]! + for preset in settings.groups { + let presetSettings = settingGroups[preset]! buildSettings += getBuildSettings(settings: presetSettings, config: config) } diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 88d456eb..eb225ec4 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -114,26 +114,26 @@ func specLoadingTests() { let spec = try ProjectSpec(path: fixturePath + "settings_test.yml") let buildSettings: BuildSettings = ["SETTING": "value"] let configSettings: [String: Settings] = ["config1": Settings(buildSettings: ["SETTING1": "value"])] - let presets = ["preset1"] + let groups = ["preset1"] - let preset1 = Settings(buildSettings: buildSettings, configSettings: [:], presets: []) - let preset2 = Settings(buildSettings: [:], configSettings: configSettings, presets: []) - let preset3 = Settings(buildSettings: buildSettings, configSettings: configSettings, presets: []) - let preset4 = Settings(buildSettings: buildSettings, configSettings: [:], presets: []) - let preset5 = Settings(buildSettings: buildSettings, configSettings: [:], presets: presets) - let preset6 = Settings(buildSettings: buildSettings, configSettings: configSettings, presets: presets) - let preset7 = Settings(buildSettings: buildSettings, configSettings: ["config1": Settings(buildSettings: buildSettings, presets: presets)]) + let preset1 = Settings(buildSettings: buildSettings, configSettings: [:], groups: []) + let preset2 = Settings(buildSettings: [:], configSettings: configSettings, groups: []) + let preset3 = Settings(buildSettings: buildSettings, configSettings: configSettings, groups: []) + let preset4 = Settings(buildSettings: buildSettings, configSettings: [:], groups: []) + let preset5 = Settings(buildSettings: buildSettings, configSettings: [:], groups: groups) + let preset6 = Settings(buildSettings: buildSettings, configSettings: configSettings, groups: groups) + let preset7 = Settings(buildSettings: buildSettings, configSettings: ["config1": Settings(buildSettings: buildSettings, groups: groups)]) let preset8 = Settings(buildSettings: [:], configSettings: ["config1": Settings(configSettings: configSettings)]) - try expect(spec.settingPresets.count) == 8 - try expect(spec.settingPresets["preset1"]) == preset1 - try expect(spec.settingPresets["preset2"]) == preset2 - try expect(spec.settingPresets["preset3"]) == preset3 - try expect(spec.settingPresets["preset4"]) == preset4 - try expect(spec.settingPresets["preset5"]) == preset5 - try expect(spec.settingPresets["preset6"]) == preset6 - try expect(spec.settingPresets["preset7"]) == preset7 - try expect(spec.settingPresets["preset8"]) == preset8 + try expect(spec.settingGroups.count) == 8 + try expect(spec.settingGroups["preset1"]) == preset1 + try expect(spec.settingGroups["preset2"]) == preset2 + try expect(spec.settingGroups["preset3"]) == preset3 + try expect(spec.settingGroups["preset4"]) == preset4 + try expect(spec.settingGroups["preset5"]) == preset5 + try expect(spec.settingGroups["preset6"]) == preset6 + try expect(spec.settingGroups["preset7"]) == preset7 + try expect(spec.settingGroups["preset8"]) == preset8 } $0.it("parses run scripts") { diff --git a/docs/ProjectSpec.md b/docs/ProjectSpec.md index a2e2c71f..7d380111 100644 --- a/docs/ProjectSpec.md +++ b/docs/ProjectSpec.md @@ -10,9 +10,9 @@ Required properties are marked 🔵 and optional properties with ⚪️. - [Project](#project) - [Options](#options) - [Configs](#configs) - - [Setting Presets](#setting-presets) + - [Setting Groups](#setting-groups) - [Settings](#settings) -- [Target](#target) +- [Target](#target) - [Product Type](#product-type) - [Platform](#platform) - [Sources](#sources) @@ -28,7 +28,7 @@ Required properties are marked 🔵 and optional properties with ⚪️. - ⚪️ **options**: [Options](#options) - Various options to override default behaviour - ⚪️ **configs**: [Configs](#configs) - Project build configurations. Defaults to `Debug` and `Release` configs - ⚪️ **settings**: [Settings](#settings) - Project specific settings. Default base and config type settings will be applied first before any settings defined here -- ⚪️ **settingPresets**: [Setting Presets](#setting-presets) - Setting presets mapped by name +- ⚪️ **settingGroups**: [Setting Groups](#setting-groups) - Setting groups mapped by name - ⚪️ **targets**: [[Target](#target)] - The list of targets in the project ### Options @@ -45,29 +45,29 @@ configs: If no configs are specified, default `Debug` and `Release` configs will be created automatically. -### Setting Presets -Setting presets are named groups of build settings that can be reused elsewhere. Each preset is a [Settings](#settings) schema, so can include other presets +### Setting Groups +Setting groups are named groups of build settings that can be reused elsewhere. Each preset is a [Settings](#settings) schema, so can include other groups ```yaml -settingPresets: +settingGroups: preset1: BUILD_SETTING: value preset2: base: BUILD_SETTING: value - presets: + groups: - preset preset3: configs: debug: - presets: + groups: - preset ``` ## Settings Settings can either be a simple map of build settings `[String: String]`, or can be more advanced with the following properties: -- ⚪️ **presets**: `[String]` - List of presets to include and merge +- ⚪️ **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 - ⚪️ **base**: `[String: String]` - Used to specify default settings that apply to any config @@ -84,11 +84,11 @@ settings: configs: my_config: BUILD_SETTING_2: value 2 - presets: + groups: - my_settings ``` -Settings are merged in the following order: presets, configs, base. +Settings are merged in the following order: groups, configs, base. ## Target @@ -152,7 +152,7 @@ settings: INFOPLIST_FILE: MyApp/Info.plist PRODUCT_BUNDLE_IDENTIFIER: com.myapp MY_SETTING: platform $platform - presets: + groups: - $platform ``` The above will generate 2 targets named `MyFramework_iOS` and `MyFramework_tvOS`, with all the relevant platform build settings. They will both have a `PRODUCT_NAME` of `MyFramework`