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

Feature: Ability to set executable to Ask to Launch #871

Merged
merged 5 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions Sources/ProjectSpec/Scheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public struct Scheme: Equatable {
public var stopOnEveryMainThreadCheckerIssue: Bool
public var language: String?
public var region: String?
public var askForAppToLaunch: Bool?
public var launchAutomaticallySubstyle: String?
public var debugEnabled: Bool
public var simulateLocation: SimulateLocation?
Expand All @@ -125,6 +126,7 @@ public struct Scheme: Equatable {
stopOnEveryMainThreadCheckerIssue: Bool = stopOnEveryMainThreadCheckerIssueDefault,
language: String? = nil,
region: String? = nil,
askForAppToLaunch: Bool? = nil,
launchAutomaticallySubstyle: String? = nil,
debugEnabled: Bool = debugEnabledDefault,
simulateLocation: SimulateLocation? = nil
Expand All @@ -138,6 +140,7 @@ public struct Scheme: Equatable {
self.stopOnEveryMainThreadCheckerIssue = stopOnEveryMainThreadCheckerIssue
self.language = language
self.region = region
self.askForAppToLaunch = askForAppToLaunch
self.launchAutomaticallySubstyle = launchAutomaticallySubstyle
self.debugEnabled = debugEnabled
self.simulateLocation = simulateLocation
Expand Down Expand Up @@ -364,6 +367,10 @@ extension Scheme.Run: JSONObjectConvertible {
} else if let string: String = jsonDictionary.json(atKeyPath: "launchAutomaticallySubstyle") {
launchAutomaticallySubstyle = string
}

if let askLaunch: Bool = jsonDictionary.json(atKeyPath: "askForAppToLaunch") {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about defaulting to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the key is by default non-existing instead of false

Copy link
Owner

Choose a reason for hiding this comment

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

If this value were false, then the property would be nil. Is that what is intended?

askForAppToLaunch = askLaunch
}
}
}

Expand All @@ -377,6 +384,7 @@ extension Scheme.Run: JSONEncodable {
"config": config,
"language": language,
"region": region,
"askForAppToLaunch": askForAppToLaunch,
"launchAutomaticallySubstyle": launchAutomaticallySubstyle,
]

Expand Down
11 changes: 10 additions & 1 deletion Sources/XcodeGenKit/SchemeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ public class SchemeGenerator {
}
locationScenarioReference = XCScheme.LocationScenarioReference(identifier: identifier, referenceType: referenceType.rawValue)
}

let appExtensionTarget = scheme.build.targets.compactMap { bt -> Target? in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we instead just use schemeTarget?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in my case the share extension needs both the normal app and the extension set for build targets. When either one of the targets is the app extension I set it to askForAppToLaunch otherwise the key can be nil. Using the schemeTarget doesn't have the same result.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh, okay. Let's not default it at all then. If its not specified in the yml we will behave like we do now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, this way we don't enforce anything upon the user but let them take care of setting the right values in the yml.

return project.getTarget(bt.target.name)
}.first { $0.type == .appExtension }

let askAppForLaunch = scheme.run?.askForAppToLaunch ?? ((appExtensionTarget != nil) ? true : nil)
let launchAutomaticallySubstyle = scheme.run?.launchAutomaticallySubstyle ?? ((appExtensionTarget != nil) ? "2" : nil)

let launchAction = XCScheme.LaunchAction(
runnable: shouldExecuteOnLaunch ? runnables.launch : nil,
buildConfiguration: scheme.run?.config ?? defaultDebugConfig.name,
Expand All @@ -241,6 +249,7 @@ public class SchemeGenerator {
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",
askForAppToLaunch: askAppForLaunch,
allowLocationSimulation: allowLocationSimulation,
locationScenarioReference: locationScenarioReference,
disableMainThreadChecker: scheme.run?.disableMainThreadChecker ?? Scheme.Run.disableMainThreadCheckerDefault,
Expand All @@ -249,7 +258,7 @@ public class SchemeGenerator {
environmentVariables: launchVariables,
language: scheme.run?.language,
region: scheme.run?.region,
launchAutomaticallySubstyle: scheme.run?.launchAutomaticallySubstyle
launchAutomaticallySubstyle: launchAutomaticallySubstyle
)

let profileAction = XCScheme.ProfileAction(
Expand Down