@@ -36,28 +36,28 @@ extension Generator {
36
36
return nil
37
37
}
38
38
39
+ let isLaunchable = pbxTarget. isLaunchable
40
+ let isTestable = pbxTarget. isTestable
41
+ let productType = pbxTarget. productType ?? . none
42
+
39
43
let buildableReference = try pbxTarget. createBuildableReference (
40
44
referencedContainer: referencedContainer
41
45
)
42
46
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
61
61
62
62
let buildAction = XCScheme . BuildAction (
63
63
buildActionEntries: [ . init(
@@ -79,22 +79,28 @@ extension Generator {
79
79
parallelizeBuild: true ,
80
80
buildImplicitDependencies: true
81
81
)
82
- let testAction = XCScheme . TestAction (
82
+ let launchAction = XCScheme . LaunchAction (
83
+ runnable: runnables. launch,
83
84
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,
86
91
customLLDBInitFile: " $(BAZEL_LLDB_INIT) "
87
92
)
88
- let launchAction = XCScheme . LaunchAction (
89
- runnable: buildableProductRunnable,
93
+ let testAction = XCScheme . TestAction (
90
94
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
+ ) ,
94
100
customLLDBInitFile: " $(BAZEL_LLDB_INIT) "
95
101
)
96
102
let profileAction = XCScheme . ProfileAction (
97
- buildableProductRunnable: buildableProductRunnable ,
103
+ buildableProductRunnable: runnables . profile ,
98
104
buildConfiguration: buildConfigurationName
99
105
)
100
106
let analyzeAction = XCScheme . AnalyzeAction (
@@ -115,10 +121,72 @@ extension Generator {
115
121
profileAction: profileAction,
116
122
analyzeAction: analyzeAction,
117
123
archiveAction: archiveAction,
118
- wasCreatedForAppExtension: nil
124
+ wasCreatedForAppExtension: productType . isExtension ? true : nil
119
125
)
120
126
}
121
127
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
+
122
190
private static func createBuildPreActions(
123
191
buildMode: BuildMode ,
124
192
pbxTarget: PBXTarget ,
0 commit comments