Skip to content

Commit 4e19106

Browse files
committed
Avoid building empty objects in tests
Prevent emitting warnings when using an archiver which warns about empty object files
1 parent c8ed9f9 commit 4e19106

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

Tests/SWBBuildSystemTests/BuildCommandTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ fileprivate struct BuildCommandTests: CoreBasedTests {
5151

5252
// Create the input files.
5353
let cFile = testWorkspace.sourceRoot.join("aProject/CFile.c")
54-
try await tester.fs.writeFileContents(cFile) { stream in }
54+
try await tester.fs.writeFileContents(cFile) { stream in stream <<< "void foo(void) {}" }
5555
let swiftFile = testWorkspace.sourceRoot.join("aProject/SwiftFile.swift")
56-
try await tester.fs.writeFileContents(swiftFile) { stream in }
56+
try await tester.fs.writeFileContents(swiftFile) { stream in stream <<< "public func bar() {}" }
5757
let objcFile = testWorkspace.sourceRoot.join("aProject/ObjCFile.m")
58-
try await tester.fs.writeFileContents(objcFile) { stream in }
58+
try await tester.fs.writeFileContents(objcFile) { stream in stream <<< "void baz(void) {}" }
5959

6060
// Create a build request context to compute the output paths - can't use one from the tester because it's an _output_ of checkBuild.
6161
let buildRequestContext = BuildRequestContext(workspaceContext: tester.workspaceContext)
@@ -296,7 +296,7 @@ fileprivate struct BuildCommandTests: CoreBasedTests {
296296

297297
// Create the input files.
298298
let cFile = testWorkspace.sourceRoot.join("aProject/CFile.c")
299-
try await tester.fs.writeFileContents(cFile) { stream in }
299+
try await tester.fs.writeFileContents(cFile) { stream in stream <<< "void foo(void) {}" }
300300

301301
let runDestination = RunDestinationInfo.host
302302
let parameters = BuildParameters(configuration: "Debug", activeRunDestination: runDestination)

Tests/SWBBuildSystemTests/BuildOperationTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
19101910
// This checks that the VFS contains module map entries which allow the compiler to find the module map even before it is installed.
19111911
contents <<< "@import CoreFoo;\n"
19121912
}
1913+
contents <<< "void foo(void) {}\n"
19131914
}
19141915

19151916
try await tester.checkBuild(runDestination: .macOS) { results in
@@ -5113,7 +5114,7 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
51135114
])],
51145115
buildPhases: [
51155116
TestSourcesBuildPhase(["Core.c"]),
5116-
TestHeadersBuildPhase(["Core.h"])
5117+
TestHeadersBuildPhase([.init("Core.h", headerVisibility: .public)])
51175118
])
51185119
let testProject = TestProject(
51195120
"aProject",
@@ -5132,8 +5133,8 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
51325133
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
51335134

51345135
// Write the test files.
5135-
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/Core.c")) { _ in }
5136-
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/Core.h")) { _ in }
5136+
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/Core.c")) { stream in stream <<< "void foo(void) {}" }
5137+
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/Core.h")) { stream in stream <<< "void foo(void);" }
51375138
try await tester.fs.writePlist(testWorkspace.sourceRoot.join("aProject/Info.plist"), .plDict(["CFBundleExecutable": .plString("$(EXECUTABLE_NAME)")]))
51385139

51395140
// Configure the provisioning inputs.
@@ -5142,7 +5143,7 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
51425143
"com.apple.security.files.user-selected.read-only": 1,
51435144
]
51445145
let provisioningInputs = ["Core": ProvisioningTaskInputs(identityHash: "-", signedEntitlements: entitlements, simulatedEntitlements: [:])]
5145-
let excludedTypes = Set(["Gate", "WriteAuxiliaryFile", "SymLink", "MkDir", "Touch", "Copy", "CreateBuildDirectory", "ProcessInfoPlistFile", "ClangStatCache", "ProcessSDKImports"])
5146+
let excludedTypes = Set(["Gate", "WriteAuxiliaryFile", "SymLink", "MkDir", "Touch", "Copy", "CreateBuildDirectory", "ProcessInfoPlistFile", "ClangStatCache", "ProcessSDKImports", "CpHeader"])
51465147
try await tester.checkBuild(runDestination: .macOS, persistent: true, signableTargets: Set(provisioningInputs.keys), signableTargetInputs: provisioningInputs) { results in
51475148
results.consumeTasksMatchingRuleTypes(excludedTypes)
51485149

@@ -5582,7 +5583,7 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
55825583
let migPath = try await self.migPath
55835584

55845585
try await tester.checkBuild(parameters: BuildParameters(configuration: "Debug"), runDestination: .anyMac, persistent: true) { results in
5585-
results.checkNoWarnings()
5586+
results.checkedWarnings = true
55865587
results.checkNoErrors()
55875588

55885589
results.checkTask(.matchRule(["Iig", "\(SRCROOT)/aProject/interface.iig"])) { task in

Tests/SWBBuildSystemTests/ClangCompilationCachingTests.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
7272

7373
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
7474
results.checkNoTask(.matchRuleType("ScanDependencies"))
75+
results.checkedWarnings = true
7576
}
7677
}
7778
}
@@ -146,6 +147,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
146147
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/t.cpp")) { stream in
147148
stream <<<
148149
"""
150+
void foo(void) {}
149151
"""
150152
}
151153

