From 20f7797df77c07d188d7f94eabe500e9a0925aaf Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Sun, 22 Oct 2017 19:24:14 +0100 Subject: [PATCH 1/2] add applySettingPresets option --- Sources/ProjectSpec/ProjectSpec.swift | 23 +++++++++++++++++++ Sources/XcodeGenKit/SettingsBuilder.swift | 12 ++++++---- .../ProjectGeneratorTests.swift | 10 ++++++++ docs/ProjectSpec.md | 8 +++++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Sources/ProjectSpec/ProjectSpec.swift b/Sources/ProjectSpec/ProjectSpec.swift index a5d177311..e086b503a 100644 --- a/Sources/ProjectSpec/ProjectSpec.swift +++ b/Sources/ProjectSpec/ProjectSpec.swift @@ -29,6 +29,28 @@ public struct ProjectSpec { public struct Options { public var carthageBuildPath: String? public var bundleIdPrefix: String? + public var applySettingPresets: SettingPresets = .all + + public enum SettingPresets: String { + case all + case none + case project + case targets + + public var applyTarget: Bool { + switch self { + case .all, .targets: return true + default: return false + } + } + + public var applyProject: Bool { + switch self { + case .all, .project: return true + default: return false + } + } + } public init() { } @@ -133,5 +155,6 @@ extension ProjectSpec.Options: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { carthageBuildPath = jsonDictionary.json(atKeyPath: "carthageBuildPath") bundleIdPrefix = jsonDictionary.json(atKeyPath: "bundleIdPrefix") + applySettingPresets = jsonDictionary.json(atKeyPath: "applySettingPresets") ?? .all } } diff --git a/Sources/XcodeGenKit/SettingsBuilder.swift b/Sources/XcodeGenKit/SettingsBuilder.swift index 6c81e28c0..e8257ce18 100644 --- a/Sources/XcodeGenKit/SettingsBuilder.swift +++ b/Sources/XcodeGenKit/SettingsBuilder.swift @@ -18,7 +18,7 @@ extension ProjectSpec { public func getProjectBuildSettings(config: Config) -> BuildSettings { var buildSettings: BuildSettings = [:] - if let type = config.type { + if let type = config.type, options.applySettingPresets.applyProject { buildSettings += SettingsPresetFile.base.getBuildSettings() buildSettings += SettingsPresetFile.config(type).getBuildSettings() } @@ -30,10 +30,12 @@ extension ProjectSpec { public func getTargetBuildSettings(target: Target, config: Config) -> BuildSettings { var buildSettings = BuildSettings() - - buildSettings += SettingsPresetFile.platform(target.platform).getBuildSettings() - buildSettings += SettingsPresetFile.product(target.type).getBuildSettings() - buildSettings += SettingsPresetFile.productPlatform(target.type, target.platform).getBuildSettings() + + if options.applySettingPresets.applyTarget { + buildSettings += SettingsPresetFile.platform(target.platform).getBuildSettings() + buildSettings += SettingsPresetFile.product(target.type).getBuildSettings() + buildSettings += SettingsPresetFile.productPlatform(target.type, target.platform).getBuildSettings() + } buildSettings += getBuildSettings(settings: target.settings, config: config) return buildSettings diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index 6fb551a8a..b1020607a 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -41,6 +41,16 @@ func projectGeneratorTests() { } try expect(buildConfig.buildSettings["PRODUCT_BUNDLE_IDENTIFIER"] as? String) == "com.test.MyFramework" } + + $0.it("clears setting presets") { + var options = ProjectSpec.Options() + options.applySettingPresets = .none + let spec = ProjectSpec(name: "test", targets: [framework], options: options) + let project = try getProject(spec) + let allSettings = project.pbxproj.buildConfigurations.reduce([:]) { $0.merged($1.buildSettings)}.keys.sorted() + try expect(allSettings) == ["SETTING_2"] + } + } $0.describe("Config") { diff --git a/docs/ProjectSpec.md b/docs/ProjectSpec.md index 2b1c8d97b..98ad69dc1 100644 --- a/docs/ProjectSpec.md +++ b/docs/ProjectSpec.md @@ -64,9 +64,13 @@ Note that target names can also be changed by adding a `name` property to a targ ### Options - ⚪️ **carthageBuildPath**: `String` - The path to the carthage build directory. Defaults to `Carthage/Build`. This is used when specifying target carthage dependencies - ⚪️ **bundleIdPrefix**: `String` - If this is specified then any target that doesn't have an `PRODUCT_BUNDLE_IDENTIFIER` (via all levels of build settings) will get an autogenerated one by combining `bundleIdPrefix` and the target name: `bundleIdPrefix.name`. The target name will be stripped of all characters that aren't alphanumerics, hyphens, or periods. Underscores will be replace with hyphens. - +- ⚪️ **applySettingPresets**: `String` - This controls the settings that are automatically applied to the project and its targets. These are the same build settings that Xcode would add when creating a new project. Project settings are applied by config type. Target settings are applied by the product type and platform. By default this is set to `all` + - `all`: project and target settings + - `project`: only project settings + - `targets`: only target settings + - `none`: no settings are automatically applied ### Configs -Each config maps to a build type of either `debug` or `release` which will then apply default build settings. Any value other than `debug` or `release` (for example "none"), will mean no default build settings will be applied. +Each config maps to a build type of either `debug` or `release` which will then apply default build settings to the project. Any value other than `debug` or `release` (for example `none`), will mean no default build settings will be applied to the project. ```yaml configs: From 0204f27c8283e50774cde6d6b3b80494e08b4a5d Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Sun, 22 Oct 2017 20:37:03 +0100 Subject: [PATCH 2/2] rename Options.applySettingPresets to Options.settingPresets --- Sources/ProjectSpec/ProjectSpec.swift | 4 ++-- Sources/XcodeGenKit/SettingsBuilder.swift | 4 ++-- Tests/XcodeGenKitTests/ProjectGeneratorTests.swift | 2 +- docs/ProjectSpec.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/ProjectSpec/ProjectSpec.swift b/Sources/ProjectSpec/ProjectSpec.swift index e086b503a..494e212f5 100644 --- a/Sources/ProjectSpec/ProjectSpec.swift +++ b/Sources/ProjectSpec/ProjectSpec.swift @@ -29,7 +29,7 @@ public struct ProjectSpec { public struct Options { public var carthageBuildPath: String? public var bundleIdPrefix: String? - public var applySettingPresets: SettingPresets = .all + public var settingPresets: SettingPresets = .all public enum SettingPresets: String { case all @@ -155,6 +155,6 @@ extension ProjectSpec.Options: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { carthageBuildPath = jsonDictionary.json(atKeyPath: "carthageBuildPath") bundleIdPrefix = jsonDictionary.json(atKeyPath: "bundleIdPrefix") - applySettingPresets = jsonDictionary.json(atKeyPath: "applySettingPresets") ?? .all + settingPresets = jsonDictionary.json(atKeyPath: "settingPresets") ?? .all } } diff --git a/Sources/XcodeGenKit/SettingsBuilder.swift b/Sources/XcodeGenKit/SettingsBuilder.swift index e8257ce18..a6491f0b3 100644 --- a/Sources/XcodeGenKit/SettingsBuilder.swift +++ b/Sources/XcodeGenKit/SettingsBuilder.swift @@ -18,7 +18,7 @@ extension ProjectSpec { public func getProjectBuildSettings(config: Config) -> BuildSettings { var buildSettings: BuildSettings = [:] - if let type = config.type, options.applySettingPresets.applyProject { + if let type = config.type, options.settingPresets.applyProject { buildSettings += SettingsPresetFile.base.getBuildSettings() buildSettings += SettingsPresetFile.config(type).getBuildSettings() } @@ -31,7 +31,7 @@ extension ProjectSpec { public func getTargetBuildSettings(target: Target, config: Config) -> BuildSettings { var buildSettings = BuildSettings() - if options.applySettingPresets.applyTarget { + if options.settingPresets.applyTarget { buildSettings += SettingsPresetFile.platform(target.platform).getBuildSettings() buildSettings += SettingsPresetFile.product(target.type).getBuildSettings() buildSettings += SettingsPresetFile.productPlatform(target.type, target.platform).getBuildSettings() diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index b1020607a..262687197 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -44,7 +44,7 @@ func projectGeneratorTests() { $0.it("clears setting presets") { var options = ProjectSpec.Options() - options.applySettingPresets = .none + options.settingPresets = .none let spec = ProjectSpec(name: "test", targets: [framework], options: options) let project = try getProject(spec) let allSettings = project.pbxproj.buildConfigurations.reduce([:]) { $0.merged($1.buildSettings)}.keys.sorted() diff --git a/docs/ProjectSpec.md b/docs/ProjectSpec.md index 98ad69dc1..e8bed4546 100644 --- a/docs/ProjectSpec.md +++ b/docs/ProjectSpec.md @@ -64,7 +64,7 @@ Note that target names can also be changed by adding a `name` property to a targ ### Options - ⚪️ **carthageBuildPath**: `String` - The path to the carthage build directory. Defaults to `Carthage/Build`. This is used when specifying target carthage dependencies - ⚪️ **bundleIdPrefix**: `String` - If this is specified then any target that doesn't have an `PRODUCT_BUNDLE_IDENTIFIER` (via all levels of build settings) will get an autogenerated one by combining `bundleIdPrefix` and the target name: `bundleIdPrefix.name`. The target name will be stripped of all characters that aren't alphanumerics, hyphens, or periods. Underscores will be replace with hyphens. -- ⚪️ **applySettingPresets**: `String` - This controls the settings that are automatically applied to the project and its targets. These are the same build settings that Xcode would add when creating a new project. Project settings are applied by config type. Target settings are applied by the product type and platform. By default this is set to `all` +- ⚪️ **settingPresets**: `String` - This controls the settings that are automatically applied to the project and its targets. These are the same build settings that Xcode would add when creating a new project. Project settings are applied by config type. Target settings are applied by the product type and platform. By default this is set to `all` - `all`: project and target settings - `project`: only project settings - `targets`: only target settings