diff --git a/CHANGELOG.md b/CHANGELOG.md index cf01884c..393a4151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Next Version +#### Added +- Added ability to disable main thread checker on Run and Test schemes and TargetSchemes [#601](https://github.com/yonaskolb/XcodeGen/pull/601) @wag-miles + #### Fixed - Fixed included specs that were referenced multiple times from duplicating content [#599](https://github.com/yonaskolb/XcodeGen/pull/599) @haritowa - Fixed `.orig` files being added to the project [#627](https://github.com/yonaskolb/XcodeGen/pull/627) @keith diff --git a/Docs/ProjectSpec.md b/Docs/ProjectSpec.md index b1c05ee7..01264599 100644 --- a/Docs/ProjectSpec.md +++ b/Docs/ProjectSpec.md @@ -547,6 +547,7 @@ This is a convenience used to automatically generate schemes for a target based - [x] **configVariants**: **[String]** - This generates a scheme for each entry, using configs that contain the name with debug and release variants. This is useful for having different environment schemes. - [ ] **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 - [ ] **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 @@ -679,6 +680,7 @@ The different actions share some properties: - [ ] **preActions**: **[[Execution Action](#execution-action)]** - Scripts that are run *before* the action - [ ] **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 ### Execution Action diff --git a/Sources/ProjectSpec/Scheme.swift b/Sources/ProjectSpec/Scheme.swift index 3a39d615..6ab9c3c6 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -68,31 +68,39 @@ public struct Scheme: Equatable { } public struct Run: BuildAction { + public static let disableMainThreadCheckerDefault = false + public var config: String? public var commandLineArguments: [String: Bool] public var preActions: [ExecutionAction] public var postActions: [ExecutionAction] public var environmentVariables: [XCScheme.EnvironmentVariable] + public var disableMainThreadChecker: Bool + public init( config: String, commandLineArguments: [String: Bool] = [:], preActions: [ExecutionAction] = [], postActions: [ExecutionAction] = [], - environmentVariables: [XCScheme.EnvironmentVariable] = [] + environmentVariables: [XCScheme.EnvironmentVariable] = [], + disableMainThreadChecker: Bool = disableMainThreadCheckerDefault ) { self.config = config self.commandLineArguments = commandLineArguments self.preActions = preActions self.postActions = postActions self.environmentVariables = environmentVariables + self.disableMainThreadChecker = disableMainThreadChecker } } public struct Test: BuildAction { public static let gatherCoverageDataDefault = false + public static let disableMainThreadCheckerDefault = false public var config: String? public var gatherCoverageData: Bool + public var disableMainThreadChecker: Bool public var commandLineArguments: [String: Bool] public var targets: [TestTarget] public var preActions: [ExecutionAction] @@ -131,6 +139,7 @@ public struct Scheme: Equatable { public init( config: String, gatherCoverageData: Bool = gatherCoverageDataDefault, + disableMainThreadChecker: Bool = disableMainThreadCheckerDefault, randomExecutionOrder: Bool = false, parallelizable: Bool = false, commandLineArguments: [String: Bool] = [:], @@ -141,6 +150,7 @@ public struct Scheme: Equatable { ) { self.config = config self.gatherCoverageData = gatherCoverageData + self.disableMainThreadChecker = disableMainThreadChecker self.commandLineArguments = commandLineArguments self.targets = targets self.preActions = preActions @@ -250,18 +260,25 @@ extension Scheme.Run: JSONObjectConvertible { preActions = jsonDictionary.json(atKeyPath: "preActions") ?? [] postActions = jsonDictionary.json(atKeyPath: "postActions") ?? [] environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary) + disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? Scheme.Run.disableMainThreadCheckerDefault } } extension Scheme.Run: JSONEncodable { public func toJSONValue() -> Any { - return [ + var dict: [String: Any?] = [ "commandLineArguments": commandLineArguments, "preActions": preActions.map { $0.toJSONValue() }, "postActions": postActions.map { $0.toJSONValue() }, "environmentVariables": environmentVariables.map { $0.toJSONValue() }, "config": config - ] as [String: Any?] + ] + + if disableMainThreadChecker != Scheme.Run.disableMainThreadCheckerDefault { + dict["disableMainThreadChecker"] = disableMainThreadChecker + } + + return dict } } @@ -270,6 +287,7 @@ extension Scheme.Test: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { config = jsonDictionary.json(atKeyPath: "config") gatherCoverageData = jsonDictionary.json(atKeyPath: "gatherCoverageData") ?? Scheme.Test.gatherCoverageDataDefault + disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? Scheme.Test.disableMainThreadCheckerDefault commandLineArguments = jsonDictionary.json(atKeyPath: "commandLineArguments") ?? [:] if let targets = jsonDictionary["targets"] as? [Any] { self.targets = try targets.compactMap { target in @@ -292,15 +310,24 @@ extension Scheme.Test: JSONObjectConvertible { extension Scheme.Test: JSONEncodable { public func toJSONValue() -> Any { - return [ - "gatherCoverageData": gatherCoverageData, + var dict: [String: Any?] = [ "commandLineArguments": commandLineArguments, "targets": targets.map { $0.toJSONValue() }, "preActions": preActions.map { $0.toJSONValue() }, "postActions": postActions.map { $0.toJSONValue() }, "environmentVariables": environmentVariables.map { $0.toJSONValue() }, "config": config - ] as [String: Any?] + ] + + if gatherCoverageData != Scheme.Test.gatherCoverageDataDefault { + dict["gatherCoverageData"] = gatherCoverageData + } + + if disableMainThreadChecker != Scheme.Test.disableMainThreadCheckerDefault { + dict["disableMainThreadChecker"] = disableMainThreadChecker + } + + return dict } } diff --git a/Sources/ProjectSpec/TargetScheme.swift b/Sources/ProjectSpec/TargetScheme.swift index e0bf1b03..4682e3a7 100644 --- a/Sources/ProjectSpec/TargetScheme.swift +++ b/Sources/ProjectSpec/TargetScheme.swift @@ -4,10 +4,12 @@ import XcodeProj public struct TargetScheme: Equatable { public static let gatherCoverageDataDefault = false + public static let disableMainThreadCheckerDefault = false public var testTargets: [Scheme.Test.TestTarget] public var configVariants: [String] public var gatherCoverageData: Bool + public var disableMainThreadChecker: Bool public var commandLineArguments: [String: Bool] public var environmentVariables: [XCScheme.EnvironmentVariable] public var preActions: [Scheme.ExecutionAction] @@ -17,6 +19,7 @@ public struct TargetScheme: Equatable { testTargets: [Scheme.Test.TestTarget] = [], configVariants: [String] = [], gatherCoverageData: Bool = gatherCoverageDataDefault, + disableMainThreadChecker: Bool = disableMainThreadCheckerDefault, commandLineArguments: [String: Bool] = [:], environmentVariables: [XCScheme.EnvironmentVariable] = [], preActions: [Scheme.ExecutionAction] = [], @@ -25,6 +28,7 @@ public struct TargetScheme: Equatable { self.testTargets = testTargets self.configVariants = configVariants self.gatherCoverageData = gatherCoverageData + self.disableMainThreadChecker = disableMainThreadChecker self.commandLineArguments = commandLineArguments self.environmentVariables = environmentVariables self.preActions = preActions @@ -50,6 +54,7 @@ extension TargetScheme: JSONObjectConvertible { } configVariants = jsonDictionary.json(atKeyPath: "configVariants") ?? [] gatherCoverageData = jsonDictionary.json(atKeyPath: "gatherCoverageData") ?? TargetScheme.gatherCoverageDataDefault + disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? TargetScheme.disableMainThreadCheckerDefault commandLineArguments = jsonDictionary.json(atKeyPath: "commandLineArguments") ?? [:] environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary) preActions = jsonDictionary.json(atKeyPath: "preActions") ?? [] @@ -72,6 +77,10 @@ extension TargetScheme: JSONEncodable { dict["gatherCoverageData"] = gatherCoverageData } + if disableMainThreadChecker != TargetScheme.disableMainThreadCheckerDefault { + dict["disableMainThreadChecker"] = disableMainThreadChecker + } + return dict } } diff --git a/Sources/XcodeGenKit/SchemeGenerator.swift b/Sources/XcodeGenKit/SchemeGenerator.swift index 8e0c9ce5..1da86a81 100644 --- a/Sources/XcodeGenKit/SchemeGenerator.swift +++ b/Sources/XcodeGenKit/SchemeGenerator.swift @@ -153,7 +153,8 @@ public class SchemeGenerator { preActions: scheme.test?.preActions.map(getExecutionAction) ?? [], postActions: scheme.test?.postActions.map(getExecutionAction) ?? [], shouldUseLaunchSchemeArgsEnv: scheme.test?.shouldUseLaunchSchemeArgsEnv ?? true, - codeCoverageEnabled: scheme.test?.gatherCoverageData ?? false, + codeCoverageEnabled: scheme.test?.gatherCoverageData ?? Scheme.Test.gatherCoverageDataDefault, + disableMainThreadChecker: scheme.test?.disableMainThreadChecker ?? Scheme.Test.disableMainThreadCheckerDefault, commandlineArguments: testCommandLineArgs, environmentVariables: testVariables ) @@ -164,6 +165,7 @@ public class SchemeGenerator { preActions: scheme.run?.preActions.map(getExecutionAction) ?? [], postActions: scheme.run?.postActions.map(getExecutionAction) ?? [], macroExpansion: shouldExecuteOnLaunch ? nil : buildableReference, + disableMainThreadChecker: scheme.run?.disableMainThreadChecker ?? Scheme.Run.disableMainThreadCheckerDefault, commandlineArguments: launchCommandLineArgs, environmentVariables: launchVariables ) @@ -212,11 +214,13 @@ extension Scheme { commandLineArguments: targetScheme.commandLineArguments, preActions: targetScheme.preActions, postActions: targetScheme.postActions, - environmentVariables: targetScheme.environmentVariables + environmentVariables: targetScheme.environmentVariables, + disableMainThreadChecker: targetScheme.disableMainThreadChecker ), test: .init( config: debugConfig, gatherCoverageData: targetScheme.gatherCoverageData, + disableMainThreadChecker: targetScheme.disableMainThreadChecker, commandLineArguments: targetScheme.commandLineArguments, targets: targetScheme.testTargets, preActions: targetScheme.preActions, diff --git a/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/App_iOS Production.xcscheme b/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/App_iOS Production.xcscheme index 3e1f5424..03bfc9f7 100644 --- a/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/App_iOS Production.xcscheme +++ b/Tests/Fixtures/TestProject/Project.xcodeproj/xcshareddata/xcschemes/App_iOS Production.xcscheme @@ -27,7 +27,8 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" codeCoverageEnabled = "YES" - shouldUseLaunchSchemeArgsEnv = "NO"> + shouldUseLaunchSchemeArgsEnv = "NO" + disableMainThreadChecker = "YES"> @@ -83,7 +84,8 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" - allowLocationSimulation = "YES"> + allowLocationSimulation = "YES" + disableMainThreadChecker = "YES"> + shouldUseLaunchSchemeArgsEnv = "NO" + disableMainThreadChecker = "YES"> @@ -83,7 +84,8 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" - allowLocationSimulation = "YES"> + allowLocationSimulation = "YES" + disableMainThreadChecker = "YES"> + shouldUseLaunchSchemeArgsEnv = "NO" + disableMainThreadChecker = "YES"> @@ -83,7 +84,8 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" - allowLocationSimulation = "YES"> + allowLocationSimulation = "YES" + disableMainThreadChecker = "YES">