Skip to content

Commit bc6f8b7

Browse files
committed
Make many clang explicit modules tests cross-platform
1 parent 018218e commit bc6f8b7

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
972972
// Check that this is the same toolchain and version as the compiler. Mismatched clang/libclang is not supported with explicit modules.
973973
let compilerAndLibraryAreInSameToolchain = toolchainPath.isAncestor(of: compiler)
974974
let libclangVersion = cbc.producer.lookupLibclang(path: path).version
975-
let compilerAndLibraryVersionsMatch = libclangVersion != nil && libclangVersion == clangInfo?.clangVersion
975+
// On macOS we enforce a matching clang and libclang version, the versioning schemes on other host platforms currently make this difficult.
976+
let compilerAndLibraryVersionsMatch = libclangVersion != nil && libclangVersion == clangInfo?.clangVersion || cbc.producer.hostOperatingSystem != .macOS
976977
if compilerAndLibraryAreInSameToolchain && (compilerAndLibraryVersionsMatch || cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_IGNORE_LIBCLANG_VERSION_MISMATCH)) {
977978
return path
978979
}

Tests/SWBBuildSystemTests/ClangExplicitModulesTests.swift

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import SwiftBuildTestSupport
2121
import SWBUtil
2222
import SWBProtocol
2323

24-
@Suite(.requireDependencyScanner, .requireXcode16())
24+
@Suite(.requireDependencyScanner)
2525
fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
26-
@Test(.requireSDKs(.macOS))
26+
@Test(.requireSDKs(.host))
2727
func explicitModulesBasic() async throws {
2828
try await withTemporaryDirectory { tmpDirPath in
2929
let testWorkspace = TestWorkspace(
@@ -63,7 +63,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
6363
"""
6464
}
6565

66-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
66+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
6767
let scanTask: Task = try results.checkTask(.matchRuleType("ScanDependencies")) { $0 }
6868
let compileTask: Task = try results.checkTask(.matchRuleType("CompileC")) { $0 }
6969

@@ -89,7 +89,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
8989
"""
9090
}
9191

92-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
92+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
9393
// the test stops at point of failure, so no additional failures are observed. behaves correctly
9494
let scanTask: Task = try results.checkTask(.matchRuleType("ScanDependencies")) { $0 }
9595
let compileTask: Task = try results.checkTask(.matchRuleType("CompileC")) { $0 }
@@ -105,7 +105,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
105105
}
106106
}
107107

