forked from swiftlang/swift-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsTests.swift
More file actions
5993 lines (5349 loc) · 375 KB
/
Copy pathSettingsTests.swift
File metadata and controls
5993 lines (5349 loc) · 375 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 Foundation
import Testing
import enum SWBProtocol.BuildAction
import struct SWBProtocol.ArenaInfo
import struct SWBProtocol.BuildConfiguration
import struct SWBProtocol.ImpartedBuildProperties
import SWBTestSupport
@_spi(Testing) import SWBUtil
@_spi(Testing) import SWBMacro
@_spi(Testing) import SWBCore
@Suite fileprivate struct SettingsTests: CoreBasedTests {
@Test(.requireSDKs(.macOS), .requireXcode26())
func projectBasics() async throws {
let core = try await getCore()
// Test the basic settings construction for a trivial test project.
let files: [Path: String] = [
// The paths and includes in these .xcconfigs are devised to test searching the includer’s directory in addition to relative paths.
.root.join("tmp/xcconfigs/Base0.xcconfig"): (
"XCCONFIG_USER_SETTING = from-xcconfig\n"),
.root.join("tmp/xcconfigs/Base1.xcconfig"): (
"#include \"Base0.xcconfig\""),
.root.join("tmp/Test.xcconfig"): (
"#include \"xcconfigs/Base1.xcconfig\"\n" +
"XCCONFIG_HEADER_SEARCH_PATHS = /tmp/path /tmp/other-path\n"
)]
let testWorkspace = try TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles",
children: [TestFile(Path.root.join("tmp/Test.xcconfig").str)]),
buildConfigurations:[
TestBuildConfiguration("Config1", baseConfig: "Test.xcconfig", buildSettings: [
"USER_PROJECT_SETTING": "USER_PROJECT_VALUE",
"OTHER_CFLAGS[arch=*]": "-Wall",
"OTHER_CFLAGS": "this value should be shadowed",
"HEADER_SEARCH_PATHS": "$(inherited) $(SRCROOT)/include $(XCCONFIG_HEADER_SEARCH_PATHS)",
"MACOSX_DEPLOYMENT_TARGET": "26.0"
])
],
appPreferencesBuildSettings: [
"APP_PREF_SETTING": "APP_PREF_VALUE",
]
)
]
).load(core)
// Construct a mock environment.
let environment = [
"ENV_VAR": "ENV_VAR Value",
"WEIRD_VAR[notacondition]okay": "weird value",
]
let context = try await contextForTestData(testWorkspace, environment: environment, files: files)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let parameters = BuildParameters(action: .build, configuration: "Debug")
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject)
#expect(settings.project === testProject)
#expect(settings.target === nil)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
// Verify that the environment was added.
let ENV_VAR = try #require(settings.userNamespace.lookupMacroDeclaration("ENV_VAR"))
#expect(settings.tableForTesting.lookupMacro(ENV_VAR)?.expression.stringRep == "ENV_VAR Value")
let WEIRD_VAR = try #require(settings.userNamespace.lookupMacroDeclaration("WEIRD_VAR[notacondition]okay"))
#expect(settings.tableForTesting.lookupMacro(WEIRD_VAR)?.expression.stringRep == "weird value")
// Verify that the command line tool defaults were added.
let swiftModuleNameMacro = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("SWIFT_MODULE_NAME"))
#expect(settings.tableForTesting.lookupMacro(swiftModuleNameMacro)?.expression.stringRep == "$(PRODUCT_MODULE_NAME)")
// Verify that neither OutputFormat nor OutputPath were set.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.OutputFormat) === nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.OutputPath) === nil)
// Verify that the computed path defaults were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.DEVELOPER_DIR)?.expression.stringRep == core.developerPath.path.str)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.AVAILABLE_PLATFORMS)?.expression.stringRep.contains("macosx") == true)
// Verify that the CACHE_ROOT was added.
let cacheRootMacro = try #require(settings.tableForTesting.lookupMacro(BuiltinMacros.CACHE_ROOT))
#expect(cacheRootMacro.expression.stringRep.hasPrefix("/var/folders"))
// Verify that the correct target-specific build system default settings were added.
//
// FIXME: This definition is always overridden by the project dynamic settings, so it is isn't clear it ever is used.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.CONFIGURATION_BUILD_DIR)?.next?.expression.stringRep == "$(BUILD_DIR)")
let VERSION_INFO_FILE = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("VERSION_INFO_FILE"))
#expect(settings.tableForTesting.lookupMacro(VERSION_INFO_FILE)?.expression.stringRep == "")
// Verify that the project dynamic settings were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PROJECT_NAME)?.expression.stringRep == "aProject")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SRCROOT)?.expression.stringRep.hasSuffix("/aProject") == true)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PROJECT_TEMP_DIR)?.expression.stringRep == "$(OBJROOT)/$(PROJECT_NAME).build")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.CONFIGURATION)?.expression.stringRep == "Config1")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.CONFIGURATION_BUILD_DIR)?.expression.stringRep == "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)")
#if !RC_PLAYGROUNDS
func checkXcodeVersion(_ settingName: StringMacroDeclaration, expectedVersion: Version, sourceLocation: SourceLocation = #_sourceLocation) {
if let value = settings.tableForTesting.lookupMacro(settingName)?.expression.stringRep {
if value.count >= 4, let uintValue = UInt(value) {
let version = Version(uintValue / 100, (uintValue % 100) / 10, uintValue % 10)
#expect(version == expectedVersion, sourceLocation: sourceLocation)
} else {
Issue.record("Unexpected value for \(settingName.name): \(value)", sourceLocation: sourceLocation)
}
} else {
Issue.record("\(settingName.name) is undefined", sourceLocation: sourceLocation)
}
}
checkXcodeVersion(BuiltinMacros.XCODE_VERSION_MAJOR, expectedVersion: core.xcodeVersion.normalized(toNumberOfComponents: 1))
checkXcodeVersion(BuiltinMacros.XCODE_VERSION_MINOR, expectedVersion: core.xcodeVersion.normalized(toNumberOfComponents: 2))
checkXcodeVersion(BuiltinMacros.XCODE_VERSION_ACTUAL, expectedVersion: core.xcodeVersion)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.XCODE_PRODUCT_BUILD_VERSION)?.expression.stringRep == core.xcodeProductBuildVersionString)
#endif
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.USER)?.expression.stringRep == "exampleUser")
// Verify that the settings from the xcconfig were added.
let XCCONFIG_USER_SETTING = try #require(settings.userNamespace.lookupMacroDeclaration("XCCONFIG_USER_SETTING"))
#expect(settings.tableForTesting.lookupMacro(XCCONFIG_USER_SETTING)?.expression.stringRep == "from-xcconfig")
#expect(settings.tableForTesting.location(of: XCCONFIG_USER_SETTING) == MacroValueAssignmentLocation(path: .init("/tmp/xcconfigs/Base0.xcconfig"), startLine: 1, endLine: 1, startColumn: 24, endColumn: 38))
// Verify the user project settings.
let USER_PROJECT_SETTING = try #require(settings.userNamespace.lookupMacroDeclaration("USER_PROJECT_SETTING"))
#expect(settings.tableForTesting.lookupMacro(USER_PROJECT_SETTING)?.expression.stringRep == "USER_PROJECT_VALUE")
let headerSearchPaths = settings.globalScope.evaluate(BuiltinMacros.HEADER_SEARCH_PATHS)
#expect(headerSearchPaths == ["/tmp/Workspace/aProject/include", "/tmp/path", "/tmp/other-path"])
let otherCFlags = settings.globalScope.evaluate(BuiltinMacros.OTHER_CFLAGS)
#expect(otherCFlags == ["-Wall"])
// Verify the application preferences build settings.
let APP_PREF_SETTING = try #require(settings.userNamespace.lookupMacroDeclaration("APP_PREF_SETTING"))
#expect(settings.tableForTesting.lookupMacro(APP_PREF_SETTING)?.expression.stringRep == "APP_PREF_VALUE")
// Verify that the platform settings were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_NAME)?.expression.stringRep.hasPrefix("macosx") == true)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_FAMILY_NAME)?.expression.stringRep == "macOS")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_DISPLAY_NAME)?.expression.stringRep == "macOS")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.EFFECTIVE_PLATFORM_NAME)?.expression.stringRep == "")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.EFFECTIVE_PLATFORM_SUFFIX)?.expression.stringRep == "os")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_DIR)?.expression.stringRep.contains("MacOSX.platform") == true)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SUPPORTED_PLATFORMS)?.expression.stringRep == "macosx")
let ARCHS_STANDARD = try #require(settings.userNamespace.lookupMacroDeclaration("ARCHS_STANDARD"))
#expect(settings.tableForTesting.lookupMacro(ARCHS_STANDARD)?.expression.stringRep == "arm64 x86_64")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.VALID_ARCHS)?.expression.stringRep.contains("i386 x86_64") == true)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_PREFERRED_ARCH)?.expression.stringRep == "x86_64")
// Verify that the SDK settings were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SDK_NAME)?.expression.stringRep.hasPrefix("macosx") == true)
let sdkVersionString = try #require(settings.tableForTesting.lookupMacro(BuiltinMacros.SDK_VERSION))
#expect(try Version(sdkVersionString.expression.stringRep) >= Version(10, 9))
// Verify that the toolchain settings were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TOOLCHAIN_DIR)?.expression.stringRep.hasSuffix("XcodeDefault.xctoolchain") == true)
// Verify that the global overrides were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.DERIVED_DATA_DIR)?.expression.stringRep.hasPrefix("/var/folders") == true)
// This setting is explicitly cleared.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MODULE_CACHE_DIR)?.expression.stringRep == "")
// check the exported macro names.
#expect(settings.exportedMacroNames.contains(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET))
#expect(settings.exportedMacroNames.contains(BuiltinMacros.CACHE_ROOT))
#expect(settings.exportedMacroNames.contains(BuiltinMacros.PROJECT_NAME))
#expect(settings.exportedNativeMacroNames.contains(BuiltinMacros.SDK_NAME))
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.DERIVED_DATA_DIR))
#expect(!settings.exportedNativeMacroNames.contains(BuiltinMacros.DERIVED_DATA_DIR))
// check the global scope.
let result = settings.globalScope.evaluate(BuiltinMacros.PROJECT_NAME)
#expect(result == "aProject")
var xcconfigPath: Path
var scope: MacroEvaluationScope
var macro: MacroDeclaration
// Verify that changes to XCConfigs are being picked up
xcconfigPath = Path.root.join("tmp/Test.xcconfig")
scope = MacroEvaluationScope(table: buildRequestContext.getCachedMacroConfigFile(xcconfigPath, project: testProject, context: .baseConfiguration).table)
macro = try #require(scope.namespace.lookupMacroDeclaration("XCCONFIG_HEADER_SEARCH_PATHS"))
#expect(scope.evaluateAsString(macro) == "/tmp/path /tmp/other-path")
try context.fs.write(xcconfigPath,
contents: ByteString(encodingAsUTF8: "#include \"xcconfigs/Base1.xcconfig\"\n" +
"XCCONFIG_HEADER_SEARCH_PATHS = /tmp/changed\n"))
do {
let buildRequestContext = BuildRequestContext(workspaceContext: context)
scope = MacroEvaluationScope(table: buildRequestContext.getCachedMacroConfigFile(xcconfigPath, project: testProject, context: .baseConfiguration).table)
#expect(scope.evaluateAsString(macro) == "/tmp/changed")
}
// Verify that missing XCConfigs will be picked up once they appear
xcconfigPath = Path.root.join("tmp/Other.xcconfig")
#expect(buildRequestContext.getCachedMacroConfigFile(xcconfigPath, project: testProject, context: .baseConfiguration).diagnostics.map { $0.formatLocalizedDescription(.debug) } == ["/tmp/Workspace/aProject/aProject.xcodeproj: error: Unable to open base configuration reference file '/tmp/Other.xcconfig'."])
try context.fs.write(xcconfigPath,
contents: ByteString(encodingAsUTF8: "#include \"xcconfigs/Base1.xcconfig\"\n" +
"XCCONFIG_HEADER_SEARCH_PATHS = /tmp/changed\n"))
do {
let buildRequestContext = BuildRequestContext(workspaceContext: context)
scope = MacroEvaluationScope(table: buildRequestContext.getCachedMacroConfigFile(xcconfigPath, project: testProject, context: .baseConfiguration).table)
macro = try #require(scope.namespace.lookupMacroDeclaration("XCCONFIG_HEADER_SEARCH_PATHS"))
#expect(scope.evaluateAsString(macro) == "/tmp/changed")
}
}
@Test(.requireSDKs(.macOS), .requireXcode26())
func standardTargetBasics() async throws {
let core = try await getCore()
try await withTemporaryDirectory { (sdksDirPath: Path) in
let additionalSDKPath = sdksDirPath.join("TestSDK.sdk")
try await writeSDK(name: additionalSDKPath.basename, parentDir: sdksDirPath, settings: [
"CanonicalName": "com.apple.sdk.1.0",
"IsBaseSDK": "NO",
])
// Test the basic settings construction for a trivial test target.
let testWorkspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: [TestFile("Mock.cpp")]),
buildConfigurations:[
TestBuildConfiguration("Config1", buildSettings: [
"USER_PROJECT_SETTING": "USER_PROJECT_VALUE",
"HEADER_SEARCH_PATHS": "$(inherited) $(SRCROOT)/include /usr/include .",
"FRAMEWORK_SEARCH_PATHS": "$(inherited) /System/Library/Frameworks /Applications/Xcode.app /usr",
"OTHER_LDFLAGS": "-current_version $(DYLIB_CURRENT_VERSION)",
"GCC_PREFIX_HEADER": "/Cocoa.pch",
"ADDITIONAL_SDKS": "\(additionalSDKPath.str)",
"ARCHS": "x86_64 x86_64h",
"RC_ARCHS": "x86_64 x86_64h",
"VALID_ARCHS": "$(inherited) x86_64h",
"MACOSX_DEPLOYMENT_TARGET": "26.0",
])],
targets: [
TestStandardTarget("Target1",
type: .application,
buildConfigurations: [
TestBuildConfiguration("Config1", buildSettings: [
"BUILD_VARIANTS": "normal other",
"ENABLE_TESTABILITY": "YES",
"INSTALL_PATH": "",
// Use this to check conditions end to end.
"PRODUCT_NAME[sdk=macosx*]": "Foo",
"USER_TARGET_SETTING": "USER_TARGET_VALUE"])],
buildPhases: [TestSourcesBuildPhase(["Mock.cpp"])])])]).load(core)
let context = try await contextForTestData(testWorkspace,
files: [
core.loadSDK(.macOS).path.join("Cocoa.pch"): "",
core.loadSDK(.macOS).path.join("System/Library/Frameworks/mock.txt"): "",
core.loadSDK(.macOS).path.join("usr/include/mock.txt"): "",
additionalSDKPath.join("Applications/Xcode.app/mock.txt"): "",
additionalSDKPath.join("usr/mock.txt"): "",
]
)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
let parameters = BuildParameters(action: .build, configuration: "Debug")
var settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
// There should be no diagnostics.
#expect(settings.warnings == [])
#expect(settings.errors == [])
// Verify that the global scope has the expected conditions (sdk and config).
#expect(Set(settings.globalScope.conditionParameterValues.keys) == Set([BuiltinMacros.sdkCondition, BuiltinMacros.targetNameCondition, BuiltinMacros.configurationCondition, BuiltinMacros.sdkBuildVersionCondition, BuiltinMacros.hostPlatformCondition, BuiltinMacros.destinationPlatformCondition]))
// Verify that the target configuration was captured. Notice that this is *not* the configuration the build parameters were configured with.
#expect(settings.targetConfiguration?.name == "Config1")
#expect(settings.targetConfiguration?.name != parameters.configuration)
// Verify that the environment settings work properly.
#expect(settings.globalScope.evaluate(BuiltinMacros.RC_ARCHS) == ["x86_64", "x86_64h"])
// Verify that the defaults from additional specs were added.
let EMBEDDED_CONTENT_CONTAINS_SWIFT = try #require(settings.userNamespace.lookupMacroDeclaration("EMBEDDED_CONTENT_CONTAINS_SWIFT"))
#expect(settings.tableForTesting.lookupMacro(EMBEDDED_CONTENT_CONTAINS_SWIFT)?.expression.stringRep == "NO")
let ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = try #require(settings.userNamespace.lookupMacroDeclaration("ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES"))
#expect(settings.tableForTesting.lookupMacro(ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES)?.expression.stringRep == "$(EMBEDDED_CONTENT_CONTAINS_SWIFT)")
// Verify that all the deployment target settings were added.
let IPHONEOS_DEPLOYMENT_TARGET = try #require(settings.userNamespace.lookupMacroDeclaration("IPHONEOS_DEPLOYMENT_TARGET"))
#expect(settings.tableForTesting.lookupMacro(IPHONEOS_DEPLOYMENT_TARGET)?.expression.stringRep != "")
// Verify that the correct target-specific build system default settings were added.
let VERSION_INFO_FILE = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("VERSION_INFO_FILE"))
#expect(settings.tableForTesting.lookupMacro(VERSION_INFO_FILE)?.expression.stringRep == "$(PRODUCT_NAME)_vers.c")
// Verify that the target "dynamic" settings were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TARGET_NAME)?.expression.stringRep == "Target1")
let USER_TARGET_SETTING = try #require(settings.userNamespace.lookupMacroDeclaration("USER_TARGET_SETTING"))
#expect(settings.tableForTesting.lookupMacro(USER_TARGET_SETTING)?.expression.stringRep == "USER_TARGET_VALUE")
// Verify that the product and package settings were added (they will have overwritten the previous definition).
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.INSTALL_PATH)?.next?.expression.stringRep == nil)
let EXECUTABLE_PATH = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("EXECUTABLE_PATH"))
#expect(settings.tableForTesting.lookupMacro(EXECUTABLE_PATH)?.expression.stringRep == "$(EXECUTABLE_FOLDER_PATH)/$(EXECUTABLE_NAME)")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PACKAGE_TYPE)?.expression.stringRep == "com.apple.package-type.wrapper.application")
// Verify that the "target task" overrides were added.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.ACTION)?.expression.stringRep == "build")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SEPARATE_SYMBOL_EDIT)?.expression.stringRep == "NO")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.GCC_SYMBOLS_PRIVATE_EXTERN)?.expression.stringRep == "NO")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.LLVM_LTO)?.expression.stringRep == "NO")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SKIP_INSTALL)?.expression.stringRep == "YES")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.STRIP_INSTALLED_PRODUCT)?.expression.stringRep == "NO")
// Verify the SDK path and other settings which are interesting to verify for the macOS SDK.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SDKROOT)?.expression.stringRep == core.loadSDK(.macOS).path.str)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.DEVELOPER_SDK_DIR)?.expression.stringRep == core.loadSDK(.macOS).path.dirname.str)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_DEVELOPER_SDK_DIR)?.expression.stringRep == "$(DEVELOPER_SDK_DIR)")
// Verify that we rewrote the SDK into certain paths.
#expect(settings.globalScope.evaluate(BuiltinMacros.HEADER_SEARCH_PATHS) == ["/tmp/Workspace/aProject/build/Config1/include", "/tmp/Workspace/aProject/include", core.loadSDK(.macOS).path.join("usr/include").str, "."])
#expect(settings.globalScope.evaluate(BuiltinMacros.FRAMEWORK_SEARCH_PATHS) == [
"/tmp/Workspace/aProject/build/Config1",
// Paths found in SDKROOT get prefixed
core.loadSDK(.macOS).path.join("System/Library/Frameworks").str,
// Paths found in additional SDKs get mentioned twice: once prefixed and once as is
additionalSDKPath.join("Applications/Xcode.app").str,
"/Applications/Xcode.app",
// Paths found in both SDKROOT and additional SDKs get mentioned twice: once prefixed with the additional SDK and once prefixed with the SDKROOT
additionalSDKPath.join("usr").str,
core.loadSDK(.macOS).path.join("usr").str,
])
#expect(settings.globalScope.evaluate(BuiltinMacros.GCC_PREFIX_HEADER) == core.loadSDK(.macOS).path.join("Cocoa.pch"))
// Check that we resolved toolchains paths.
#expect(settings.globalScope.evaluate(BuiltinMacros.EFFECTIVE_TOOLCHAINS_DIRS) == (core.toolchainRegistry.defaultToolchain?.path.str).map { [$0] } ?? [])
// Check that we set up the LINK_FILE_LIST_... macros.
#expect(settings.tableForTesting.lookupMacro(try #require(settings.userNamespace.lookupMacroDeclaration("LINK_FILE_LIST_normal_x86_64")))?.expression.stringRep == "$(OBJECT_FILE_DIR)-normal/x86_64/$(PRODUCT_NAME).LinkFileList")
// Check that we set up the SWIFT_RESPONSE_FILE_PATH_... macros
#expect(settings.tableForTesting.lookupMacro(try #require(settings.userNamespace.lookupMacroDeclaration("SWIFT_RESPONSE_FILE_PATH_normal_x86_64")))?.expression.stringRep == "$(OBJECT_FILE_DIR)-normal/x86_64/$(PRODUCT_NAME).SwiftFileList")
// Verify that the 'variant' and 'arch' settings were set up properly.
#expect(settings.globalScope.evaluate(BuiltinMacros.BUILD_VARIANTS) == ["normal", "other"])
#expect(settings.globalScope.evaluate(BuiltinMacros.ARCHS) == ["x86_64", "x86_64h"])
#expect(settings.globalScope.evaluate(BuiltinMacros.variant) == "normal")
#expect(settings.globalScope.evaluate(BuiltinMacros.arch) == "undefined_arch")
let variantScope = settings.globalScope.subscope(binding: BuiltinMacros.variantCondition, to: "other")
#expect(variantScope.evaluate(BuiltinMacros.variant) == "other")
let archScope = settings.globalScope.subscope(binding: BuiltinMacros.archCondition, to: "x86_64")
#expect(archScope.evaluate(BuiltinMacros.arch) == "x86_64")
// Verify that the appropriate extra exports were added.
#expect(settings.exportedMacroNames.contains(BuiltinMacros.TARGET_NAME))
// Verify that "install"/"archive" actions behaves as expected.
for action in [BuildAction.install, BuildAction.archive] {
let context2 = try await contextForTestData(testWorkspace,
environment: [:],
files: [
core.loadSDK(.macOS).path.join("Cocoa.pch"): "",
core.loadSDK(.macOS).path.join("System/Library/Frameworks/mock.txt"): "",
])
let parameters2 = BuildParameters(action: action, configuration: "Debug")
settings = Settings(workspaceContext: context2, buildRequestContext: buildRequestContext, parameters: parameters2, project: testProject, target: testTarget)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.ACTION)?.expression.stringRep == action.actionName)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.DEPLOYMENT_LOCATION)?.expression.stringRep == "YES")
// Verify that the product location overrides were set properly (they will have overwritten the previous definition).
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TARGET_BUILD_DIR)?.expression.stringRep == "$(UNINSTALLED_PRODUCTS_DIR)/$(PLATFORM_NAME)$(TARGET_BUILD_SUBPATH)")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TARGET_BUILD_DIR)?.next?.expression.stringRep == "$(CONFIGURATION_BUILD_DIR)$(TARGET_BUILD_SUBPATH)")
// Verify that the input paths were normalized.
//
// FIXME: This only happens for targets, which is confusing and inconsistent.
if let project = settings.project {
#expect(settings.globalScope.evaluate(BuiltinMacros.OBJROOT) == Path("\(project.sourceRoot.str)/build"))
#expect(settings.globalScope.evaluate(BuiltinMacros.CONFIGURATION_BUILD_DIR) == Path("\(project.sourceRoot.str)/build/Config1"))
#expect(settings.globalScope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH).str == "\(project.sourceRoot.str)/build/ExplicitPrecompiledModules")
// SDK_EXPLICIT_MODULES_OUTPUT_PATH is defined in terms of DERIVED_DATA_DIR, so it is explicitly cleared when there is no DerivedData (as with MODULE_CACHE_DIR above).
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SDK_EXPLICIT_MODULES_OUTPUT_PATH)?.expression.stringRep == "")
}
// check that we get the right value for VERSION_INFO_STRING, which validates we parsed it correctly.
let VERSION_INFO_STRING = try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("VERSION_INFO_STRING") as? StringMacroDeclaration)
let result: String = settings.globalScope.evaluate(VERSION_INFO_STRING)
#expect(result == "\"@(#)PROGRAM:Foo PROJECT:aProject-\"")
// check handle of empty default macro assignments inside list evaluation (rdar://problem/24786941).
#expect(settings.globalScope.evaluate(try #require(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("OTHER_LDFLAGS") as? StringListMacroDeclaration)) == ["-current_version", ""])
// check target task overrides.
#expect(settings.globalScope.evaluate(BuiltinMacros.ACTION) == action.actionName)
#expect(settings.globalScope.evaluate(BuiltinMacros.BUILD_COMPONENTS) == ["headers", "build"])
#expect(settings.globalScope.evaluate(BuiltinMacros.GCC_VERSION) == "com.apple.compilers.llvm.clang.1_0")
// Check build system defaults are exported.
#expect(settings.exportedMacroNames.contains(BuiltinMacros.ALTERNATE_MODE))
#expect(settings.exportedMacroNames.contains(BuiltinMacros.ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES))
#expect(settings.exportedMacroNames.contains(BuiltinMacros.EMBEDDED_CONTENT_CONTAINS_SWIFT))
#expect(settings.exportedMacroNames.contains(BuiltinMacros.VERSION_INFO_FILE))
#expect(settings.exportedMacroNames.contains(BuiltinMacros.YACC))
}
}
}
@Test(.requireSDKs(.iOS))
func iOSStandardTargetBasics() async throws {
let core = try await getCore()
// Test the basic settings construction for a trivial test target.
let testWorkspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: [TestFile("Mock.cpp")]),
targets: [
TestStandardTarget("Target1",
type: .application,
buildConfigurations: [
TestBuildConfiguration("Debug",
buildSettings: [
"SDKROOT": "iphoneos",
"IPHONEOS_SETTING[sdk=iphoneos*]": "correct",
"IPHONESIM_SETTING[sdk=iphonesimulator*]": "correct",
"EMBEDDED_SETTING[sdk=embedded*]": "correct",
// These are disabled because at the moment we don't enforce ordering of 'iphoneos' over 'embedded', so the success of evaluating this setting is not guaranteed.
// "UNIFIED_SETTING[sdk=iphoneos*]": "iphoneos",
// "UNIFIED_SETTING[sdk=embedded*]": "embedded",
])],
buildPhases: [TestSourcesBuildPhase(["Mock.cpp"])])])]).load(core)
let context = try await contextForTestData(testWorkspace)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
let parameters = BuildParameters(action: .build, configuration: "Debug")
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
let scope = settings.globalScope
// Verify the SDK path and other settings which are interesting to verify for the macOS SDK.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SDKROOT)?.expression.stringRep == core.loadSDK(.iOS).path.str)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.DEVELOPER_SDK_DIR)?.expression.stringRep == core.loadSDK(.macOS).path.dirname.str)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.PLATFORM_DEVELOPER_SDK_DIR)?.expression.stringRep == core.loadSDK(.iOS).path.dirname.str)
// Validate the conditional settings.
#expect(scope.evaluateAsString(try #require(settings.userNamespace.lookupMacroDeclaration("IPHONEOS_SETTING"))) == "correct")
#expect(scope.evaluateAsString(try #require(settings.userNamespace.lookupMacroDeclaration("IPHONESIM_SETTING"))) == "")
#expect(scope.evaluateAsString(try #require(settings.userNamespace.lookupMacroDeclaration("EMBEDDED_SETTING"))) == "correct")
}
@Test(.requireSDKs(.macOS))
func bogusSupportedPlatforms() async throws {
let testWorkspace = try await TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: [TestFile("Mock.cpp")]),
targets: [
TestStandardTarget("Target1",
type: .application,
buildConfigurations: [
TestBuildConfiguration("Debug",
buildSettings: [
"SDKROOT": "macosx",
"ONLY_ACTIVE_ARCH": "YES",
"SUPPORTED_PLATFORMS": "macOS fakeOS"
])],
buildPhases: [TestSourcesBuildPhase(["Mock.cpp"])])])]).load(getCore())
let context = try await contextForTestData(testWorkspace)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
let parameters = BuildParameters(action: .build, configuration: "Debug", activeRunDestination: .macOS)
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
#expect(settings.errors == [])
#expect(settings.warnings == ["Did not find any platform for SUPPORTED_PLATFORMS 'macOS, fakeOS'"])
}
@Test(.requireSDKs(.macOS, .iOS))
func deploymentTargetFallback() async throws {
// Test the basic settings construction for a trivial test target.
let core = try await getCore()
let testWorkspace = try TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: [
TestFile("Mock.cpp")
]),
targets: [
TestStandardTarget("macOSTarget",
type: .application,
buildConfigurations: [
TestBuildConfiguration("Debug",
buildSettings: [
"SDKROOT": "macosx",
"MACOSX_DEPLOYMENT_TARGET": "",
"IPHONEOS_DEPLOYMENT_TARGET": "",
])],
buildPhases: [TestSourcesBuildPhase(["Mock.cpp"])]),
TestStandardTarget("iOSTarget",
type: .application,
buildConfigurations: [
TestBuildConfiguration("Debug",
buildSettings: [
"SDKROOT": "iphoneos",
"MACOSX_DEPLOYMENT_TARGET": "",
"IPHONEOS_DEPLOYMENT_TARGET": "",
])],
buildPhases: [TestSourcesBuildPhase(["Mock.cpp"])]),
])]).load(core)
let context = try await contextForTestData(testWorkspace)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let macOSTestTarget = testProject.targets[0]
let iOSTestTarget = testProject.targets[1]
let buildParameters = BuildParameters(action: .build, configuration: "Debug")
let macOSTargetSettings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: buildParameters, project: testProject, target: macOSTestTarget)
let iOSTargetSettings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: buildParameters, project: testProject, target: iOSTestTarget)
// Check that overriding the deployment target with the empty string results in the default value for the SDK.
#expect(macOSTargetSettings.globalScope.evaluateAsString(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET) == core.loadSDK(.macOS).defaultDeploymentTarget)
#expect(macOSTargetSettings.globalScope.evaluateAsString(BuiltinMacros.IPHONEOS_DEPLOYMENT_TARGET) == "")
#expect(iOSTargetSettings.globalScope.evaluateAsString(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET) == "")
#expect(iOSTargetSettings.globalScope.evaluateAsString(BuiltinMacros.IPHONEOS_DEPLOYMENT_TARGET) == core.loadSDK(.iOS).defaultDeploymentTarget)
}
@Test(.requireSDKs(.macOS))
func aggregateTargetBasics() async throws {
let core = try await getCore()
// Test the basic settings construction for an aggregate test target.
let testWorkspace = try TestWorkspace("Workspace",
projects: [TestProject(
"aProject",
groupTree: TestGroup("SomeFiles"),
buildConfigurations:[
TestBuildConfiguration("TargetConfig",
buildSettings: [
"SDKROOT": "macosx",
]),
],
targets: [
TestAggregateTarget("AggregateTarget1",
buildConfigurations: [
TestBuildConfiguration("TargetConfig"),
]),
]),
]).load(core)
let testProject = testWorkspace.projects[0]
let testTarget = testProject.targets[0]
let context = try await contextForTestData(testWorkspace, environment: ["INSTALLED_PRODUCT_ASIDES": "YES", "USE_PER_CONFIGURATION_BUILD_LOCATIONS": "NO"])
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let parameters = BuildParameters(action: .install, configuration: "TargetConfig")
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
// Verify that the toolchains are correct.
#expect(settings.toolchains == [core.coreSettings.defaultToolchain])
// Aggregate targets' settings are substantially similar to standard targets, but it is common for certain values to not be defined for aggregate targets.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TARGET_NAME)?.expression.stringRep == "AggregateTarget1")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.SDKROOT)?.expression.stringRep.hasPrefix(try context.fs.realpath(core.developerPath.path).str) == true)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TARGET_BUILD_DIR)?.expression.stringRep == "$(UNINSTALLED_PRODUCTS_DIR)$(TARGET_BUILD_SUBPATH)")
// Subsequent definitions will have overwritten the previous definition.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.TARGET_BUILD_DIR)?.next?.next?.expression.stringRep == "$(CONFIGURATION_BUILD_DIR)$(TARGET_BUILD_SUBPATH)")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.CONFIGURATION_TEMP_DIR)?.next?.next?.expression.stringRep == nil)
// This setting is always overridden by the project defaults.
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.CONFIGURATION_BUILD_DIR)?.next?.next?.expression.stringRep == nil)
// Check that the correct build system defaults are exported (should be the native ones).
#expect(settings.exportedMacroNames.contains(BuiltinMacros.YACC))
}
@Test(.requireHostOS(.macOS))
func executablePaths() async throws {
let core = try await getCore()
// Check that we locate executables in the right places.
let testWorkspaceData = TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
targets: [
TestAggregateTarget("AggregateTarget")])])
// We test against the actual FS, to check the real executable paths.
let context = WorkspaceContext(core: core, workspace: try testWorkspaceData.load(core), fs: SWBUtil.localFS, processExecutionCache: .sharedForTesting)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
let parameters = BuildParameters(action: .build, configuration: "Debug")
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
// Check we can find clang in the toolchain.
#expect(settings.executableSearchPaths.lookup(Path("clang")) == core.developerPath.path.join("Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"))
// Check that we find ibtool outside the toolchain.
#expect(settings.executableSearchPaths.lookup(Path("ibtool")) == core.developerPath.path.join("usr/bin/ibtool"))
// Check the paths directly.
let paths = settings.executableSearchPaths.paths
let toolchainPathIndex = paths.firstIndex(of: core.developerPath.path.join("Toolchains/XcodeDefault.xctoolchain/usr/bin")) ?? Int.max
let platformPathIndex = paths.firstIndex(of: core.developerPath.path.join("Platforms/MacOSX.platform/usr/bin")) ?? Int.max
let developerLocalBinIndex = paths.firstIndex(of: core.developerPath.path.join("usr/local/bin")) ?? Int.max
let developerBinIndex = paths.firstIndex(of: core.developerPath.path.join("usr/bin")) ?? Int.max
#expect(toolchainPathIndex < platformPathIndex)
#expect(platformPathIndex < developerBinIndex)
#expect(developerBinIndex < developerLocalBinIndex)
}
/// Check the handling of the various override mechanisms.
@Test
func settingOverrides() async throws {
try await withTemporaryDirectory { tmpDir async throws -> Void in
let testWorkspace = try await TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [
"BAZ": "project-$(inherited)"])],
targets: [
TestAggregateTarget("AggregateTarget",
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [
"BAZ": "target-$(inherited)"])])])]).load(getCore())
let context = try await contextForTestData(testWorkspace, environment: ["BAZ": "environment-$(inherited)"])
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
try context.fs.createDirectory(tmpDir, recursive: true)
let cliPath = tmpDir.join("cliPath.xcconfig")
try context.fs.write(cliPath, contents: "BAZ = commandlineconfig-$(inherited)-fromfile")
let envPath = tmpDir.join("envPath.xcconfig")
try context.fs.write(envPath, contents: "BAZ = environmentconfig-$(inherited)-fromfile")
let parameters = BuildParameters(
action: .build,
configuration: "Debug",
overrides: ["BAZ": "overrides-$(inherited)"],
commandLineOverrides: ["BAZ": "commandline-$(inherited)"],
commandLineConfigOverridesPath: cliPath,
commandLineConfigOverrides: ["BAZ": "commandlineconfig-$(inherited)"],
environmentConfigOverridesPath: envPath,
environmentConfigOverrides: ["BAZ": "environmentconfig-$(inherited)"])
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
let diagnosticErrors = settings.diagnostics.filter { $0.behavior == .error }
guard diagnosticErrors.isEmpty else {
Issue.record("Errors creating settings: \(diagnosticErrors)")
return
}
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
let scope = settings.globalScope
#expect(scope.evaluateAsString(try #require(settings.userNamespace.lookupMacroDeclaration("BAZ"))) == "environmentconfig-commandlineconfig-commandline-overrides-target-project-environment--fromfile-fromfile")
}
}
@Test
func settingsOverridesDevelopmentAssets() async throws {
func test(buildSettings: [String: String], action: BuildAction = .install, overrides: [String: String] = [:], extraFiles: [Path: String] = [:], configuration: String = "Debug", baseConfig: String? = nil, expectedExcludedFileNames: [String] = [], sourceLocation: SourceLocation = #_sourceLocation) async throws {
let testWorkspace = try await TestWorkspace("Workspace", projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: [TestFile("main.swift"), TestFile("Test.xcconfig")]),
buildConfigurations: [
TestBuildConfiguration("Debug", baseConfig: baseConfig, buildSettings: buildSettings), TestBuildConfiguration("Release", baseConfig: baseConfig, buildSettings: buildSettings)],
targets: [
TestAggregateTarget("AppTarget", buildConfigurations: [TestBuildConfiguration("Debug"), TestBuildConfiguration("Release")], buildPhases: [TestSourcesBuildPhase(["main.swift"])])])]).load(getCore())
let context = try await contextForTestData(testWorkspace, systemInfo: SystemInfo(operatingSystemVersion: Version(), productBuildVersion: "", nativeArchitecture: "arm64"), files: [
.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/AppIcon.png"): "a picture",
.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/Info.plist"): "a plist"
].merging(extraFiles, uniquingKeysWith: { original, override in override }))
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
let parameters = BuildParameters(
action: action,
configuration: configuration,
overrides: overrides)
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
#expect(settings.errors.isEmpty, "Expect to not produce any errors", sourceLocation: sourceLocation)
let scope = settings.globalScope
#expect(scope.evaluate(BuiltinMacros.EXCLUDED_SOURCE_FILE_NAMES) == expectedExcludedFileNames, sourceLocation: sourceLocation)
}
// Specifying DEVELOPMENT_ASSET_PATHS and EXCLUDED_SOURCE_FILE_NAMES should merge them
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
expectedExcludedFileNames: ["docs/*", Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
// Specifying DEVELOPMENT_ASSET_PATHS which are absolute should work as well
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'\(Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources").strWithPosixSlashes)'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
expectedExcludedFileNames: ["docs/*", Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
// Specifying DEVELOPMENT_ASSET_PATHS which are absolute that are not part of SRCROOT should work as well
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'\(Path.root.join("tmp/Workspace/bProject/AppTarget/Preview Resources").strWithPosixSlashes)'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
// the directory needs to exist (for /* at the end), so we write a mock file here
extraFiles: [.root.join("tmp/Workspace/bProject/AppTarget/Preview Resources/afile.txt"): ""],
expectedExcludedFileNames: ["docs/*", Path.root.join("tmp/Workspace/bProject/AppTarget/Preview Resources/*").str])
// Not specifying DEVELOPMENT_ASSET_PATHS should not affect EXCLUDED_SOURCE_FILE_NAMES
try await test(buildSettings: ["EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
expectedExcludedFileNames: ["docs/*"])
// Not specifying EXCLUDED_SOURCE_FILE_NAMES but DEVELOPMENT_ASSET_PATHS should create a list with DEVELOPMENT_ASSET_PATHS' contents
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'"],
expectedExcludedFileNames: [Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
// If the specified directory does not exist, we expect to not receive an error during Settings creation
// Since the directory does not exist, it gets added as a file (without '*')
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Does Not Exist'"],
expectedExcludedFileNames: [Path.root.join("tmp/Workspace/aProject/AppTarget/Does Not Exist").str])
// If the build action is install, development resources should be excluded
for action in [BuildAction.install, .installAPI, .installHeaders, .installLoc, .installSource, .archive] {
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
action: action,
expectedExcludedFileNames: ["docs/*", Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
}
// If the build action is anything else but install (and DEPLOYMENT_POSTPROCESSING is not specified), we don't exclude
for action in [BuildAction.analyze, .clean, .build] {
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
action: action,
expectedExcludedFileNames: ["docs/*"])
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
action: action,
overrides: ["DEPLOYMENT_LOCATION": "YES"],
expectedExcludedFileNames: ["docs/*"])
}
// If the build action is anything else but install *but* DEPLOYMENT_POSTPROCESSING is specified, we exclude
for action in [BuildAction.analyze, .clean, .build] {
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
action: action,
overrides: ["DEPLOYMENT_POSTPROCESSING": "YES"],
expectedExcludedFileNames: ["docs/*", Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
}
// However, if DEPLOYMENT_LOCATION is explicitly set to NO, development assets should not be excluded
for action in [BuildAction.analyze, .clean, .build] {
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
action: action,
overrides: ["DEPLOYMENT_LOCATION": "NO"],
expectedExcludedFileNames: ["docs/*"])
}
// Exclude directories and files
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources' 'AppTarget/DevelopmentResourceFile.txt'",
"EXCLUDED_SOURCE_FILE_NAMES": "$(inherited) docs/*"],
expectedExcludedFileNames: ["docs/*", Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str, Path.root.join("tmp/Workspace/aProject/AppTarget/DevelopmentResourceFile.txt").str])
let baseConfigFiles: [Path: String] = [
.root.join("tmp/Workspace/aProject/Test.xcconfig"): "EXCLUDED_SOURCE_FILE_NAMES[config=Debug] = 'debug/files/*'"
]
// Check that specified paths get added for condition sets as well
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'"],
action: .install,
extraFiles: baseConfigFiles,
configuration: "Debug",
baseConfig: "Test.xcconfig",
expectedExcludedFileNames: ["debug/files/*", Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
// If the condition set states debug, but we build release, we should only have dev assets in the value
try await test(buildSettings: ["DEVELOPMENT_ASSET_PATHS": "'AppTarget/Preview Resources'"],
action: .install,
extraFiles: baseConfigFiles,
configuration: "Release",
baseConfig: "Test.xcconfig",
expectedExcludedFileNames: [Path.root.join("tmp/Workspace/aProject/AppTarget/Preview Resources/*").str])
}
@Test
func arenaSettings() async throws {
let testWorkspace = try await TestWorkspace("Workspace",
projects: [
TestProject("aProject",
groupTree: TestGroup("SomeFiles"),
buildConfigurations: [TestBuildConfiguration("Debug", buildSettings: [:])],
targets: [
TestAggregateTarget("AggregateTarget",
buildConfigurations: [TestBuildConfiguration("Debug", buildSettings: [:])])])]).load(getCore())
let context = try await contextForTestData(testWorkspace)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let testTarget = testProject.targets[0]
let arena = ArenaInfo(derivedDataPath: Path.root.join("tmp/foo/$(SDK_NAME)"), buildProductsPath: Path.root.join("tmp/foo/$(SDK_NAME)/products"), buildIntermediatesPath: Path.root.join("tmp/foo/$(SDK_NAME)/intermediates"), pchPath: Path(""), indexRegularBuildProductsPath: Path.root.join("tmp/foo/$(SDK_NAME)/regular-products"), indexRegularBuildIntermediatesPath: Path.root.join("tmp/foo/$(SDK_NAME)/regular-intermediates"), indexPCHPath: Path.root.join("tmp/foo/$(SDK_NAME)/indexpch"), indexDataStoreFolderPath: Path.root.join("tmp/foo/$(SDK_NAME)/index"), indexEnableDataStore: true)
let parameters = BuildParameters(
action: .build,
configuration: "Debug",
arena: arena)
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject, target: testTarget)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
// Verify that indexing settings from the workspace arena are not exported
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.INDEX_REGULAR_BUILD_PRODUCTS_DIR))
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.INDEX_REGULAR_BUILD_INTERMEDIATES_DIR))
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.INDEX_PRECOMPS_DIR))
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.INDEX_DATA_STORE_DIR))
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.INDEX_ENABLE_DATA_STORE))
#expect(!settings.exportedMacroNames.contains(BuiltinMacros.INDEX_PRECOMPS_DIR))
let scope = settings.globalScope
let sdk = scope.evaluateAsString(BuiltinMacros.SDK_NAME)
#expect(scope.evaluateAsString(BuiltinMacros.INDEX_DATA_STORE_DIR) == Path.root.join("tmp/foo/\(sdk)/index").str)
#expect(scope.evaluateAsString(BuiltinMacros.INDEX_ENABLE_DATA_STORE) == "YES")
#expect(scope.evaluateAsString(BuiltinMacros.INDEX_PRECOMPS_DIR) == Path.root.join("tmp/foo/\(sdk)/indexpch").str)
}
@Test
func hostOperatingSystemVersionSettings() async throws {
let workspace = try await TestWorkspace("Workspace", projects: [TestProject("aProject", groupTree: TestGroup("SomeFiles", children: []))]).load(getCore())
// Check the values for modern macOS (v11+)
do {
let context = try await contextForTestData(workspace, systemInfo: SystemInfo(operatingSystemVersion: Version(11, 1, 2), productBuildVersion: "20C129", nativeArchitecture: "arm64e"))
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let parameters = BuildParameters(action: .build, configuration: "Debug")
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject)
#expect(settings.project === testProject)
#expect(settings.target === nil)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
if context.core.hostOperatingSystem == .macOS {
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MAJOR)?.expression.stringRep == "110000")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MINOR)?.expression.stringRep == "110100")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_ACTUAL)?.expression.stringRep == "110102")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_PRODUCT_BUILD_VERSION)?.expression.stringRep == "20C129")
}
else {
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MAJOR) == nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MINOR) == nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_ACTUAL) == nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_PRODUCT_BUILD_VERSION) == nil)
}
}
// Check the values for legacy macOS (v10.x)
do {
let context = try await contextForTestData(workspace, systemInfo: SystemInfo(operatingSystemVersion: Version(10, 15, 4), productBuildVersion: "19E287", nativeArchitecture: "x86_64h"))
let buildRequestContext = BuildRequestContext(workspaceContext: context)
let testProject = context.workspace.projects[0]
let parameters = BuildParameters(action: .build, configuration: "Debug")
let settings = Settings(workspaceContext: context, buildRequestContext: buildRequestContext, parameters: parameters, project: testProject)
#expect(settings.project === testProject)
#expect(settings.target === nil)
guard settings.errors.isEmpty else {
Issue.record("Errors creating settings: \(settings.errors)")
return
}
if context.core.hostOperatingSystem == .macOS {
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MAJOR)?.expression.stringRep == "101500")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MINOR)?.expression.stringRep == "1504")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_ACTUAL)?.expression.stringRep == "101504")
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_PRODUCT_BUILD_VERSION)?.expression.stringRep == "19E287")
}
else {
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MAJOR) == nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_MINOR) == nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_VERSION_ACTUAL) == nil)
#expect(settings.tableForTesting.lookupMacro(BuiltinMacros.MAC_OS_X_PRODUCT_BUILD_VERSION) == nil)
}
}
}
@Test(.requireSDKs(.macOS))
func SDKVersionSettings() async throws {
// Use a separate Core instance to avoid corrupting the state of other test cases
// due to the registration of temporary SDKs in this test case.
let core = try await Self.makeCore(simulatedInferiorProductsPath: simulatedInferiorProductsPath())
let macosx = try #require(core.platformRegistry.lookup(name: "macosx"), "could not load macosx platform")
// Construct the test project.
let testWorkspace = TestWorkspace("Workspace",
projects: [TestProject("aProject",
groupTree: TestGroup("SomeFiles", children: [TestFile("Mock.cpp")]),
buildConfigurations:[
TestBuildConfiguration("Debug", buildSettings: [:])
],
targets: [
TestStandardTarget("Target1",
type: .application,
buildConfigurations: [
TestBuildConfiguration("Debug", buildSettings: [:]
)],
buildPhases: [TestSourcesBuildPhase(["Mock.cpp"])]
),
])
])
let context = try await contextForTestData(testWorkspace, core: core)
let buildRequestContext = BuildRequestContext(workspaceContext: context)
// Create multiple SDKs
try await withTemporaryDirectory { sdksDirPath in
do {
let sdk = sdksDirPath.join("MacOSX11.1.2.sdk")
try await writeSDK(name: sdk.basename, parentDir: sdksDirPath, settings: [
"CanonicalName": "macosx11.1.2",
"IsBaseSDK": "YES",
"Version": "11.1.2",
"DefaultProperties": [
"PLATFORM_NAME": "macosx"
],
])
}
do {
let sdk = sdksDirPath.join("MacOSX10.15.4.sdk")
try await writeSDK(name: sdk.basename, parentDir: sdksDirPath, settings: [
"CanonicalName": "macosx10.15.4",
"IsBaseSDK": "YES",
"Version": "10.15.4",
"DefaultProperties": [
"PLATFORM_NAME": "macosx"
],
])
}