From cb3ffc3d2bb420c5140157cc7bfa42dc7291a6db Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Fri, 22 Dec 2017 18:59:23 +0800 Subject: [PATCH 1/2] change Scheme.Build.targets spec --- Docs/ProjectSpec.md | 19 ++++++------- Sources/ProjectSpec/Scheme.swift | 46 +++++++++++++------------------- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index 0ae496786..1a4f0af8e 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -396,14 +396,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: @@ -422,9 +420,8 @@ scheme: Production: build: targets: - - name: MyTarget1 - - name: MyTarget2 - buildTypes: [run, archive] + MyTarget1: all + MyTarget2: [run, archive] run: config: prod-debug commandLineArguments: "--option value" diff --git a/Sources/ProjectSpec/Scheme.swift b/Sources/ProjectSpec/Scheme.swift index 28763a313..df58fca1d 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -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 } } } From a53b3b93b9c9d756bb493edc6565518c2adce495 Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Thu, 21 Dec 2017 20:38:02 +0800 Subject: [PATCH 2/2] fix tests --- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 648c207f3..6a67d2204 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -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