Skip to content

Commit b409fa7

Browse files
committed
Improve schemes for application extensions
Also cleanup scheme creation code, in preparation for better more app extension scheme support.
1 parent 297c8e3 commit b409fa7

File tree

5 files changed

+217
-39
lines changed

5 files changed

+217
-39
lines changed

test/fixtures/multiplatform/bwb.xcodeproj/xcshareddata/xcschemes/WidgetExtension.xcscheme

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "1320"
4-
version = "1.7">
4+
version = "1.7"
5+
wasCreatedForAppExtension = "YES">
56
<BuildAction
67
parallelizeBuildables = "YES"
78
buildImplicitDependencies = "YES">
@@ -51,15 +52,16 @@
5152
</TestAction>
5253
<LaunchAction
5354
buildConfiguration = "Debug"
54-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
55-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
55+
selectedDebuggerIdentifier = ""
56+
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
5657
customLLDBInitFile = "$(BAZEL_LLDB_INIT)"
5758
launchStyle = "0"
5859
useCustomWorkingDirectory = "NO"
5960
ignoresPersistentStateOnLaunch = "NO"
6061
debugDocumentVersioning = "YES"
6162
debugServiceExtension = "internal"
62-
allowLocationSimulation = "YES">
63+
allowLocationSimulation = "YES"
64+
launchAutomaticallySubstyle = "2">
6365
<BuildableProductRunnable
6466
runnableDebuggingMode = "0">
6567
<BuildableReference

test/fixtures/multiplatform/bwx.xcodeproj/xcshareddata/xcschemes/WidgetExtension.xcscheme

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "1320"
4-
version = "1.7">
4+
version = "1.7"
5+
wasCreatedForAppExtension = "YES">
56
<BuildAction
67
parallelizeBuildables = "YES"
78
buildImplicitDependencies = "YES">
@@ -33,15 +34,16 @@
3334
</TestAction>
3435
<LaunchAction
3536
buildConfiguration = "Debug"
36-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
37-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
selectedDebuggerIdentifier = ""
38+
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
3839
customLLDBInitFile = "$(BAZEL_LLDB_INIT)"
3940
launchStyle = "0"
4041
useCustomWorkingDirectory = "NO"
4142
ignoresPersistentStateOnLaunch = "NO"
4243
debugDocumentVersioning = "YES"
4344
debugServiceExtension = "internal"
44-
allowLocationSimulation = "YES">
45+
allowLocationSimulation = "YES"
46+
launchAutomaticallySubstyle = "2">
4547
<BuildableProductRunnable
4648
runnableDebuggingMode = "0">
4749
<BuildableReference

tools/generator/src/Extensions/PBXProductType+Extensions.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ extension PBXProductType {
9393
}
9494
}
9595

