Skip to content

Commit

Permalink
Merge pull request #203 from yonaskolb/scheme_build_types
Browse files Browse the repository at this point in the history
Change Scheme.Build.targets spec
  • Loading branch information
yonaskolb authored Dec 26, 2017
2 parents e18a6a7 + a53b3b9 commit d4fc091
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 52 deletions.
19 changes: 8 additions & 11 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,12 @@ Schemes allows for more control than the convenience [Target Scheme](#target-sch
- [ ] ***archive***: The archive action
### Build
- [x] **targets**: **[Build Target]** - A list of targets to build
- [x] **name**: **String** - the name of the target
- [ ] **buildTypes**: **[String]** - A list of build types for this target. The default is all types. The build types are:
- `run`
- `test`
- `profile`
- `analyze`
- `archive`
- [x] **targets**: **String** or **[String]** - A map of target names to build and which build types they should be enabled for. The buildTypes can either be `all`, `none` or an array of the following types:
- `run`
- `test`
- `profile`
- `analyze`
- `archive`
### Common Build Action options
The different actions share some properties:
Expand All @@ -427,9 +425,8 @@ scheme:
Production:
build:
targets:
- name: MyTarget1
- name: MyTarget2
buildTypes: [run, archive]
MyTarget1: all
MyTarget2: [run, archive]
run:
config: prod-debug
commandLineArguments: "--option value"
Expand Down
46 changes: 19 additions & 27 deletions Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,36 +189,28 @@ extension Scheme: NamedJSONDictionaryConvertible {
extension Scheme.Build: JSONObjectConvertible {

public init(jsonDictionary: JSONDictionary) throws {
targets = try jsonDictionary.json(atKeyPath: "targets")
}
}

extension Scheme.BuildTarget: JSONObjectConvertible {

public init(jsonDictionary: JSONDictionary) throws {
target = try jsonDictionary.json(atKeyPath: "target")
if jsonDictionary["buildTypes"] == nil {
buildTypes = BuildType.all
} else if let types: String = jsonDictionary.json(atKeyPath: "buildTypes") {
switch types {
case "all": buildTypes = BuildType.all
case "none": buildTypes = []
case "testing": buildTypes = [.testing, .analyzing]
case "indexing": buildTypes = [.testing, .analyzing, .archiving]
default: buildTypes = BuildType.all
}
} else if let types: [String: Bool] = jsonDictionary.json(atKeyPath: "buildTypes") {
var buildTypes: [BuildType] = []
for (type, build) in types {
if build, let buildType = BuildType.from(jsonValue: type) {
buildTypes.append(buildType)
let targetDictionary: JSONDictionary = try jsonDictionary.json(atKeyPath: "targets")
var targets: [Scheme.BuildTarget] = []
for (target, possibleBuildTypes) in targetDictionary {
let buildTypes: [BuildType]
if let string = possibleBuildTypes as? String {
switch string {
case "all": buildTypes = BuildType.all
case "none": buildTypes = []
case "testing": buildTypes = [.testing, .analyzing]
case "indexing": buildTypes = [.testing, .analyzing, .archiving]
default: buildTypes = BuildType.all
}
} else if let enabledDictionary = possibleBuildTypes as? [String: Bool] {
buildTypes = enabledDictionary.filter { $0.value }.flatMap { BuildType.from(jsonValue: $0.key) }
} else if let array = possibleBuildTypes as? [String] {
buildTypes = array.flatMap(BuildType.from)
} else {
buildTypes = BuildType.all
}
self.buildTypes = buildTypes
} else {
let stringBuildTypes: [String] = try jsonDictionary.json(atKeyPath: "buildTypes")
self.buildTypes = stringBuildTypes.flatMap(BuildType.from)
targets.append(Scheme.BuildTarget(target: target, buildTypes: buildTypes))
}
self.targets = targets.sorted { $0.target < $1.target }
}
}

Expand Down
26 changes: 12 additions & 14 deletions Tests/XcodeGenKitTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,24 +157,22 @@ func specLoadingTests() {
$0.it("parses schemes") {
let schemeDictionary: [String: Any] = [
"build": ["targets": [
["target": "Target"],
["target": "Target", "buildTypes": "testing"],
["target": "Target", "buildTypes": "none"],
["target": "Target", "buildTypes": "all"],
["target": "Target", "buildTypes": ["testing": true]],
["target": "Target", "buildTypes": ["testing": false]],
["target": "Target", "buildTypes": ["test", "analyze"]],
"Target1": "all",
"Target2": "testing",
"Target3": "none",
"Target4": ["testing": true],
"Target5": ["testing": false],
"Target6": ["test", "analyze"],
]],
]
let scheme = try Scheme(name: "Scheme", jsonDictionary: schemeDictionary)
let expectedTargets: [Scheme.BuildTarget] = [
Scheme.BuildTarget(target: "Target", buildTypes: BuildType.all),
Scheme.BuildTarget(target: "Target", buildTypes: [.testing, .analyzing]),
Scheme.BuildTarget(target: "Target", buildTypes: []),
Scheme.BuildTarget(target: "Target", buildTypes: BuildType.all),
Scheme.BuildTarget(target: "Target", buildTypes: [.testing]),
Scheme.BuildTarget(target: "Target", buildTypes: []),
Scheme.BuildTarget(target: "Target", buildTypes: [.testing, .analyzing]),
Scheme.BuildTarget(target: "Target1", buildTypes: BuildType.all),
Scheme.BuildTarget(target: "Target2", buildTypes: [.testing, .analyzing]),
Scheme.BuildTarget(target: "Target3", buildTypes: []),
Scheme.BuildTarget(target: "Target4", buildTypes: [.testing]),
Scheme.BuildTarget(target: "Target5", buildTypes: []),
Scheme.BuildTarget(target: "Target6", buildTypes: [.testing, .analyzing]),
]
try expect(scheme.name) == "Scheme"
try expect(scheme.build.targets) == expectedTargets
Expand Down

0 comments on commit d4fc091

Please sign in to comment.