-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathCommandLineSpecTests.swift
2207 lines (1973 loc) · 158 KB
/
CommandLineSpecTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
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 SWBTestSupport
import SWBUtil
import enum SWBProtocol.ExternalToolResult
import struct SWBProtocol.BuildOperationTaskEnded
import SWBTaskExecution
import SWBMacro
@_spi(Testing) import SWBCore
@Suite fileprivate struct CommandLineSpecTests: CoreBasedTests {
@Test(.skipHostOS(.windows, "output parsing on Windows needs a lot of work"))
func genericOutputParser() async throws {
let delegate = CapturingTaskParserDelegate()
let task = OutputParserMockTask(basenames: ["ld", "yacc"], exec: "clang")
let core = try await getCore()
let workspaceContext = try WorkspaceContext(core: core, workspace: TestWorkspace("test", projects: []).load(core), processExecutionCache: .sharedForTesting)
let parser = GenericOutputParser(for: task, workspaceContext: workspaceContext, buildRequestContext: BuildRequestContext(workspaceContext: workspaceContext), delegate: delegate, progressReporter: nil)
parser.write(bytes: "foo bar\n")
parser.write(bytes: "error: is an error\n")
parser.write(bytes: " error: is another error\n")
parser.write(bytes: "NOT error: is not an error\n")
parser.write(bytes: "file: error: an error, no line\n")
parser.write(bytes: "file:1: error: an error, with line\n")
parser.write(bytes: "file:1:1: error: an error, with line & col\n")
parser.write(bytes: "file:12:13: error: an error with 2 fixits\n")
parser.write(bytes: "file:12:13-14:15: fixit: fixit \\\"#1\\u0022 text\n")
parser.write(bytes: "file:16:17-18:19: fixit: fixit \\f#2 text\n")
parser.write(bytes: "file: warning: a warning\n")
parser.write(bytes: "file: note: a note\n")
parser.write(bytes: "file: note: a different note\n")
parser.write(bytes: "../file: error: an error, no line\n")
parser.write(bytes: "../file:1: error: an error, with line\n")
parser.write(bytes: "../file:1:1: error: an error, with line & col\n")
parser.write(bytes: "../file:12:13: error: an error with 2 fixits\n")
parser.write(bytes: "../file:12:13-14:15: fixit: fixit \\\"#1\\u0022 text\n")
parser.write(bytes: "../file:16:17-18:19: fixit: fixit \\f#2 text\n")
parser.write(bytes: "../file: warning: a warning\n")
parser.write(bytes: "../file: note: a note\n")
parser.write(bytes: "../file: note: a different note\n")
parser.write(bytes: "ld: warning: linker can have warnings\n")
parser.write(bytes: "ld: linker doesn't like you\n")
parser.write(bytes: "/tmp/foo:/bar:/ld: linker with colons\n")
parser.write(bytes: "yacc: yacc doesn't like you either\n")
parser.write(bytes: "swiftc: swiftc shouldn't be an error\n")
parser.write(bytes: "/tmp/clang: clang is angry\n")
parser.write(bytes: "yacc : shouldn't match\n")
parser.write(bytes: "snazzle.ypp:30.15-17: warning: symbol INT redeclared\n")
parser.write(bytes: "snazzle.ypp:31.15-19: error: symbol FLOAT redeclared\n")
parser.write(bytes: "snazzle.ypp:32.15-20: note: symbol STRING redeclared\n")
parser.write(bytes: "\n")
parser.write(bytes: " \n")
parser.write(bytes: ":\n")
parser.write(bytes: "a:\n")
parser.write(bytes: "exprs.c:45:15:{45:8-45:14}{45:17-45:24}: error: invalid foobar...\n")
parser.close(result: nil)
DiagnosticsEngineTester(delegate.diagnosticsEngine) { result in
result.check(diagnostic: "is an error", behavior: .error)
result.check(diagnostic: "is another error", behavior: .error)
result.check(diagnostic: "an error, no line", behavior: .error, location: "/taskdir/file")
result.check(diagnostic: "an error, with line", behavior: .error, location: "/taskdir/file:1")
result.check(diagnostic: "an error, with line & col", behavior: .error, location: "/taskdir/file:1:1")
result.check(diagnostic: "an error with 2 fixits", behavior: .error, location: "/taskdir/file:12:13", fixItStrings: ["/taskdir/file:12:13-14:15: fixit: fixit \u{22}#1\u{22} text", "/taskdir/file:16:17-18:19: fixit: fixit \u{0c}#2 text"])
result.check(diagnostic: "a warning", behavior: .warning, location: "/taskdir/file")
result.check(diagnostic: "a note", behavior: .note, location: "/taskdir/file")
result.check(diagnostic: "a different note", behavior: .note, location: "/taskdir/file")
result.check(diagnostic: "an error, no line", behavior: .error, location: "/file")
result.check(diagnostic: "an error, with line", behavior: .error, location: "/file:1")
result.check(diagnostic: "an error, with line & col", behavior: .error, location: "/file:1:1")
result.check(diagnostic: "an error with 2 fixits", behavior: .error, location: "/file:12:13", fixItStrings: ["/file:12:13-14:15: fixit: fixit \u{22}#1\u{22} text", "/file:16:17-18:19: fixit: fixit \u{0c}#2 text"])
result.check(diagnostic: "a warning", behavior: .warning, location: "/file")
result.check(diagnostic: "a note", behavior: .note, location: "/file")
result.check(diagnostic: "a different note", behavior: .note, location: "/file")
result.check(diagnostic: "linker can have warnings", behavior: .warning)
result.check(diagnostic: "linker doesn't like you", behavior: .note)
result.check(diagnostic: "linker with colons", behavior: .note)
result.check(diagnostic: "yacc doesn't like you either", behavior: .note)
result.check(diagnostic: "clang is angry", behavior: .note)
result.check(diagnostic: "symbol INT redeclared", behavior: .warning)
result.check(diagnostic: "symbol FLOAT redeclared", behavior: .error)
result.check(diagnostic: "symbol STRING redeclared", behavior: .note)
result.check(diagnostic: "invalid foobar...", behavior: .error)
}
}
@Test(.skipHostOS(.windows, "output parsing needs some work"))
func shellScriptOutputParser() async throws {
let delegate = CapturingTaskParserDelegate()
let task = OutputParserMockTask(basenames: ["ld", "yacc"], exec: "clang")
let core = try await getCore()
let workspaceContext = try WorkspaceContext(core: core, workspace: TestWorkspace("test", projects: []).load(core), processExecutionCache: .sharedForTesting)
let parser = ShellScriptOutputParser(for: task, workspaceContext: workspaceContext, buildRequestContext: BuildRequestContext(workspaceContext: workspaceContext), delegate: delegate, progressReporter: nil)
parser.write(bytes: "make foo\n")
parser.write(bytes: "Compile foo.c\n")
parser.write(bytes: "file:1:1: warning: a warning with line and column numbers\n")
parser.write(bytes: "../file:1:1: warning: a warning with line and column numbers\n")
parser.write(bytes: "\n")
parser.write(bytes: "Link bar\n")
parser.write(bytes: "ld: warning: linker can have warnings\n")
parser.write(bytes: "ld: linker doesn't like you\n")
parser.write(bytes: " some other kind of text\n")
parser.write(bytes: ".\n")
parser.close(result: nil)
DiagnosticsEngineTester(delegate.diagnosticsEngine) { result in
result.check(diagnostic: "make foo", behavior: .note)
result.check(diagnostic: "Compile foo.c", behavior: .note)
result.check(diagnostic: "a warning with line and column numbers", behavior: .warning, location: "/taskdir/file:1:1")
result.check(diagnostic: "", behavior: .note)
result.check(diagnostic: "Link bar", behavior: .note)
result.check(diagnostic: "a warning with line and column numbers", behavior: .warning, location: "/file:1:1")
result.check(diagnostic: "linker can have warnings", behavior: .warning)
result.check(diagnostic: " some other kind of text", behavior: .note)
result.check(diagnostic: ".", behavior: .note)
result.check(diagnostic: "linker doesn't like you", behavior: .note)
}
}
@Test
func ldLinkerOutputParser() async throws {
let delegate = CapturingTaskParserDelegate()
let task = OutputParserMockTask(basenames: ["ld"], exec: "clang")
let core = try await getCore()
let workspaceContext = try WorkspaceContext(core: core, workspace: TestWorkspace("test", projects: []).load(core), processExecutionCache: .sharedForTesting)
let parser = LdLinkerOutputParser(for: task, workspaceContext: workspaceContext, buildRequestContext: BuildRequestContext(workspaceContext: workspaceContext), delegate: delegate, progressReporter: nil)
parser.write(bytes: "ld: ṣómething bad happened\n") // tests proper capitalization
parser.write(bytes: "ld: warning: heed my warning, Hapless Traveller\n") // tests proper capitalization
parser.write(bytes: "Undefined symbols for architecture z80:\n")
parser.write(bytes: " \"_println\", referenced from:\n")
parser.write(bytes: " _main in main.o\n")
parser.write(bytes: " \"_scanln\", referenced from:\n")
parser.write(bytes: " _func1 in file1.o\n")
parser.write(bytes: " _func2 in file2.o\n")
parser.write(bytes: " _func3 in file3.o\n")
parser.write(bytes: " \"_missing\", referenced from:\n")
parser.write(bytes: " -u command line option\n")
parser.write(bytes: " ...\n")
parser.write(bytes: "ld: symbol(s) not found for architecture z80\n")
parser.write(bytes: "clang: error: linker command failed with exit code 1 (use -v to see invocation)\n")
parser.close(result: nil)
DiagnosticsEngineTester(delegate.diagnosticsEngine) { result in
result.check(diagnostic: "Ṣómething bad happened", behavior: .error)
result.check(diagnostic: "Heed my warning, Hapless Traveller", behavior: .warning)
result.check(diagnostic: "Undefined symbol: _println", behavior: .error)
result.check(diagnostic: "Undefined symbol: _scanln", behavior: .error)
result.check(diagnostic: "Undefined symbol: _missing", behavior: .error)
result.check(diagnostic: "Linker command failed with exit code 1 (use -v to see invocation)", behavior: .error)
}
}
@Test(.requireHostOS(.macOS))
func swiftTaskConstruction() async throws {
let core = try await getCore()
let swiftSpec = try core.specRegistry.getSpec() as SwiftCompilerSpec
let headerSpec = try core.specRegistry.getSpec("com.apple.build-tools.swift-header-tool") as SwiftHeaderToolSpec
let swiftCompilerPath = try await self.swiftCompilerPath
// Create the mock table.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(BuiltinMacros.SWIFT_EXEC, literal: swiftCompilerPath.str)
try await table.push(BuiltinMacros.TAPI_EXEC, literal: self.tapiToolPath.str)
table.push(BuiltinMacros.COMPILER_WORKING_DIRECTORY, literal: Path.root.join("tmp/src").str)
table.push(BuiltinMacros.TARGET_NAME, literal: "App1")
let targetName = core.specRegistry.internalMacroNamespace.parseString("$(TARGET_NAME)")
table.push(BuiltinMacros.SWIFT_MODULE_NAME, targetName)
table.push(BuiltinMacros.PRODUCT_TYPE, literal: "com.apple.product-type.application")
table.push(BuiltinMacros.CURRENT_ARCH, literal: "x86_64")
table.push(BuiltinMacros.ARCHS, literal: ["x86_64"])
table.push(BuiltinMacros.CURRENT_VARIANT, literal: "normal")
table.push(BuiltinMacros.SWIFT_PLATFORM_TARGET_PREFIX, literal: "macos")
table.push(BuiltinMacros.DEPLOYMENT_TARGET_SETTING_NAME, literal: "MACOSX_DEPLOYMENT_TARGET")
table.push(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET, literal: "10.11")
table.push(BuiltinMacros.SWIFT_DEPLOYMENT_TARGET, core.specRegistry.internalMacroNamespace.parseString("$($(DEPLOYMENT_TARGET_SETTING_NAME))"))
table.push(BuiltinMacros.SWIFT_TARGET_TRIPLE, core.specRegistry.internalMacroNamespace.parseString("$(CURRENT_ARCH)-apple-$(SWIFT_PLATFORM_TARGET_PREFIX)$(SWIFT_DEPLOYMENT_TARGET)$(LLVM_TARGET_TRIPLE_SUFFIX)"))
table.push(BuiltinMacros.OBJECT_FILE_DIR, literal: Path.root.join("tmp/output/obj").str)
table.push(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR, BuiltinMacros.namespace.parseString(Path.root.join("tmp/output/obj-normal/x86_64").str))
table.push(BuiltinMacros.ENABLE_DEFAULT_SEARCH_PATHS, literal: true)
table.push(BuiltinMacros.BUILT_PRODUCTS_DIR, literal: Path.root.join("tmp/output/sym").str)
let builtProductsDirList = core.specRegistry.internalMacroNamespace.parseStringList("$(BUILT_PRODUCTS_DIR)")
table.push(BuiltinMacros.FRAMEWORK_SEARCH_PATHS, builtProductsDirList)
table.push(BuiltinMacros.PRODUCT_TYPE, literal: "com.apple.product-type.framework")
table.push(BuiltinMacros.PRODUCT_TYPE_FRAMEWORK_SEARCH_PATHS, literal: ["ProductTypeFwkPath"])
table.push(BuiltinMacros.DERIVED_FILE_DIR, literal: Path.root.join("tmp/output/obj/DerivedFiles").str)
table.push(BuiltinMacros.SWIFT_OBJC_INTERFACE_HEADER_NAME, literal: "App1-Swift.h")
table.push(BuiltinMacros.SWIFT_INSTALL_OBJC_HEADER, literal: true)
table.push(BuiltinMacros.SWIFT_RESPONSE_FILE_PATH, core.specRegistry.internalMacroNamespace.parseString("$(PER_ARCH_OBJECT_FILE_DIR)/$(TARGET_NAME).SwiftFileList"))
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE, literal: true)
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE_FOR_DEPLOYMENT, literal: true)
table.push(BuiltinMacros.SWIFT_ENABLE_EMIT_CONST_VALUES, literal: true)
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE_ABI_DESCRIPTOR, literal: true)
// remove in rdar://53000820
table.push(BuiltinMacros.USE_SWIFT_RESPONSE_FILE, literal: true)
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let inputFiles = [FileToBuild(absolutePath: Path.root.join("tmp/one.swift"), fileType: mockFileType), FileToBuild(absolutePath: Path.root.join("tmp/two.swift"), fileType: mockFileType)]
let archSpec = try core.specRegistry.getSpec("x86_64", domain: "macosx") as ArchitectureSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: inputFiles, currentArchSpec: archSpec, output: nil)
await swiftSpec.constructTasks(cbc, delegate)
headerSpec.constructSwiftHeaderToolTask(cbc, delegate, inputs: delegate.generatedSwiftObjectiveCHeaderFiles(), outputPath: Path("App1-Swift.h"))
#expect(delegate.shellTasks.count == 8)
// The Swift response file should be constructed
do {
let task = try #require(delegate.shellTasks[safe: 0])
#expect(task.ruleInfo == ["WriteAuxiliaryFile", "/tmp/output/obj-normal/x86_64/App1.SwiftFileList"])
#expect(task.execDescription == "Write App1.SwiftFileList (x86_64)")
}
// We should construct the output file map.
do {
let task = try #require(delegate.shellTasks[safe: 1])
#expect(task.ruleInfo == ["WriteAuxiliaryFile", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json"])
#expect(task.execDescription == "Write App1-OutputFileMap.json (x86_64)")
}
// Check the compile task.
do {
let task = try #require(delegate.shellTasks[safe: 2])
#expect(task.ruleInfo == ["CompileSwiftSources", "normal", "x86_64", "com.apple.xcode.tools.swift.compiler"])
#expect(task.execDescription == "Compile Swift source files (x86_64)")
var additionalCommandLineArgs = [String]()
if let swiftABIVersion = await (swiftSpec.discoveredCommandLineToolSpecInfo(producer, mockScope, delegate) as? DiscoveredSwiftCompilerToolSpecInfo)?.swiftABIVersion {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift-\(swiftABIVersion)"]
}
else {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift"]
}
// FIXME: Temporary paper over expected output change.
if task.commandLine.contains("-disable-bridging-pch") {
task.checkCommandLine([swiftCompilerPath.str, "-disable-bridging-pch", "-module-name", "App1", "-Xfrontend", "-disable-all-autolinking", "@/tmp/output/obj-normal/x86_64/App1.SwiftFileList", "-target", "x86_64-apple-macos10.11", "-Xfrontend", "-no-serialize-debugging-options", "-F", "/tmp/output/sym", "-F", "ProductTypeFwkPath", "-c", "-j\(SwiftCompilerSpec.parallelismLevel)", "-disable-batch-mode", "-output-file-map", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json", "-parseable-output", "-serialize-diagnostics", "-emit-dependencies", "-emit-module", "-emit-module-path", "/tmp/output/obj-normal/x86_64/App1.swiftmodule", "-Xcc", "-Iswift-overrides.hmap", "-Xcc", "-I/tmp/output/obj/DerivedFiles-normal/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles", "-emit-objc-header", "-emit-objc-header-path", "/tmp/output/obj-normal/x86_64/App1-Swift.h", "-working-directory", "/tmp/src"])
} else {
task.checkCommandLine([swiftCompilerPath.str, "-module-name", "App1", "@/tmp/output/obj-normal/x86_64/App1.SwiftFileList", "-target", "x86_64-apple-macos10.11", "-F", "/tmp/output/sym", "-F", "ProductTypeFwkPath", "-c", "-j\(SwiftCompilerSpec.parallelismLevel)", "-output-file-map", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json", "-parseable-output", "-serialize-diagnostics", "-emit-dependencies", "-emit-module", "-emit-module-path", "/tmp/output/obj-normal/x86_64/App1.swiftmodule", "-Xcc", "-Iswift-overrides.hmap", "-Xcc", "-I/tmp/output/obj/DerivedFiles/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles", "-emit-objc-header", "-emit-objc-header-path", "/tmp/output/obj-normal/x86_64/App1-Swift.h", "-working-directory", "/tmp/src"] + additionalCommandLineArgs)
}
task.checkInputs([
.path("/tmp/one.swift"),
.path("/tmp/two.swift"),
.path("/tmp/output/obj-normal/x86_64/App1.SwiftFileList"),
.path("/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json")
])
task.checkOutputs([
.path("/tmp/output/obj-normal/x86_64/one.o"),
.path("/tmp/output/obj-normal/x86_64/two.o"),
.path("/tmp/output/obj-normal/x86_64/one.swiftconstvalues"),
.path("/tmp/output/obj-normal/x86_64/two.swiftconstvalues"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftmodule"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftsourceinfo"),
.path("/tmp/output/obj-normal/x86_64/App1.abi.json"),
.path("/tmp/output/obj-normal/x86_64/App1-Swift.h"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftdoc")
])
}
// We should have copy commands to move the arch-specific outputs.
do {
let task = try #require(delegate.shellTasks[safe: 3])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/x86_64-apple-macos.swiftmodule", "/tmp/output/obj-normal/x86_64/App1.swiftmodule"])
#expect(task.execDescription == "Copy App1.swiftmodule (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 4])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/x86_64-apple-macos.abi.json", "/tmp/output/obj-normal/x86_64/App1.abi.json"])
#expect(task.execDescription == "Copy App1.abi.json (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 5])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/Project/x86_64-apple-macos.swiftsourceinfo", "/tmp/output/obj-normal/x86_64/App1.swiftsourceinfo"])
#expect(task.execDescription == "Copy App1.swiftsourceinfo (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 6])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/x86_64-apple-macos.swiftdoc", "/tmp/output/obj-normal/x86_64/App1.swiftdoc"])
#expect(task.execDescription == "Copy App1.swiftdoc (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 7])
#expect(task.ruleInfo == ["SwiftMergeGeneratedHeaders", "App1-Swift.h", "/tmp/output/obj-normal/x86_64/App1-Swift.h"])
#expect(task.execDescription == "Merge Objective-C generated interface headers")
}
// Check that we put the generated header in the right place, if not installing it.
do {
table.push(BuiltinMacros.SWIFT_INSTALL_OBJC_HEADER, literal: false)
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let inputFiles = [FileToBuild(absolutePath: Path.root.join("tmp/one.swift"), fileType: mockFileType), FileToBuild(absolutePath: Path.root.join("tmp/two.swift"), fileType: mockFileType)]
let archSpec = try core.specRegistry.getSpec("x86_64", domain: "macosx") as ArchitectureSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: inputFiles, currentArchSpec: archSpec, output: nil)
await swiftSpec.constructTasks(cbc, delegate)
headerSpec.constructSwiftHeaderToolTask(cbc, delegate, inputs: delegate.generatedSwiftObjectiveCHeaderFiles(), outputPath: Path.root.join("tmp/output/obj/DerivedFiles/App1-Swift.h"))
do {
let task = try #require(delegate.shellTasks[safe: 7])
#expect(task.ruleInfo == ["SwiftMergeGeneratedHeaders", "/tmp/output/obj/DerivedFiles/App1-Swift.h", "/tmp/output/obj-normal/x86_64/App1-Swift.h"])
}
}
}
@Test(.requireHostOS(.macOS), .requireLLBuild(apiVersion: 12))
func swiftTaskConstruction_integratedDriver() async throws {
let core = try await getCore()
let swiftSpec = try core.specRegistry.getSpec() as SwiftCompilerSpec
let headerSpec = try core.specRegistry.getSpec("com.apple.build-tools.swift-header-tool") as SwiftHeaderToolSpec
let swiftCompilerPath = try await self.swiftCompilerPath
// Create the mock table.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(BuiltinMacros.SWIFT_EXEC, literal: swiftCompilerPath.str)
try await table.push(BuiltinMacros.TAPI_EXEC, literal: self.tapiToolPath.str)
table.push(BuiltinMacros.COMPILER_WORKING_DIRECTORY, literal: "/tmp/src")
table.push(BuiltinMacros.TARGET_NAME, literal: "App1")
let targetName = core.specRegistry.internalMacroNamespace.parseString("$(TARGET_NAME)")
table.push(BuiltinMacros.PRODUCT_NAME, targetName)
table.push(BuiltinMacros.SWIFT_MODULE_NAME, targetName)
table.push(BuiltinMacros.PRODUCT_TYPE, literal: "com.apple.product-type.application")
table.push(BuiltinMacros.CURRENT_ARCH, literal: "x86_64")
table.push(BuiltinMacros.ARCHS, literal: ["x86_64"])
table.push(BuiltinMacros.CURRENT_VARIANT, literal: "normal")
table.push(BuiltinMacros.SWIFT_PLATFORM_TARGET_PREFIX, literal: "macos")
table.push(BuiltinMacros.DEPLOYMENT_TARGET_SETTING_NAME, literal: "MACOSX_DEPLOYMENT_TARGET")
table.push(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET, literal: "10.11")
table.push(BuiltinMacros.SWIFT_DEPLOYMENT_TARGET, core.specRegistry.internalMacroNamespace.parseString("$($(DEPLOYMENT_TARGET_SETTING_NAME))"))
table.push(BuiltinMacros.SWIFT_TARGET_TRIPLE, core.specRegistry.internalMacroNamespace.parseString("$(CURRENT_ARCH)-apple-$(SWIFT_PLATFORM_TARGET_PREFIX)$(SWIFT_DEPLOYMENT_TARGET)$(LLVM_TARGET_TRIPLE_SUFFIX)"))
table.push(BuiltinMacros.OBJECT_FILE_DIR, literal: "/tmp/output/obj")
table.push(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR, BuiltinMacros.namespace.parseString("/tmp/output/obj-normal/x86_64"))
table.push(BuiltinMacros.ENABLE_DEFAULT_SEARCH_PATHS, literal: true)
table.push(BuiltinMacros.BUILT_PRODUCTS_DIR, literal: "/tmp/output/sym")
let builtProductsDirList = core.specRegistry.internalMacroNamespace.parseStringList("$(BUILT_PRODUCTS_DIR)")
table.push(BuiltinMacros.FRAMEWORK_SEARCH_PATHS, builtProductsDirList)
table.push(BuiltinMacros.PRODUCT_TYPE, literal: "com.apple.product-type.framework")
table.push(BuiltinMacros.PRODUCT_TYPE_FRAMEWORK_SEARCH_PATHS, literal: ["ProductTypeFwkPath"])
table.push(BuiltinMacros.DERIVED_FILE_DIR, literal: "/tmp/output/obj/DerivedFiles")
table.push(BuiltinMacros.SWIFT_OBJC_INTERFACE_HEADER_NAME, literal: "App1-Swift.h")
table.push(BuiltinMacros.SWIFT_INSTALL_OBJC_HEADER, literal: true)
table.push(BuiltinMacros.SWIFT_RESPONSE_FILE_PATH, core.specRegistry.internalMacroNamespace.parseString("$(PER_ARCH_OBJECT_FILE_DIR)/$(TARGET_NAME).SwiftFileList"))
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE, literal: true)
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE_FOR_DEPLOYMENT, literal: true)
table.push(BuiltinMacros.SWIFT_USE_INTEGRATED_DRIVER, literal: true)
table.push(BuiltinMacros.SWIFT_ENABLE_EMIT_CONST_VALUES, literal: true)
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE_ABI_DESCRIPTOR, literal: true)
// remove in rdar://53000820
table.push(BuiltinMacros.USE_SWIFT_RESPONSE_FILE, literal: true)
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let inputFiles = [FileToBuild(absolutePath: Path.root.join("tmp/one.swift"), fileType: mockFileType), FileToBuild(absolutePath: Path.root.join("tmp/two.swift"), fileType: mockFileType)]
let archSpec = try core.specRegistry.getSpec("x86_64", domain: "macosx") as ArchitectureSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: inputFiles, currentArchSpec: archSpec, output: nil)
await swiftSpec.constructTasks(cbc, delegate)
headerSpec.constructSwiftHeaderToolTask(cbc, delegate, inputs: delegate.generatedSwiftObjectiveCHeaderFiles(), outputPath: Path("App1-Swift.h"))
#expect(delegate.shellTasks.count == 9)
// The Swift response file should be constructed
do {
let task = try #require(delegate.shellTasks[safe: 0])
#expect(task.ruleInfo == ["WriteAuxiliaryFile", "/tmp/output/obj-normal/x86_64/App1.SwiftFileList"])
#expect(task.execDescription == "Write App1.SwiftFileList (x86_64)")
}
// We should construct the output file map.
do {
let task = try #require(delegate.shellTasks[safe: 1])
#expect(task.ruleInfo == ["WriteAuxiliaryFile", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json"])
#expect(task.execDescription == "Write App1-OutputFileMap.json (x86_64)")
}
// Check the compilation requirements
do {
let task = try #require(delegate.shellTasks[safe: 2])
#expect(task.ruleInfo == ["SwiftDriver Compilation Requirements", "App1", "normal", "x86_64", "com.apple.xcode.tools.swift.compiler"])
#expect(task.execDescription == "Unblock downstream dependents of App1 (x86_64)")
var additionalCommandLineArgs = [String]()
if let swiftABIVersion = await (swiftSpec.discoveredCommandLineToolSpecInfo(producer, mockScope, delegate) as? DiscoveredSwiftCompilerToolSpecInfo)?.swiftABIVersion {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift-\(swiftABIVersion)"]
}
else {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift"]
}
task.checkCommandLine(["builtin-Swift-Compilation-Requirements", "--", swiftCompilerPath.str, "-disable-bridging-pch", "-module-name", "App1", "-Xfrontend", "-disable-all-autolinking", "@/tmp/output/obj-normal/x86_64/App1.SwiftFileList", "-target", "x86_64-apple-macos10.11", "-Xfrontend", "-no-serialize-debugging-options", "-F", "/tmp/output/sym", "-F", "ProductTypeFwkPath", "-c", "-j\(SwiftCompilerSpec.parallelismLevel)", "-disable-batch-mode", "-output-file-map", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json", "-use-frontend-parseable-output", "-save-temps", "-no-color-diagnostics", "-serialize-diagnostics", "-emit-dependencies", "-emit-module", "-emit-module-path", "/tmp/output/obj-normal/x86_64/App1.swiftmodule", "-Xcc", "-Iswift-overrides.hmap", "-Xcc", "-I/tmp/output/obj/DerivedFiles-normal/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles", "-emit-objc-header", "-emit-objc-header-path", "/tmp/output/obj-normal/x86_64/App1-Swift.h", "-working-directory", "/tmp/src", "-experimental-emit-module-separately", "-disable-cmo"])
task.checkInputs([
.path("/tmp/one.swift"),
.path("/tmp/two.swift"),
.path("/tmp/output/obj-normal/x86_64/App1.SwiftFileList"),
.path("/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json"),
])
task.checkOutputs([
.path("/tmp/output/obj-normal/x86_64/App1 Swift Compilation Requirements Finished"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftmodule"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftsourceinfo"),
.path("/tmp/output/obj-normal/x86_64/App1.abi.json"),
.path("/tmp/output/obj-normal/x86_64/App1-Swift.h"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftdoc")
])
}
// Check the compilation
do {
let task = delegate.shellTasks[3]
#expect(task.ruleInfo == ["SwiftDriver Compilation", "App1", "normal", "x86_64", "com.apple.xcode.tools.swift.compiler"])
#expect(task.execDescription == "Compile App1 (x86_64)")
var additionalCommandLineArgs = [String]()
if let swiftABIVersion = await (swiftSpec.discoveredCommandLineToolSpecInfo(producer, mockScope, delegate) as? DiscoveredSwiftCompilerToolSpecInfo)?.swiftABIVersion {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift-\(swiftABIVersion)"]
}
else {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift"]
}
task.checkCommandLine(["builtin-Swift-Compilation", "--", swiftCompilerPath.str, "-disable-bridging-pch", "-module-name", "App1", "-Xfrontend", "-disable-all-autolinking", "@/tmp/output/obj-normal/x86_64/App1.SwiftFileList", "-target", "x86_64-apple-macos10.11", "-Xfrontend", "-no-serialize-debugging-options", "-F", "/tmp/output/sym", "-F", "ProductTypeFwkPath", "-c", "-j\(SwiftCompilerSpec.parallelismLevel)", "-disable-batch-mode", "-output-file-map", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json", "-use-frontend-parseable-output", "-save-temps", "-no-color-diagnostics", "-serialize-diagnostics", "-emit-dependencies", "-emit-module", "-emit-module-path", "/tmp/output/obj-normal/x86_64/App1.swiftmodule", "-Xcc", "-Iswift-overrides.hmap", "-Xcc", "-I/tmp/output/obj/DerivedFiles-normal/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles", "-emit-objc-header", "-emit-objc-header-path", "/tmp/output/obj-normal/x86_64/App1-Swift.h", "-working-directory", "/tmp/src", "-experimental-emit-module-separately", "-disable-cmo"])
task.checkInputs([
.path("/tmp/one.swift"),
.path("/tmp/two.swift"),
.path("/tmp/output/obj-normal/x86_64/App1.SwiftFileList"),
.path("/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json"),
])
task.checkOutputs([
.path("/tmp/output/obj-normal/x86_64/App1 Swift Compilation Finished"),
.path("/tmp/output/obj-normal/x86_64/one.o"),
.path("/tmp/output/obj-normal/x86_64/two.o"),
.path("/tmp/output/obj-normal/x86_64/one.swiftconstvalues"),
.path("/tmp/output/obj-normal/x86_64/two.swiftconstvalues"),
])
}
// We should have copy commands to move the arch-specific outputs.
do {
let task = try #require(delegate.shellTasks[safe: 4])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/x86_64-apple-macos.swiftmodule", "/tmp/output/obj-normal/x86_64/App1.swiftmodule"])
#expect(task.execDescription == "Copy App1.swiftmodule (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 5])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/x86_64-apple-macos.abi.json", "/tmp/output/obj-normal/x86_64/App1.abi.json"])
#expect(task.execDescription == "Copy App1.abi.json (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 6])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/Project/x86_64-apple-macos.swiftsourceinfo", "/tmp/output/obj-normal/x86_64/App1.swiftsourceinfo"])
#expect(task.execDescription == "Copy App1.swiftsourceinfo (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 7])
#expect(task.ruleInfo == ["Copy", "App1.swiftmodule/x86_64-apple-macos.swiftdoc", "/tmp/output/obj-normal/x86_64/App1.swiftdoc"])
#expect(task.execDescription == "Copy App1.swiftdoc (x86_64)")
}
do {
let task = try #require(delegate.shellTasks[safe: 8])
#expect(task.ruleInfo == ["SwiftMergeGeneratedHeaders", "App1-Swift.h", "/tmp/output/obj-normal/x86_64/App1-Swift.h"])
#expect(task.execDescription == "Merge Objective-C generated interface headers")
}
// Check that we put the generated header in the right place, if not installing it.
do {
table.push(BuiltinMacros.SWIFT_INSTALL_OBJC_HEADER, literal: false)
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let inputFiles = [FileToBuild(absolutePath: Path.root.join("tmp/one.swift"), fileType: mockFileType), FileToBuild(absolutePath: Path.root.join("tmp/two.swift"), fileType: mockFileType)]
let archSpec = try core.specRegistry.getSpec("x86_64", domain: "macosx") as ArchitectureSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: inputFiles, currentArchSpec: archSpec, output: nil)
await swiftSpec.constructTasks(cbc, delegate)
headerSpec.constructSwiftHeaderToolTask(cbc, delegate, inputs: delegate.generatedSwiftObjectiveCHeaderFiles(), outputPath: Path.root.join("tmp/output/obj/DerivedFiles/App1-Swift.h"))
do {
let task = try #require(delegate.shellTasks[safe: 8])
#expect(task.ruleInfo == ["SwiftMergeGeneratedHeaders", "/tmp/output/obj/DerivedFiles/App1-Swift.h", "/tmp/output/obj-normal/x86_64/App1-Swift.h"])
}
}
}
// remove in rdar://53000820
@Test(.requireSDKs(.macOS))
func swiftTaskConstructionWithoutResponseFile() async throws {
let core = try await getCore()
let swiftSpec = try core.specRegistry.getSpec() as SwiftCompilerSpec
let headerSpec = try core.specRegistry.getSpec("com.apple.build-tools.swift-header-tool") as SwiftHeaderToolSpec
let swiftCompilerPath = try await self.swiftCompilerPath
// Create the mock table.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(BuiltinMacros.SWIFT_EXEC, literal: swiftCompilerPath.str)
try await table.push(BuiltinMacros.TAPI_EXEC, literal: self.tapiToolPath.str)
table.push(BuiltinMacros.COMPILER_WORKING_DIRECTORY, literal: "/tmp/src")
table.push(BuiltinMacros.TARGET_NAME, literal: "App1")
let targetName = core.specRegistry.internalMacroNamespace.parseString("$(TARGET_NAME)")
table.push(BuiltinMacros.SWIFT_MODULE_NAME, targetName)
table.push(BuiltinMacros.PRODUCT_TYPE, literal: "com.apple.product-type.application")
table.push(BuiltinMacros.CURRENT_ARCH, literal: "x86_64")
table.push(BuiltinMacros.ARCHS, literal: ["x86_64"])
table.push(BuiltinMacros.CURRENT_VARIANT, literal: "normal")
table.push(BuiltinMacros.SWIFT_PLATFORM_TARGET_PREFIX, literal: "macos")
table.push(BuiltinMacros.DEPLOYMENT_TARGET_SETTING_NAME, literal: "MACOSX_DEPLOYMENT_TARGET")
table.push(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET, literal: "10.11")
table.push(BuiltinMacros.SWIFT_DEPLOYMENT_TARGET, core.specRegistry.internalMacroNamespace.parseString("$($(DEPLOYMENT_TARGET_SETTING_NAME))"))
table.push(BuiltinMacros.SWIFT_TARGET_TRIPLE, core.specRegistry.internalMacroNamespace.parseString("$(CURRENT_ARCH)-apple-$(SWIFT_PLATFORM_TARGET_PREFIX)$(SWIFT_DEPLOYMENT_TARGET)$(LLVM_TARGET_TRIPLE_SUFFIX)"))
table.push(BuiltinMacros.OBJECT_FILE_DIR, literal: "/tmp/output/obj")
table.push(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR, BuiltinMacros.namespace.parseString("/tmp/output/obj-normal/x86_64"))
table.push(BuiltinMacros.ENABLE_DEFAULT_SEARCH_PATHS, literal: true)
table.push(BuiltinMacros.BUILT_PRODUCTS_DIR, literal: "/tmp/output/sym")
let builtProductsDirList = core.specRegistry.internalMacroNamespace.parseStringList("$(BUILT_PRODUCTS_DIR)")
table.push(BuiltinMacros.FRAMEWORK_SEARCH_PATHS, builtProductsDirList)
table.push(BuiltinMacros.PRODUCT_TYPE, literal: "com.apple.product-type.framework")
table.push(BuiltinMacros.PRODUCT_TYPE_FRAMEWORK_SEARCH_PATHS, literal: ["ProductTypeFwkPath"])
table.push(BuiltinMacros.DERIVED_FILE_DIR, literal: "/tmp/output/obj/DerivedFiles")
table.push(BuiltinMacros.SWIFT_OBJC_INTERFACE_HEADER_NAME, literal: "App1-Swift.h")
table.push(BuiltinMacros.SWIFT_INSTALL_OBJC_HEADER, literal: true)
table.push(BuiltinMacros.USE_SWIFT_RESPONSE_FILE, literal: false)
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE, literal: true)
table.push(BuiltinMacros.SWIFT_ENABLE_EMIT_CONST_VALUES, literal: true)
table.push(BuiltinMacros.SWIFT_INSTALL_MODULE_ABI_DESCRIPTOR, literal: true)
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let inputFiles = [FileToBuild(absolutePath: Path.root.join("tmp/one.swift"), fileType: mockFileType), FileToBuild(absolutePath: Path.root.join("tmp/two.swift"), fileType: mockFileType)]
let archSpec = try core.specRegistry.getSpec("x86_64", domain: "macosx") as ArchitectureSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: inputFiles, currentArchSpec: archSpec, output: nil)
await swiftSpec.constructTasks(cbc, delegate)
headerSpec.constructSwiftHeaderToolTask(cbc, delegate, inputs: delegate.generatedSwiftObjectiveCHeaderFiles(), outputPath: Path("App1-Swift.h"))
#expect(delegate.shellTasks.count == 7)
// Check the compile task.
do {
let task = try #require(delegate.shellTasks[safe: 1])
#expect(task.ruleInfo == ["CompileSwiftSources", "normal", "x86_64", "com.apple.xcode.tools.swift.compiler"])
#expect(task.execDescription == "Compile Swift source files (x86_64)")
var additionalCommandLineArgs = [String]()
if let swiftABIVersion = await (swiftSpec.discoveredCommandLineToolSpecInfo(producer, mockScope, delegate) as? DiscoveredSwiftCompilerToolSpecInfo)?.swiftABIVersion {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift-\(swiftABIVersion)"]
}
else {
additionalCommandLineArgs += ["-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift"]
}
// FIXME: Temporary paper over expected output change.
if task.commandLine.contains("-disable-bridging-pch") {
task.checkCommandLine([swiftCompilerPath.str, "-disable-bridging-pch", "-module-name", "App1", "-Xfrontend", "-disable-all-autolinking", "-target", "x86_64-apple-macos10.11", "-Xfrontend", "-no-serialize-debugging-options", "-F", "/tmp/output/sym", "-F", "ProductTypeFwkPath", "-c", "-j\(SwiftCompilerSpec.parallelismLevel)", "-disable-batch-mode", "-output-file-map", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json", "-parseable-output", "-serialize-diagnostics", "-emit-dependencies", "-emit-module", "-emit-module-path", "/tmp/output/obj-normal/x86_64/App1.swiftmodule", "-Xcc", "-Iswift-overrides.hmap", "-Xcc", "-I/tmp/output/obj/DerivedFiles-normal/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles", "-emit-objc-header", "-emit-objc-header-path", "/tmp/output/obj-normal/x86_64/App1-Swift.h", "-working-directory", "/tmp/src", "/tmp/one.swift", "/tmp/two.swift"])
} else {
task.checkCommandLine([swiftCompilerPath.str, "-module-name", "App1", "-target", "x86_64-apple-macos10.11", "-F", "/tmp/output/sym", "-F", "ProductTypeFwkPath", "-c", "-j\(SwiftCompilerSpec.parallelismLevel)", "-output-file-map", "/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json", "-parseable-output", "-serialize-diagnostics", "-emit-dependencies", "-emit-module", "-emit-module-path", "/tmp/output/obj-normal/x86_64/App1.swiftmodule", "-Xcc", "-Iswift-overrides.hmap", "-Xcc", "-I/tmp/output/obj/DerivedFiles/x86_64", "-Xcc", "-I/tmp/output/obj/DerivedFiles", "-emit-objc-header", "-emit-objc-header-path", "/tmp/output/obj-normal/x86_64/App1-Swift.h", "-working-directory", "/tmp/src"] + additionalCommandLineArgs + ["/tmp/one.swift", "/tmp/two.swift"])
}
task.checkInputs([
.path("/tmp/one.swift"),
.path("/tmp/two.swift"),
.path("/tmp/output/obj-normal/x86_64/App1-OutputFileMap.json")
])
task.checkOutputs([
.path("/tmp/output/obj-normal/x86_64/one.o"),
.path("/tmp/output/obj-normal/x86_64/two.o"),
.path("/tmp/output/obj-normal/x86_64/one.swiftconstvalues"),
.path("/tmp/output/obj-normal/x86_64/two.swiftconstvalues"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftmodule"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftsourceinfo"),
.path("/tmp/output/obj-normal/x86_64/App1.abi.json"),
.path("/tmp/output/obj-normal/x86_64/App1-Swift.h"),
.path("/tmp/output/obj-normal/x86_64/App1.swiftdoc")
])
}
}
@Test(.skipHostOS(.windows, "tmp/not-mainone.swift not in command line"))
func singleFileSwiftTaskConstruction() async throws {
let core = try await getCore()
let swiftSpec = try core.specRegistry.getSpec() as SwiftCompilerSpec
// Create the mock table.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
try await table.push(BuiltinMacros.SWIFT_EXEC, literal: self.swiftCompilerPath.str)
if core.hostOperatingSystem == .macOS {
try await table.push(BuiltinMacros.TAPI_EXEC, literal: self.tapiToolPath.str)
}
table.push(BuiltinMacros.TARGET_NAME, literal: "App1")
table.push(BuiltinMacros.BUILT_PRODUCTS_DIR, literal: Path.root.join("build").str)
table.push(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR, literal: Path.root.join("build/objects").str)
table.push(BuiltinMacros.SWIFT_MODULE_NAME, literal: "MyModule")
table.push(BuiltinMacros.SWIFT_RESPONSE_FILE_PATH, core.specRegistry.internalMacroNamespace.parseString("$(PER_ARCH_OBJECT_FILE_DIR)/$(TARGET_NAME).SwiftFileList"))
// remove in rdar://53000820
table.push(BuiltinMacros.USE_SWIFT_RESPONSE_FILE, literal: true)
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let inputFiles = [FileToBuild(absolutePath: Path.root.join("tmp/not-mainone.swift"), fileType: mockFileType)]
let archSpec = try core.specRegistry.getSpec("x86_64", domain: "macosx") as ArchitectureSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: inputFiles, currentArchSpec: archSpec, output: nil)
await swiftSpec.constructTasks(cbc, delegate)
// Get the Swift task itself.
let tasks = delegate.shellTasks.filter { $0.ruleInfo[0] == "CompileSwiftSources" }
#expect(tasks.count == 1)
let swiftTask = try #require(tasks.only)
#expect(swiftTask.execDescription == "Compile Swift source files")
// Verify we passed -parse-as-library
#expect(swiftTask.commandLine.contains("-parse-as-library"), "\(swiftTask.commandLine)")
#expect(swiftTask.commandLine.contains(where: { $0.asString.replacingOccurrences(of: "\\", with: "/") == "@" + Path.root.join("build/objects/App1.SwiftFileList").str }), "\(swiftTask.commandLine)")
#expect(!swiftTask.commandLine.contains(.literal(ByteString(encodingAsUTF8: Path.root.join("tmp/not-mainone.swift").str))), "\(swiftTask.commandLine)")
// Check that we created the Swift response file
#expect(delegate.shellTasks.contains { $0.ruleInfo == ["WriteAuxiliaryFile", "/build/objects/App1.SwiftFileList"] })
}
@Test
func stripTaskConstruction() async throws {
let core = try await getCore()
let stripSpec = try core.specRegistry.getSpec("com.apple.build-tools.strip") as CommandLineToolSpec
// Create the mock table.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("STRIP_STYLE") as! EnumMacroDeclaration<StripStyle>, literal: .debugging)
table.push(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("STRIPFLAGS") as! StringListMacroDeclaration, literal: ["-foo", "-bar"])
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: [FileToBuild(absolutePath: Path.root.join("tmp/input"), fileType: mockFileType)], output: Path.root.join("tmp/output"))
await stripSpec.constructTasks(cbc, delegate)
// There should be exactly one shell task.
#expect(delegate.shellTasks.count == 1)
let task = try #require(delegate.shellTasks[safe: 0])
#expect(task.ruleInfo == ["Strip", Path.root.join("tmp/input").str])
#expect(task.execDescription == "Strip input")
// FIXME: We aren't handling the list type correctly yet.
task.checkCommandLine(["strip", "-S", "-foo", "-bar", Path.root.join("tmp/input").str])
}
@Test(.requireSDKs(.macOS))
func swiftStdlibTool() async throws {
let core = try await getCore()
let stdlibTool = try core.specRegistry.getSpec("com.apple.build-tools.swift-stdlib-tool") as SwiftStdLibToolSpec
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(BuiltinMacros.CODESIGN_ALLOCATE, literal: "/path/to/codesign_allocate")
table.push(BuiltinMacros.WRAPPER_NAME, literal: "wrapper")
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.application", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: [FileToBuild(absolutePath: Path.root.join("tmp/input"), fileType: mockFileType)], output: nil)
// Check that task construction sets the correct env bindings.
await stdlibTool.constructSwiftStdLibraryToolTask(cbc, delegate, foldersToScan: nil, filterForSwiftOS: false, backDeploySwiftConcurrency: false)
#expect(delegate.shellTasks.count == 1)
let task = try #require(delegate.shellTasks[safe: 0])
#expect(task.environment.bindingsDictionary == ["CODESIGN_ALLOCATE": "/path/to/codesign_allocate"])
#expect(task.execDescription == "Copy Swift standard libraries into wrapper")
}
@Test
func dsymutilTaskConstruction() async throws {
let core = try await getCore()
let dsymutilSpec = try core.specRegistry.getSpec("com.apple.tools.dsymutil") as DsymutilToolSpec
do {
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("DSYMUTIL_VERBOSE") as! BooleanMacroDeclaration, literal: false)
table.push(BuiltinMacros.DWARF_DSYM_FOLDER_PATH, literal: Path.root.join("tmp").str)
table.push(BuiltinMacros.DWARF_DSYM_FILE_NAME, literal: "output.dSYM")
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: [FileToBuild(absolutePath: Path.root.join("tmp/input"), fileType: mockFileType)], output: Path.root.join("tmp/output"))
await dsymutilSpec.constructTasks(cbc, delegate, dsymBundle: Path.root.join("tmp/output.dSYM"))
// There should be exactly one shell task.
#expect(delegate.shellTasks.count == 1)
let task = try #require(delegate.shellTasks[safe: 0])
#expect(task.ruleInfo == ["GenerateDSYMFile", Path.root.join("tmp/output.dSYM").str, Path.root.join("tmp/input").str])
#expect(task.execDescription == "Generate output.dSYM for input")
task.checkCommandLine(["dsymutil", Path.root.join("tmp/input").str, "-o", Path.root.join("tmp/output.dSYM").str])
// FIXME: Check the inputs and outputs.
}
do {
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
table.push(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("DSYMUTIL_VERBOSE") as! BooleanMacroDeclaration, literal: true)
table.push(BuiltinMacros.DWARF_DSYM_FOLDER_PATH, literal: "/tmp")
table.push(BuiltinMacros.DWARF_DSYM_FILE_NAME, literal: "output.dSYM")
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("file") as FileTypeSpec
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: [FileToBuild(absolutePath: Path.root.join("tmp/input"), fileType: mockFileType)], output: Path.root.join("tmp/output"))
await dsymutilSpec.constructTasks(cbc, delegate, dsymBundle: Path.root.join("tmp/output.dSYM"))
// There should be exactly one shell task.
#expect(delegate.shellTasks.count == 1)
let task = try #require(delegate.shellTasks[safe: 0])
#expect(task.ruleInfo == ["GenerateDSYMFile", Path.root.join("tmp/output.dSYM").str, Path.root.join("tmp/input").str])
#expect(task.execDescription == "Generate output.dSYM for input")
task.checkCommandLine(["dsymutil", "--verbose", Path.root.join("tmp/input").str, "-o", Path.root.join("tmp/output.dSYM").str])
// FIXME: Check the inputs and outputs.
}
}
@Test(.skipHostOS(.windows, "prefix.h header path is coming over as tmp\\tmp\\prefix.h"), .requireSDKs(.macOS))
func clangCompileTaskConstruction() async throws {
let core = try await getCore()
let clangSpec = try core.specRegistry.getSpec("com.apple.compilers.llvm.clang.1_0") as CommandLineToolSpec
// Create the mock table. We include all the defaults for the tool specification.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
for option in clangSpec.flattenedOrderedBuildOptions {
guard let value = option.defaultValue else { continue }
table.push(option.macro, value)
}
// We also add some other settings that are more contextual in nature.
table.push(BuiltinMacros.CURRENT_ARCH, literal: "x86_64")
table.push(BuiltinMacros.arch, literal: "x86_64")
table.push(BuiltinMacros.LLVM_TARGET_TRIPLE_VENDOR, literal: "apple")
table.push(BuiltinMacros.LLVM_TARGET_TRIPLE_OS_VERSION, BuiltinMacros.namespace.parseString("$(SWIFT_PLATFORM_TARGET_PREFIX)$($(DEPLOYMENT_TARGET_SETTING_NAME))"))
table.push(BuiltinMacros.SWIFT_PLATFORM_TARGET_PREFIX, literal: "macos")
table.push(BuiltinMacros.DEPLOYMENT_TARGET_SETTING_NAME, literal: "MACOSX_DEPLOYMENT_TARGET")
table.push(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET, literal: "13.0")
table.push(BuiltinMacros.CURRENT_VARIANT, literal: "normal")
table.push(BuiltinMacros.PRODUCT_NAME, literal: "Product")
table.push(BuiltinMacros.TEMP_DIR, literal: Path.root.join("tmp").str)
table.push(BuiltinMacros.PROJECT_TEMP_DIR, literal: Path.root.join("tmp/ptmp").str)
table.push(BuiltinMacros.OBJECT_FILE_DIR, literal: Path.root.join("tmp/output/obj").str)
table.push(BuiltinMacros.BUILT_PRODUCTS_DIR, literal: Path.root.join("tmp/output/sym").str)
table.push(BuiltinMacros.GCC_PREFIX_HEADER, literal: "prefix.h")
table.push(BuiltinMacros.DERIVED_FILE_DIR, literal: Path.root.join("tmp/derived").str)
table.push(try core.specRegistry.internalMacroNamespace.declareUserDefinedMacro("PER_ARCH_CFLAGS_i386"), core.specRegistry.internalMacroNamespace.parseLiteralStringList(["-DX86.32"]))
table.push(try core.specRegistry.internalMacroNamespace.declareUserDefinedMacro("PER_ARCH_CFLAGS_x86_64"), core.specRegistry.internalMacroNamespace.parseLiteralStringList(["-DX86.64"]))
table.push(BuiltinMacros.PER_ARCH_CFLAGS, BuiltinMacros.namespace.parseStringList("$(PER_ARCH_CFLAGS_$(CURRENT_ARCH)"))
table.push(try core.specRegistry.internalMacroNamespace.declareUserDefinedMacro("OTHER_CFLAGS_normal"), core.specRegistry.internalMacroNamespace.parseLiteralStringList(["-DFrom_OTHER_CFLAGS_normal"]))
table.push(try core.specRegistry.internalMacroNamespace.declareUserDefinedMacro("OTHER_CFLAGS_profile"), core.specRegistry.internalMacroNamespace.parseLiteralStringList(["-DFrom_OTHER_CFLAGS_profile"]))
table.push(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR, BuiltinMacros.namespace.parseString("$(OBJECT_FILE_DIR)-$(CURRENT_VARIANT)/$(CURRENT_ARCH)"))
table.push(BuiltinMacros.ENABLE_DEFAULT_SEARCH_PATHS, literal: true)
table.push(BuiltinMacros.PER_VARIANT_CFLAGS, BuiltinMacros.namespace.parseStringList("$(OTHER_CFLAGS_$(CURRENT_VARIANT)"))
table.push(BuiltinMacros.USE_HEADERMAP, literal: true)
table.push(BuiltinMacros.HEADERMAP_USES_VFS, literal: true)
table.push(BuiltinMacros.CLANG_ENABLE_MODULES, literal: true)
table.push(try core.specRegistry.internalMacroNamespace.declareStringListMacro("GLOBAL_CFLAGS"), literal: ["-DFrom_GLOBAL_CFLAGS"])
table.push(BuiltinMacros.GCC_GENERATE_PROFILING_CODE, literal: true)
table.push(BuiltinMacros.GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS, literal: ["defn1", "defn2"])
table.push(BuiltinMacros.GCC_OTHER_CFLAGS_NOT_USED_IN_PRECOMPS, literal: ["-DFrom_GCC_OTHER_CFLAGS_NOT_USED_IN_PRECOMPS"])
table.push(BuiltinMacros.PRODUCT_TYPE_HEADER_SEARCH_PATHS, literal: [Path.root.join("tmp/product/type/specific/header/search/path").str])
table.push(BuiltinMacros.PRODUCT_TYPE_FRAMEWORK_SEARCH_PATHS, literal: [Path.root.join("tmp/product/type/specific/framework/search/path").str])
table.push(BuiltinMacros.CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING, literal: "")
table.push(BuiltinMacros.CLANG_WARN_COMMA, literal: "")
table.push(BuiltinMacros.CLANG_WARN_FLOAT_CONVERSION, literal: "")
table.push(BuiltinMacros.CLANG_WARN_IMPLICIT_FALLTHROUGH, literal: "")
table.push(BuiltinMacros.CLANG_WARN_NON_LITERAL_NULL_CONVERSION, literal: "")
table.push(BuiltinMacros.CLANG_WARN_OBJC_LITERAL_CONVERSION, literal: "")
table.push(BuiltinMacros.CLANG_WARN_STRICT_PROTOTYPES, literal: "")
// Override CLANG_DEBUG_MODULES, to be independent of recent changes to the Clang.xcspec.
table.push(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("CLANG_DEBUG_MODULES") as! BooleanMacroDeclaration, literal: false)
// Turn off response files, so we can directly check arguments
table.push(BuiltinMacros.CLANG_USE_RESPONSE_FILE, literal: false)
// TODO: We could move this outside of this test and have other tests use it.
/// Utility method to create a task and pass it to a checker block.
func createTask(with table: MacroValueAssignmentTable, _ checkTask: ((inout PlannedTaskBuilder) -> Void), sourceLocation: SourceLocation = #_sourceLocation) async throws {
// Create the delegate, scope, file type, etc.
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("sourcecode.c.c") as FileTypeSpec
// Create the build context for the command.
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: [FileToBuild(absolutePath: Path.root.join("tmp/input.c"), fileType: mockFileType)], output: nil)
// Ask the specification to construct the tasks.
await clangSpec.constructTasks(cbc, delegate)
guard var task = delegate.shellTasks.last, task.ruleInfo.first == "CompileC" else {
Issue.record("Failed to find compile task")
return
}
checkTask(&task)
}
try await createTask(with: table) { task in
#expect(task.ruleInfo == ["CompileC", Path.root.join("tmp/output/obj-normal/x86_64/input.o").str, Path.root.join("tmp/input.c").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
#expect(task.execDescription == "Compile input.c (x86_64)")
#expect(clangSpec.interestingPath(for: Task(&task))?.str == Path.root.join("tmp/input.c").str)
// Check to see that we got the command line we expected based on the inputs.
task.checkCommandLine(["clang", "-x", "c", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-fmodules-ignore-macro=defn1", "-fmodules-ignore-macro=defn2", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", "/--VFS/all-product-headers.yaml", "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/product/type/specific/header/search/path").str)", "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-DX86.64", "-iframework", Path.root.join("tmp/product/type/specific/framework/search/path").str, "-DFrom_GLOBAL_CFLAGS", "-DFrom_OTHER_CFLAGS_normal", "-include", Path.root.join("tmp/prefix.h").str, "-Ddefn1", "-Ddefn2", "-DFrom_GCC_OTHER_CFLAGS_NOT_USED_IN_PRECOMPS", "-MMD", "-MT", "dependencies", "-MF", Path.root.join("tmp/output/obj-normal/x86_64/input.d").str, "--serialize-diagnostics", Path.root.join("tmp/output/obj-normal/x86_64/input.dia").str, "-c", Path.root.join("tmp/input.c").str, "-o", Path.root.join("tmp/output/obj-normal/x86_64/input.o").str])
task.checkInputs([
.path(Path.root.join("tmp/prefix.h").str),
.path(Path.root.join("tmp/input.c").str)
])
task.checkOutputs([
.path(Path.root.join("tmp/output/obj-normal/x86_64/input.o").str)
])
#expect(task.dependencyData != nil)
#expect(task.payload != nil)
}
// Also test that setting ENABLE_DEFAULT_SEARCH_PATHS_IN_HEADER_SEARCH_PATHS to NO disables the default header search paths.
table.push(BuiltinMacros.ENABLE_DEFAULT_SEARCH_PATHS_IN_HEADER_SEARCH_PATHS, literal: false)
try await createTask(with: table) { task in
#expect(task.ruleInfo == ["CompileC", Path.root.join("tmp/output/obj-normal/x86_64/input.o").str, Path.root.join("tmp/input.c").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
#expect(task.execDescription == "Compile input.c (x86_64)")
#expect(clangSpec.interestingPath(for: Task(&task))?.str == Path.root.join("tmp/input.c").str)
// Check to see that we got the command line we expected based on the inputs.
task.checkCommandLine(["clang", "-x", "c", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-fmodules-ignore-macro=defn1", "-fmodules-ignore-macro=defn2", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", "/--VFS/all-product-headers.yaml", "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/product/type/specific/header/search/path").str)", "-DX86.64", "-iframework", Path.root.join("tmp/product/type/specific/framework/search/path").str, "-DFrom_GLOBAL_CFLAGS", "-DFrom_OTHER_CFLAGS_normal", "-include", Path.root.join("tmp/prefix.h").str, "-Ddefn1", "-Ddefn2", "-DFrom_GCC_OTHER_CFLAGS_NOT_USED_IN_PRECOMPS", "-MMD", "-MT", "dependencies", "-MF", Path.root.join("tmp/output/obj-normal/x86_64/input.d").str, "--serialize-diagnostics", Path.root.join("tmp/output/obj-normal/x86_64/input.dia").str, "-c", Path.root.join("tmp/input.c").str, "-o", Path.root.join("tmp/output/obj-normal/x86_64/input.o").str])
task.checkInputs([
.path(Path.root.join("tmp/prefix.h").str),
.path(Path.root.join("tmp/input.c").str)
])
task.checkOutputs([
.path(Path.root.join("tmp/output/obj-normal/x86_64/input.o").str)
])
#expect(task.dependencyData != nil)
#expect(task.payload != nil)
}
}
@Test
func clangCompileWithPrefixHeaderTaskConstruction() async throws {
let core = try await getCore()
let clangSpec = try core.specRegistry.getSpec("com.apple.compilers.llvm.clang.1_0") as CommandLineToolSpec
// Create the mock table. We include all the defaults for the tool specification.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
for option in clangSpec.flattenedOrderedBuildOptions {
guard let value = option.defaultValue else { continue }
table.push(option.macro, value)
}
// We also add some other settings that are more contextual in nature.
table.push(BuiltinMacros.CURRENT_ARCH, literal: "x86_64")
table.push(BuiltinMacros.arch, literal: "x86_64")
table.push(BuiltinMacros.LLVM_TARGET_TRIPLE_VENDOR, literal: "apple")
table.push(BuiltinMacros.LLVM_TARGET_TRIPLE_OS_VERSION, BuiltinMacros.namespace.parseString("$(SWIFT_PLATFORM_TARGET_PREFIX)$($(DEPLOYMENT_TARGET_SETTING_NAME))"))
table.push(BuiltinMacros.SWIFT_PLATFORM_TARGET_PREFIX, literal: "macos")
table.push(BuiltinMacros.DEPLOYMENT_TARGET_SETTING_NAME, literal: "MACOSX_DEPLOYMENT_TARGET")
table.push(BuiltinMacros.MACOSX_DEPLOYMENT_TARGET, literal: "13.0")
table.push(BuiltinMacros.CURRENT_VARIANT, literal: "normal")
table.push(BuiltinMacros.PRODUCT_NAME, literal: "Product")
table.push(BuiltinMacros.TEMP_DIR, literal: Path.root.join("tmp").str)
table.push(BuiltinMacros.PROJECT_TEMP_DIR, literal: Path.root.join("tmp/ptmp").str)
table.push(BuiltinMacros.OBJECT_FILE_DIR, literal: Path.root.join("tmp/output/obj").str)
table.push(BuiltinMacros.PER_ARCH_OBJECT_FILE_DIR, BuiltinMacros.namespace.parseString("$(OBJECT_FILE_DIR)-$(CURRENT_VARIANT)/$(CURRENT_ARCH)"))
table.push(BuiltinMacros.ENABLE_DEFAULT_SEARCH_PATHS, literal: true)
table.push(BuiltinMacros.BUILT_PRODUCTS_DIR, literal: Path.root.join("tmp/output/sym").str)
table.push(BuiltinMacros.GCC_PREFIX_HEADER, literal: Path.root.join("tmp/prefix.h").str)
table.push(BuiltinMacros.DERIVED_FILE_DIR, literal: Path.root.join("tmp/derived").str)
table.push(BuiltinMacros.GCC_PRECOMPILE_PREFIX_HEADER, literal: true)
table.push(BuiltinMacros.SHARED_PRECOMPS_DIR, literal: Path.root.join("tmp/precomps").str)
table.push(BuiltinMacros.ALWAYS_SEARCH_USER_PATHS, literal: true)
table.push(BuiltinMacros.CLANG_ENABLE_MODULES, literal: true)
table.push(BuiltinMacros.CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING, literal: "")
table.push(BuiltinMacros.CLANG_WARN_COMMA, literal: "")
table.push(BuiltinMacros.CLANG_WARN_FLOAT_CONVERSION, literal: "")
table.push(BuiltinMacros.CLANG_WARN_NON_LITERAL_NULL_CONVERSION, literal: "")
table.push(BuiltinMacros.CLANG_WARN_OBJC_LITERAL_CONVERSION, literal: "")
table.push(BuiltinMacros.CLANG_WARN_STRICT_PROTOTYPES, literal: "")
// Override CLANG_DEBUG_MODULES, to be independent of recent changes to the Clang.xcspec.
table.push(core.specRegistry.internalMacroNamespace.lookupMacroDeclaration("CLANG_DEBUG_MODULES") as! BooleanMacroDeclaration, literal: false)
// Turn off response files, so we can directly check arguments
table.push(BuiltinMacros.CLANG_USE_RESPONSE_FILE, literal: false)
// Create the delegate, scope, file type, etc.
let producer = try MockCommandProducer(core: core, productTypeIdentifier: "com.apple.product-type.framework", platform: "macosx")
let delegate = try CapturingTaskGenerationDelegate(producer: producer, userPreferences: .defaultForTesting)
let mockScope = MacroEvaluationScope(table: table)
let mockFileType = try core.specRegistry.getSpec("sourcecode.c.c") as FileTypeSpec
// We need to construct multiple tasks to ensure that they correctly share one precompiled header
let numCompileTasks = 2
for compileTaskIndex in 0..<numCompileTasks {
// Create the build context for the command.
let cbc = CommandBuildContext(producer: producer, scope: mockScope, inputs: [FileToBuild(absolutePath: Path.root.join("tmp/input-\(compileTaskIndex).c"), fileType: mockFileType)], output: nil)
// Ask the specification to construct the tasks.
await clangSpec.constructTasks(cbc, delegate)
}
// We should have one task for precompiling and `numCompileTasks` tasks for compiling
#expect(delegate.shellTasks.count == 1 + numCompileTasks)
let pchHash: String
if core.hostOperatingSystem == .windows {
// non-constant on Windows because Path.root may evaluate to any drive letter
pchHash = String(ClangCompilerSpec.sharedPrecompiledHeaderSharingIdentifier(commandLine: [
"clang.exe",
"-x",
"c",
"-target",
"x86_64-apple-macos13.0",
"-fmodules",
"-fpascal-strings",
"-Os",
"-fasm-blocks",
"-iquote",
Path.root.join("tmp/Product-generated-files.hmap").str,
"-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)",
"-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)",
"-ivfsoverlay",
"\\--VFS\\all-product-headers.yaml",
"-iquote",
Path.root.join("tmp/Product-project-headers.hmap").str,
"-I\(Path.root.join("tmp/derived-normal/x86_64").str)",
"-I\(Path.root.join("tmp/derived/x86_64").str)",
"-I\(Path.root.join("tmp/derived").str)",
Path.root.join("tmp/prefix.h").str,
]).hashValue)
} else {
pchHash = "1041705040740768206"
}
// Check the precompilation task
let precompileTask = delegate.shellTasks.first{ $0.ruleInfo.first! == "ProcessPCH" }!
precompileTask.checkCommandLine([core.hostOperatingSystem.imageFormat.executableName(basename: "clang"), "-x", "c-header", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-Wno-implicit-fallthrough", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", Path("/--VFS/all-product-headers.yaml").str, "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-c", Path.root.join("tmp/prefix.h").str, "-MD", "-MT", "dependencies", "-MF", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.d").str)", "-o", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str)", "--serialize-diagnostics", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.dia").str)"])
#expect(precompileTask.ruleInfo == ["ProcessPCH", Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str, Path.root.join("tmp/prefix.h").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
#expect(precompileTask.execDescription == "Precompile prefix.h (x86_64)")
precompileTask.checkInputs([
.path(Path.root.join("tmp/prefix.h").str)
])
precompileTask.checkOutputs([
.path(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str)
])
#expect(precompileTask.payload != nil)
#expect(precompileTask.additionalOutput == ["Precompile of \'\(Path.root.join("tmp/prefix.h").str)\' required by \'\(Path.root.join("tmp/input-0.c").str)\'"])
// Check the compile tasks
for compileTaskIndex in 0..<numCompileTasks {
let compileTask = delegate.shellTasks.first{ $0.ruleInfo.first! == "CompileC" && $0.inputs.contains{ $0.path.basename == "input-\(compileTaskIndex).c" } }!
#expect(compileTask.ruleInfo == ["CompileC", Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).o").str, Path.root.join("tmp/input-\(compileTaskIndex).c").str, "normal", "x86_64", "c", "com.apple.compilers.llvm.clang.1_0"])
#expect(compileTask.execDescription == "Compile input-\(compileTaskIndex).c (x86_64)")
compileTask.checkCommandLine([core.hostOperatingSystem.imageFormat.executableName(basename: "clang"), "-x", "c", "-target", "x86_64-apple-macos13.0", "-fmessage-length=0", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fno-color-diagnostics", "-fmodules", "-fmodules-prune-interval=86400", "-fmodules-prune-after=345600", "-Wnon-modular-include-in-framework-module", "-Werror=non-modular-include-in-framework-module", "-Wno-trigraphs", "-fpascal-strings", "-Os", "-Wno-missing-field-initializers", "-Wno-missing-prototypes", "-Wno-return-type", "-Wno-missing-braces", "-Wparentheses", "-Wswitch", "-Wno-unused-function", "-Wno-unused-label", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wunused-value", "-Wno-empty-body", "-Wno-uninitialized", "-Wno-unknown-pragmas", "-Wno-shadow", "-Wno-four-char-constants", "-Wno-conversion", "-Wno-constant-conversion", "-Wno-int-conversion", "-Wno-bool-conversion", "-Wno-enum-conversion", "-Wno-shorten-64-to-32", "-Wpointer-sign", "-Wno-newline-eof", "-Wno-implicit-fallthrough", "-fasm-blocks", "-fstrict-aliasing", "-Wdeprecated-declarations", "-Wno-sign-conversion", "-Wno-infinite-recursion", "-Wno-semicolon-before-method-body", "-iquote", Path.root.join("tmp/Product-generated-files.hmap").str, "-I\(Path.root.join("tmp/Product-own-target-headers.hmap").str)", "-I\(Path.root.join("tmp/Product-all-non-framework-target-headers.hmap").str)", "-ivfsoverlay", Path("/--VFS/all-product-headers.yaml").str, "-iquote", Path.root.join("tmp/Product-project-headers.hmap").str, "-I\(Path.root.join("tmp/derived-normal/x86_64").str)", "-I\(Path.root.join("tmp/derived/x86_64").str)", "-I\(Path.root.join("tmp/derived").str)", "-include", "\(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h").str)", "-MMD", "-MT", "dependencies", "-MF", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).d").str)", "--serialize-diagnostics", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).dia").str)", "-c", "\(Path.root.join("tmp/input-\(compileTaskIndex).c").str)", "-o", "\(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).o").str)"])
compileTask.checkInputs([
.path(Path.root.join("tmp/precomps/SharedPrecompiledHeaders/\(pchHash)/prefix.h.gch").str),
.path(Path.root.join("tmp/input-\(compileTaskIndex).c").str)
])
compileTask.checkOutputs([
.path(Path.root.join("tmp/output/obj-normal/x86_64/input-\(compileTaskIndex).o").str)
])
#expect(compileTask.payload != nil)
}
}
@Test
func clangCompileTaskConstructionWithCXXModulesDisabled() async throws {
let core = try await getCore()
let clangSpec = try core.specRegistry.getSpec("com.apple.compilers.llvm.clang.1_0") as CommandLineToolSpec
// Create the dummy table. We include all the defaults for the tool specification.
var table = MacroValueAssignmentTable(namespace: core.specRegistry.internalMacroNamespace)
for option in clangSpec.flattenedOrderedBuildOptions {
guard let value = option.defaultValue else { continue }
table.push(option.macro, value)
}
// We also add some other settings that are more contextual in nature.
table.push(BuiltinMacros.CURRENT_ARCH, literal: "x86_64")
table.push(BuiltinMacros.arch, literal: "x86_64")
table.push(BuiltinMacros.LLVM_TARGET_TRIPLE_VENDOR, literal: "apple")
table.push(BuiltinMacros.LLVM_TARGET_TRIPLE_OS_VERSION, BuiltinMacros.namespace.parseString("$(SWIFT_PLATFORM_TARGET_PREFIX)$($(DEPLOYMENT_TARGET_SETTING_NAME))"))