96+
var isExtension: Bool {
97+
switch self {
98+
case .appExtension,
99+
.tvExtension,
100+
.watchExtension,
101+
.watch2Extension,
102+
.messagesExtension,
103+
.stickerPack,
104+
.xcodeExtension,
105+
.intentsServiceExtension:
106+
return true
107+
default:
108+
return false
109+
}
110+
}
111+
96112
var isFramework: Bool {
97113
switch self {
98114
case .framework,
@@ -238,6 +254,15 @@ extension PBXProductType {
238254
return isLaunchable ? .bazelLaunchVariables : nil
239255
}
240256

257+
var canUseDebugLauncher: Bool {
258+
// Extensions don't use the lldb launcher
259+
return !isExtension
260+
}
261+
262+
var launchAutomaticallySubstyle: String? {
263+
return isExtension ? "2" : nil
264+
}
265+
241266
var shouldCreateScheme: Bool {
242267
switch self {
243268
case .watchExtension,

tools/generator/src/Generator/CreateAutogeneratedXCSchemes.swift

Lines changed: 96 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ extension Generator {
3636
return nil
3737
}
3838

39+
let isLaunchable = pbxTarget.isLaunchable
40+
let isTestable = pbxTarget.isTestable
41+
let productType = pbxTarget.productType ?? .none
42+
3943
let buildableReference = try pbxTarget.createBuildableReference(
4044
referencedContainer: referencedContainer
4145
)
4246
let buildConfigurationName = pbxTarget.defaultBuildConfigurationName
43-
44-
let buildableProductRunnable: XCScheme.BuildableProductRunnable?
45-
let macroExpansion: XCScheme.BuildableReference?
46-
let testables: [XCScheme.TestableReference]
47-
if pbxTarget.isTestable {
48-
buildableProductRunnable = nil
49-
macroExpansion = buildableReference
50-
testables = [.init(
51-
skipped: false,
52-
buildableReference: buildableReference
53-
)]
54-
// swiftlint:disable:previous trailing_comma
55-
} else {
56-
buildableProductRunnable = pbxTarget.isLaunchable ?
57-
.init(buildableReference: buildableReference) : nil
58-
macroExpansion = nil
59-
testables = []
60-
}
47+
let runnables = createRunnables(
48+
buildableReference: buildableReference,
49+
isLaunchable: isLaunchable,
50+
isTestable: isTestable
51+
)
52+
let macroExpansions = createMacroExpansions(
53+
buildableReference: buildableReference,
54+
isTestable: isTestable
55+
)
56+
let selectedIdentifiers = createSelectedIdentifiers(
57+
productType: productType
58+
)
59+
let launchAutomaticallySubstyle = productType
60+
.launchAutomaticallySubstyle
6161

6262
let buildAction = XCScheme.BuildAction(
6363
buildActionEntries: [.init(
@@ -79,22 +79,28 @@ extension Generator {
7979
parallelizeBuild: true,
8080
buildImplicitDependencies: true
8181
)
82-
let testAction = XCScheme.TestAction(
82+
let launchAction = XCScheme.LaunchAction(
83+
runnable: runnables.launch,
8384
buildConfiguration: buildConfigurationName,
84-
macroExpansion: nil,
85-
testables: testables,
85+
macroExpansion: macroExpansions.launch,
86+
selectedDebuggerIdentifier: selectedIdentifiers.debugger,
87+
selectedLauncherIdentifier: selectedIdentifiers.launcher,
88+
environmentVariables: buildMode.usesBazelEnvironmentVariables ?
89+
productType.bazelLaunchEnvironmentVariables : nil,
90+
launchAutomaticallySubstyle: launchAutomaticallySubstyle,
8691
customLLDBInitFile: "$(BAZEL_LLDB_INIT)"
8792
)
88-
let launchAction = XCScheme.LaunchAction(
89-
runnable: buildableProductRunnable,
93+
let testAction = XCScheme.TestAction(
9094
buildConfiguration: buildConfigurationName,
91-
macroExpansion: macroExpansion,
92-
environmentVariables: buildMode.usesBazelEnvironmentVariables ?
93-
pbxTarget.productType?.bazelLaunchEnvironmentVariables : nil,
95+
macroExpansion: macroExpansions.test,
96+
testables: createTestables(
97+
buildableReference: buildableReference,
98+
isTestable: isTestable
99+
),
94100
customLLDBInitFile: "$(BAZEL_LLDB_INIT)"
95101
)
96102
let profileAction = XCScheme.ProfileAction(
97-
buildableProductRunnable: buildableProductRunnable,
103+
buildableProductRunnable: runnables.profile,
98104
buildConfiguration: buildConfigurationName
99105
)
100106
let analyzeAction = XCScheme.AnalyzeAction(
@@ -115,10 +121,72 @@ extension Generator {
115121
profileAction: profileAction,
116122
analyzeAction: analyzeAction,
117123
archiveAction: archiveAction,
118-
wasCreatedForAppExtension: nil
124+
wasCreatedForAppExtension: productType.isExtension ? true : nil
119125
)
120126
}
121127

128+
private static func createRunnables(
129+
buildableReference: XCScheme.BuildableReference,
130+
isLaunchable: Bool,
131+
isTestable: Bool
132+
) -> (
133+
launch: XCScheme.Runnable?,
134+
profile: XCScheme.BuildableProductRunnable?
135+
) {
136+
guard !isTestable else {
137+
return (launch: nil, profile: nil)
138+
}
139+
140+
let runnable: XCScheme.BuildableProductRunnable? = isLaunchable ?
141+
.init(buildableReference: buildableReference) : nil
142+
143+
return (launch: runnable, profile: runnable)
144+
}
145+
146+
private static func createMacroExpansions(
147+
buildableReference: XCScheme.BuildableReference,
148+
isTestable: Bool
149+
) -> (
150+
launch: XCScheme.BuildableReference?,
151+
test: XCScheme.BuildableReference?
152+
) {
153+
if isTestable {
154+
return (launch: buildableReference, test: nil)
155+
} else {
156+
return (launch: nil, test: nil)
157+
}
158+
}
159+
160+
private static func createSelectedIdentifiers(
161+
productType: PBXProductType
162+
) -> (launcher: String, debugger: String) {
163+
if productType.canUseDebugLauncher {
164+
return (
165+
launcher: XCScheme.defaultLauncher,
166+
debugger: XCScheme.defaultDebugger
167+
)
168+
} else {
169+
return (
170+
launcher: "Xcode.IDEFoundation.Launcher.PosixSpawn",
171+
debugger: ""
172+
)
173+
}
174+
}
175+
176+
private static func createTestables(
177+
buildableReference: XCScheme.BuildableReference,
178+
isTestable: Bool
179+
) -> [XCScheme.TestableReference] {
180+
guard isTestable else {
181+
return []
182+
}
183+
184+
return [.init(
185+
skipped: false,
186+
buildableReference: buildableReference
187+
)]
188+
}
189+
122190
private static func createBuildPreActions(
123191
buildMode: BuildMode,
124192
pbxTarget: PBXTarget,

0 commit comments

Comments
 (0)