forked from yonaskolb/XcodeGen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemeGenerator.swift
More file actions
572 lines (501 loc) · 26.8 KB
/
SchemeGenerator.swift
File metadata and controls
572 lines (501 loc) · 26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
import Foundation
import ProjectSpec
import XcodeProj
import PathKit
private func suitableConfig(for type: ConfigType, in project: Project) -> Config {
if let defaultConfig = Config.defaultConfigs.first(where: { $0.type == type }),
project.configs.contains(defaultConfig) {
return defaultConfig
}
return project.configs.first { $0.type == type }!
}
public class SchemeGenerator {
let project: Project
let pbxProj: PBXProj
var defaultDebugConfig: Config {
suitableConfig(for: .debug, in: project)
}
var defaultReleaseConfig: Config {
suitableConfig(for: .release, in: project)
}
public init(project: Project, pbxProj: PBXProj) {
self.project = project
self.pbxProj = pbxProj
}
private var projects: [ProjectReference: PBXProj] = [:]
func getPBXProj(from reference: ProjectReference) throws -> PBXProj {
if let cachedProject = projects[reference] {
return cachedProject
}
let pbxproj = try XcodeProj(path: project.basePath + Path(reference.path)).pbxproj
projects[reference] = pbxproj
return pbxproj
}
public func generateSchemes() throws -> (
shared: [XCScheme],
user: [XCScheme],
management: XCSchemeManagement?
) {
var schemes: [(Scheme, ProjectTarget?)] = []
for scheme in project.schemes {
schemes.append((scheme, nil))
}
for target in project.projectTargets {
if let targetScheme = target.scheme {
if targetScheme.configVariants.isEmpty {
let schemeName = target.name
let debugConfig = suitableConfig(for: .debug, in: project)
let releaseConfig = suitableConfig(for: .release, in: project)
let scheme = Scheme(
name: schemeName,
target: target,
targetScheme: targetScheme,
project: project,
debugConfig: debugConfig.name,
releaseConfig: releaseConfig.name
)
schemes.append((scheme, target))
} else {
for configVariant in targetScheme.configVariants {
let schemeName = "\(target.name) \(configVariant)"
let debugConfig = project.configs
.first(including: configVariant, for: .debug)!
let releaseConfig = project.configs
.first(including: configVariant, for: .release)!
let scheme = Scheme(
name: schemeName,
target: target,
targetScheme: targetScheme,
project: project,
debugConfig: debugConfig.name,
releaseConfig: releaseConfig.name
)
schemes.append((scheme, target))
}
}
}
}
var sharedSchemes: [XCScheme] = []
var userSchemes: [XCScheme] = []
var schemeManagements: [XCSchemeManagement.UserStateScheme] = []
for (scheme, projectTarget) in schemes {
let xcscheme = try generateScheme(scheme, for: projectTarget)
if scheme.management?.shared == false {
userSchemes.append(xcscheme)
} else {
sharedSchemes.append(xcscheme)
}
if let management = scheme.management {
schemeManagements.append(
XCSchemeManagement.UserStateScheme(
name: scheme.name + ".xcscheme",
shared: management.shared,
orderHint: management.orderHint,
isShown: management.isShown
)
)
}
}
return (
shared: sharedSchemes,
user: userSchemes,
management: schemeManagements.isEmpty
? nil
: XCSchemeManagement(schemeUserState: schemeManagements, suppressBuildableAutocreation: nil)
)
}
public func generateScheme(_ scheme: Scheme, for target: ProjectTarget? = nil) throws -> XCScheme {
func getBuildableReference(_ target: TargetReference) throws -> XCScheme.BuildableReference {
let pbxProj: PBXProj
let projectFilePath: String
switch target.location {
case .project(let project):
guard let projectReference = self.project.getProjectReference(project) else {
throw SchemeGenerationError.missingProject(project)
}
pbxProj = try getPBXProj(from: projectReference)
projectFilePath = projectReference.path
case .local:
pbxProj = self.pbxProj
projectFilePath = "\(self.project.name).xcodeproj"
}
guard let pbxTarget = pbxProj.targets(named: target.name).first else {
throw SchemeGenerationError.missingTarget(target, projectPath: projectFilePath)
}
let buildableName: String
switch target.location {
case .project:
buildableName = pbxTarget.productNameWithExtension() ?? pbxTarget.name
case .local:
guard let _buildableName =
project.getTarget(target.name)?.filename ??
project.getAggregateTarget(target.name)?.name else {
fatalError("Unable to determinate \"buildableName\" for build target: \(target)")
}
buildableName = _buildableName
}
return XCScheme.BuildableReference(
referencedContainer: "container:\(projectFilePath)",
blueprint: pbxTarget,
buildableName: buildableName,
blueprintName: target.name
)
}
func getBuildableTestableReference(_ target: TestableTargetReference) throws -> XCScheme.BuildableReference {
switch target.location {
case .package(let packageName):
guard let package = self.project.getPackage(packageName),
case let .local(path, _, _) = package else {
throw SchemeGenerationError.missingPackage(packageName)
}
return XCScheme.BuildableReference(
referencedContainer: "container:\(path)",
blueprintIdentifier: target.name,
buildableName: target.name,
blueprintName: target.name
)
default:
return try getBuildableReference(target.targetReference)
}
}
func getBuildEntry(_ buildTarget: Scheme.BuildTarget) throws -> XCScheme.BuildAction.Entry {
let buildableReference = try getBuildableTestableReference(buildTarget.target)
return XCScheme.BuildAction.Entry(buildableReference: buildableReference, buildFor: buildTarget.buildTypes)
}
let testTargets = scheme.test?.targets ?? []
let testBuildTargets = testTargets.map {
Scheme.BuildTarget(target: $0.targetReference, buildTypes: BuildType.testOnly)
}
let testBuildTargetEntries = try testBuildTargets.map(getBuildEntry)
let buildActionEntries: [XCScheme.BuildAction.Entry] = try scheme.build.targets.map(getBuildEntry)
func getExecutionAction(_ action: Scheme.ExecutionAction) -> XCScheme.ExecutionAction {
// ExecutionActions can require the use of build settings. Xcode allows the settings to come from a build or test target.
let environmentBuildable = action.settingsTarget.flatMap { settingsTarget in
(buildActionEntries + testBuildTargetEntries)
.first { settingsTarget == $0.buildableReference.blueprintName }?
.buildableReference
}
return XCScheme.ExecutionAction(
scriptText: action.script,
title: action.name,
shellToInvoke: action.shell,
environmentBuildable: environmentBuildable
)
}
let schemeTarget: ProjectTarget?
if let targetName = scheme.run?.executable {
schemeTarget = project.getTarget(targetName)
} else {
guard let firstTarget = scheme.build.targets.first else {
throw SchemeGenerationError.missingBuildTargets(scheme.name)
}
let name = scheme.build.targets.first { $0.buildTypes.contains(.running) }?.target.name ?? firstTarget.target.name
schemeTarget = target ?? project.getTarget(name)
}
let shouldExecuteOnLaunch = schemeTarget?.shouldExecuteOnLaunch == true
let buildableReference = buildActionEntries.first(where: { $0.buildableReference.blueprintName == schemeTarget?.name })?.buildableReference ?? buildActionEntries.first!.buildableReference
let runnables = makeProductRunnables(for: schemeTarget, buildableReference: buildableReference)
let buildAction = XCScheme.BuildAction(
buildActionEntries: buildActionEntries,
preActions: scheme.build.preActions.map(getExecutionAction),
postActions: scheme.build.postActions.map(getExecutionAction),
parallelizeBuild: scheme.build.parallelizeBuild,
buildImplicitDependencies: scheme.build.buildImplicitDependencies,
runPostActionsOnFailure: scheme.build.runPostActionsOnFailure
)
let testables: [XCScheme.TestableReference] = zip(testTargets, testBuildTargetEntries).map { testTarget, testBuildEntries in
var locationScenarioReference: XCScheme.LocationScenarioReference?
if var location = testTarget.location {
if location.contains(".gpx") {
var path = Path(components: [project.options.schemePathPrefix, location])
path = path.simplifyingParentDirectoryReferences()
location = path.string
}
let referenceType = location.contains(".gpx") ? "0" : "1"
locationScenarioReference = XCScheme.LocationScenarioReference(identifier: location, referenceType: referenceType)
}
return XCScheme.TestableReference(
skipped: testTarget.skipped,
parallelizable: testTarget.parallelizable,
randomExecutionOrdering: testTarget.randomExecutionOrder,
buildableReference: testBuildEntries.buildableReference,
locationScenarioReference: locationScenarioReference,
skippedTests: testTarget.skippedTests.map(XCScheme.TestItem.init),
selectedTests: testTarget.selectedTests.map(XCScheme.TestItem.init),
useTestSelectionWhitelist: !testTarget.selectedTests.isEmpty ? true : nil
)
}
let coverageBuildableTargets = try scheme.test?.coverageTargets.map {
try getBuildableTestableReference($0)
} ?? []
let testCommandLineArgs = scheme.test.map { XCScheme.CommandLineArguments($0.commandLineArguments) }
let launchCommandLineArgs = scheme.run.map { XCScheme.CommandLineArguments($0.commandLineArguments) }
let profileCommandLineArgs = scheme.profile.map { XCScheme.CommandLineArguments($0.commandLineArguments) }
let testVariables = scheme.test.flatMap { $0.environmentVariables.isEmpty ? nil : $0.environmentVariables }
let launchVariables = scheme.run.flatMap { $0.environmentVariables.isEmpty ? nil : $0.environmentVariables }
let profileVariables = scheme.profile.flatMap { $0.environmentVariables.isEmpty ? nil : $0.environmentVariables }
let defaultTestPlanIndex = scheme.test?.testPlans.firstIndex { $0.defaultPlan } ?? 0
let testPlans = scheme.test?.testPlans.enumerated().map { index, testPlan in
XCScheme.TestPlanReference(reference: "container:\(testPlan.path)", default: defaultTestPlanIndex == index)
} ?? []
let testBuildableEntries = buildActionEntries.filter({ $0.buildFor.contains(.testing) }) + testBuildTargetEntries
let testMacroExpansionBuildableRef = testBuildableEntries.map(\.buildableReference).contains(buildableReference) ? buildableReference : testBuildableEntries.first?.buildableReference
let testMacroExpansion: XCScheme.BuildableReference = buildActionEntries.first(
where: { value in
if let macroExpansion = scheme.test?.macroExpansion {
return value.buildableReference.blueprintName == macroExpansion
}
return false
}
)?.buildableReference ?? testMacroExpansionBuildableRef ?? buildableReference
let testAction = XCScheme.TestAction(
buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name,
macroExpansion: testMacroExpansion,
testables: testables,
testPlans: testPlans.isEmpty ? nil : testPlans,
preActions: scheme.test?.preActions.map(getExecutionAction) ?? [],
postActions: scheme.test?.postActions.map(getExecutionAction) ?? [],
selectedDebuggerIdentifier: (scheme.test?.debugEnabled ?? Scheme.Test.debugEnabledDefault) ? XCScheme.defaultDebugger : "",
selectedLauncherIdentifier: (scheme.test?.debugEnabled ?? Scheme.Test.debugEnabledDefault) ? XCScheme.defaultLauncher : "Xcode.IDEFoundation.Launcher.PosixSpawn",
shouldUseLaunchSchemeArgsEnv: scheme.test?.shouldUseLaunchSchemeArgsEnv ?? true,
codeCoverageEnabled: scheme.test?.gatherCoverageData ?? Scheme.Test.gatherCoverageDataDefault,
codeCoverageTargets: coverageBuildableTargets,
onlyGenerateCoverageForSpecifiedTargets: !coverageBuildableTargets.isEmpty,
enableAddressSanitizer: scheme.test?.enableAddressSanitizer ?? Scheme.Test.enableAddressSanitizerDefault,
enableASanStackUseAfterReturn: scheme.test?.enableASanStackUseAfterReturn ?? Scheme.Test.enableASanStackUseAfterReturnDefault,
enableThreadSanitizer: scheme.test?.enableThreadSanitizer ?? Scheme.Test.enableThreadSanitizerDefault,
enableUBSanitizer: scheme.test?.enableUBSanitizer ?? Scheme.Test.enableUBSanitizerDefault,
disableMainThreadChecker: scheme.test?.disableMainThreadChecker ?? Scheme.Test.disableMainThreadCheckerDefault,
commandlineArguments: testCommandLineArgs,
environmentVariables: testVariables,
language: scheme.test?.language,
region: scheme.test?.region,
systemAttachmentLifetime: scheme.test?.systemAttachmentLifetime,
preferredScreenCaptureFormat: scheme.test?.preferredScreenCaptureFormat,
customLLDBInitFile: scheme.test?.customLLDBInit
)
let allowLocationSimulation = scheme.run?.simulateLocation?.allow ?? true
var locationScenarioReference: XCScheme.LocationScenarioReference?
if let simulateLocation = scheme.run?.simulateLocation, var identifier = simulateLocation.defaultLocation, let referenceType = simulateLocation.referenceType {
if referenceType == .gpx {
var path = Path(components: [project.options.schemePathPrefix, identifier])
path = path.simplifyingParentDirectoryReferences()
identifier = path.string
}
locationScenarioReference = XCScheme.LocationScenarioReference(identifier: identifier, referenceType: referenceType.rawValue)
}
var storeKitConfigurationFileReference: XCScheme.StoreKitConfigurationFileReference?
if let storeKitConfiguration = scheme.run?.storeKitConfiguration {
let storeKitConfigurationPath = Path(components: [project.options.schemePathPrefix, storeKitConfiguration]).simplifyingParentDirectoryReferences()
storeKitConfigurationFileReference = XCScheme.StoreKitConfigurationFileReference(identifier: storeKitConfigurationPath.string)
}
let macroExpansion: XCScheme.BuildableReference?
if let macroExpansionName = scheme.run?.macroExpansion,
let resolvedMacroExpansion = buildActionEntries.first(where: { $0.buildableReference.blueprintName == macroExpansionName })?.buildableReference {
macroExpansion = resolvedMacroExpansion
} else {
macroExpansion = shouldExecuteOnLaunch ? nil : buildableReference
}
let launchAction = XCScheme.LaunchAction(
runnable: shouldExecuteOnLaunch ? runnables.launch : nil,
buildConfiguration: scheme.run?.config ?? defaultDebugConfig.name,
preActions: scheme.run?.preActions.map(getExecutionAction) ?? [],
postActions: scheme.run?.postActions.map(getExecutionAction) ?? [],
macroExpansion: macroExpansion,
selectedDebuggerIdentifier: selectedDebuggerIdentifier(for: schemeTarget, run: scheme.run),
selectedLauncherIdentifier: selectedLauncherIdentifier(for: schemeTarget, run: scheme.run),
askForAppToLaunch: scheme.run?.askForAppToLaunch,
allowLocationSimulation: allowLocationSimulation,
locationScenarioReference: locationScenarioReference,
enableGPUFrameCaptureMode: scheme.run?.enableGPUFrameCaptureMode ?? XCScheme.LaunchAction.defaultGPUFrameCaptureMode,
disableGPUValidationMode: !(scheme.run?.enableGPUValidationMode ?? Scheme.Run.enableGPUValidationModeDefault),
enableAddressSanitizer: scheme.run?.enableAddressSanitizer ?? Scheme.Run.enableAddressSanitizerDefault,
enableASanStackUseAfterReturn: scheme.run?.enableASanStackUseAfterReturn ?? Scheme.Run.enableASanStackUseAfterReturnDefault,
enableThreadSanitizer: scheme.run?.enableThreadSanitizer ?? Scheme.Run.enableThreadSanitizerDefault,
enableUBSanitizer: scheme.run?.enableUBSanitizer ?? Scheme.Run.enableUBSanitizerDefault,
disableMainThreadChecker: scheme.run?.disableMainThreadChecker ?? Scheme.Run.disableMainThreadCheckerDefault,
disablePerformanceAntipatternChecker: scheme.run?.disableThreadPerformanceChecker ?? Scheme.Run.disableThreadPerformanceCheckerDefault,
stopOnEveryMainThreadCheckerIssue: scheme.run?.stopOnEveryMainThreadCheckerIssue ?? Scheme.Run.stopOnEveryMainThreadCheckerIssueDefault,
commandlineArguments: launchCommandLineArgs,
environmentVariables: launchVariables,
language: scheme.run?.language,
region: scheme.run?.region,
launchAutomaticallySubstyle: scheme.run?.launchAutomaticallySubstyle ?? launchAutomaticallySubstyle(for: schemeTarget),
storeKitConfigurationFileReference: storeKitConfigurationFileReference,
customLLDBInitFile: scheme.run?.customLLDBInit
)
let profileAction = XCScheme.ProfileAction(
buildableProductRunnable: shouldExecuteOnLaunch ? runnables.profile : nil,
buildConfiguration: scheme.profile?.config ?? defaultReleaseConfig.name,
preActions: scheme.profile?.preActions.map(getExecutionAction) ?? [],
postActions: scheme.profile?.postActions.map(getExecutionAction) ?? [],
macroExpansion: shouldExecuteOnLaunch ? nil : buildableReference,
shouldUseLaunchSchemeArgsEnv: scheme.profile?.shouldUseLaunchSchemeArgsEnv ?? true,
askForAppToLaunch: scheme.profile?.askForAppToLaunch,
commandlineArguments: profileCommandLineArgs,
environmentVariables: profileVariables
)
let analyzeAction = XCScheme.AnalyzeAction(buildConfiguration: scheme.analyze?.config ?? defaultDebugConfig.name)
let archiveAction = XCScheme.ArchiveAction(
buildConfiguration: scheme.archive?.config ?? defaultReleaseConfig.name,
revealArchiveInOrganizer: scheme.archive?.revealArchiveInOrganizer ?? true,
customArchiveName: scheme.archive?.customArchiveName,
preActions: scheme.archive?.preActions.map(getExecutionAction) ?? [],
postActions: scheme.archive?.postActions.map(getExecutionAction) ?? []
)
let lastUpgradeVersion = project.attributes["LastUpgradeCheck"] as? String ?? project.xcodeVersion
return XCScheme(
name: scheme.name,
lastUpgradeVersion: lastUpgradeVersion,
version: project.schemeVersion,
buildAction: buildAction,
testAction: testAction,
launchAction: launchAction,
profileAction: profileAction,
analyzeAction: analyzeAction,
archiveAction: archiveAction,
wasCreatedForAppExtension: schemeTarget
.flatMap { $0.type.isExtension ? true : nil }
)
}
private func launchAutomaticallySubstyle(for target: ProjectTarget?) -> String? {
if target?.type.isExtension == true {
return "2"
} else {
return nil
}
}
private func makeProductRunnables(for target: ProjectTarget?, buildableReference: XCScheme.BuildableReference) -> (launch: XCScheme.Runnable, profile: XCScheme.BuildableProductRunnable) {
let buildable = XCScheme.BuildableProductRunnable(buildableReference: buildableReference)
if target?.type.isWatchApp == true {
let remote = XCScheme.RemoteRunnable(
buildableReference: buildableReference,
bundleIdentifier: "com.apple.Carousel",
runnableDebuggingMode: "2"
)
return (remote, buildable)
} else {
return (buildable, buildable)
}
}
private func selectedDebuggerIdentifier(for target: ProjectTarget?, run: Scheme.Run?) -> String {
if target?.type.canUseDebugLauncher != false && run?.debugEnabled ?? Scheme.Run.debugEnabledDefault {
return XCScheme.defaultDebugger
} else {
return ""
}
}
private func selectedLauncherIdentifier(for target: ProjectTarget?, run: Scheme.Run?) -> String {
if target?.type.canUseDebugLauncher != false && run?.debugEnabled ?? Scheme.Run.debugEnabledDefault {
return XCScheme.defaultLauncher
} else {
return "Xcode.IDEFoundation.Launcher.PosixSpawn"
}
}
}
enum SchemeGenerationError: Error, CustomStringConvertible {
case missingTarget(TargetReference, projectPath: String)
case missingPackage(String)
case missingProject(String)
case missingBuildTargets(String)
var description: String {
switch self {
case .missingTarget(let target, let projectPath):
return "Unable to find target named \"\(target)\" in \"\(projectPath)\""
case .missingProject(let project):
return "Unable to find project reference named \"\(project)\" in project.yml"
case .missingBuildTargets(let name):
return "Unable to find at least one build target in scheme \"\(name)\""
case .missingPackage(let package):
return "Unable to find swift package named \"\(package)\" in project.yml"
}
}
}
extension Scheme {
public init(name: String, target: ProjectTarget, targetScheme: TargetScheme, project: Project, debugConfig: String, releaseConfig: String) {
self.init(
name: name,
build: .init(
targets: Scheme.buildTargets(for: target, project: project),
buildImplicitDependencies: targetScheme.buildImplicitDependencies,
preActions: targetScheme.preActions,
postActions: targetScheme.postActions
),
run: .init(
config: debugConfig,
commandLineArguments: targetScheme.commandLineArguments,
environmentVariables: targetScheme.environmentVariables,
disableMainThreadChecker: targetScheme.disableMainThreadChecker,
stopOnEveryMainThreadCheckerIssue: targetScheme.stopOnEveryMainThreadCheckerIssue,
disableThreadPerformanceChecker: targetScheme.disableThreadPerformanceChecker,
language: targetScheme.language,
region: targetScheme.region,
storeKitConfiguration: targetScheme.storeKitConfiguration
),
test: .init(
config: debugConfig,
gatherCoverageData: targetScheme.gatherCoverageData,
coverageTargets: targetScheme.coverageTargets,
disableMainThreadChecker: targetScheme.disableMainThreadChecker,
commandLineArguments: targetScheme.commandLineArguments,
targets: targetScheme.testTargets,
environmentVariables: targetScheme.environmentVariables,
testPlans: targetScheme.testPlans,
language: targetScheme.language,
region: targetScheme.region
),
profile: .init(
config: releaseConfig,
commandLineArguments: targetScheme.commandLineArguments,
environmentVariables: targetScheme.environmentVariables
),
analyze: .init(
config: debugConfig
),
archive: .init(
config: releaseConfig
),
management: targetScheme.management
)
}
private static func buildTargets(for target: ProjectTarget, project: Project) -> [BuildTarget] {
let buildTarget = Scheme.BuildTarget(target: TestableTargetReference.local(target.name))
switch target.type {
case .watchApp, .watch2App:
let hostTarget = project.targets
.first { projectTarget in
projectTarget.dependencies.contains { $0.reference == target.name }
}
.map { BuildTarget(target: TestableTargetReference.local($0.name)) }
return hostTarget.map { [buildTarget, $0] } ?? [buildTarget]
default:
return [buildTarget]
}
}
}
extension PBXProductType {
var canUseDebugLauncher: Bool {
// Extensions don't use the lldb launcher
return !isExtension
}
var isWatchApp: Bool {
switch self {
case .watchApp, .watch2App:
return true
default:
return false
}
}
}
extension Scheme.Test {
var systemAttachmentLifetime: XCScheme.TestAction.AttachmentLifetime? {
switch (captureScreenshotsAutomatically, deleteScreenshotsWhenEachTestSucceeds) {
case (false, _):
return .keepNever
case (true, false):
return .keepAlways
case (true, true):
return nil
}
}
}