Skip to content

Add debugEnabled option for run and test #657

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

Merged
merged 6 commits into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `includes` to `sources` for a Target. This follows the same glob-style as `excludes` but functions as a way to only include files that match a specified pattern. Useful if you only want a certain file type, for example specifying `**/*.swift`. [#637](https://github.com/yonaskolb/XcodeGen/pull/637) @bclymer
- Support `dylib` SDK. [#650](https://github.com/yonaskolb/XcodeGen/pull/650)
- Added `language` and `region` options for `run` and `test` scheme [#654](https://github.com/yonaskolb/XcodeGen/pull/654)
- Added `debugEnabled` option for `run` and `test` scheme [#657](https://github.com/yonaskolb/XcodeGen/pull/657)

#### Fixed

Expand Down
1 change: 1 addition & 0 deletions Docs/ProjectSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ The different actions share some properties:
- [ ] **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
- [ ] **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.

### Execution Action

Expand Down
21 changes: 19 additions & 2 deletions Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public struct Scheme: Equatable {

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

public var config: String?
public var commandLineArguments: [String: Bool]
Expand All @@ -78,6 +79,7 @@ public struct Scheme: Equatable {
public var disableMainThreadChecker: Bool
public var language: String?
public var region: String?
public var debugEnabled: Bool

public init(
config: String,
Expand All @@ -87,7 +89,8 @@ public struct Scheme: Equatable {
environmentVariables: [XCScheme.EnvironmentVariable] = [],
disableMainThreadChecker: Bool = disableMainThreadCheckerDefault,
language: String? = nil,
region: String? = nil
region: String? = nil,
debugEnabled: Bool = debugEnabledDefault
) {
self.config = config
self.commandLineArguments = commandLineArguments
Expand All @@ -97,12 +100,14 @@ public struct Scheme: Equatable {
self.disableMainThreadChecker = disableMainThreadChecker
self.language = language
self.region = region
self.debugEnabled = debugEnabled
}
}

public struct Test: BuildAction {
public static let gatherCoverageDataDefault = false
public static let disableMainThreadCheckerDefault = false
public static let debugEnabledDefault = true

public var config: String?
public var gatherCoverageData: Bool
Expand All @@ -114,6 +119,7 @@ public struct Scheme: Equatable {
public var environmentVariables: [XCScheme.EnvironmentVariable]
public var language: String?
public var region: String?
public var debugEnabled: Bool

public struct TestTarget: Equatable, ExpressibleByStringLiteral {
public static let randomExecutionOrderDefault = false
Expand Down Expand Up @@ -156,7 +162,8 @@ public struct Scheme: Equatable {
postActions: [ExecutionAction] = [],
environmentVariables: [XCScheme.EnvironmentVariable] = [],
language: String? = nil,
region: String? = nil
region: String? = nil,
debugEnabled: Bool = debugEnabledDefault
) {
self.config = config
self.gatherCoverageData = gatherCoverageData
Expand All @@ -168,6 +175,7 @@ public struct Scheme: Equatable {
self.environmentVariables = environmentVariables
self.language = language
self.region = region
self.debugEnabled = debugEnabled
}

public var shouldUseLaunchSchemeArgsEnv: Bool {
Expand Down Expand Up @@ -275,6 +283,7 @@ extension Scheme.Run: JSONObjectConvertible {
disableMainThreadChecker = jsonDictionary.json(atKeyPath: "disableMainThreadChecker") ?? Scheme.Run.disableMainThreadCheckerDefault
language = jsonDictionary.json(atKeyPath: "language")
region = jsonDictionary.json(atKeyPath: "region")
debugEnabled = jsonDictionary.json(atKeyPath: "debugEnabled") ?? Scheme.Run.debugEnabledDefault
}
}

Expand All @@ -294,6 +303,9 @@ extension Scheme.Run: JSONEncodable {
dict["disableMainThreadChecker"] = disableMainThreadChecker
}

if debugEnabled != Scheme.Run.debugEnabledDefault {
dict["debugEnabled"] = debugEnabled
}
return dict
}
}
Expand Down Expand Up @@ -323,6 +335,7 @@ extension Scheme.Test: JSONObjectConvertible {
environmentVariables = try XCScheme.EnvironmentVariable.parseAll(jsonDictionary: jsonDictionary)
language = jsonDictionary.json(atKeyPath: "language")
region = jsonDictionary.json(atKeyPath: "region")
debugEnabled = jsonDictionary.json(atKeyPath: "debugEnabled") ?? Scheme.Test.debugEnabledDefault
}
}

Expand All @@ -347,6 +360,10 @@ extension Scheme.Test: JSONEncodable {
dict["disableMainThreadChecker"] = disableMainThreadChecker
}

if debugEnabled != Scheme.Run.debugEnabledDefault {
dict["debugEnabled"] = debugEnabled
}

return dict
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public class SchemeGenerator {
testables: testables,
preActions: scheme.test?.preActions.map(getExecutionAction) ?? [],
postActions: scheme.test?.postActions.map(getExecutionAction) ?? [],
selectedDebuggerIdentifier: (scheme.test?.debugEnabled ?? Scheme.Test.debugEnabledDefault) ? XCScheme.defaultDebugger : "",
shouldUseLaunchSchemeArgsEnv: scheme.test?.shouldUseLaunchSchemeArgsEnv ?? true,
codeCoverageEnabled: scheme.test?.gatherCoverageData ?? Scheme.Test.gatherCoverageDataDefault,
disableMainThreadChecker: scheme.test?.disableMainThreadChecker ?? Scheme.Test.disableMainThreadCheckerDefault,
Expand All @@ -167,6 +168,8 @@ public class SchemeGenerator {
preActions: scheme.run?.preActions.map(getExecutionAction) ?? [],
postActions: scheme.run?.postActions.map(getExecutionAction) ?? [],
macroExpansion: shouldExecuteOnLaunch ? nil : buildableReference,
selectedDebuggerIdentifier: (scheme.run?.debugEnabled ?? Scheme.Run.debugEnabledDefault) ? XCScheme.defaultDebugger : "",
selectedLauncherIdentifier: (scheme.run?.debugEnabled ?? Scheme.Run.debugEnabledDefault) ? XCScheme.defaultLauncher : "Xcode.IDEFoundation.Launcher.PosixSpawn",
disableMainThreadChecker: scheme.run?.disableMainThreadChecker ?? Scheme.Run.disableMainThreadCheckerDefault,
commandlineArguments: launchCommandLineArgs,
environmentVariables: launchVariables,
Expand Down
24 changes: 24 additions & 0 deletions Tests/XcodeGenKitTests/SchemeGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class SchemeGeneratorTests: XCTestCase {
try expect(xcscheme.profileAction?.buildConfiguration) == "Release"
try expect(xcscheme.analyzeAction?.buildConfiguration) == "Debug"
try expect(xcscheme.archiveAction?.buildConfiguration) == "Release"

try expect(xcscheme.launchAction?.selectedDebuggerIdentifier) == XCScheme.defaultDebugger
try expect(xcscheme.testAction?.selectedDebuggerIdentifier) == XCScheme.defaultDebugger
}

$0.it("sets environment variables for a scheme") {
Expand Down Expand Up @@ -174,6 +177,27 @@ class SchemeGeneratorTests: XCTestCase {
try expect(xcscheme.profileAction?.environmentVariables) == variables
}

$0.it("generate scheme without debugger") {
let scheme = Scheme(
name: "TestScheme",
build: Scheme.Build(targets: [buildTarget]),
run: Scheme.Run(config: "Debug", debugEnabled: false)
)
let project = Project(
name: "test",
targets: [app, framework],
schemes: [scheme]
)
let xcodeProject = try project.generateXcodeProject()

guard let xcscheme = xcodeProject.sharedData?.schemes.first else {
throw failure("Scheme not found")
}

try expect(xcscheme.launchAction?.selectedDebuggerIdentifier) == ""
try expect(xcscheme.launchAction?.selectedLauncherIdentifier) == "Xcode.IDEFoundation.Launcher.PosixSpawn"
}

$0.it("generates pre and post actions for target schemes") {
var target = app
target.scheme = TargetScheme(
Expand Down