108-
@Test(.requireSDKs(.macOS))
108+
@Test(.requireSDKs(.host))
109109
func explicitModulesLibclangOpenFailure() async throws {
110110
try await withTemporaryDirectory { tmpDirPath in
111111
let testWorkspace = TestWorkspace(
@@ -146,14 +146,14 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
146146
"""
147147
}
148148

149-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
149+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
150150
results.checkError(.and(.contains("error scanning dependencies for source"), .contains("could not load \(Path.null.str)")))
151151
results.checkNoDiagnostics()
152152
}
153153
}
154154
}
155155

156-
@Test(.requireSDKs(.macOS))
156+
@Test(.requireSDKs(.host))
157157
func explicitModulesMultipleSources() async throws {
158158
try await withTemporaryDirectory { tmpDirPath in
159159
let testWorkspace = TestWorkspace(
@@ -202,7 +202,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
202202
"""
203203
}
204204

205-
try await tester.checkBuild(runDestination: .macOS) { results in
205+
try await tester.checkBuild(runDestination: .host) { results in
206206
// There should only be 2 scanning actions.
207207
results.checkTasks(.matchRuleType("ScanDependencies")) { scanTasks in
208208
#expect(scanTasks.count == 2)
@@ -283,7 +283,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
283283
}
284284
}
285285

286-
@Test(.requireSDKs(.macOS))
286+
@Test(.requireSDKs(.host))
287287
func explicitModulesWithPrecompiledHeader() async throws {
288288
try await withTemporaryDirectory { tmpDirPath in
289289
let testWorkspace = TestWorkspace(
@@ -353,7 +353,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
353353
"""
354354
}
355355

356-
try await tester.checkBuild(runDestination: .macOS) { results in
356+
try await tester.checkBuild(runDestination: .host) { results in
357357
// There should be 2 scanning actions - one for the precompiled header, one for the translation unit.
358358
results.checkTasks(.matchRuleType("ScanDependencies")) { scanTasks in
359359
#expect(scanTasks.count == 2)
@@ -428,7 +428,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
428428
}
429429
}
430430

431-
@Test(.requireSDKs(.macOS))
431+
@Test(.requireSDKs(.host))
432432
func explicitModulesWorkingDirectory() async throws {
433433
try await withTemporaryDirectory { tmpDirPath in
434434
let testWorkspace = TestWorkspace(
@@ -481,7 +481,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
481481
"""
482482
}
483483

484-
try await tester.checkBuild(runDestination: .macOS) { results in
484+
try await tester.checkBuild(runDestination: .host) { results in
485485
// Check that the "Includes" header search path got picked up due to CompileC being executed in the project source directory.
486486
results.checkNoDiagnostics()
487487
}
@@ -596,7 +596,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
596596
}
597597
}
598598

599-
@Test(.requireSDKs(.macOS))
599+
@Test(.requireSDKs(.host))
600600
func explicitModulesDriverExpandsToMultipleCC1s() async throws {
601601
try await withTemporaryDirectory { tmpDirPath in
602602
let testWorkspace = TestWorkspace(
@@ -654,7 +654,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
654654
"""
655655
}
656656

657-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
657+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
658658
results.checkTask(.matchRuleType("ScanDependencies")) { _ in }
659659
results.checkTask(.matchRuleType("PrecompileModule")) { _ in }
660660
var outputs = results.checkTask(.matchRuleType("CompileC")) { task in
@@ -1074,7 +1074,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
10741074
}
10751075
}
10761076

1077-
@Test(.requireSDKs(.macOS))
1077+
@Test(.requireSDKs(.host))
10781078
func outputPath() async throws {
10791079
try await withTemporaryDirectory { tmpDir in
10801080
func outputPathTest(given outputPathBuildSetting: String?, expected outputPath: Path, sourceLocation: SourceLocation = #_sourceLocation) async throws {
@@ -1119,7 +1119,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
11191119
"""
11201120
}
11211121

1122-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
1122+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
11231123

11241124
results.checkNoErrors()
11251125

@@ -1146,12 +1146,10 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
11461146

11471147
try await outputPathTest(given: nil, expected: tmpDir.join("aProject/build/ExplicitPrecompiledModules"))
11481148
try await outputPathTest(given: "$(SRCROOT)/Modules", expected: tmpDir.join("aProject/Modules"))
1149-
try await outputPathTest(given: "$(PER_ARCH_OBJECT_FILE_DIR)/Modules", expected: tmpDir.join("aProject/build/aProject.build/Debug/Library.build/Objects-normal/x86_64/Modules"))
1150-
try await outputPathTest(given: "$(BUILT_PRODUCTS_DIR)/Modules", expected: tmpDir.join("aProject/build/Debug/Modules"))
11511149
}
11521150
}
11531151

1154-
@Test(.requireSDKs(.macOS))
1152+
@Test(.requireSDKs(.host))
11551153
func explicitModulesSharingOfDependencies() async throws {
11561154
try await withTemporaryDirectory { tmpDirPath in
11571155
let testWorkspace = TestWorkspace(
@@ -1241,7 +1239,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
12411239

12421240
let target_1 = try #require(tester.workspace.targets(named: "Library_1").only)
12431241
let target_2 = try #require(tester.workspace.targets(named: "Library_2").only)
1244-
try await tester.checkBuild(runDestination: .macOS, buildRequest: BuildRequest(parameters: parameters, buildTargets: [.init(parameters: parameters, target: target_1), .init(parameters: parameters, target: target_2)], continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: true, useDryRun: false)) { results in
1242+
try await tester.checkBuild(runDestination: .host, buildRequest: BuildRequest(parameters: parameters, buildTargets: [.init(parameters: parameters, target: target_1), .init(parameters: parameters, target: target_2)], continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: true, useDryRun: false)) { results in
12451243

12461244
results.checkTasks(.matchRuleType("ScanDependencies")) { scanTasks in
12471245
#expect(scanTasks.count == 2)
@@ -1260,7 +1258,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
12601258
}
12611259

12621260
let target_1_2 = try #require(tester.workspace.targets(named: "Library_1_2").only)
1263-
try await tester.checkBuild(runDestination: .macOS, buildRequest: BuildRequest(parameters: parameters, buildTargets: [.init(parameters: parameters, target: target_1_2)], continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: true, useDryRun: false)) { results in
1261+
try await tester.checkBuild(runDestination: .host, buildRequest: BuildRequest(parameters: parameters, buildTargets: [.init(parameters: parameters, target: target_1_2)], continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: true, useDryRun: false)) { results in
12641262

12651263
results.checkTasks(.matchRuleType("ScanDependencies")) { scanTasks in
12661264
#expect(scanTasks.count == 2)
@@ -1280,7 +1278,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
12801278
}
12811279
}
12821280

1283-
@Test(.requireSDKs(.macOS))
1281+
@Test(.requireSDKs(.host))
12841282
func sharingBetweenTargets() async throws {
12851283

12861284
try await withTemporaryDirectory { tmpDir in
@@ -1363,7 +1361,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
13631361
let parameters = BuildParameters(configuration: "Debug")
13641362
let buildRequest = BuildRequest(parameters: parameters, buildTargets: tester.workspace.projects[0].targets.map({ BuildRequest.BuildTargetInfo(parameters: parameters, target: $0) }), continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: false, useDryRun: false)
13651363

1366-
try await tester.checkBuild(runDestination: .macOS, buildRequest: buildRequest, persistent: true) { results in
1364+
try await tester.checkBuild(runDestination: .host, buildRequest: buildRequest, persistent: true) { results in
13671365

13681366
for targetName in ["Library_1", "Library_2"] {
13691367
results.checkTaskExists(.matchTargetName(targetName), .matchRuleType("ScanDependencies"))
@@ -1379,7 +1377,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
13791377
}
13801378
}
13811379

1382-
@Test(.requireSDKs(.macOS), .requireDependencyScanner, .requireDependencyScannerWorkingDirectoryOptimization)
1380+
@Test(.requireSDKs(.host), .requireDependencyScanner, .requireDependencyScannerWorkingDirectoryOptimization)
13831381
func sharingBetweenProjects() async throws {
13841382
try await withTemporaryDirectory { tmpDir in
13851383
let testWorkspace = TestWorkspace(
@@ -1469,7 +1467,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
14691467
let parameters = BuildParameters(configuration: "Debug")
14701468
let buildRequest = BuildRequest(parameters: parameters, buildTargets: tester.workspace.projects[0].targets.map({ BuildRequest.BuildTargetInfo(parameters: parameters, target: $0) }) + tester.workspace.projects[1].targets.map({ BuildRequest.BuildTargetInfo(parameters: parameters, target: $0) }), continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: false, useDryRun: false)
14711469

1472-
try await tester.checkBuild(runDestination: .macOS, buildRequest: buildRequest, persistent: true) { results in
1470+
try await tester.checkBuild(runDestination: .host, buildRequest: buildRequest, persistent: true) { results in
14731471

14741472
for targetName in ["Library_1", "Library_2"] {
14751473
results.checkTaskExists(.matchTargetName(targetName), .matchRuleType("ScanDependencies"))
@@ -1486,7 +1484,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
14861484
}
14871485
}
14881486

1489-
@Test(.requireSDKs(.macOS))
1487+
@Test(.requireSDKs(.host))
14901488
func incrementalBuildBasics() async throws {
14911489
try await withTemporaryDirectory { tmpDir in
14921490
let testWorkspace = TestWorkspace(
@@ -1527,7 +1525,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
15271525
}
15281526

15291527
// Clean build
1530-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
1528+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
15311529
results.checkTaskExists(.matchRuleType("ScanDependencies"))
15321530
results.checkTaskExists(.matchRuleType("CompileC"))
15331531

@@ -1537,7 +1535,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
15371535
}
15381536

15391537
// Null build
1540-
try await tester.checkNullBuild(runDestination: .macOS, persistent: true)
1538+
try await tester.checkNullBuild(runDestination: .host, persistent: true)
15411539

15421540
// Touch the source file to trigger a new scan.
15431541
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
@@ -1548,7 +1546,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
15481546
"""
15491547
}
15501548

1551-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
1549+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
15521550
results.checkTaskExists(.matchRuleType("ScanDependencies"))
15531551
results.checkTaskExists(.matchRuleType("CompileC"))
15541552

@@ -1559,7 +1557,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
15591557
}
15601558
}
15611559

1562-
@Test(.requireSDKs(.macOS))
1560+
@Test(.requireSDKs(.host))
15631561
func incrementalTUChangeDoesNotForceModuleRebuilds() async throws {
15641562
try await withTemporaryDirectory { tmpDir in
15651563
let testWorkspace = TestWorkspace(
@@ -1600,7 +1598,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
16001598
}
16011599

16021600
// Clean build
1603-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
1601+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
16041602
results.checkTaskExists(.matchRuleType("ScanDependencies"))
16051603
results.checkTaskExists(.matchRuleType("CompileC"))
16061604
results.checkTasks(.matchRuleType("PrecompileModule")) { _ in }
@@ -1609,7 +1607,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
16091607
}
16101608

16111609
// Null build
1612-
try await tester.checkNullBuild(runDestination: .macOS, persistent: true)
1610+
try await tester.checkNullBuild(runDestination: .host, persistent: true)
16131611

16141612
// Touch the source file to trigger a new scan.
16151613
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file.c")) { stream in
@@ -1620,7 +1618,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
16201618
"""
16211619
}
16221620

1623-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
1621+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
16241622
results.checkTaskExists(.matchRuleType("ScanDependencies"))
16251623
results.checkTaskExists(.matchRuleType("CompileC"))
16261624

@@ -2785,7 +2783,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
27852783
}
27862784
}
27872785

2788-
@Test(.requireSDKs(.macOS))
2786+
@Test(.requireSDKs(.host))
27892787
func explicitModulesWithResponseFiles() async throws {
27902788
try await withTemporaryDirectory { tmpDirPath in
27912789
let testWorkspace = TestWorkspace(
@@ -2826,7 +2824,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
28262824
"""
28272825
}
28282826

2829-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
2827+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
28302828
let responseFileTask: Task = try results.checkTask(.matchRuleType("WriteAuxiliaryFile"), .matchRuleItemPattern(.suffix(".resp"))) { $0 }
28312829
let scanTask: Task = try results.checkTask(.matchRuleType("ScanDependencies")) { $0 }
28322830
let compileTask: Task = try results.checkTask(.matchRuleType("CompileC")) { $0 }
@@ -2837,7 +2835,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
28372835
}
28382836
}
28392837

2840-
@Test(.requireSDKs(.macOS))
2838+
@Test(.requireSDKs(.host))
28412839
func disablement() async throws {
28422840
try await withTemporaryDirectory { tmpDir in
28432841
let testWorkspace = TestWorkspace(
@@ -2877,7 +2875,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
28772875
"""
28782876
}
28792877

2880-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
2878+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
28812879
results.checkNoTask(.matchRuleType("ScanDependencies"))
28822880
results.checkNoTask(.matchRuleType("PrecompileModule"))
28832881

@@ -3110,7 +3108,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
31103108
}
31113109
}
31123110

3113-
@Test(.requireSDKs(.macOS))
3111+
@Test(.requireSDKs(.host))
31143112
func explicitModulesProducesCorrectDependencyInfoWhenPathContainsWhitespace() async throws {
31153113
try await withTemporaryDirectory { tmpDirParentPath in
31163114
let tmpDirPath = tmpDirParentPath.join("has whitespace")
@@ -3153,7 +3151,7 @@ fileprivate struct ClangExplicitModulesTests: CoreBasedTests {
31533151
}
31543152

31553153
// The build should succeed if we produced dependency info which can be parsed correctly.
3156-
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
3154+
try await tester.checkBuild(runDestination: .host, persistent: true) { results in
31573155
results.checkNoDiagnostics()
31583156
}
31593157
}

0 commit comments

Comments
 (0)