Skip to content

Commit

Permalink
Merge pull request #728 from FranzBusch/feature/language-and-region-f…
Browse files Browse the repository at this point in the history
…or-target-schemes

Add support for language and region settings for target schemes
  • Loading branch information
yonaskolb authored Dec 4, 2019
2 parents f064bdf + bedbfef commit 99ce87d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Next Version

#### Added
- Support for language and region settings on a target basis [#728](https://github.com/yonaskolb/XcodeGen/pull/728) @FranzBusch

## 2.11.0

#### Added
Expand Down
2 changes: 2 additions & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ This is a convenience used to automatically generate schemes for a target based
- [ ] **testTargets**: **[[Test Target](#test-target)]** - a list of test targets that should be included in the scheme. These will be added to the build targets and the test entries. Each entry can either be a simple string, or a [Test Target](#test-target)
- [ ] **gatherCoverageData**: **Bool** - a boolean that indicates if this scheme should gather coverage data. This defaults to false
- [ ] **disableMainThreadChecker**: **Bool** - a boolean that indicates if this scheme should disable disable the Main Thread Checker. This defaults to false
- [ ] **language**: **String** - a String that indicates the language used for running and testing. This defaults to nil
- [ ] **region**: **String** - a String that indicates the region used for running and testing. This defaults to nil
- [ ] **commandLineArguments**: **[String:Bool]** - a dictionary from the argument name (`String`) to if it is enabled (`Bool`). These arguments will be added to the Test, Profile and Run scheme actions
- [ ] **environmentVariables**: **[[Environment Variable](#environment-variable)]** or **[String:String]** - environment variables for Run, Test and Profile scheme actions. When passing a dictionary, every key-value entry maps to a corresponding variable that is enabled.
- [ ] **preActions**: **[[Execution Action](#execution-action)]** - Scripts that are run *before* all actions
Expand Down
16 changes: 16 additions & 0 deletions Sources/ProjectSpec/TargetScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public struct TargetScheme: Equatable {
public var testTargets: [Scheme.Test.TestTarget]
public var configVariants: [String]
public var gatherCoverageData: Bool
public var language: String?
public var region: String?
public var disableMainThreadChecker: Bool
public var commandLineArguments: [String: Bool]
public var environmentVariables: [XCScheme.EnvironmentVariable]
Expand All @@ -19,6 +21,8 @@ public struct TargetScheme: Equatable {
testTargets: [Scheme.Test.TestTarget] = [],
configVariants: [String] = [],
gatherCoverageData: Bool = gatherCoverageDataDefault,
language: String? = nil,
region: String? = nil,
disableMainThreadChecker: Bool = disableMainThreadCheckerDefault,
commandLineArguments: [String: Bool] = [:],
environmentVariables: [XCScheme.EnvironmentVariable] = [],
Expand All @@ -28,6 +32,8 @@ public struct TargetScheme: Equatable {
self.testTargets = testTargets
self.configVariants = configVariants
self.gatherCoverageData = gatherCoverageData
self.language = language
self.region = region
self.disableMainThreadChecker = disableMainThreadChecker
self.commandLineArguments = commandLineArguments
self.environmentVariables = environmentVariables
Expand All @@ -54,6 +60,8 @@ extension TargetScheme: JSONObjectConvertible {
}
configVariants = jsonDictionary.json(atKeyPath: "configVariants") ?? []
gatherCoverageData = jsonDictionary.json(atKeyPath: "gatherCoverageData") ?? TargetScheme.gatherCoverageDataDefault
language = jsonDictionary.json(atKeyPath: "language")
region = jsonDictionary.json(atKeyPath: "region")
disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? TargetScheme.disableMainThreadCheckerDefault
commandLineArguments = jsonDictionary.json(atKeyPath: "commandLineArguments") ?? [:]
environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary)
Expand Down Expand Up @@ -81,6 +89,14 @@ extension TargetScheme: JSONEncodable {
dict["disableMainThreadChecker"] = disableMainThreadChecker
}

if let language = language {
dict["language"] = language
}

if let region = region {
dict["region"] = region
}

return dict
}
}
10 changes: 7 additions & 3 deletions Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class SchemeGenerator {
let debugConfig = suitableConfig(for: .debug, in: project)
let releaseConfig = suitableConfig(for: .release, in: project)

let scheme = Scheme(
let scheme = Scheme.init(
name: schemeName,
target: target,
targetScheme: targetScheme,
Expand Down Expand Up @@ -288,7 +288,9 @@ extension Scheme {
preActions: targetScheme.preActions,
postActions: targetScheme.postActions,
environmentVariables: targetScheme.environmentVariables,
disableMainThreadChecker: targetScheme.disableMainThreadChecker
disableMainThreadChecker: targetScheme.disableMainThreadChecker,
language: targetScheme.language,
region: targetScheme.region
),
test: .init(
config: debugConfig,
Expand All @@ -298,7 +300,9 @@ extension Scheme {
targets: targetScheme.testTargets,
preActions: targetScheme.preActions,
postActions: targetScheme.postActions,
environmentVariables: targetScheme.environmentVariables
environmentVariables: targetScheme.environmentVariables,
language: targetScheme.language,
region: targetScheme.region
),
profile: .init(
config: releaseConfig,
Expand Down
4 changes: 4 additions & 0 deletions Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ class SpecLoadingTests: XCTestCase {
"ENV1": true,
],
"gatherCoverageData": true,
"language": "en",
"region": "US",
"disableMainThreadChecker": true,
"environmentVariables": [
"TEST_VAR": "TEST_VAL",
Expand All @@ -724,6 +726,8 @@ class SpecLoadingTests: XCTestCase {
testTargets: ["t1", "t2"],
configVariants: ["dev", "app-store"],
gatherCoverageData: true,
language: "en",
region: "US",
disableMainThreadChecker: true,
commandLineArguments: ["ENV1": true],
environmentVariables: [XCScheme.EnvironmentVariable(variable: "TEST_VAR", value: "TEST_VAL", enabled: true)],
Expand Down

0 comments on commit 99ce87d

Please sign in to comment.