-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathTargetDependencyResolverTests.swift
More file actions
4847 lines (4381 loc) · 290 KB
/
Copy pathTargetDependencyResolverTests.swift
File metadata and controls
4847 lines (4381 loc) · 290 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
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Testing
@_spi(Testing) import SWBCore
import SWBProtocol
import SWBTestSupport
@_spi(Testing) import SWBUtil
import Foundation
import SWBMacro
fileprivate enum TargetPlatformSpecializationMode {
/// The v1 support of target platform specialization that uses SDKROOT=auto and SDK_VARIANT=auto to opt-in.
case sdkroot
/// The v2 support that uses an explicit opt-in setting: ALLOW_TARGET_PLATFORM_SPECIALIZATION=YES
case explicit
func settings(isPackage: Bool = false, _ additional: [String:String] = [:]) -> [String:String] {
var dict = additional
if (self == .sdkroot) || isPackage {
dict["SDKROOT"] = "auto"
dict["SDK_VARIANT"] = "auto"
}
else {
dict["ALLOW_TARGET_PLATFORM_SPECIALIZATION"] = "YES"
}
return dict
}
}
// MARK: Test cases for utility methods supporting dependency resolution.
@Suite fileprivate struct DependencyResolutionSupportTests: CoreBasedTests {
/// Test `BuildRequestContext.potentialOverride(for:buildParameters:)`.
@Test
func potentialOverride() async throws {
try await withTemporaryDirectory { tmpDirPath in
let core = try await self.getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestStandardTarget("anApp", type: .application),
]
)]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, fs: localFS, processExecutionCache: .sharedForTesting)
// Configure all the overrides.
let overrides = [
"OVERRIDE": "override_level",
]
let commandLineOverrides = [
"COMMAND_LINE_OVERRIDE": "commandLineOverride_level",
]
let commandLineConfigOverrides = [
"COMMAND_LINE_CONFIG_OVERRIDE": "commandLineConfigOverride_level",
]
let commandLineConfigOverridesPath = tmpDirPath.join("commandLine.xcconfig")
try localFS.write(commandLineConfigOverridesPath, contents: ByteString(stringLiteral: "COMMAND_LINE_CONFIG_PATH_OVERRIDE = commandLineConfigPathOverride_level"))
let environmentConfigOverrides = [
"ENV_LINE_CONFIG_OVERRIDE": "environmentLineConfigOverride_level",
]
let environmentConfigOverridesPath = tmpDirPath.join("environment.xcconfig")
try localFS.write(environmentConfigOverridesPath, contents: ByteString(stringLiteral: "ENV_LINE_CONFIG_PATH_OVERRIDE = environmentLineConfigPathOverride_level"))
// Create a BuildRequest with all the relevant override levels.
let buildParameters = BuildParameters(configuration: "Debug", overrides: overrides, commandLineOverrides: commandLineOverrides, commandLineConfigOverridesPath: commandLineConfigOverridesPath, commandLineConfigOverrides: commandLineConfigOverrides, environmentConfigOverridesPath: environmentConfigOverridesPath, environmentConfigOverrides: environmentConfigOverrides)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
// Check the expected values of the various overrides
if let override = buildRequestContext.potentialOverride(for: "OVERRIDE", buildParameters: buildParameters) {
#expect(override.value == "override_level")
if case .buildParametersOverrides(_) = override.source {} else {
Issue.record("Source of value of OVERRIDE was not .buildParametersOverrides but was \(override.source)")
}
}
else {
Issue.record("Expected value for COMMAND_LINE_OVERRIDE not found")
}
if let override = buildRequestContext.potentialOverride(for: "COMMAND_LINE_OVERRIDE", buildParameters: buildParameters) {
#expect(override.value == "commandLineOverride_level")
if case .commandLineOverrides(_) = override.source {} else {
Issue.record("Source of value of COMMAND_LINE_OVERRIDE was not .commandLineOverrides but was \(override.source)")
}
}
else {
Issue.record("Expected value for COMMAND_LINE_OVERRIDE not found")
}
if let override = buildRequestContext.potentialOverride(for: "COMMAND_LINE_CONFIG_OVERRIDE", buildParameters: buildParameters) {
#expect(override.value == "commandLineConfigOverride_level")
if case .commandLineConfigOverrides(_) = override.source {} else {
Issue.record("Source of value of COMMAND_LINE_CONFIG_OVERRIDE was not .commandLineConfigOverrides but was \(override.source)")
}
}
else {
Issue.record("Expected value for COMMAND_LINE_CONFIG_OVERRIDE not found")
}
if let override = buildRequestContext.potentialOverride(for: "COMMAND_LINE_CONFIG_PATH_OVERRIDE", buildParameters: buildParameters) {
#expect(override.value == "commandLineConfigPathOverride_level")
if case .commandLineConfigOverridesPath(_,_) = override.source {} else {
Issue.record("Source of value of COMMAND_LINE_CONFIG_PATH_OVERRIDE was not .commandLineConfigOverridesPath but was \(override.source)")
}
}
else {
Issue.record("Expected value for COMMAND_LINE_CONFIG_PATH_OVERRIDE not found")
}
if let override = buildRequestContext.potentialOverride(for: "ENV_LINE_CONFIG_OVERRIDE", buildParameters: buildParameters) {
#expect(override.value == "environmentLineConfigOverride_level")
if case .environmentConfigOverrides(_) = override.source {} else {
Issue.record("Source of value of ENV_LINE_CONFIG_OVERRIDE was not .environmentConfigOverrides but was \(override.source)")
}
}
else {
Issue.record("Expected value for ENV_LINE_CONFIG_OVERRIDE not found")
}
if let override = buildRequestContext.potentialOverride(for: "ENV_LINE_CONFIG_PATH_OVERRIDE", buildParameters: buildParameters) {
#expect(override.value == "environmentLineConfigPathOverride_level")
if case .environmentConfigOverridesPath(_,_) = override.source {} else {
Issue.record("Source of value of ENV_LINE_CONFIG_PATH_OVERRIDE was not .buildParametersOverrides but was \(override.source)")
}
}
else {
Issue.record("Expected value for ENV_LINE_CONFIG_PATH_OVERRIDE not found")
}
// Also check the case where there is no override.
if let noSuchOverride = buildRequestContext.potentialOverride(for: "NO_SUCH_OVERRIDE", buildParameters: buildParameters) {
Issue.record("Unexpected value '\(noSuchOverride.value)' for NO_SUCH_OVERRIDE from \(noSuchOverride.source)" )
}
}
}
}
// MARK: Test cases for resolving explicit dependencies
@Suite fileprivate struct ExplicitDependencyResolutionTests: CoreBasedTests {
@Test(.requireSDKs(.macOS))
func twoAppsAndAFramework() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestStandardTarget("anApp", type: .application, dependencies: ["aFramework"]),
TestStandardTarget("anotherApp", type: .application, dependencies: ["aFramework"]),
TestStandardTarget("aFramework", type: .application)])]).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Perform some simple correctness tests.
#expect(project.targets.count == 3)
// Configure the targets and create a BuildRequest.
let buildParameters = BuildParameters(configuration: "Debug")
let appTarget1 = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let appTarget2 = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[1])
let fwkTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[2])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [appTarget1, appTarget2], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let dependencyClosure = buildGraph.allTargets
#expect(dependencyClosure.map({ $0.target.name }) == ["aFramework", "anApp", "anotherApp"])
#expect(try buildGraph.dependencies(appTarget1) == [try buildGraph.target(for: fwkTarget)])
#expect(try buildGraph.dependencies(appTarget2) == [try buildGraph.target(for: fwkTarget)])
#expect(try buildGraph.dependencies(fwkTarget) == [])
delegate.checkNoDiagnostics()
}
@Test(.requireSDKs(.macOS, .iOS))
func twoAppsAFrameworkAndDifferentBuildParameters() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestStandardTarget("anApp", type: .application, dependencies: ["aFramework"]),
TestStandardTarget("anotherApp", type: .application, dependencies: ["aFramework"]),
TestStandardTarget("aFramework", type: .application)])]).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Perform some simple correctness tests.
#expect(project.targets.count == 3)
// Configure the targets and create a BuildRequest.
let buildParametersmacOS = BuildParameters(configuration: "macOS", overrides: ["SDKROOT": "macosx"])
let buildParametersiOS = BuildParameters(configuration: "iOS", overrides: ["SDKROOT": "iphoneos"])
let appTarget1 = BuildRequest.BuildTargetInfo(parameters: buildParametersmacOS, target: project.targets[0])
let appTarget2 = BuildRequest.BuildTargetInfo(parameters: buildParametersiOS, target: project.targets[1])
let fwkTargetmacOS = BuildRequest.BuildTargetInfo(parameters: buildParametersmacOS, target: project.targets[2])
let fwkTargetiOS = BuildRequest.BuildTargetInfo(parameters: buildParametersiOS, target: project.targets[2])
let buildRequest = BuildRequest(parameters: buildParametersiOS, buildTargets: [appTarget1, appTarget2], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let dependencyClosure = buildGraph.allTargets
#expect(dependencyClosure.count == 4)
#expect(dependencyClosure.map({ $0.target.name }) == ["aFramework", "anApp", "aFramework", "anotherApp"])
#expect(dependencyClosure[safe: 0]?.target === project.targets[safe: 2]) // The framework target configured for macOS is first
#expect(dependencyClosure[safe: 0]?.parameters == buildParametersmacOS)
#expect(dependencyClosure[safe: 1]?.target === project.targets[safe: 0]) // The first app target is second
#expect(dependencyClosure[safe: 1]?.parameters == buildParametersmacOS)
#expect(dependencyClosure[safe: 2]?.target === project.targets[safe: 2]) // The framework target configured for iOS is third
#expect(dependencyClosure[safe: 2]?.parameters == buildParametersiOS)
#expect(dependencyClosure[safe: 3]?.target === project.targets[safe: 1]) // The second app target is fourth
#expect(dependencyClosure[safe: 3]?.parameters == buildParametersiOS)
#expect(try buildGraph.dependencies(appTarget1) == [try buildGraph.target(for: fwkTargetmacOS)])
#expect(try buildGraph.dependencies(appTarget2) == [try buildGraph.target(for: fwkTargetiOS)])
#expect(try buildGraph.dependencies(fwkTargetmacOS) == [])
#expect(try buildGraph.dependencies(fwkTargetiOS) == [])
delegate.checkNoDiagnostics()
}
@Test
func missingExplicitDependency() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestStandardTarget("anApp", type: .application, dependencies: ["aFramework", "Missing"]),
TestStandardTarget("aFramework", type: .application),
]
)]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Perform some simple correctness tests.
#expect(project.targets.count == 2)
// Configure the targets and create a BuildRequest.
let buildParameters = BuildParameters(configuration: "Debug")
let appTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let fwkTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[1])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [appTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let dependencyClosure = buildGraph.allTargets
#expect(dependencyClosure.map({ $0.target.name }) == ["aFramework", "anApp"])
#expect(try buildGraph.dependencies(appTarget) == [try buildGraph.target(for: fwkTarget)])
if workspaceContext.userPreferences.enableDebugActivityLogs {
delegate.checkDiagnostics(["Skipping target dependency 'Missing' because there is no target with GUID 'Missing' in the workspace (it may exist in a project pointed to by a missing project reference). (in target 'anApp' from project 'aProject')"])
} else {
delegate.checkNoDiagnostics()
}
}
@Test
func excludedExplicitDependency() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestStandardTarget("anApp", type: .application, buildConfigurations: [
TestBuildConfiguration("Debug"),
TestBuildConfiguration("Debug-LimitedDeps", buildSettings: [
"EXCLUDED_EXPLICIT_TARGET_DEPENDENCIES": "excludedFramework",
]),
], dependencies: ["aFramework", "excludedFramework"]),
TestStandardTarget("aFramework", type: .framework),
TestStandardTarget("excludedFramework", type: .framework),
]
)]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Perform some simple correctness tests.
#expect(project.targets.count == 3)
// Test the Debug configuration first (which does not exclude any dependencies).
do {
let buildParameters = BuildParameters(configuration: "Debug")
let appTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [appTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let dependencyClosure = buildGraph.allTargets
#expect(dependencyClosure.map { $0.target.name } == ["aFramework", "excludedFramework", "anApp"])
}
// Next, test the Debug-LimitedDeps configuration (which _does_ exclude a dependency).
do {
let buildParameters = BuildParameters(configuration: "Debug-LimitedDeps")
let appTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [appTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let dependencyClosure = buildGraph.allTargets
#expect(dependencyClosure.map { $0.target.name } == ["aFramework", "anApp"])
}
}
/// Check the behavior of target-specialization through package product targets.
@Test(.requireSDKs(.iOS, .watchOS))
func packageProductBasedSpecialization() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestAggregateTarget("ALL", dependencies: ["iOSFwk", "watchOSFwk"]),
TestStandardTarget(
"iOSFwk",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "iphoneos"]),
],
dependencies: ["PackageLibProduct"]
),
TestStandardTarget(
"watchOSFwk",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "watchos"]),
],
dependencies: ["PackageLibProduct"]
),
]
),
TestPackageProject("Package",
groupTree: TestGroup("SomeFile"),
targets: [
TestPackageProductTarget(
"PackageLibProduct",
frameworksBuildPhase: TestFrameworksBuildPhase([
TestBuildFile(.target("PackageLib"))]),
buildConfigurations: [
// Targets need to opt-in to specialization.
TestBuildConfiguration("Debug", buildSettings: [
"SDKROOT": "auto",
"SDK_VARIANT": "auto",
"SUPPORTED_PLATFORMS": "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator",
]),
],
dependencies: ["PackageLib"]
),
TestStandardTarget("PackageLib", type: .staticLibrary),
])]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Configure the targets and create a BuildRequest.
let buildParameters = BuildParameters(configuration: "Debug")
let allTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [allTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let targetList = Array(buildGraph.allTargets.reversed())
#expect(targetList.map({ $0.target.name }) == ["ALL", "watchOSFwk", "PackageLibProduct", "PackageLib", "iOSFwk", "PackageLibProduct", "PackageLib"])
// Check the immediate dependencies lists.
let allDeps = buildGraph.dependencies(of: targetList[0])
#expect(allDeps.map({ $0.target.name }) == ["iOSFwk", "watchOSFwk"])
do {
let iOSFwk = allDeps[0]
let clientSettings = buildRequestContext.getCachedSettings(iOSFwk.parameters, target: iOSFwk.target)
let deps = buildGraph.dependencies(of: iOSFwk)
#expect(deps.map({ $0.target.name }) == ["PackageLibProduct"])
guard let dep = deps[safe: 0] else {
Issue.record()
return
}
let depSettings = buildRequestContext.getCachedSettings(dep.parameters, target: dep.target)
XCTAssertMatch(depSettings.sdk?.displayName, .prefix("iOS"))
#expect(depSettings.deploymentTarget == clientSettings.deploymentTarget)
#expect(depSettings.globalScope.evaluate(BuiltinMacros.SUPPORTED_PLATFORMS) == ["iphoneos", "iphonesimulator"])
}
do {
let watchOSFwk = allDeps[1]
let clientSettings = buildRequestContext.getCachedSettings(watchOSFwk.parameters, target: watchOSFwk.target)
let deps = buildGraph.dependencies(of: watchOSFwk)
#expect(deps.map({ $0.target.name }) == ["PackageLibProduct"])
guard let dep = deps[safe: 0] else {
Issue.record()
return
}
let depSettings = buildRequestContext.getCachedSettings(dep.parameters, target: dep.target)
XCTAssertMatch(depSettings.sdk?.displayName, .prefix("watchOS"))
#expect(depSettings.deploymentTarget == clientSettings.deploymentTarget)
#expect(depSettings.globalScope.evaluate(BuiltinMacros.SUPPORTED_PLATFORMS) == ["watchos", "watchsimulator"])
}
delegate.checkNoDiagnostics()
}
private func _testSpecializationWithPlatformFiltering(_ mode: TargetPlatformSpecializationMode) async throws {
let core = try await getCore()
let workspace = try TestWorkspace(
"Workspace",
projects: [
TestProject(
"aProject",
groupTree: TestGroup(
"SomeFiles",
children: [
TestFile("AppSource.m"),
]
),
targets: [
TestStandardTarget(
"Universal",
type: .framework,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: mode.settings(["SUPPORTED_PLATFORMS": "$(AVAILABLE_PLATFORMS)"])
),
],
buildPhases: [
TestSourcesBuildPhase([
"AppSource.m",
]),
],
dependencies: [
TestTargetDependency(
"PackageLibProduct",
platformFilters: Set([
PlatformFilter.iOSFilters,
PlatformFilter.watchOSFilters
].flatMap { $0 })
),
]
),
]),
TestPackageProject("Package", groupTree: TestGroup("SomeFiles"), targets: [
TestPackageProductTarget(
"PackageLibProduct",
frameworksBuildPhase: TestFrameworksBuildPhase([
TestBuildFile(.target("PackageLib"))
]),
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: mode.settings(isPackage: true, ["SUPPORTED_PLATFORMS": "$(AVAILABLE_PLATFORMS)"])
),
],
dependencies: ["PackageLib"]
),
TestStandardTarget("PackageLib", type: .staticLibrary),
]
)
]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let expectedDependencies: [RunDestinationInfo: [String]] = [
.iOSSimulator: ["PackageLibProduct"],
.iOS: ["PackageLibProduct"],
.macOS: [],
.watchOS: ["PackageLibProduct"],
.watchOSSimulator: ["PackageLibProduct"],
.tvOS: [],
.tvOSSimulator: [],
]
for (runDestination, expectedDependencies) in expectedDependencies {
let buildParameters = BuildParameters(
configuration: "Debug",
activeRunDestination: runDestination
)
let expectedDiagnostics: [String]
if workspaceContext.userPreferences.enableDebugActivityLogs && expectedDependencies.isEmpty {
expectedDiagnostics = ["Skipping target dependency 'PackageLibProduct' because its platform filter (ios, watchos) does not match the platform filter of the current context (\(runDestination.platformFilterString)). (in target 'Universal' from project 'aProject')"]
} else {
expectedDiagnostics = []
}
let buildGraph = try await computeBuildGraph(
of: workspace,
context: workspaceContext,
buildRequestContext: buildRequestContext,
buildParameters: buildParameters,
expectedDiagnostics: expectedDiagnostics,
type: .dependency
)
let universalTarget = try #require(buildGraph.allTargets.first{ $0.target.name == "Universal" })
let deps = buildGraph.dependencies(of: universalTarget)
#expect(deps.map{ $0.target.name } == expectedDependencies)
}
}
@Test(.requireSDKs(.iOS, .watchOS))
func specializationWithPlatformFilteringV1() async throws {
try await _testSpecializationWithPlatformFiltering(.sdkroot)
}
@Test(.requireSDKs(.iOS, .watchOS))
func specializationWithPlatformFilteringV2() async throws {
try await _testSpecializationWithPlatformFiltering(.explicit)
}
private func _testSpecializationWithCommandLineOverrides(_ mode: TargetPlatformSpecializationMode) async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace", projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestStandardTarget("BestTarget", type: .framework, buildConfigurations: [ TestBuildConfiguration("Debug", buildSettings: mode.settings(["SUPPORTED_PLATFORMS": "macosx iphoneos iphonesimulator"]))])
])
]).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
let buildParameters = BuildParameters(action: .build, configuration: "Debug", activeRunDestination: .macOS, activeArchitecture: "x86_64", overrides: [:], commandLineOverrides: ["SDKROOT": "iphonesimulator\(core.loadSDK(.iOS).version)"], commandLineConfigOverrides: [:], environmentConfigOverrides: [:], toolchainOverride: nil, arena: nil)
let allTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [allTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
for type in TargetGraphFactory.GraphType.allCases {
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: type)
let target = buildGraph.allTargets.first!
let settings = buildRequestContext.getCachedSettings(target.parameters, target: target.target)
#expect(settings.platform?.displayName == "iOS Simulator")
delegate.checkNoDiagnostics()
}
}
@Test(.requireSDKs(.macOS, .iOS))
func specializationWithCommandLineOverridesV1() async throws {
try await _testSpecializationWithCommandLineOverrides(.sdkroot)
}
@Test(.requireSDKs(.macOS, .iOS))
func specializationWithCommandLineOverridesV2() async throws {
try await _testSpecializationWithCommandLineOverrides(.explicit)
}
/// Check that we don't create unnecessary specialized targets, just because one was created without specialization active.
@Test
func packageProductBasedSpecializationUniquing() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
// We check specialization by having both direct dependencies and ones from a consumer (and we have two instances, to check that order doesn't matter).
TestAggregateTarget("ALL", dependencies: ["Lib", "SpecializingConsumer", "Lib2"]),
// This is an intermediate target, used to drive specialization.
TestStandardTarget(
"SpecializingConsumer",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "macosx"]),
],
dependencies: ["PackageProduct"]
),
]
),
TestPackageProject("Package",
groupTree: TestGroup("SomeFiles"),
targets: [
TestPackageProductTarget(
"PackageProduct",
frameworksBuildPhase: TestFrameworksBuildPhase([
TestBuildFile(.target("Lib")),
TestBuildFile(.target("Lib2"))]),
dependencies: ["Lib", "Lib2"]
),
// These are the targets we are testing specialization of.
TestStandardTarget("Lib", type: .staticLibrary),
TestStandardTarget("Lib2", type: .staticLibrary),
]
),
]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Configure the targets and create a BuildRequest.
let buildParameters = BuildParameters(configuration: "Debug")
let allTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [allTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
for type in TargetGraphFactory.GraphType.allCases {
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
// Get the dependency closure for the build request and examine it.
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: type)
let targetList = Array(buildGraph.allTargets.reversed())
if type == .linkage { // <rdar://problem/61461826> `TargetLinkageGraph.allTargets` isn't sorted in dependency order
#expect(targetList.map({ $0.target.name }).sorted() == ["ALL", "Lib", "Lib2", "PackageProduct", "SpecializingConsumer"])
} else {
#expect(targetList.map({ $0.target.name }) == ["ALL", "SpecializingConsumer", "PackageProduct", "Lib2", "Lib"])
}
delegate.checkNoDiagnostics()
}
}
func setupWatchOSProject(dynamic: Bool) async throws -> (SWBCore.Project, WorkspaceContext) {
let core = try await getCore()
let packageProductTarget: any TestTarget
if dynamic {
packageProductTarget = TestStandardTarget(
"PackageLibProduct",
type: .dynamicLibrary,
buildConfigurations: [
// Targets need to opt-in to specialization.
TestBuildConfiguration("Debug", buildSettings: [
"SDKROOT": "auto",
"SDK_VARIANT": "auto",
"SUPPORTED_PLATFORMS": "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator",
]),
],
buildPhases: [
TestFrameworksBuildPhase([
TestBuildFile(.target("PackageLib"))]),
TestSourcesBuildPhase([
"Package.m",
]),
],
dependencies: ["PackageLib"])
} else {
packageProductTarget = TestPackageProductTarget(
"PackageLibProduct",
frameworksBuildPhase: TestFrameworksBuildPhase([
TestBuildFile(.target("PackageLib"))]),
buildConfigurations: [
// Targets need to opt-in to specialization.
TestBuildConfiguration("Debug", buildSettings: [
"SDKROOT": "auto",
"SDK_VARIANT": "auto",
"SUPPORTED_PLATFORMS": "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator",
]),
],
dependencies: ["PackageLib"]
)
}
let watchosSDKVersion = "5.2"
let workspace = try await TestWorkspace(
"Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup(
"Sources", path: "Sources",
children: [
// iOS app files
TestFile("iosApp/main.m"),
TestFile("iosApp/CompanionClass.swift"),
TestFile("iosApp/Main.storyboard"),
TestFile("iosApp/Assets.xcassets"),
TestFile("iosApp/Info.plist"),
// watchOS app files
TestFile("watchosApp/Interface.storyboard"),
TestFile("watchosApp/Assets.xcassets"),
TestFile("watchosApp/Info.plist"),
// watchOS extension files
TestFile("watchosExtension/Controller.m"),
TestFile("watchosExtension/WatchClass.swift"),
TestFile("watchosExtension/Assets.xcassets"),
TestFile("watchosExtension/Info.plist"),
]),
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"PRODUCT_NAME": "$(TARGET_NAME)",
"CODE_SIGN_IDENTITY": "Apple Development",
"SDKROOT": "iphoneos",
"SWIFT_VERSION": swiftVersion,
]),
],
targets: [
TestStandardTarget(
"Watchable",
type: .application,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"INFOPLIST_FILE": "Sources/iosApp/Info.plist",
"LD_RUNPATH_SEARCH_PATHS": "$(inherited) @executable_path/Frameworks",
"TARGETED_DEVICE_FAMILY": "1,2",
]),
],
buildPhases: [
TestSourcesBuildPhase([
"main.m",
"iosApp/CompanionClass.swift",
]),
TestResourcesBuildPhase([
"Main.storyboard",
"iosApp/Assets.xcassets",
]),
TestCopyFilesBuildPhase([
"Watchable WatchKit App.app",
], destinationSubfolder: .builtProductsDir, destinationSubpath: "$(CONTENTS_FOLDER_PATH)/Watch", onlyForDeployment: false
),
],
dependencies: ["Watchable WatchKit App", "PackageLibProduct"]
),
TestStandardTarget(
"Watchable WatchKit App",
type: .watchKitApp,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"ARCHS[sdk=watchos*]": "armv7k",
"ARCHS[sdk=watchsimulator*]": "i386",
"ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES": "YES",
"ASSETCATALOG_COMPILER_APPICON_NAME": "AppIcon",
"INFOPLIST_FILE": "Sources/watchosApp/Info.plist",
"SDKROOT": "watchos",
"SKIP_INSTALL": "YES",
"TARGETED_DEVICE_FAMILY": "4",
"WATCHOS_DEPLOYMENT_TARGET": watchosSDKVersion,
]),
],
buildPhases: [
TestResourcesBuildPhase([
"Interface.storyboard",
"watchosApp/Assets.xcassets",
]),
TestCopyFilesBuildPhase([
"Watchable WatchKit Extension.appex",
], destinationSubfolder: .plugins, onlyForDeployment: false
),
],
dependencies: ["Watchable WatchKit Extension"]
),
TestStandardTarget(
"Watchable WatchKit Extension",
type: .watchKitExtension,
buildConfigurations: [
TestBuildConfiguration(
"Debug",
buildSettings: [
"ARCHS[sdk=watchos*]": "armv7k",
"ARCHS[sdk=watchsimulator*]": "i386",
"ASSETCATALOG_COMPILER_COMPLICATION_NAME": "Complication",
"INFOPLIST_FILE": "Sources/watchosExtension/Info.plist",
"LD_RUNPATH_SEARCH_PATHS": "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks",
"SDKROOT": "watchos",
"SKIP_INSTALL": "YES",
"SWIFT_VERSION": swiftVersion,
"TARGETED_DEVICE_FAMILY": "4",
"WATCHOS_DEPLOYMENT_TARGET": watchosSDKVersion,
]),
],
buildPhases: [
TestSourcesBuildPhase([
"Controller.m",
"watchosExtension/WatchClass.swift",
]),
TestResourcesBuildPhase([
"Interface.storyboard",
"watchosExtension/Assets.xcassets",
]),
],
dependencies: ["PackageLibProduct"]
),
]),
TestPackageProject(
"Package",
groupTree: TestGroup(
"Sources", path: "Sources",
children: [
TestFile("Package.m"),
]),
targets: [
packageProductTarget,
TestStandardTarget("PackageLib", type: .staticLibrary),
])
]).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
return (workspace.projects[0], workspaceContext)
}
// Compute dependency graph for phone app with embedded watch app and verify that a package product used by both will be specialized accordingly and build twice.
func instantiateMultiplePackageProductsTest(dynamicPackageProduct: Bool) async throws {
let (project, workspaceContext) = try await setupWatchOSProject(dynamic: dynamicPackageProduct)
let buildParameters = BuildParameters(configuration: "Debug")
let allTargets = project.targets.filter { $0.name == "Watchable" }.map { BuildRequest.BuildTargetInfo(parameters: buildParameters, target: $0) }
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: allTargets, continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
let buildGraph = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: .dependency)
let targetList = Array(buildGraph.allTargets.reversed())
#expect(targetList.map({ $0.target.name }) == ["Watchable", "PackageLibProduct", "PackageLib", "Watchable WatchKit App", "Watchable WatchKit Extension", "PackageLibProduct", "PackageLib"])
if targetList.count < 6 {
Issue.record("cannot continue with incomplete target list")
return
}
let watchProduct = targetList[5]
let watchProductSettings = buildRequestContext.getCachedSettings(watchProduct.parameters, target: watchProduct.target)
XCTAssertMatch(watchProductSettings.sdk?.displayName, .prefix("watchOS"))
#expect(watchProductSettings.globalScope.evaluate(BuiltinMacros.SUPPORTED_PLATFORMS) == ["watchos", "watchsimulator"])
#expect(watchProductSettings.globalScope.evaluate(BuiltinMacros.TOOLCHAINS).map { Path($0).basename } == [])
let phoneProduct = targetList[1]
let phoneProductSettings = buildRequestContext.getCachedSettings(phoneProduct.parameters, target: phoneProduct.target)
XCTAssertMatch(phoneProductSettings.sdk?.displayName, .prefix("iOS"))
#expect(phoneProductSettings.globalScope.evaluate(BuiltinMacros.SUPPORTED_PLATFORMS) == ["iphoneos", "iphonesimulator"])
#expect(phoneProductSettings.globalScope.evaluate(BuiltinMacros.TOOLCHAINS).map { Path($0).basename } == [])
delegate.checkNoDiagnostics()
}
@Test(.requireSDKs(.iOS, .watchOS))
func instantiateMultiplePackageProductsStatic() async throws {
try await instantiateMultiplePackageProductsTest(dynamicPackageProduct: false)
}
@Test(.requireSDKs(.iOS, .watchOS))
func instantiateMultiplePackageProductsDynamic() async throws {
try await instantiateMultiplePackageProductsTest(dynamicPackageProduct: true)
}
@Test
func toolchainOverridesDoNotConflictWithSpecialization() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestPackageProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestAggregateTarget("ALL", dependencies: ["iOSFwk", "PackageLibProduct"]),
TestStandardTarget(
"iOSFwk",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "macosx"]),
],
dependencies: ["PackageLibProduct"]
),
TestPackageProductTarget(
"PackageLibProduct",
frameworksBuildPhase: TestFrameworksBuildPhase([
TestBuildFile(.target("PackageLib"))]),
buildConfigurations: [
// Targets need to opt-in to specialization.
TestBuildConfiguration("Debug", buildSettings: [
"SDKROOT": "auto",
"SDK_VARIANT": "auto",
"SUPPORTED_PLATFORMS": "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator",
]),
],
dependencies: ["PackageLib"]
),
TestStandardTarget("PackageLib", type: .staticLibrary),
]
)]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Configure the targets and create a BuildRequest.
let buildParameters = BuildParameters(configuration: "Debug", activeRunDestination: RunDestinationInfo.macOS, toolchainOverride: "com.apple.dt.toolchain.OSX10_15")
let allTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let packageTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[2])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [allTarget, packageTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
for type in TargetGraphFactory.GraphType.allCases {
// Get the dependency closure for the build request and examine it.
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
_ = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: type)
delegate.checkNoDiagnostics()
}
}
@Test
func toolchainOverlaysViaOverridesDoNotConflictWithSpecialization() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace",
projects: [TestPackageProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestAggregateTarget("ALL", dependencies: ["iOSFwk", "PackageLibProduct"]),
TestStandardTarget(
"iOSFwk",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "macosx"]),
],
dependencies: ["PackageLibProduct"]
),
TestPackageProductTarget(
"PackageLibProduct",
frameworksBuildPhase: TestFrameworksBuildPhase([
TestBuildFile(.target("PackageLib"))]),
buildConfigurations: [
// Targets need to opt-in to specialization.
TestBuildConfiguration("Debug", buildSettings: [
"SDKROOT": "auto",
"SDK_VARIANT": "auto",
"SUPPORTED_PLATFORMS": "macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator",
]),
],
dependencies: ["PackageLib"]
),
TestStandardTarget("PackageLib", type: .staticLibrary),
]
)]
).load(core)
let workspaceContext = WorkspaceContext(core: core, workspace: workspace, processExecutionCache: .sharedForTesting)
let project = workspace.projects[0]
// Configure the targets and create a BuildRequest.
let buildParameters = BuildParameters(configuration: "Debug", activeRunDestination: RunDestinationInfo.macOS, overrides: ["TOOLCHAINS": "com.fake-toolchain-identifier"])
let allTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[0])
let packageTarget = BuildRequest.BuildTargetInfo(parameters: buildParameters, target: project.targets[2])
let buildRequest = BuildRequest(parameters: buildParameters, buildTargets: [allTarget, packageTarget], continueBuildingAfterErrors: true, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
let buildRequestContext = BuildRequestContext(workspaceContext: workspaceContext)
for type in TargetGraphFactory.GraphType.allCases {
// Get the dependency closure for the build request and examine it.
let delegate = EmptyTargetDependencyResolverDelegate(workspace: workspaceContext.workspace)
_ = await TargetGraphFactory(workspaceContext: workspaceContext, buildRequest: buildRequest, buildRequestContext: buildRequestContext, delegate: delegate).graph(type: type)
delegate.checkNoDiagnostics()
}
}
@Test(.requireSDKs(.macOS))
func macCatalystSpecialization() async throws {
let core = try await getCore()
let workspace = try TestWorkspace("Workspace", projects: [TestProject("aProject", groupTree: TestGroup("SomeFiles"), targets: [
TestAggregateTarget("ALL", dependencies: ["macOSFwk", "macCatalystFwk"]),
TestStandardTarget(
"macOSFwk",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "macosx"]),
],
dependencies: ["PackageLibProduct"]
),
TestStandardTarget(
"macCatalystFwk",
type: .framework,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: ["SDKROOT": "macosx", "SDK_VARIANT": MacCatalystInfo.sdkVariantName]),
],
dependencies: ["PackageLibProduct"]
),
]), TestPackageProject("Package", groupTree: TestGroup("SomeFiles"), targets: [
TestPackageProductTarget(
"PackageLibProduct",