forked from tuist/tuist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SchemesGenerator.swift
632 lines (558 loc) · 32.3 KB
/
SchemesGenerator.swift
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
import Basic
import Foundation
import TuistCore
import TuistSupport
import XcodeProj
/// Protocol that defines the interface of the schemes generation.
protocol SchemesGenerating {
/// Generates the schemes for the workspace targets.
///
/// - Parameters:
/// - workspace: Workspace model.
/// - xcworkspacePath: Path to the workspace.
/// - generatedProject: Generated Xcode project.
/// - graph: Tuist graph.
/// - Throws: A FatalError if the generation of the schemes fails.
func generateWorkspaceSchemes(workspace: Workspace,
xcworkspacePath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject],
graph: Graphing) throws
/// Generates the schemes for the project targets.
///
/// - Parameters:
/// - project: Project manifest.
/// - xcprojectPath: Path to the Xcode project.
/// - generatedProject: Generated Xcode project.
/// - graph: Tuist graph.
/// - Throws: A FatalError if the generation of the schemes fails.
func generateProjectSchemes(project: Project,
xcprojectPath: AbsolutePath,
generatedProject: GeneratedProject,
graph: Graphing) throws
/// Wipes shared and user schemes at a workspace or project path. This is needed
/// currently to support the workspace scheme generation case where a workspace that
/// already exists on disk is being regenerated. Wiping the schemes directory prevents
/// older custom schemes from persisting after regeneration.
///
/// - Parameter at: Path to the workspace or project.
func wipeSchemes(at: AbsolutePath) throws
}
// swiftlint:disable:next type_body_length
final class SchemesGenerator: SchemesGenerating {
/// Default last upgrade version for generated schemes.
private static let defaultLastUpgradeVersion = "1010"
/// Default version for generated schemes.
private static let defaultVersion = "1.3"
/// Generates the schemes for the workspace targets.
///
/// - Parameters:
/// - workspace: Workspace model.
/// - xcworkspacePath: Path to the workspace.
/// - generatedProject: Generated Xcode project.
/// - graph: Tuist graph.
/// - Throws: A FatalError if the generation of the schemes fails.
func generateWorkspaceSchemes(workspace: Workspace,
xcworkspacePath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject],
graph: Graphing) throws {
try workspace.schemes.forEach { scheme in
try generateScheme(scheme: scheme,
xcPath: xcworkspacePath,
path: workspace.path,
graph: graph,
generatedProjects: generatedProjects)
}
}
/// Generate schemes for a project.
///
/// - Parameters:
/// - project: Project manifest.
/// - xcprojectPath: Path to project's .xcodeproj.
/// - generatedProject: Generated Project
/// - graph: Tuist graph.
func generateProjectSchemes(project: Project,
xcprojectPath: AbsolutePath,
generatedProject: GeneratedProject,
graph: Graphing) throws {
/// Generate custom schemes from manifest
try project.schemes.forEach { scheme in
try generateScheme(scheme: scheme,
xcPath: xcprojectPath,
path: project.path,
graph: graph,
generatedProjects: [project.path: generatedProject])
}
/// Generate default schemes for targets in Project that are not defined in Manifest
let buildConfiguration = defaultDebugBuildConfigurationName(in: project)
let userDefinedSchemes = Set(project.schemes.map(\.name))
let defaultSchemeTargets = project.targets.filter { !userDefinedSchemes.contains($0.name) }
try defaultSchemeTargets.forEach { target in
let scheme = createDefaultScheme(target: target, project: project, buildConfiguration: buildConfiguration)
try generateScheme(scheme: scheme,
xcPath: xcprojectPath,
path: project.path,
graph: graph,
generatedProjects: [project.path: generatedProject])
}
}
/// Wipes shared and user schemes at a workspace or project path. This is needed
/// currently to support the workspace scheme generation case where a workspace that
/// already exists on disk is being regenerated. Wiping the schemes directory prevents
/// older custom schemes from persisting after regeneration.
///
/// - Parameter at: Path to the workspace or project.
func wipeSchemes(at path: AbsolutePath) throws {
let fileHandler = FileHandler.shared
let userPath = schemeDirectory(path: path, shared: false)
let sharedPath = schemeDirectory(path: path, shared: true)
if fileHandler.exists(userPath) { try fileHandler.delete(userPath) }
if fileHandler.exists(sharedPath) { try fileHandler.delete(sharedPath) }
}
private func createDefaultScheme(target: Target, project: Project, buildConfiguration: String) -> Scheme {
let targetReference = TargetReference.project(path: project.path, target: target.name)
let testTargets = target.product.testsBundle ? [TestableTarget(target: targetReference)] : []
return Scheme(name: target.name,
shared: true,
buildAction: BuildAction(targets: [targetReference]),
testAction: TestAction(targets: testTargets, configurationName: buildConfiguration),
runAction: RunAction(configurationName: buildConfiguration, executable: targetReference, arguments: Arguments(environment: target.environment)))
}
/// Generate schemes for a project or workspace.
///
/// - Parameters:
/// - scheme: Project scheme.
/// - xcPath: Path to workspace's .xcworkspace or project's .xcodeproj.
/// - path: Path to workspace or project folder.
/// - graph: Tuist graph.
/// - generatedProjects: Project paths mapped to generated projects.
private func generateScheme(scheme: Scheme,
xcPath: AbsolutePath,
path: AbsolutePath,
graph: Graphing,
generatedProjects: [AbsolutePath: GeneratedProject]) throws {
let schemeDirectory = try createSchemesDirectory(path: xcPath, shared: scheme.shared)
let schemePath = schemeDirectory.appending(component: "\(scheme.name).xcscheme")
let generatedBuildAction = try schemeBuildAction(scheme: scheme,
graph: graph,
rootPath: path,
generatedProjects: generatedProjects)
let generatedTestAction = try schemeTestAction(scheme: scheme,
graph: graph,
rootPath: path,
generatedProjects: generatedProjects)
let generatedLaunchAction = try schemeLaunchAction(scheme: scheme,
graph: graph,
rootPath: path,
generatedProjects: generatedProjects)
let generatedProfileAction = try schemeProfileAction(scheme: scheme,
graph: graph,
rootPath: path,
generatedProjects: generatedProjects)
let generatedAnalyzeAction = try schemeAnalyzeAction(scheme: scheme,
graph: graph,
rootPath: path,
generatedProjects: generatedProjects)
let generatedArchiveAction = try schemeArchiveAction(scheme: scheme,
graph: graph,
rootPath: path,
generatedProjects: generatedProjects)
let scheme = XCScheme(name: scheme.name,
lastUpgradeVersion: SchemesGenerator.defaultLastUpgradeVersion,
version: SchemesGenerator.defaultVersion,
buildAction: generatedBuildAction,
testAction: generatedTestAction,
launchAction: generatedLaunchAction,
profileAction: generatedProfileAction,
analyzeAction: generatedAnalyzeAction,
archiveAction: generatedArchiveAction)
try scheme.write(path: schemePath.path, override: true)
}
/// Generates the scheme build action.
///
/// - Parameters:
/// - scheme: Scheme manifest.
/// - graph: Tuist graph.
/// - rootPath: Path to the project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
/// - Returns: Scheme build action.
func schemeBuildAction(scheme: Scheme,
graph: Graphing,
rootPath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject]) throws -> XCScheme.BuildAction? {
guard let buildAction = scheme.buildAction else { return nil }
let buildFor: [XCScheme.BuildAction.Entry.BuildFor] = [
.analyzing, .archiving, .profiling, .running, .testing,
]
var entries: [XCScheme.BuildAction.Entry] = []
var preActions: [XCScheme.ExecutionAction] = []
var postActions: [XCScheme.ExecutionAction] = []
try buildAction.targets.forEach { buildActionTarget in
guard let buildableReference = try createBuildableReference(targetReference: buildActionTarget,
graph: graph,
rootPath: rootPath,
generatedProjects: generatedProjects) else { return }
entries.append(XCScheme.BuildAction.Entry(buildableReference: buildableReference, buildFor: buildFor))
}
preActions = try buildAction.preActions.map {
try schemeExecutionAction(action: $0, graph: graph, generatedProjects: generatedProjects, rootPath: rootPath)
}
postActions = try buildAction.postActions.map {
try schemeExecutionAction(action: $0, graph: graph, generatedProjects: generatedProjects, rootPath: rootPath)
}
return XCScheme.BuildAction(buildActionEntries: entries,
preActions: preActions,
postActions: postActions,
parallelizeBuild: true,
buildImplicitDependencies: true)
}
/// Generates the scheme test action.
///
/// - Parameters:
/// - scheme: Scheme manifest.
/// - graph: Tuist graph.
/// - rootPath: Root path to either project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
/// - Returns: Scheme test action.
func schemeTestAction(scheme: Scheme,
graph: Graphing,
rootPath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject]) throws -> XCScheme.TestAction? {
guard let testAction = scheme.testAction else { return nil }
var testables: [XCScheme.TestableReference] = []
var preActions: [XCScheme.ExecutionAction] = []
var postActions: [XCScheme.ExecutionAction] = []
try testAction.targets.forEach { testableTarget in
guard let reference = try createBuildableReference(targetReference: testableTarget.target,
graph: graph,
rootPath: rootPath,
generatedProjects: generatedProjects) else { return }
let testable = XCScheme.TestableReference(skipped: testableTarget.isSkipped,
parallelizable: testableTarget.isParallelizable,
randomExecutionOrdering: testableTarget.isRandomExecutionOrdering,
buildableReference: reference)
testables.append(testable)
}
preActions = try testAction.preActions.map { try schemeExecutionAction(action: $0,
graph: graph,
generatedProjects: generatedProjects,
rootPath: rootPath) }
postActions = try testAction.postActions.map { try schemeExecutionAction(action: $0,
graph: graph,
generatedProjects: generatedProjects,
rootPath: rootPath) }
var args: XCScheme.CommandLineArguments?
var environments: [XCScheme.EnvironmentVariable]?
if let arguments = testAction.arguments {
args = XCScheme.CommandLineArguments(arguments: commandlineArgruments(arguments.launch))
environments = environmentVariables(arguments.environment)
}
let codeCoverageTargets = try testAction.codeCoverageTargets.compactMap {
try testCoverageTargetReferences(target: $0,
graph: graph,
generatedProjects: generatedProjects,
rootPath: rootPath)
}
let onlyGenerateCoverageForSpecifiedTargets = codeCoverageTargets.count > 0 ? true : nil
let shouldUseLaunchSchemeArgsEnv: Bool = args == nil && environments == nil
return XCScheme.TestAction(buildConfiguration: testAction.configurationName,
macroExpansion: nil,
testables: testables,
preActions: preActions,
postActions: postActions,
shouldUseLaunchSchemeArgsEnv: shouldUseLaunchSchemeArgsEnv,
codeCoverageEnabled: testAction.coverage,
codeCoverageTargets: codeCoverageTargets,
onlyGenerateCoverageForSpecifiedTargets: onlyGenerateCoverageForSpecifiedTargets,
commandlineArguments: args,
environmentVariables: environments)
}
/// Generates the scheme launch action.
///
/// - Parameters:
/// - scheme: Scheme manifest.
/// - graph: Tuist graph.
/// - rootPath: Root path to either project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
/// - Returns: Scheme launch action.
func schemeLaunchAction(scheme: Scheme,
graph: Graphing,
rootPath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject]) throws -> XCScheme.LaunchAction? {
guard var target = try defaultTargetReference(scheme: scheme) else { return nil }
if let executable = scheme.runAction?.executable {
target = executable
}
guard let targetNode = try graph.target(path: target.projectPath, name: target.name) else { return nil }
guard let buildableReference = try createBuildableReference(targetReference: target,
graph: graph,
rootPath: rootPath,
generatedProjects: generatedProjects) else { return nil }
var buildableProductRunnable: XCScheme.BuildableProductRunnable?
var macroExpansion: XCScheme.BuildableReference?
if targetNode.target.product.runnable {
buildableProductRunnable = XCScheme.BuildableProductRunnable(buildableReference: buildableReference, runnableDebuggingMode: "0")
} else {
macroExpansion = buildableReference
}
var commandlineArguments: XCScheme.CommandLineArguments?
var environments: [XCScheme.EnvironmentVariable]?
if let arguments = scheme.runAction?.arguments {
commandlineArguments = XCScheme.CommandLineArguments(arguments: commandlineArgruments(arguments.launch))
environments = environmentVariables(arguments.environment)
}
let buildConfiguration = scheme.runAction?.configurationName ?? defaultDebugBuildConfigurationName(in: targetNode.project)
return XCScheme.LaunchAction(runnable: buildableProductRunnable,
buildConfiguration: buildConfiguration,
macroExpansion: macroExpansion,
commandlineArguments: commandlineArguments,
environmentVariables: environments)
}
/// Generates the scheme profile action for a given target.
///
/// - Parameters:
/// - scheme: Target manifest.
/// - graph: Tuist graph.
/// - rootPath: Root path to either project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
/// - Returns: Scheme profile action.
func schemeProfileAction(scheme: Scheme,
graph: Graphing,
rootPath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject]) throws -> XCScheme.ProfileAction? {
guard var target = try defaultTargetReference(scheme: scheme) else { return nil }
if let executable = scheme.runAction?.executable {
target = executable
}
guard let targetNode = try graph.target(path: target.projectPath, name: target.name) else { return nil }
guard let buildableReference = try createBuildableReference(targetReference: target,
graph: graph,
rootPath: rootPath,
generatedProjects: generatedProjects) else { return nil }
var buildableProductRunnable: XCScheme.BuildableProductRunnable?
var macroExpansion: XCScheme.BuildableReference?
if targetNode.target.product.runnable {
buildableProductRunnable = XCScheme.BuildableProductRunnable(buildableReference: buildableReference, runnableDebuggingMode: "0")
} else {
macroExpansion = buildableReference
}
let buildConfiguration = defaultReleaseBuildConfigurationName(in: targetNode.project)
return XCScheme.ProfileAction(buildableProductRunnable: buildableProductRunnable,
buildConfiguration: buildConfiguration,
macroExpansion: macroExpansion)
}
/// Returns the scheme analyze action.
///
/// - Parameters:
/// - scheme: Scheme manifest.
/// - graph: Tuist graph.
/// - rootPath: Root path to either project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
/// - Returns: Scheme analyze action.
func schemeAnalyzeAction(scheme: Scheme,
graph: Graphing,
rootPath _: AbsolutePath,
generatedProjects _: [AbsolutePath: GeneratedProject]) throws -> XCScheme.AnalyzeAction? {
guard let target = try defaultTargetReference(scheme: scheme),
let targetNode = try graph.target(path: target.projectPath, name: target.name) else { return nil }
let buildConfiguration = defaultDebugBuildConfigurationName(in: targetNode.project)
return XCScheme.AnalyzeAction(buildConfiguration: buildConfiguration)
}
/// Generates the scheme archive action.
///
/// - Parameters:
/// - scheme: Scheme manifest.
/// - graph: Tuist graph.
/// - rootPath: Root path to either project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
/// - Returns: Scheme archive action.
func schemeArchiveAction(scheme: Scheme,
graph: Graphing,
rootPath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject]) throws -> XCScheme.ArchiveAction? {
guard let target = try defaultTargetReference(scheme: scheme),
let targetNode = try graph.target(path: target.projectPath, name: target.name) else { return nil }
guard let archiveAction = scheme.archiveAction else {
return defaultSchemeArchiveAction(for: targetNode.project)
}
let preActions = try archiveAction.preActions.map {
try schemeExecutionAction(action: $0, graph: graph, generatedProjects: generatedProjects, rootPath: rootPath)
}
let postActions = try archiveAction.postActions.map {
try schemeExecutionAction(action: $0, graph: graph, generatedProjects: generatedProjects, rootPath: rootPath)
}
return XCScheme.ArchiveAction(buildConfiguration: archiveAction.configurationName,
revealArchiveInOrganizer: archiveAction.revealArchiveInOrganizer,
customArchiveName: archiveAction.customArchiveName,
preActions: preActions,
postActions: postActions)
}
func schemeExecutionAction(action: ExecutionAction,
graph: Graphing,
generatedProjects: [AbsolutePath: GeneratedProject],
rootPath _: AbsolutePath) throws -> XCScheme.ExecutionAction {
guard let targetReference = action.target,
let targetNode = try graph.target(path: targetReference.projectPath, name: targetReference.name),
let generatedProject = generatedProjects[targetReference.projectPath] else {
return schemeExecutionAction(action: action)
}
return schemeExecutionAction(action: action,
target: targetNode.target,
generatedProject: generatedProject)
}
private func schemeExecutionAction(action: ExecutionAction) -> XCScheme.ExecutionAction {
XCScheme.ExecutionAction(scriptText: action.scriptText,
title: action.title,
environmentBuildable: nil)
}
/// Returns the scheme pre/post actions.
///
/// - Parameters:
/// - action: pre/post action manifest.
/// - target: Project manifest.
/// - generatedProject: Generated Xcode project.
/// - Returns: Scheme actions.
private func schemeExecutionAction(action: ExecutionAction,
target: Target,
generatedProject: GeneratedProject) -> XCScheme.ExecutionAction {
/// Return Buildable Reference for Scheme Action
func schemeBuildableReference(target: Target, generatedProject: GeneratedProject) -> XCScheme.BuildableReference? {
guard let pbxTarget = generatedProject.targets[target.name] else { return nil }
return targetBuildableReference(target: target,
pbxTarget: pbxTarget,
projectPath: generatedProject.name)
}
let schemeAction = XCScheme.ExecutionAction(scriptText: action.scriptText,
title: action.title,
environmentBuildable: nil)
schemeAction.environmentBuildable = schemeBuildableReference(target: target,
generatedProject: generatedProject)
return schemeAction
}
// MARK: - Helpers
private func resolveRelativeProjectPath(targetNode: TargetNode,
generatedProject: GeneratedProject,
rootPath: AbsolutePath) -> RelativePath {
let xcodeProjectPath = targetNode.path.appending(component: generatedProject.name)
return xcodeProjectPath.relative(to: rootPath)
}
/// Creates a target buildable refernece for a target
///
/// - Parameters:
/// - targetReference: The target reference.
/// - graph: Tuist graph.
/// - rootPath: Path to the project or workspace.
/// - generatedProjects: Project paths mapped to generated projects.
private func createBuildableReference(targetReference: TargetReference,
graph: Graphing,
rootPath: AbsolutePath,
generatedProjects: [AbsolutePath: GeneratedProject]) throws -> XCScheme.BuildableReference? {
let projectPath = targetReference.projectPath
guard let target = try graph.target(path: projectPath, name: targetReference.name) else { return nil }
guard let generatedProject = generatedProjects[projectPath] else { return nil }
guard let pbxTarget = generatedProject.targets[targetReference.name] else { return nil }
let relativeXcodeProjectPath = resolveRelativeProjectPath(targetNode: target,
generatedProject: generatedProject,
rootPath: rootPath)
return targetBuildableReference(target: target.target,
pbxTarget: pbxTarget,
projectPath: relativeXcodeProjectPath.pathString)
}
/// Generates the array of BuildableReference for targets that the
/// coverage report should be generated for them.
///
/// - Parameters:
/// - target: test actions.
/// - graph: tuist graph.
/// - generatedProjects: Generated Xcode projects.
/// - rootPath: Root path to workspace or project.
/// - Returns: Array of buildable references.
private func testCoverageTargetReferences(target: TargetReference,
graph: Graphing,
generatedProjects: [AbsolutePath: GeneratedProject],
rootPath: AbsolutePath) throws -> XCScheme.BuildableReference? {
try createBuildableReference(targetReference: target,
graph: graph,
rootPath: rootPath,
generatedProjects: generatedProjects)
}
/// Creates the directory where the schemes are stored inside the project.
/// If the directory exists it does not re-create it.
///
/// - Parameters:
/// - path: Path to the Xcode workspace or project.
/// - shared: Scheme should be shared or not
/// - Returns: Path to the schemes directory.
/// - Throws: A FatalError if the creation of the directory fails.
private func createSchemesDirectory(path: AbsolutePath, shared: Bool = true) throws -> AbsolutePath {
let schemePath = schemeDirectory(path: path, shared: shared)
if !FileHandler.shared.exists(schemePath) {
try FileHandler.shared.createFolder(schemePath)
}
return schemePath
}
private func schemeDirectory(path: AbsolutePath, shared: Bool = true) -> AbsolutePath {
if shared {
return path.appending(RelativePath("xcshareddata/xcschemes"))
} else {
let username = NSUserName()
return path.appending(RelativePath("xcuserdata/\(username).xcuserdatad/xcschemes"))
}
}
/// Returns the scheme commandline argument passed on launch
///
/// - Parameters:
/// - environments: commandline argument keys.
/// - Returns: XCScheme.CommandLineArguments.CommandLineArgument.
private func commandlineArgruments(_ arguments: [String: Bool]) -> [XCScheme.CommandLineArguments.CommandLineArgument] {
arguments.map { key, enabled in
XCScheme.CommandLineArguments.CommandLineArgument(name: key, enabled: enabled)
}.sorted { $0.name < $1.name }
}
/// Returns the scheme environment variables
///
/// - Parameters:
/// - environments: environment variables
/// - Returns: XCScheme.EnvironmentVariable.
private func environmentVariables(_ environments: [String: String]) -> [XCScheme.EnvironmentVariable] {
environments.map { key, value in
XCScheme.EnvironmentVariable(variable: key, value: value, enabled: true)
}.sorted { $0.variable < $1.variable }
}
private func defaultDebugBuildConfigurationName(in project: Project) -> String {
let debugConfiguration = project.settings.defaultDebugBuildConfiguration()
let buildConfiguration = debugConfiguration ?? project.settings.configurations.keys.first
return buildConfiguration?.name ?? BuildConfiguration.debug.name
}
/// Returns the scheme buildable reference for a given target.
///
/// - Parameters:
/// - target: Target manifest.
/// - pbxTarget: Xcode native target.
/// - projectPath: Project name with the .xcodeproj extension.
/// - Returns: Buildable reference.
private func targetBuildableReference(target: Target,
pbxTarget: PBXNativeTarget,
projectPath: String) -> XCScheme.BuildableReference {
XCScheme.BuildableReference(referencedContainer: "container:\(projectPath)",
blueprint: pbxTarget,
buildableName: target.productNameWithExtension,
blueprintName: target.name,
buildableIdentifier: "primary")
}
/// Returns the scheme archive action
///
/// - Returns: Scheme archive action.
func defaultSchemeArchiveAction(for project: Project) -> XCScheme.ArchiveAction {
let buildConfiguration = defaultReleaseBuildConfigurationName(in: project)
return XCScheme.ArchiveAction(buildConfiguration: buildConfiguration,
revealArchiveInOrganizer: true)
}
private func defaultReleaseBuildConfigurationName(in project: Project) -> String {
let releaseConfiguration = project.settings.defaultReleaseBuildConfiguration()
let buildConfiguration = releaseConfiguration ?? project.settings.configurations.keys.first
return buildConfiguration?.name ?? BuildConfiguration.release.name
}
private func defaultTargetReference(scheme: Scheme) throws -> TargetReference? {
scheme.buildAction?.targets.first
}
}