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 stopOnEveryMainThreadCheckerIssue #799

Merged
merged 11 commits into from
Mar 18, 2020
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
- Added ability to stop on every main thread checker issue on Run schemes and TargetSchemes [#799](https://github.com/yonaskolb/XcodeGen/pull/799) @ionutivan

## 2.14.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 @@ -597,6 +597,7 @@ 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
- [ ] **stopOnEveryMainThreadCheckerIssue**: **Bool** - a boolean that indicates if this scheme should stop at every Main Thread Checker issue. This defaults to false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add docs to down below in Schemes as well https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#scheme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! Done

- [ ] **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
Expand Down Expand Up @@ -732,6 +733,7 @@ The different actions share some properties:
- [ ] **postActions**: **[[Execution Action](#execution-action)]** - Scripts that are run *after* the action
- [ ] **environmentVariables**: **[[Environment Variable](#environment-variable)]** or **[String:String]** - `run`, `test` and `profile` actions can define the environment variables. When passing a dictionary, every key-value entry maps to a corresponding variable that is enabled.
- [ ] **disableMainThreadChecker**: **Bool** - `run` and `test` actions can define a boolean that indicates that this scheme should disable the Main Thread Checker. This defaults to false
- [ ] **stopOnEveryMainThreadCheckerIssue**: **Bool** - a boolean that indicates if this scheme should stop at every Main Thread Checker issue. This defaults to false
- [ ] **language**: **String** - `run` and `test` actions can define a language that is used for Application Language
- [ ] **region**: **String** - `run` and `test` actions can define a language that is used for Application Region
- [ ] **debugEnabled**: **Bool** - `run` and `test` actions can define a whether debugger should be used. This defaults to true.
Expand Down
9 changes: 9 additions & 0 deletions Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public struct Scheme: Equatable {

public struct Run: BuildAction {
public static let disableMainThreadCheckerDefault = false
public static let stopOnEveryMainThreadCheckerIssueDefault = false
public static let debugEnabledDefault = true

public var config: String?
Expand All @@ -103,6 +104,7 @@ public struct Scheme: Equatable {
public var postActions: [ExecutionAction]
public var environmentVariables: [XCScheme.EnvironmentVariable]
public var disableMainThreadChecker: Bool
public var stopOnEveryMainThreadCheckerIssue: Bool
public var language: String?
public var region: String?
public var debugEnabled: Bool
Expand All @@ -115,6 +117,7 @@ public struct Scheme: Equatable {
postActions: [ExecutionAction] = [],
environmentVariables: [XCScheme.EnvironmentVariable] = [],
disableMainThreadChecker: Bool = disableMainThreadCheckerDefault,
stopOnEveryMainThreadCheckerIssue: Bool = stopOnEveryMainThreadCheckerIssueDefault,
language: String? = nil,
region: String? = nil,
debugEnabled: Bool = debugEnabledDefault,
Expand All @@ -126,6 +129,7 @@ public struct Scheme: Equatable {
self.postActions = postActions
self.environmentVariables = environmentVariables
self.disableMainThreadChecker = disableMainThreadChecker
self.stopOnEveryMainThreadCheckerIssue = stopOnEveryMainThreadCheckerIssue
self.language = language
self.region = region
self.debugEnabled = debugEnabled
Expand Down Expand Up @@ -340,6 +344,7 @@ extension Scheme.Run: JSONObjectConvertible {
postActions = jsonDictionary.json(atKeyPath: "postActions") ?? []
environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary)
disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? Scheme.Run.disableMainThreadCheckerDefault
stopOnEveryMainThreadCheckerIssue = jsonDictionary.json(atKeyPath: "stopOnEveryMainThreadCheckerIssue") ?? Scheme.Run.stopOnEveryMainThreadCheckerIssueDefault
language = jsonDictionary.json(atKeyPath: "language")
region = jsonDictionary.json(atKeyPath: "region")
debugEnabled = jsonDictionary.json(atKeyPath: "debugEnabled") ?? Scheme.Run.debugEnabledDefault
Expand All @@ -362,6 +367,10 @@ extension Scheme.Run: JSONEncodable {
if disableMainThreadChecker != Scheme.Run.disableMainThreadCheckerDefault {
dict["disableMainThreadChecker"] = disableMainThreadChecker
}

if stopOnEveryMainThreadCheckerIssue != Scheme.Run.stopOnEveryMainThreadCheckerIssueDefault {
dict["stopOnEveryMainThreadCheckerIssue"] = stopOnEveryMainThreadCheckerIssue
}

if debugEnabled != Scheme.Run.debugEnabledDefault {
dict["debugEnabled"] = debugEnabled
Expand Down
9 changes: 9 additions & 0 deletions Sources/ProjectSpec/TargetScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import XcodeProj
public struct TargetScheme: Equatable {
public static let gatherCoverageDataDefault = false
public static let disableMainThreadCheckerDefault = false
public static let stopOnEveryMainThreadCheckerIssueDefault = false

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 stopOnEveryMainThreadCheckerIssue: Bool
public var commandLineArguments: [String: Bool]
public var environmentVariables: [XCScheme.EnvironmentVariable]
public var preActions: [Scheme.ExecutionAction]
Expand All @@ -24,6 +26,7 @@ public struct TargetScheme: Equatable {
language: String? = nil,
region: String? = nil,
disableMainThreadChecker: Bool = disableMainThreadCheckerDefault,
stopOnEveryMainThreadCheckerIssue: Bool = stopOnEveryMainThreadCheckerIssueDefault,
commandLineArguments: [String: Bool] = [:],
environmentVariables: [XCScheme.EnvironmentVariable] = [],
preActions: [Scheme.ExecutionAction] = [],
Expand All @@ -35,6 +38,7 @@ public struct TargetScheme: Equatable {
self.language = language
self.region = region
self.disableMainThreadChecker = disableMainThreadChecker
self.stopOnEveryMainThreadCheckerIssue = stopOnEveryMainThreadCheckerIssue
self.commandLineArguments = commandLineArguments
self.environmentVariables = environmentVariables
self.preActions = preActions
Expand Down Expand Up @@ -63,6 +67,7 @@ extension TargetScheme: JSONObjectConvertible {
language = jsonDictionary.json(atKeyPath: "language")
region = jsonDictionary.json(atKeyPath: "region")
disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? TargetScheme.disableMainThreadCheckerDefault
stopOnEveryMainThreadCheckerIssue = jsonDictionary.json(atKeyPath: "stopOnEveryMainThreadCheckerIssue") ?? TargetScheme.stopOnEveryMainThreadCheckerIssueDefault
commandLineArguments = jsonDictionary.json(atKeyPath: "commandLineArguments") ?? [:]
environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary)
preActions = jsonDictionary.json(atKeyPath: "preActions") ?? []
Expand All @@ -88,6 +93,10 @@ extension TargetScheme: JSONEncodable {
if disableMainThreadChecker != TargetScheme.disableMainThreadCheckerDefault {
dict["disableMainThreadChecker"] = disableMainThreadChecker
}

if stopOnEveryMainThreadCheckerIssue != TargetScheme.stopOnEveryMainThreadCheckerIssueDefault {
dict["stopOnEveryMainThreadCheckerIssue"] = stopOnEveryMainThreadCheckerIssue
}

if let language = language {
dict["language"] = language
Expand Down
2 changes: 2 additions & 0 deletions Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public class SchemeGenerator {
allowLocationSimulation: allowLocationSimulation,
locationScenarioReference: locationScenarioReference,
disableMainThreadChecker: scheme.run?.disableMainThreadChecker ?? Scheme.Run.disableMainThreadCheckerDefault,
stopOnEveryMainThreadCheckerIssue: scheme.run?.stopOnEveryMainThreadCheckerIssue ?? Scheme.Run.stopOnEveryMainThreadCheckerIssueDefault,
commandlineArguments: launchCommandLineArgs,
environmentVariables: launchVariables,
language: scheme.run?.language,
Expand Down Expand Up @@ -302,6 +303,7 @@ extension Scheme {
postActions: targetScheme.postActions,
environmentVariables: targetScheme.environmentVariables,
disableMainThreadChecker: targetScheme.disableMainThreadChecker,
stopOnEveryMainThreadCheckerIssue: targetScheme.stopOnEveryMainThreadCheckerIssue,
language: targetScheme.language,
region: targetScheme.region
),
Expand Down
1 change: 1 addition & 0 deletions Tests/Fixtures/TestProject/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ targets:
- App_iOS_UITests
gatherCoverageData: true
disableMainThreadChecker: true
stopOnEveryMainThreadCheckerIssue: false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set this to true to generate the diff in the checked in fixture 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the default should be false because it shouldn't stop on every main thread checker issue. Am I right?

configVariants:
- Test
- Staging
Expand Down
1 change: 1 addition & 0 deletions Tests/PerformanceTests/TestProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension Project {
configVariants: ["Test", "Staging", "Prod"],
gatherCoverageData: true,
disableMainThreadChecker: true,
stopOnEveryMainThreadCheckerIssue: false,
commandLineArguments: [
"--command": true,
"--command2": false,
Expand Down
1 change: 1 addition & 0 deletions Tests/ProjectSpecTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ class ProjectSpecTests: XCTestCase {
configVariants: ["foo"],
gatherCoverageData: true,
disableMainThreadChecker: true,
stopOnEveryMainThreadCheckerIssue: false,
commandLineArguments: ["foo": true],
environmentVariables: [XCScheme.EnvironmentVariable(variable: "environmentVariable",
value: "bar",
Expand Down
4 changes: 4 additions & 0 deletions Tests/ProjectSpecTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ class SpecLoadingTests: XCTestCase {
"language": "en",
"region": "US",
"disableMainThreadChecker": true,
"stopOnEveryMainThreadCheckerIssue": false,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set this to true, otherwise we're not testing the parsing as false is the default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the default should be false because it shouldn't stop on every main thread checker issue. Am I right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yonaskolb / @brentleyjones Can I please get a bit of help on this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ionutivan you are correct about the default, what @yonaskolb was asking for is that we set it to true in a test, so we can test the parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brentleyjones Thank you for the help!

"environmentVariables": [
"TEST_VAR": "TEST_VAL",
],
Expand All @@ -738,6 +739,7 @@ class SpecLoadingTests: XCTestCase {
language: "en",
region: "US",
disableMainThreadChecker: true,
stopOnEveryMainThreadCheckerIssue: false,
commandLineArguments: ["ENV1": true],
environmentVariables: [XCScheme.EnvironmentVariable(variable: "TEST_VAR", value: "TEST_VAL", enabled: true)],
preActions: [.init(name: "Do Thing", script: "dothing", settingsTarget: "test")],
Expand Down Expand Up @@ -782,6 +784,7 @@ class SpecLoadingTests: XCTestCase {
],
"gatherCoverageData": true,
"disableMainThreadChecker": true,
"stopOnEveryMainThreadCheckerIssue": false,
],
]
let scheme = try Scheme(name: "Scheme", jsonDictionary: schemeDictionary)
Expand Down Expand Up @@ -931,6 +934,7 @@ class SpecLoadingTests: XCTestCase {
],
"gatherCoverageData": true,
"disableMainThreadChecker": true,
"stopOnEveryMainThreadCheckerIssue": false,
],
],
],
Expand Down