forked from swiftlang/swift-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoPlistProcessorTaskTests.swift
More file actions
2439 lines (2173 loc) · 145 KB
/
Copy pathInfoPlistProcessorTaskTests.swift
File metadata and controls
2439 lines (2173 loc) · 145 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 SWBTestSupport
import SWBUtil
import SWBCore
import SWBTaskExecution
import SWBMacro
@Suite(.requireHostOS(.macOS))
fileprivate struct InfoPlistProcessorTaskTests: CoreBasedTests {
private func prepareContext(_ context: InfoPlistProcessorTaskActionContext, fs: any FSProxy) throws -> Path {
let serializer = MsgPackSerializer()
serializer.serialize(context)
let path = Path("/context")
try fs.write(path, contents: serializer.byteString)
return path
}
/// Utility method to create and run the task action on the given plist data and call back to a checker to validate the results.
private func createAndRunTaskAction(inputPlistData: [String: PropertyListItem], scope: MacroEvaluationScope, platformName: String, sdkName: String? = nil, sdkVariant: String? = nil, productTypeId: String? = nil, sourceLocation: SourceLocation = #_sourceLocation, checkResults: (CommandResult, [String: PropertyListItem], MockTaskOutputDelegate) throws -> Void) async throws {
let core = try await getCore()
// Create and write the input plist.
let inputFilePath = Path("/tmp/input.plist")
let executionDelegate = MockExecutionDelegate(core: try await getCore())
try executionDelegate.fs.createDirectory(inputFilePath.dirname)
try await executionDelegate.fs.writePlist(inputFilePath, .plDict(inputPlistData))
// Look up the product type.
var productType: ProductTypeSpec? = nil
if let productTypeId {
productType = try core.specRegistry.getSpec(productTypeId, domain: platformName, ofType: ProductTypeSpec.self)
}
// Create the task action.
let outputFilePath = Path("/tmp/output.plist")
let platform = try #require(core.platformRegistry.lookup(name: platformName), "invalid platform name '\(platformName)'", sourceLocation: sourceLocation)
let sdkName = sdkName ?? platformName
let sdk = try #require(core.sdkRegistry.lookup(sdkName), "invalid SDK name '\(sdkName)'", sourceLocation: sourceLocation)
let sdkVariant = sdkVariant.map(sdk.variant(for:)) ?? nil
let action = InfoPlistProcessorTaskAction(try prepareContext(InfoPlistProcessorTaskActionContext(scope: scope, productType: productType, platform: platform, sdk: sdk, sdkVariant: sdkVariant, cleanupRequiredArchitectures: []), fs: executionDelegate.fs))
let task = Task(forTarget: nil, ruleInfo: [], commandLine: ["builtin-infoPlistUtility", "-expandbuildsettings", "-platform", platformName, inputFilePath.str, "-o", outputFilePath.str], workingDirectory: inputFilePath.dirname, outputs: [], action: action, execDescription: "Copy Info.plist")
// Run the task action.
let outputDelegate = MockTaskOutputDelegate()
let result = await action.performTaskAction(
task,
dynamicExecutionDelegate: MockDynamicTaskExecutionDelegate(),
executionDelegate: executionDelegate,
clientDelegate: MockTaskExecutionClientDelegate(),
outputDelegate: outputDelegate
)
guard result == .succeeded else {
try checkResults(result, [:], outputDelegate)
return
}
// Read the output file and pass the results to the checker block.
let contents = try executionDelegate.fs.read(outputFilePath)
let plist = try PropertyList.fromBytes(contents.bytes)
guard case .plDict(let dict) = plist else {
Issue.record("Output property list is not a dictionary.", sourceLocation: sourceLocation)
return
}
try checkResults(result, dict, outputDelegate)
}
@Test
func diagnostics() async throws {
let core = try await getCore()
// Check basic diagnostics.
func checkDiagnostics(_ commandLine: [String], errors: [String], sourceLocation: SourceLocation = #_sourceLocation) async throws {
let namespace = MacroNamespace(parent: BuiltinMacros.namespace, debugDescription: #function)
let table = MacroValueAssignmentTable(namespace: namespace)
let scope = MacroEvaluationScope(table: table)
let platformName = "macosx"
let platform = try #require(core.platformRegistry.lookup(name: platformName), "invalid platform name '\(platformName)'", sourceLocation: sourceLocation)
let sdk = try #require(core.sdkRegistry.lookup(platformName), "invalid SDK name '\(platformName)'", sourceLocation: sourceLocation)
let executionDelegate = MockExecutionDelegate(core: try await getCore())
let action = InfoPlistProcessorTaskAction(try prepareContext(InfoPlistProcessorTaskActionContext(scope: scope, productType: nil, platform: platform, sdk: sdk, sdkVariant: nil, cleanupRequiredArchitectures: []), fs: executionDelegate.fs))
let task = Task(forTarget: nil, ruleInfo: [], commandLine: commandLine, workingDirectory: .root, outputs: [], action: action, execDescription: "Copy Info.plist")
let outputDelegate = MockTaskOutputDelegate()
let result = await action.performTaskAction(
task,
dynamicExecutionDelegate: MockDynamicTaskExecutionDelegate(),
executionDelegate: executionDelegate,
clientDelegate: MockTaskExecutionClientDelegate(),
outputDelegate: outputDelegate
)
#expect(result == .failed)
#expect(outputDelegate.messages == errors.map { "error: \($0)" })
}
try await checkDiagnostics([], errors: ["no input file specified"])
try await checkDiagnostics(["infoPlistUtility", "-format", "openstep", "-format", "xml", "-format", "binary", "-format", "unknown"], errors: ["unrecognized argument to -format: 'unknown' (use 'openstep', 'xml', or 'binary')"])
try await checkDiagnostics(["infoPlistUtility", "-format"], errors: ["missing argument for -format (use 'openstep', 'xml', or 'binary')"])
try await checkDiagnostics(["infoPlistUtility", "-genpkginfo", "a", "-genpkginfo", "b"], errors: ["multiple pkginfo paths specified"])
try await checkDiagnostics(["infoPlistUtility", "-requiredArchitecture", "a", "-requiredArchitecture", "b"], errors: ["multiple -requiredArchitecture specified"])
try await checkDiagnostics(["infoPlistUtility", "-platform", "a"], errors: ["argument to -platform 'a' differs from platform being targeted 'macosx'"])
try await checkDiagnostics(["infoPlistUtility", "-platform", "macosx", "-platform", "macosx2"], errors: ["multiple platform names specified"])
try await checkDiagnostics(["infoPlistUtility", "-resourcerulesfile", "a", "-resourcerulesfile", "b"], errors: ["multiple resource rules files specified"])
try await checkDiagnostics(["infoPlistUtility", "-o", "a", "-o", "b"], errors: ["multiple output files specified"])
try await checkDiagnostics(["infoPlistUtility", "input1", "input2"], errors: ["multiple input files specified"])
try await checkDiagnostics(["infoPlistUtility", "-format", "xml", "-genpkginfo", "foo", "-platform", "macosx", "-enforceminimumos", "-expandbuildsettings", "-resourcerulesfile", "foo", "-additionalcontentfile", "foo2", "-requiredArchitecture", "x86_64", "-o", "output", "input", "-unknown"], errors: ["unrecognized option: -unknown"])
for missingArgOpt in ["-genpkginfo", "-platform", "-resourcerulesfile", "-additionalcontentfile", "-requiredArchitecture", "-o"] {
try await checkDiagnostics(["infoPlistUtility", missingArgOpt], errors: ["missing argument for \(missingArgOpt)"])
}
// Check diagnostics emitted when trying to merge additional content files.
func checkAdditionalContentDiagnostics(_ additionalContentFilePaths: [String], errors: [String], sourceLocation: SourceLocation = #_sourceLocation, setup: (any FSProxy) async throws -> Void) async throws {
let namespace = MacroNamespace(parent: BuiltinMacros.namespace, debugDescription: #function)
let table = MacroValueAssignmentTable(namespace: namespace)
let scope = MacroEvaluationScope(table: table)
let platformName = "macosx"
let platform = try #require(core.platformRegistry.lookup(name: platformName), "invalid platform name '\(platformName)'", sourceLocation: sourceLocation)
let sdk = try #require(core.sdkRegistry.lookup(platformName), "invalid SDK name '\(platformName)'", sourceLocation: sourceLocation)
let executionDelegate = MockExecutionDelegate(core: try await getCore())
let action = InfoPlistProcessorTaskAction(try prepareContext(InfoPlistProcessorTaskActionContext(scope: scope, productType: nil, platform: platform, sdk: sdk, sdkVariant: nil, cleanupRequiredArchitectures: []), fs: executionDelegate.fs))
try executionDelegate.fs.createDirectory(Path.root.join("tmp"))
try await executionDelegate.fs.writePlist(Path("/tmp/input.plist"), [
"CFBundleDevelopmentRegion": "en",
"Integer": 1,
"Array": [1, 2],
])
try await setup(executionDelegate.fs)
var commandLine = ["builtin-infoPlistUtility", "-platform", platformName, "/tmp/input.plist"]
for path in additionalContentFilePaths { commandLine.append(contentsOf: ["-additionalcontentfile", path]) }
commandLine.append(contentsOf: ["-o", "/tmp/output.plist"])
let task = Task(forTarget: nil, ruleInfo: [], commandLine: commandLine, workingDirectory: Path.root.join("tmp"), outputs: [], action: action, execDescription: "Copy Info.plist")
let outputDelegate = MockTaskOutputDelegate()
let result = await action.performTaskAction(
task,
dynamicExecutionDelegate: MockDynamicTaskExecutionDelegate(),
executionDelegate: executionDelegate,
clientDelegate: MockTaskExecutionClientDelegate(),
outputDelegate: outputDelegate
)
#expect(result == .failed)
#expect(outputDelegate.messages == errors.map { "error: \($0)" })
}
// Test a missing plist file.
try await checkAdditionalContentDiagnostics(["/tmp/missing.plist"], errors: ["unable to read additional content file \'/tmp/missing.plist\': No such file or directory (2)"]) { fs in
// No setup since we're testing a missing file.
}
// Test trying to merge incompatible types.
try await checkAdditionalContentDiagnostics(["/tmp/bad.plist"], errors: ["tried to merge array value for key \'Integer\' onto integer value"]) { fs in
try await fs.writePlist(Path("/tmp/bad.plist"), [
"Integer": [1, 2],
])
}
try await checkAdditionalContentDiagnostics(["/tmp/bad.plist"], errors: ["tried to merge string value for key \'Array\' onto array value"]) { fs in
try await fs.writePlist(Path("/tmp/bad.plist"), [
"Array": "string",
])
}
}
private func createMockScope(debugDescription: String = #function, _ body: ((MacroNamespace, inout MacroValueAssignmentTable) throws -> Void)? = nil) throws -> MacroEvaluationScope {
// Create a mock table and scope for the processor to use.
let namespace = MacroNamespace(parent: BuiltinMacros.namespace, debugDescription: debugDescription)
try namespace.declareStringMacro("PRODUCT_NAME")
try namespace.declareStringMacro("EXECUTABLE_NAME")
try namespace.declareStringMacro("PRODUCT_BUNDLE_IDENTIFIER")
try namespace.declareStringMacro("MACOSX_DEPLOYMENT_TARGET")
try namespace.declareStringMacro("MAC_OS_X_PRODUCT_BUILD_VERSION")
try namespace.declareStringMacro("XCODE_VERSION_ACTUAL")
try namespace.declareStringMacro("XCODE_PRODUCT_BUILD_VERSION")
try namespace.declareStringMacro("PLATFORM_PRODUCT_BUILD_VERSION")
try namespace.declareStringMacro("GCC_VERSION")
try namespace.declareStringMacro("SDK_NAME")
try namespace.declareStringMacro("SDK_PRODUCT_BUILD_VERSION")
try namespace.declareStringMacro("MARKETING_VERSION")
try namespace.declareUserDefinedMacro("VERSION_STRING")
try namespace.declareBooleanMacro("INFOPLIST_ENABLE_CFBUNDLEICONS_MERGE")
var table = MacroValueAssignmentTable(namespace: namespace)
table.push(try #require(namespace.lookupMacroDeclaration("PRODUCT_NAME") as? StringMacroDeclaration), literal: "TestApp")
table.push(try #require(namespace.lookupMacroDeclaration("EXECUTABLE_NAME") as? StringMacroDeclaration), literal: "TestApp")
table.push(try #require(namespace.lookupMacroDeclaration("PRODUCT_BUNDLE_IDENTIFIER") as? StringMacroDeclaration), literal: "com.apple.TestApp")
table.push(try #require(namespace.lookupMacroDeclaration("MACOSX_DEPLOYMENT_TARGET") as? StringMacroDeclaration), literal: "10.12")
table.push(try #require(namespace.lookupMacroDeclaration("MAC_OS_X_PRODUCT_BUILD_VERSION") as? StringMacroDeclaration), literal: "15E35")
table.push(try #require(namespace.lookupMacroDeclaration("DEPLOYMENT_TARGET_SETTING_NAME") as? StringMacroDeclaration), literal: "MACOSX_DEPLOYMENT_TARGET")
table.push(try #require(namespace.lookupMacroDeclaration("XCODE_VERSION_ACTUAL") as? StringMacroDeclaration), literal: "0730")
table.push(try #require(namespace.lookupMacroDeclaration("XCODE_PRODUCT_BUILD_VERSION") as? StringMacroDeclaration), literal: "7D137")
table.push(try #require(namespace.lookupMacroDeclaration("PLATFORM_PRODUCT_BUILD_VERSION") as? StringMacroDeclaration), literal: "7D137")
table.push(try #require(namespace.lookupMacroDeclaration("GCC_VERSION") as? StringMacroDeclaration), literal: "com.apple.compilers.llvm.clang.1_0")
table.push(try #require(namespace.lookupMacroDeclaration("SDK_NAME") as? StringMacroDeclaration), literal: "macosx10.11")
table.push(try #require(namespace.lookupMacroDeclaration("SDK_PRODUCT_BUILD_VERSION") as? StringMacroDeclaration), literal: "15A284")
table.push(try #require(namespace.lookupMacroDeclaration("MARKETING_VERSION") as? StringMacroDeclaration), literal: "9.3")
table.push(try #require(namespace.lookupMacroDeclaration("VERSION_STRING") as? UserDefinedMacroDeclaration), namespace.parseStringList("Version number: \"$(MARKETING_VERSION)\""))
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "1,4 2, 3, 0")
table.push(try #require(namespace.lookupMacroDeclaration("INFOPLIST_ENABLE_CFBUNDLEICONS_MERGE") as? BooleanMacroDeclaration), literal: true)
try body?(namespace, &table)
return MacroEvaluationScope(table: table)
}
@Test
func infoPlistProcessorTask() async throws {
let core = try await getCore()
let scope = try createMockScope()
let platformName = "macosx"
let platform = try #require(core.platformRegistry.lookup(name: platformName), "invalid platform name '\(platformName)'")
let sdk = try #require(core.sdkRegistry.lookup(platformName), "invalid SDK name '\(platformName)'")
let executionDelegate = MockExecutionDelegate(core: try await getCore())
let action = InfoPlistProcessorTaskAction(try prepareContext(InfoPlistProcessorTaskActionContext(scope: scope, productType: nil, platform: platform, sdk: sdk, sdkVariant: nil, cleanupRequiredArchitectures: []), fs: executionDelegate.fs))
let task = Task(forTarget: nil, ruleInfo: [], commandLine: ["builtin-infoPlistUtility", "-enforceminimumos", "-genpkginfo", "/tmp/PkgInfo", "-expandbuildsettings", "-platform", platformName, "/tmp/input.plist", "-additionalcontentfile", "/tmp/newcontent.plist", "-additionalcontentfile", "/tmp/mergecontent.plist", "-additionalcontentfile", "/tmp/required.plist", "-o", "/tmp/output.plist"], workingDirectory: Path.root.join("tmp"), outputs: [], action: action, execDescription: "Copy Info.plist")
// Write the test files.
try executionDelegate.fs.createDirectory(Path.root.join("tmp"))
do {
try await executionDelegate.fs.writePlist(Path("/tmp/input.plist"), [
"CFBundleDevelopmentRegion": "en",
"CFBundleExecutable": "$(EXECUTABLE_NAME)",
"CFBundleIdentifier": "$(PRODUCT_BUNDLE_IDENTIFIER)",
"CFBundleName": "$(PRODUCT_NAME)",
"CFBundlePackageType": "APPL",
"CFBundleSignature": "FOOZ",
"CFBundleVersion": "1",
// "LSMinimumSystemVersion": "$(MACOSX_DEPLOYMENT_TARGET)", this is commented out to test that -enforceminimumos works
"NSMainNibFile": "MainMenu",
"NSPrincipalClass": "NSApplication",
"CFBundleResourceSpecification": "", // To test eliding empty string values
"DoNotElide": "", // To test *not* eliding empty string values which are not among keys we should elide
"AsideBundleIdentifier": "$(CFBundleIdentifier)", // To test evaluating $(CFBundleIdentifier)
"TestVersionString": "$(VERSION_STRING)", // To test that quotes are preserved when evaluating a user-defined macro in string form
// Content that will get merged with content from the additional content files.
"IntToInt": 1,
"IntToString": 2,
"MergeArray": [1, 2],
"MergeDict": ["one": "one", "two": "two"],
"UIRequiredDeviceCapabilities": ["arm64"],
])
}
do {
try await executionDelegate.fs.writePlist(Path("/tmp/newcontent.plist"), [
"Integer": 1,
"String": "string",
"Array": [1, 2],
"Dict": [
"one": "one",
"two": "two",
],
])
}
do {
try await executionDelegate.fs.writePlist(Path("/tmp/mergecontent.plist"), [
"IntToInt": 5,
"IntToString": "string",
"MergeArray": [1, 4],
"MergeDict": [
"two": "three",
"four": "four",
],
])
}
do {
// This will cause the array form in the base Info.plist to be promoted to a dictionary.
try await executionDelegate.fs.writePlist(Path("/tmp/required.plist"), [
"UIRequiredDeviceCapabilities": [
"armv7": true,
],
])
}
let outputDelegate = MockTaskOutputDelegate()
let result = await action.performTaskAction(
task,
dynamicExecutionDelegate: MockDynamicTaskExecutionDelegate(),
executionDelegate: executionDelegate,
clientDelegate: MockTaskExecutionClientDelegate(),
outputDelegate: outputDelegate
)
guard result == .succeeded else {
Issue.record("task failed; errors: \(outputDelegate.errors)")
return
}
// Check the output.
do {
// Read the output property list.
let contents = try executionDelegate.fs.read(Path("/tmp/output.plist"))
let plist = try PropertyList.fromBytes(contents.bytes)
guard case .plDict(let dict) = plist else {
Issue.record("Output property list is not a dictionary.")
return
}
// Check the core values in the property list.
#expect(dict["CFBundleDevelopmentRegion"]?.stringValue == "en")
#expect(dict["CFBundleExecutable"]?.stringValue == "TestApp")
#expect(dict["CFBundleIdentifier"]?.stringValue == "com.apple.TestApp")
#expect(dict["CFBundleName"]?.stringValue == "TestApp")
// Check that enforcing the minimum OS version worked
#expect(dict["LSMinimumSystemVersion"]?.stringValue == "10.12")
// Check that values we expected to be elided were, and ones we didn't were not.
#expect(dict["CFBundleResourceSpecification"] == nil)
#expect(dict["DoNotElide"]?.stringValue == "")
// Check that $(CFBundleIdentifier) was evaluated.
#expect(dict["AsideBundleIdentifier"]?.stringValue == "com.apple.TestApp")
// Check that the TestVersionString ends up with the expected value.
#expect(dict["TestVersionString"]?.stringValue == "Version number: \"9.3\"")
// Check the values we expect to get from the 'macosx' platform which we passed on the command line.
if let supportedPlatformsArray = dict["CFBundleSupportedPlatforms"]?.arrayValue {
let supportedPlatforms = supportedPlatformsArray.map { $0.stringValue }
#expect(supportedPlatforms == ["MacOSX"])
}
else {
Issue.record("CFBundleSupportedPlatforms is not an array.")
}
#expect(dict["BuildMachineOSBuild"]?.stringValue == "15E35")
#expect(dict["DTXcode"]?.stringValue == "0730")
#expect(dict["DTXcodeBuild"]?.stringValue == "7D137")
#expect(dict["DTPlatformBuild"]?.stringValue == "7D137")
#expect(dict["DTCompiler"]?.stringValue == "com.apple.compilers.llvm.clang.1_0")
#expect(dict["DTSDKName"]?.stringValue == "macosx10.11")
#expect(dict["DTSDKBuild"]?.stringValue == "15A284")
#expect(dict["UIDeviceFamily"] == nil, "unexpected device family: \(String(describing: dict["UIDeviceFamily"]))")
// Check that the contents from 'newcontent.plist' is present.
#expect(dict["Integer"]?.intValue == 1)
#expect(dict["String"]?.stringValue == "string")
#expect(dict["Array"]?.arrayValue ?? [] == [.plInt(1), .plInt(2)])
#expect(dict["Dict"]?.dictValue ?? [:] == ["one": .plString("one"), "two": .plString("two")])
// Check that we properly merged the content from 'mergecontent.plist'.
#expect(dict["IntToInt"]?.intValue == 5)
#expect(dict["IntToString"]?.stringValue == "string")
#expect(dict["MergeArray"]?.arrayValue ?? [] == [.plInt(1), .plInt(2), .plInt(4)])
#expect(dict["MergeDict"]?.dictValue ?? [:] == ["one": .plString("one"), "two": .plString("three"), "four": .plString("four")])
// Check that we properly promoted and merged the required device capabilities.
#expect(dict["UIRequiredDeviceCapabilities"]?.dictValue ?? [:] == ["arm64": .plBool(true), "armv7": .plBool(true)])
let pkgInfoContents = try executionDelegate.fs.read(Path("/tmp/PkgInfo"))
#expect(pkgInfoContents == ByteString(encodingAsUTF8: "APPLFOOZ"))
}
}
/// Test behaviors specific to merging the content from the `AdditionalInfo` dictionary in the platform's Info.plist into the final Info.plist.
@Test
func mergingPlatformAdditionalInfo() async throws {
let core = try await getCore()
// Test the macOS AdditionalInfo dictionary.
do {
let scope = try createMockScope(debugDescription: "\(#function)_macOS") { namespace, table in
try namespace.declareStringMacro("MINIMUM_SYSTEM_VERSION")
table.push(try #require(namespace.lookupMacroDeclaration("MINIMUM_SYSTEM_VERSION") as? StringMacroDeclaration), literal: "10.14.4")
}
let platformName = "macosx"
let executionDelegate = MockExecutionDelegate(core: try await getCore())
let action = InfoPlistProcessorTaskAction(try prepareContext(InfoPlistProcessorTaskActionContext(scope: scope, productType: nil, platform: core.platformRegistry.lookup(name: platformName), sdk: core.sdkRegistry.lookup(platformName), sdkVariant: nil, cleanupRequiredArchitectures: []), fs: executionDelegate.fs))
let task = Task(forTarget: nil, ruleInfo: [], commandLine: ["builtin-infoPlistUtility", "-enforceminimumos", "-genpkginfo", "/tmp/PkgInfo", "-expandbuildsettings", "-platform", platformName, "/tmp/input.plist", "-o", "/tmp/output.plist"], workingDirectory: Path.root.join("tmp"), outputs: [], action: action, execDescription: "Copy Info.plist")
// Write the test files.
try executionDelegate.fs.createDirectory(Path.root.join("tmp"))
try await executionDelegate.fs.writePlist(Path("/tmp/input.plist"), [
"CFBundleDevelopmentRegion": "en",
"CFBundleExecutable": "$(EXECUTABLE_NAME)",
"CFBundleIdentifier": "$(PRODUCT_BUNDLE_IDENTIFIER)",
"CFBundleName": "$(PRODUCT_NAME)",
"CFBundlePackageType": "APPL",
"CFBundleSignature": "FOOZ",
"CFBundleVersion": "1",
"LSMinimumSystemVersion": "$(MINIMUM_SYSTEM_VERSION)", // To check that the value of this key from the platform does not replace this value.
"NSMainNibFile": "MainMenu",
"NSPrincipalClass": "NSApplication",
])
let outputDelegate = MockTaskOutputDelegate()
let result = await action.performTaskAction(
task,
dynamicExecutionDelegate: MockDynamicTaskExecutionDelegate(),
executionDelegate: executionDelegate,
clientDelegate: MockTaskExecutionClientDelegate(),
outputDelegate: outputDelegate
)
guard result == .succeeded else {
Issue.record("task failed; errors: \(outputDelegate.errors)")
return
}
// Check the output.
do {
// Read the output property list.
let contents = try executionDelegate.fs.read(Path("/tmp/output.plist"))
let plist = try PropertyList.fromBytes(contents.bytes)
guard case .plDict(let dict) = plist else {
Issue.record("Output property list is not a dictionary.")
return
}
// Check that some expected values from the platform are present.
#expect(dict["BuildMachineOSBuild"]?.stringValue == "15E35")
if let supportedPlatformsArray = dict["CFBundleSupportedPlatforms"]?.arrayValue {
let supportedPlatforms = supportedPlatformsArray.map { $0.stringValue }
#expect(supportedPlatforms == ["MacOSX"])
}
else {
Issue.record("CFBundleSupportedPlatforms is not an array.")
}
#expect(dict["DTCompiler"]?.stringValue == "com.apple.compilers.llvm.clang.1_0")
#expect(dict["DTPlatformBuild"]?.stringValue == "7D137")
#expect(dict["DTPlatformName"]?.stringValue == "macosx")
// Skip DTPlatformVersion since we can't control for its value in this test.
#expect(dict["DTSDKBuild"]?.stringValue == "15A284")
#expect(dict["DTSDKName"]?.stringValue == "macosx10.11")
#expect(dict["DTXcode"]?.stringValue == "0730")
#expect(dict["DTXcodeBuild"]?.stringValue == "7D137")
// Check that LSMinimumSystemVersion did *not* come from the platform. Xcode.app expects this behavior; see <rdar://problem/55196427>.
#expect(dict["LSMinimumSystemVersion"]?.stringValue == "10.14.4")
}
}
}
/// Validates the `INFOPLIST_FILE_CONTENTS` build setting is applied on top of the Info.plist loaded from disk.
@Test
func infoPlistFileContentsBuildSetting() async throws {
let plistData: [String: PropertyListItem] = [
"Key1": "ExistingValue1",
"Key2": "ExistingValue2",
]
let INFOPLIST_FILE_CONTENTS = """
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Key2</key><string>NewValue2</string>
<key>Key3</key><string>NewValue3</string>
</dict>
</plist>
"""
// Test building for iOS.
do {
let scope = try createMockScope(debugDescription: "\(#function)_iOS") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
table.push(try #require(namespace.lookupMacroDeclaration("INFOPLIST_FILE_CONTENTS") as? StringMacroDeclaration), literal: INFOPLIST_FILE_CONTENTS)
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "iphoneos") { result, dict, outputDelegate in
// Check preexisting key is still present
#expect(dict["Key1"]?.stringValue == "ExistingValue1")
// Check preexisting key has been replaced
#expect(dict["Key2"]?.stringValue == "NewValue2")
// Check new key was added
#expect(dict["Key3"]?.stringValue == "NewValue3")
}
}
}
func testScenario(platformName: String, sdkName: String? = nil, sdkVariant: String = "", deploymentTargetName: String, deploymentTarget: String, minimumSystemVersion: String, sourceLocation: SourceLocation = #_sourceLocation, checkResults: ([String: PropertyListItem], String, MockTaskOutputDelegate) -> Void) async throws {
let minimumSystemVersionKey: String
switch platformName {
case "driverkit":
minimumSystemVersionKey = "OSMinimumDriverKitVersion"
case "macosx":
minimumSystemVersionKey = "LSMinimumSystemVersion"
default:
minimumSystemVersionKey = "MinimumOSVersion"
}
let plistData: [String: PropertyListItem] = [
minimumSystemVersionKey: .plString(minimumSystemVersion),
]
let scope = try createMockScope(debugDescription: "\(#function)_\(platformName)") { namespace, table in
let sdkName = sdkName ?? platformName
table.push(try #require(namespace.lookupMacroDeclaration("SDKROOT") as? PathMacroDeclaration), literal: sdkName)
table.push(try #require(namespace.lookupMacroDeclaration("SDK_NAME") as? StringMacroDeclaration), literal: "") // This is wrong but we don't have a good way to override this with the real version
table.push(try #require(namespace.lookupMacroDeclaration("SDK_VARIANT") as? StringMacroDeclaration), literal: sdkVariant)
table.push(try #require(namespace.lookupMacroDeclaration("DEPLOYMENT_TARGET_SETTING_NAME") as? StringMacroDeclaration), literal: deploymentTargetName)
table.push(try #require(namespace.lookupMacroDeclaration(deploymentTargetName) as? StringMacroDeclaration), literal: deploymentTarget)
// I'm not sure why createMockScope() includes a particular and strange value for TARGET_DEVICE_FAMILY, but we override it here.
if sdkVariant == MacCatalystInfo.sdkVariantName {
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "6") // 6 is Mac
}
else {
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "")
}
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: platformName, sdkName: sdkName, sdkVariant: sdkVariant, productTypeId: "com.apple.product-type.framework") { result, dict, outputDelegate in
#expect(result == (outputDelegate.errors.isEmpty ? .succeeded : .failed), sourceLocation: sourceLocation)
checkResults(dict, deploymentTargetName, outputDelegate)
}
}
/// Test that the processor correctly identifies invalid values for the minimum system version Info.plist key across a variety of scenarios and acts accordingly.
@Test(.requireSDKs(.macOS))
func minimumSystemVersionValidation_macOS() async throws {
// macOS
try await testScenario(platformName: "macosx", deploymentTargetName: "MACOSX_DEPLOYMENT_TARGET", deploymentTarget: "11.0", minimumSystemVersion: "10.15") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"]?.stringValue == "11.0")
#expect(dict["MinimumOSVersion"] == nil)
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: LSMinimumSystemVersion of \'10.15\' is less than the value of \(deploymentTargetName) \'11.0\' - setting to \'11.0\'."])
#expect(outputDelegate.notes == [])
}
// MacCatalyst
try await testScenario(platformName: "macosx", sdkVariant: MacCatalystInfo.sdkVariantName, deploymentTargetName: "MACOSX_DEPLOYMENT_TARGET", deploymentTarget: "11.0", minimumSystemVersion: "10.15") { dict, deploymentTargetName, outputDelegate in
// Catalyst uses the macOS key. c.f. <rdar://problem/39179904>
#expect(dict["LSMinimumSystemVersion"]?.stringValue == "11.0")
#expect(dict["MinimumOSVersion"] == nil)
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: LSMinimumSystemVersion of \'10.15\' is less than the value of \(deploymentTargetName) \'11.0\' - setting to \'11.0\'."])
#expect(outputDelegate.notes == [])
}
// Empty deployment target
try await testScenario(platformName: "macosx", deploymentTargetName: "MACOSX_DEPLOYMENT_TARGET", deploymentTarget: "", minimumSystemVersion: "10.15") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"]?.stringValue == "10.15")
#expect(dict["MinimumOSVersion"] == nil)
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
}
// Empty minimum system version - we replace it with the deployment target
try await testScenario(platformName: "macosx", deploymentTargetName: "MACOSX_DEPLOYMENT_TARGET", deploymentTarget: "11.0", minimumSystemVersion: "") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"]?.stringValue == "11.0")
#expect(dict["MinimumOSVersion"] == nil)
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: LSMinimumSystemVersion is explicitly set to empty - setting to value of \(deploymentTargetName) \'11.0\'."])
#expect(outputDelegate.notes == [])
}
// Invalid minimum system version - we emit an error but don't change the value.
try await testScenario(platformName: "macosx", deploymentTargetName: "MACOSX_DEPLOYMENT_TARGET", deploymentTarget: "11.0", minimumSystemVersion: "nuts") { dict, deploymentTargetName, outputDelegate in
// We should have added some keys.
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"] == nil)
#expect(outputDelegate.errors == ["error: LSMinimumSystemVersion \'nuts\' is not a valid version."])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
}
}
/// Test that the processor correctly identifies invalid values for the minimum system version Info.plist key across a variety of scenarios and acts accordingly.
@Test(.requireSDKs(.iOS))
func minimumSystemVersionValidation_iOS() async throws {
// iOS
try await testScenario(platformName: "iphoneos", deploymentTargetName: "IPHONEOS_DEPLOYMENT_TARGET", deploymentTarget: "14.0", minimumSystemVersion: "13.0") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"]?.stringValue == "14.0")
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: MinimumOSVersion of \'13.0\' is less than the value of \(deploymentTargetName) \'14.0\' - setting to \'14.0\'."])
#expect(outputDelegate.notes == [])
}
// Empty deployment target
try await testScenario(platformName: "iphoneos", deploymentTargetName: "IPHONEOS_DEPLOYMENT_TARGET", deploymentTarget: "", minimumSystemVersion: "13.0") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"]?.stringValue == "13.0")
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
}
// Empty minimum system version - we replace it with the deployment target
try await testScenario(platformName: "iphoneos", deploymentTargetName: "IPHONEOS_DEPLOYMENT_TARGET", deploymentTarget: "14.0", minimumSystemVersion: "") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"]?.stringValue == "14.0")
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: MinimumOSVersion is explicitly set to empty - setting to value of \(deploymentTargetName) \'14.0\'."])
#expect(outputDelegate.notes == [])
}
// Invalid minimum system version - we emit an error but don't change the value.
try await testScenario(platformName: "iphoneos", deploymentTargetName: "IPHONEOS_DEPLOYMENT_TARGET", deploymentTarget: "14.0", minimumSystemVersion: "nuts") { dict, deploymentTargetName, outputDelegate in
// We should have added some keys.
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"] == nil)
#expect(outputDelegate.errors == ["error: MinimumOSVersion \'nuts\' is not a valid version."])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
}
}
/// Test that the processor correctly identifies invalid values for the minimum system version Info.plist key across a variety of scenarios and acts accordingly.
@Test(.requireSDKs(.tvOS))
func minimumSystemVersionValidation_tvOS() async throws {
try await testScenario(platformName: "appletvos", deploymentTargetName: "TVOS_DEPLOYMENT_TARGET", deploymentTarget: "14.0", minimumSystemVersion: "13.0") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"]?.stringValue == "14.0")
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: MinimumOSVersion of \'13.0\' is less than the value of \(deploymentTargetName) \'14.0\' - setting to \'14.0\'."])
#expect(outputDelegate.notes == [])
}
}
/// Test that the processor correctly identifies invalid values for the minimum system version Info.plist key across a variety of scenarios and acts accordingly.
@Test(.requireSDKs(.driverKit))
func minimumSystemVersionValidation_DriverKit() async throws {
try await testScenario(platformName: "driverkit", sdkName: "driverkit", deploymentTargetName: "DRIVERKIT_DEPLOYMENT_TARGET", deploymentTarget: "20.0", minimumSystemVersion: "19.0") { dict, deploymentTargetName, outputDelegate in
#expect(dict["LSMinimumSystemVersion"] == nil)
#expect(dict["MinimumOSVersion"] == nil)
#expect(dict["OSMinimumDriverKitVersion"]?.stringValue == "20.0")
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == ["warning: OSMinimumDriverKitVersion of \'19.0\' is less than the value of \(deploymentTargetName) \'20.0\' - setting to \'20.0\'."])
#expect(outputDelegate.notes == [])
}
}
/// When processing an Info.plist configured to build for both macCatalyst and iOS, the results will be different depending on whether we're building for macCatalyst or for iOS.
@Test
func processingInfoPlistConfiguredForBothMacCatalystAndIOS() async throws {
let services: [[String: PropertyListItem]] = [
[
"NSMenuItem": [
"default": "Stuff",
],
"NSMessage": "This doesn't work",
],
[
"NSMenuItem": [
"default": "More",
],
"NSMessage": "This one does",
],
]
let plistData: [String: PropertyListItem] = [
"Foo": "Bar",
"LSApplicationCategoryType": "public.app-category.entertainment",
"LSRequiresIPhoneOS": true,
"NSSupportsAutomaticTermination": true,
"NSSupportsSuddenTermination": false,
"NSServices": PropertyListItem(services),
]
// Test building for iOS.
do {
let scope = try createMockScope(debugDescription: "\(#function)_iOS") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "iphoneos") { result, dict, outputDelegate in
// There will be a lot of keys in the dict which were added from the platform, so we only check the ones we're testing/
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
// Check that iOS-specific keys are present.
#expect(dict["LSRequiresIPhoneOS"]?.boolValue == true)
#expect(dict["LSApplicationCategoryType"]?.stringValue == "public.app-category.entertainment")
// Check that macOS-specific keys have been removed.
#expect(dict["NSSupportsAutomaticTermination"] == nil)
#expect(dict["NSSupportsSuddenTermination"] == nil)
#expect(dict["NSServices"] == nil)
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString.split(separator: "\n")
#expect(output.contains("removing entry for \"NSSupportsAutomaticTermination\" - only supported on macOS"))
#expect(output.contains("removing entry for \"NSSupportsSuddenTermination\" - only supported on macOS"))
}
}
// Test build for macCatalyst.
do {
let scope = try createMockScope(debugDescription: "\(#function)_macOS") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("SDK_VARIANT") as? StringMacroDeclaration), literal: MacCatalystInfo.sdkVariantName)
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "macosx", sdkVariant: MacCatalystInfo.sdkVariantName) { result, dict, outputDelegate in
// There will be a lot of keys in the dict which were added from the platform, so we only check the ones we're testing/
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
#expect(dict["LSApplicationCategoryType"]?.stringValue == "public.app-category.entertainment")
// Check that macOS-specific keys are present.
#expect(dict["NSSupportsAutomaticTermination"]?.boolValue == true)
#expect(dict["NSSupportsSuddenTermination"]?.boolValue == false)
#expect(dict["NSServices"]?.arrayValue == services.map { $0.propertyListItem })
// Check that iOS-specific keys have been removed.
#expect(dict["LSRequiresIPhoneOS"] == nil)
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString.split(separator: "\n")
#expect(output.contains("removing entry for \"LSRequiresIPhoneOS\" - not supported on macOS"))
}
}
}
/// When processing an Info.plist for macCatalyst, make sure expected keys get added or transformed.
@Test
func processingInfoPlistForMacCatalyst() async throws {
do {
let plistData: [String: PropertyListItem] = [
"Foo": "Bar",
]
let scope = try createMockScope(debugDescription: "\(#function)_app_macCatalyst_missing") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("SDK_VARIANT") as? StringMacroDeclaration), literal: MacCatalystInfo.sdkVariantName)
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "macosx", sdkVariant: MacCatalystInfo.sdkVariantName, productTypeId: "com.apple.product-type.application") { result, dict, outputDelegate in
// We should have added some keys.
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
#expect(dict["NSSupportsAutomaticTermination"]?.boolValue ?? false)
#expect(dict["NSSupportsSuddenTermination"]?.boolValue ?? false)
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString.split(separator: "\n")
#expect(output.contains("adding entry for \"NSSupportsAutomaticTermination\" => 1"))
#expect(output.contains("adding entry for \"NSSupportsSuddenTermination\" => 1"))
}
}
// Test that keys are not added (overwritten) when already present when building an application for macCatalyst.
do {
let plistData: [String: PropertyListItem] = [
"Foo": "Bar",
"NSSupportsAutomaticTermination": false,
"NSSupportsSuddenTermination": false,
]
let scope = try createMockScope(debugDescription: "\(#function)_app_macCatalyst_present") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("SDK_VARIANT") as? StringMacroDeclaration), literal: MacCatalystInfo.sdkVariantName)
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "macosx", sdkVariant: MacCatalystInfo.sdkVariantName, productTypeId: "com.apple.product-type.application") { result, dict, outputDelegate in
// We should have added some keys.
#expect(dict["Foo"]?.stringValue == "Bar")
if let autoTerm = dict["NSSupportsAutomaticTermination"]?.boolValue {
#expect(!autoTerm)
}
else {
Issue.record("NSSupportsAutomaticTermination not found")
}
if let suddenTerm = dict["NSSupportsSuddenTermination"]?.boolValue {
#expect(!suddenTerm)
}
else {
Issue.record("NSSupportsSuddenTermination not found")
}
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream.
let output = outputDelegate.textBytes.asString
#expect(output == "")
}
}
// Test that keys are not added if absent when building a non-application for macCatalyst.
do {
let plistData: [String: PropertyListItem] = [
"Foo": "Bar",
]
let scope = try createMockScope(debugDescription: "\(#function)_nonapp_macCatalyst_present") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("SDK_VARIANT") as? StringMacroDeclaration), literal: MacCatalystInfo.sdkVariantName)
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "macosx", sdkVariant: MacCatalystInfo.sdkVariantName, productTypeId: nil) { result, dict, outputDelegate in
// We should have added some keys.
#expect(dict["Foo"]?.stringValue == "Bar")
#expect(dict["NSSupportsAutomaticTermination"] == nil)
#expect(dict["NSSupportsSuddenTermination"] == nil)
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream.
let output = outputDelegate.textBytes.asString
#expect(output == "")
}
}
// Test that keys are not added if absent when building an application for iOS.
do {
let plistData: [String: PropertyListItem] = [
"Foo": "Bar",
]
let scope = try createMockScope(debugDescription: "\(#function)_app_ios_missing") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("SDK_VARIANT") as? StringMacroDeclaration), literal: MacCatalystInfo.sdkVariantName)
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "iphoneos", productTypeId: "com.apple.product-type.application") { result, dict, outputDelegate in
// We should have added some keys.
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
#expect(dict["NSSupportsAutomaticTermination"] == nil)
#expect(dict["NSSupportsSuddenTermination"] == nil)
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString
#expect(output == "")
}
}
// Test that keys are not added if absent when building an application for macOS (not macCatalyst).
do {
let plistData: [String: PropertyListItem] = [
"Foo": "Bar",
]
let scope = try createMockScope(debugDescription: "\(#function)_app_ios_missing") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: plistData, scope: scope, platformName: "macosx", productTypeId: "com.apple.product-type.application") { result, dict, outputDelegate in
// We should have added some keys.
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
#expect(dict["NSSupportsAutomaticTermination"] == nil)
#expect(dict["NSSupportsSuddenTermination"] == nil)
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString
#expect(output == "")
}
}
}
/// Common Info.plist input data for the various per-platform tests below.
private let commonProcessingInfoPlistData: [String: PropertyListItem] = [
"Foo": "Bar",
"LSApplicationCategoryType": "public.app-category.entertainment",
"LSRequiresIPhoneOS": true,
"UIBackgroundModes": [
"audio",
"location",
"voip",
"fetch",
"remote-notification",
"newsstand-content",
"external-accessory",
"bluetooth-central",
"bluetooth-peripheral",
"network-authentication",
"nearby-interaction",
"processing",
"push-to-talk",
"screen-capture"
]
]
/// When processing an Info.plist configured to build for iOS.
@Test(.requireSDKs(.iOS))
func processingInfoPlistConfiguredForPlatform_iOS() async throws {
let scope = try createMockScope(debugDescription: "\(#function)_iOS") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "2")
}
try await createAndRunTaskAction(inputPlistData: commonProcessingInfoPlistData, scope: scope, platformName: "iphoneos") { result, dict, outputDelegate in
// There will be a lot of keys in the dict which were added from the platform, so we only check the ones we're testing/
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
// Check that iOS-specific keys are present.
#expect(dict["LSRequiresIPhoneOS"]?.boolValue == true)
// Check that only the iOS-specific values exist.
let backgroundModes = try #require(dict["UIBackgroundModes"]?.stringArrayValue)
#expect(backgroundModes.contains("audio"))
#expect(backgroundModes.contains("location"))
#expect(backgroundModes.contains("voip"))
#expect(backgroundModes.contains("fetch"))
#expect(backgroundModes.contains("remote-notification"))
#expect(backgroundModes.contains("newsstand-content"))
#expect(backgroundModes.contains("external-accessory"))
#expect(backgroundModes.contains("bluetooth-central"))
#expect(backgroundModes.contains("bluetooth-peripheral"))
#expect(backgroundModes.contains("network-authentication"))
#expect(backgroundModes.contains("nearby-interaction"))
#expect(backgroundModes.contains("processing"))
#expect(backgroundModes.contains("push-to-talk"))
#expect(backgroundModes.contains("screen-capture"))
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString
#expect(output.isEmpty)
}
}
/// `INFOPLIST_KEY_UILaunchScreen_Generation = YES` must synthesize a flat, empty
/// `UILaunchScreen` dictionary, not a nested one.
@Test(.requireSDKs(.iOS))
func processingInfoPlistWithLaunchScreenGeneration_iOS() async throws {
let scope = try createMockScope { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("GENERATE_INFOPLIST_FILE") as? BooleanMacroDeclaration), literal: true)
table.push(try #require(namespace.lookupMacroDeclaration("INFOPLIST_KEY_UILaunchScreen_Generation") as? BooleanMacroDeclaration), literal: true)
}
try await createAndRunTaskAction(inputPlistData: [:], scope: scope, platformName: "iphoneos") { _, dict, _ in
#expect(dict["UILaunchScreen"]?.dictValue == [:])
}
}
/// When processing an Info.plist configured to build for tvOS.
@Test(.requireSDKs(.tvOS))
func processingInfoPlistConfiguredForPlatform_tvOS() async throws {
let scope = try createMockScope(debugDescription: "\(#function)_tvOS") { namespace, table in
table.push(try #require(namespace.lookupMacroDeclaration("TARGETED_DEVICE_FAMILY") as? StringMacroDeclaration), literal: "3")
}
try await createAndRunTaskAction(inputPlistData: commonProcessingInfoPlistData, scope: scope, platformName: "appletvos") { result, dict, outputDelegate in
// There will be a lot of keys in the dict which were added from the platform, so we only check the ones we're testing/
#expect(dict["Foo"]?.stringValue ?? "" == "Bar")
// This key applies to both iOS and tvOS.
#expect(dict["LSRequiresIPhoneOS"]?.boolValue == true)
// Check that only the tvOS-specific values exist.
let backgroundModes = try #require(dict["UIBackgroundModes"]?.stringArrayValue)
#expect(backgroundModes.contains("audio"))
#expect(!backgroundModes.contains("location"))
#expect(!backgroundModes.contains("voip"))
#expect(backgroundModes.contains("fetch"))
#expect(backgroundModes.contains("remote-notification"))
#expect(!backgroundModes.contains("newsstand-content"))
#expect(!backgroundModes.contains("external-accessory"))
#expect(!backgroundModes.contains("bluetooth-central"))
#expect(!backgroundModes.contains("bluetooth-peripheral"))
#expect(!backgroundModes.contains("network-authentication"))
#expect(!backgroundModes.contains("nearby-interaction"))
#expect(backgroundModes.contains("processing"))
#expect(!backgroundModes.contains("push-to-talk"))
#expect(!backgroundModes.contains("screen-capture"))
// Check that there were no issues.
#expect(outputDelegate.errors == [])
#expect(outputDelegate.warnings == [])
#expect(outputDelegate.notes == [])
// Check expected content in the output stream. This doesn't need to be exhaustive for all keys as the goal of this check is to make sure that the note in the transcript doesn't completely break.
let output = outputDelegate.textBytes.asString
XCTAssertMatch(output, .contains("removing value \"bluetooth-central\" for \"UIBackgroundModes\" - not supported on tvOS"))
XCTAssertMatch(output, .contains("removing value \"bluetooth-peripheral\" for \"UIBackgroundModes\" - only supported on iOS"))
XCTAssertMatch(output, .contains("removing value \"external-accessory\" for \"UIBackgroundModes\" - only supported on iOS"))
XCTAssertMatch(output, .contains("removing value \"location\" for \"UIBackgroundModes\" - not supported on tvOS"))
XCTAssertMatch(output, .contains("removing value \"network-authentication\" for \"UIBackgroundModes\" - not supported on tvOS"))
XCTAssertMatch(output, .contains("removing value \"nearby-interaction\" for \"UIBackgroundModes\" - only supported on iOS"))
XCTAssertMatch(output, .contains("removing value \"newsstand-content\" for \"UIBackgroundModes\" - only supported on iOS"))