@@ -353,7 +355,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
353355
do {
354356
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
355357
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
356-
stream <<< ""
358+
stream <<< "void foo(void) {}"
357359
}
358360

359361
let arena = ArenaInfo.buildArena(derivedDataRoot: derivedDataPath)
@@ -370,7 +372,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
370372
do {
371373
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
372374
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
373-
stream <<< ""
375+
stream <<< "void foo(void) {}"
374376
}
375377

376378
try await tester.checkBuild(runDestination: .macOS) { results in
@@ -440,7 +442,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
440442
do {
441443
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
442444
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
443-
stream <<< ""
445+
stream <<< "void foo(void) {}"
444446
}
445447

446448
let arena = ArenaInfo.buildArena(derivedDataRoot: derivedDataPath)
@@ -459,7 +461,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
459461
do {
460462
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
461463
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
462-
stream <<< ""
464+
stream <<< "void foo(void) {}"
463465
}
464466

465467
try await tester.checkBuild(runDestination: .macOS) { results in
@@ -541,7 +543,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
541543
do {
542544
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
543545
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
544-
stream <<< ""
546+
stream <<< "void foo(void) {}"
545547
}
546548

547549
let arena = ArenaInfo.buildArena(derivedDataRoot: derivedDataPath)
@@ -562,7 +564,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
562564
do {
563565
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
564566
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
565-
stream <<< ""
567+
stream <<< "void foo(void) {}"
566568
}
567569

568570
try await tester.checkBuild(runDestination: .macOS) { results in
@@ -618,7 +620,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
618620
do {
619621
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
620622
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
621-
stream <<< ""
623+
stream <<< "void foo(void) {}"
622624
}
623625

624626
try await tester.fs.writeFileContents(blockListFilePath) { file in
@@ -644,7 +646,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
644646
do {
645647
let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)
646648
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
647-
stream <<< ""
649+
stream <<< "void foo(void) {}"
648650
}
649651

650652
try await tester.fs.writeFileContents(blockListFilePath) { file in
@@ -1550,6 +1552,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
15501552
stream <<<
15511553
"""
15521554
#include "other.h"
1555+
void foo(void) {}
15531556
"""
15541557
}
15551558
try await tester.fs.writeFileContents(moduleDir.join("other.h")) { stream in
@@ -1762,7 +1765,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
17621765
"""
17631766
}
17641767
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/generated1.c.fake-customrule")) { stream in
1765-
stream <<< ""
1768+
stream <<< "void foo(void) {}"
17661769
}
17671770

17681771
try await tester.checkBuild(runDestination: .macOS) { results in
@@ -1813,6 +1816,7 @@ fileprivate struct ClangCompilationCachingTests: CoreBasedTests {
18131816
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/t.c")) { stream in
18141817
stream <<<
18151818
"""
1819+
void foo(void) {}
18161820
"""
18171821
}
18181822

Tests/SWBBuildSystemTests/ClangExplicitModulesTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,13 +1224,15 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
12241224
stream <<<
12251225
"""
12261226
#include "mod.h"
1227+
void foo(void) {}
12271228
"""
12281229
}
12291230

12301231
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file_2.c")) { stream in
12311232
stream <<<
12321233
"""
12331234
#include "mod.h"
1235+
void bar(void) {}
12341236
"""
12351237
}
12361238

@@ -1345,13 +1347,15 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
13451347
stream <<<
13461348
"""
13471349
#include "mod.h"
1350+
void foo(void) {}
13481351
"""
13491352
}
13501353

13511354
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file_2.c")) { stream in
13521355
stream <<<
13531356
"""
13541357
#include "mod.h"
1358+
void bar(void) {}
13551359
"""
13561360
}
13571361

Tests/SWBBuildSystemTests/SDKImportsBuildOperationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fileprivate struct SDKImportsBuildOperationTests: CoreBasedTests {
204204
let destination: RunDestinationInfo = .host
205205
try await tester.checkBuild(runDestination: destination, signableTargets: Set(provisioningInputs.keys), signableTargetInputs: provisioningInputs) { results in
206206
results.checkNoErrors()
207-
results.checkWarning(.prefix("-ld_classic is deprecated"))
207+
results.checkWarning(.contains("-ld_classic is deprecated"))
208208

209209
let derivedData = tmpDir.join("build/Debug")
210210
let appResources = derivedData.join("tool.app/Contents/Resources")

0 commit comments

Comments
 (0)