Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settingPresets option #101

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/ProjectSpec/ProjectSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ public struct ProjectSpec {
public struct Options {
public var carthageBuildPath: String?
public var bundleIdPrefix: String?
public var settingPresets: 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() {
}
Expand Down Expand Up @@ -133,5 +155,6 @@ extension ProjectSpec.Options: JSONObjectConvertible {
public init(jsonDictionary: JSONDictionary) throws {
carthageBuildPath = jsonDictionary.json(atKeyPath: "carthageBuildPath")
bundleIdPrefix = jsonDictionary.json(atKeyPath: "bundleIdPrefix")
settingPresets = jsonDictionary.json(atKeyPath: "settingPresets") ?? .all
}
}
12 changes: 7 additions & 5 deletions Sources/XcodeGenKit/SettingsBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.settingPresets.applyProject {
buildSettings += SettingsPresetFile.base.getBuildSettings()
buildSettings += SettingsPresetFile.config(type).getBuildSettings()
}
Expand All @@ -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.settingPresets.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
Expand Down
10 changes: 10 additions & 0 deletions Tests/XcodeGenKitTests/ProjectGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.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()
try expect(allSettings) == ["SETTING_2"]
}

}

$0.describe("Config") {
Expand Down
8 changes: 6 additions & 2 deletions docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

- ⚪️ **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
- `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:
Expand Down