Skip to content

Commit 601f3d6

Browse files
committed
Fix CachingBuildTests: testSeparateModuleJob & testModuleOnlyJob
Do not always hard-code a macOS triple and pass in explicit stdlib paths to the driver invocations
1 parent 788e6f9 commit 601f3d6

File tree

2 files changed

+63
-57
lines changed

2 files changed

+63
-57
lines changed

Tests/SwiftDriverTests/CachingBuildTests.swift

+9-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ final class CachingBuildTests: XCTestCase {
227227
let casPath = path.appending(component: "cas")
228228
let swiftModuleInterfacesPath: AbsolutePath =
229229
try testInputsPath.appending(component: "ExplicitModuleBuilds")
230-
.appending(component: "Swift")
230+
.appending(component: "Swift")
231231
let cHeadersPath: AbsolutePath =
232232
try testInputsPath.appending(component: "ExplicitModuleBuilds")
233233
.appending(component: "CHeaders")
@@ -337,6 +337,7 @@ final class CachingBuildTests: XCTestCase {
337337
}
338338

339339
func testModuleOnlyJob() throws {
340+
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
340341
try withTemporaryDirectory { path in
341342
let main = path.appending(component: "testModuleOnlyJob.swift")
342343
try localFileSystem.writeFileContents(main) {
@@ -358,10 +359,11 @@ final class CachingBuildTests: XCTestCase {
358359
let modulePath: AbsolutePath = path.appending(component: "testModuleOnlyJob.swiftmodule")
359360
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
360361
var driver = try Driver(args: ["swiftc",
361-
"-target", "x86_64-apple-macosx11.0",
362362
"-module-name", "Test",
363363
"-I", cHeadersPath.nativePathString(escaped: true),
364364
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
365+
"-I", stdlibPath.nativePathString(escaped: true),
366+
"-I", shimsPath.nativePathString(escaped: true),
365367
"-emit-module-interface-path", swiftInterfacePath.nativePathString(escaped: true),
366368
"-emit-private-module-interface-path", privateSwiftInterfacePath.nativePathString(escaped: true),
367369
"-explicit-module-build", "-emit-module-separately-wmo", "-disable-cmo", "-Rcache-compile-job",
@@ -393,6 +395,7 @@ final class CachingBuildTests: XCTestCase {
393395
}
394396

395397
func testSeparateModuleJob() throws {
398+
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
396399
try withTemporaryDirectory { path in
397400
let main = path.appending(component: "testSeparateModuleJob.swift")
398401
try localFileSystem.writeFileContents(main) {
@@ -410,16 +413,19 @@ final class CachingBuildTests: XCTestCase {
410413
let modulePath: AbsolutePath = path.appending(component: "testSeparateModuleJob.swiftmodule")
411414
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
412415
var driver = try Driver(args: ["swiftc",
413-
"-target", "x86_64-apple-macosx11.0",
414416
"-module-name", "Test",
415417
"-I", cHeadersPath.nativePathString(escaped: true),
416418
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
419+
"-I", stdlibPath.nativePathString(escaped: true),
420+
"-I", shimsPath.nativePathString(escaped: true),
417421
"-emit-module-path", modulePath.nativePathString(escaped: true),
418422
"-emit-module-interface-path", swiftInterfacePath.nativePathString(escaped: true),
419423
"-emit-private-module-interface-path", privateSwiftInterfacePath.nativePathString(escaped: true),
420424
"-explicit-module-build", "-experimental-emit-module-separately", "-Rcache-compile-job",
421425
"-enable-library-evolution", "-O",
422426
"-cache-compile-job", "-cas-path", casPath.nativePathString(escaped: true),
427+
"-Xfrontend", "-disable-implicit-concurrency-module-import",
428+
"-Xfrontend", "-disable-implicit-string-processing-module-import",
423429
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
424430
env: ProcessEnv.vars,
425431
interModuleDependencyOracle: dependencyOracle)

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

+54-54
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,60 @@ private func checkExplicitModuleBuildJobDependencies(job: Job,
112112
}
113113
}
114114

115+
internal func getDriverArtifactsForScanning() throws -> (stdLibPath: AbsolutePath,
116+
shimsPath: AbsolutePath,
117+
toolchain: Toolchain,
118+
hostTriple: Triple) {
119+
// Just instantiating to get at the toolchain path
120+
let driver = try Driver(args: ["swiftc", "-explicit-module-build",
121+
"-module-name", "testDependencyScanning",
122+
"test.swift"])
123+
let (stdLibPath, shimsPath) = try getStdlibShimsPaths(driver)
124+
XCTAssertTrue(localFileSystem.exists(stdLibPath),
125+
"expected Swift StdLib at: \(stdLibPath.description)")
126+
XCTAssertTrue(localFileSystem.exists(shimsPath),
127+
"expected Swift Shims at: \(shimsPath.description)")
128+
return (stdLibPath, shimsPath, driver.toolchain, driver.hostTriple)
129+
}
130+
131+
func getStdlibShimsPaths(_ driver: Driver) throws -> (AbsolutePath, AbsolutePath) {
132+
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
133+
.parentDirectory // bin
134+
.parentDirectory // toolchain root
135+
if driver.targetTriple.isDarwin {
136+
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
137+
processSet: ProcessSet(),
138+
fileSystem: localFileSystem,
139+
env: ProcessEnv.vars)
140+
let sdkPath = try executor.checkNonZeroExit(
141+
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
142+
let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr")
143+
.appending(component: "lib")
144+
.appending(component: "swift")
145+
return (stdLibPath, stdLibPath.appending(component: "shims"))
146+
} else if driver.targetTriple.isWindows {
147+
if let sdkroot = try driver.toolchain.defaultSDKPath(driver.targetTriple) {
148+
return (sdkroot.appending(components: "usr", "lib", "swift", "windows"),
149+
sdkroot.appending(components: "usr", "lib", "swift", "shims"))
150+
}
151+
return (toolchainRootPath
152+
.appending(component: "lib")
153+
.appending(component: "swift")
154+
.appending(component: driver.targetTriple.osNameUnversioned),
155+
toolchainRootPath
156+
.appending(component: "lib")
157+
.appending(component: "swift")
158+
.appending(component: "shims"))
159+
} else {
160+
return (toolchainRootPath.appending(component: "lib")
161+
.appending(component: "swift")
162+
.appending(component: driver.targetTriple.osNameUnversioned),
163+
toolchainRootPath.appending(component: "lib")
164+
.appending(component: "swift")
165+
.appending(component: "shims"))
166+
}
167+
}
168+
115169
/// Test that for the given JSON module dependency graph, valid jobs are generated
116170
final class ExplicitModuleBuildTests: XCTestCase {
117171
func testModuleDependencyBuildCommandGeneration() throws {
@@ -1337,60 +1391,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
13371391
}
13381392
}
13391393

1340-
func getStdlibShimsPaths(_ driver: Driver) throws -> (AbsolutePath, AbsolutePath) {
1341-
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
1342-
.parentDirectory // bin
1343-
.parentDirectory // toolchain root
1344-
if driver.targetTriple.isDarwin {
1345-
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
1346-
processSet: ProcessSet(),
1347-
fileSystem: localFileSystem,
1348-
env: ProcessEnv.vars)
1349-
let sdkPath = try executor.checkNonZeroExit(
1350-
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
1351-
let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr")
1352-
.appending(component: "lib")
1353-
.appending(component: "swift")
1354-
return (stdLibPath, stdLibPath.appending(component: "shims"))
1355-
} else if driver.targetTriple.isWindows {
1356-
if let sdkroot = try driver.toolchain.defaultSDKPath(driver.targetTriple) {
1357-
return (sdkroot.appending(components: "usr", "lib", "swift", "windows"),
1358-
sdkroot.appending(components: "usr", "lib", "swift", "shims"))
1359-
}
1360-
return (toolchainRootPath
1361-
.appending(component: "lib")
1362-
.appending(component: "swift")
1363-
.appending(component: driver.targetTriple.osNameUnversioned),
1364-
toolchainRootPath
1365-
.appending(component: "lib")
1366-
.appending(component: "swift")
1367-
.appending(component: "shims"))
1368-
} else {
1369-
return (toolchainRootPath.appending(component: "lib")
1370-
.appending(component: "swift")
1371-
.appending(component: driver.targetTriple.osNameUnversioned),
1372-
toolchainRootPath.appending(component: "lib")
1373-
.appending(component: "swift")
1374-
.appending(component: "shims"))
1375-
}
1376-
}
1377-
1378-
private func getDriverArtifactsForScanning() throws -> (stdLibPath: AbsolutePath,
1379-
shimsPath: AbsolutePath,
1380-
toolchain: Toolchain,
1381-
hostTriple: Triple) {
1382-
// Just instantiating to get at the toolchain path
1383-
let driver = try Driver(args: ["swiftc", "-explicit-module-build",
1384-
"-module-name", "testDependencyScanning",
1385-
"test.swift"])
1386-
let (stdLibPath, shimsPath) = try getStdlibShimsPaths(driver)
1387-
XCTAssertTrue(localFileSystem.exists(stdLibPath),
1388-
"expected Swift StdLib at: \(stdLibPath.description)")
1389-
XCTAssertTrue(localFileSystem.exists(shimsPath),
1390-
"expected Swift Shims at: \(shimsPath.description)")
1391-
return (stdLibPath, shimsPath, driver.toolchain, driver.hostTriple)
1392-
}
1393-
13941394
/// Test the libSwiftScan dependency scanning (import-prescan).
13951395
func testDependencyImportPrescan() throws {
13961396
let (stdLibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning()

0 commit comments

Comments
 (0)