Skip to content

Commit 8f3f7ba

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 ddec397 commit 8f3f7ba

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")
@@ -334,6 +334,7 @@ final class CachingBuildTests: XCTestCase {
334334
}
335335

336336
func testModuleOnlyJob() throws {
337+
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
337338
try withTemporaryDirectory { path in
338339
let main = path.appending(component: "testModuleOnlyJob.swift")
339340
try localFileSystem.writeFileContents(main) {
@@ -355,10 +356,11 @@ final class CachingBuildTests: XCTestCase {
355356
let modulePath: AbsolutePath = path.appending(component: "testModuleOnlyJob.swiftmodule")
356357
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
357358
var driver = try Driver(args: ["swiftc",
358-
"-target", "x86_64-apple-macosx11.0",
359359
"-module-name", "Test",
360360
"-I", cHeadersPath.nativePathString(escaped: true),
361361
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
362+
"-I", stdlibPath.nativePathString(escaped: true),
363+
"-I", shimsPath.nativePathString(escaped: true),
362364
"-emit-module-interface-path", swiftInterfacePath.nativePathString(escaped: true),
363365
"-emit-private-module-interface-path", privateSwiftInterfacePath.nativePathString(escaped: true),
364366
"-explicit-module-build", "-emit-module-separately-wmo", "-disable-cmo", "-Rcache-compile-job",
@@ -390,6 +392,7 @@ final class CachingBuildTests: XCTestCase {
390392
}
391393

392394
func testSeparateModuleJob() throws {
395+
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
393396
try withTemporaryDirectory { path in
394397
let main = path.appending(component: "testSeparateModuleJob.swift")
395398
try localFileSystem.writeFileContents(main) {
@@ -407,16 +410,19 @@ final class CachingBuildTests: XCTestCase {
407410
let modulePath: AbsolutePath = path.appending(component: "testSeparateModuleJob.swiftmodule")
408411
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
409412
var driver = try Driver(args: ["swiftc",
410-
"-target", "x86_64-apple-macosx11.0",
411413
"-module-name", "Test",
412414
"-I", cHeadersPath.nativePathString(escaped: true),
413415
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
416+
"-I", stdlibPath.nativePathString(escaped: true),
417+
"-I", shimsPath.nativePathString(escaped: true),
414418
"-emit-module-path", modulePath.nativePathString(escaped: true),
415419
"-emit-module-interface-path", swiftInterfacePath.nativePathString(escaped: true),
416420
"-emit-private-module-interface-path", privateSwiftInterfacePath.nativePathString(escaped: true),
417421
"-explicit-module-build", "-experimental-emit-module-separately", "-Rcache-compile-job",
418422
"-enable-library-evolution", "-O",
419423
"-cache-compile-job", "-cas-path", casPath.nativePathString(escaped: true),
424+
"-Xfrontend", "-disable-implicit-concurrency-module-import",
425+
"-Xfrontend", "-disable-implicit-string-processing-module-import",
420426
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
421427
env: ProcessEnv.vars,
422428
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 {
@@ -1234,60 +1288,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
12341288
}
12351289
}
12361290

1237-
func getStdlibShimsPaths(_ driver: Driver) throws -> (AbsolutePath, AbsolutePath) {
1238-
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
1239-
.parentDirectory // bin
1240-
.parentDirectory // toolchain root
1241-
if driver.targetTriple.isDarwin {
1242-
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
1243-
processSet: ProcessSet(),
1244-
fileSystem: localFileSystem,
1245-
env: ProcessEnv.vars)
1246-
let sdkPath = try executor.checkNonZeroExit(
1247-
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
1248-
let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr")
1249-
.appending(component: "lib")
1250-
.appending(component: "swift")
1251-
return (stdLibPath, stdLibPath.appending(component: "shims"))
1252-
} else if driver.targetTriple.isWindows {
1253-
if let sdkroot = try driver.toolchain.defaultSDKPath(driver.targetTriple) {
1254-
return (sdkroot.appending(components: "usr", "lib", "swift", "windows"),
1255-
sdkroot.appending(components: "usr", "lib", "swift", "shims"))
1256-
}
1257-
return (toolchainRootPath
1258-
.appending(component: "lib")
1259-
.appending(component: "swift")
1260-
.appending(component: driver.targetTriple.osNameUnversioned),
1261-
toolchainRootPath
1262-
.appending(component: "lib")
1263-
.appending(component: "swift")
1264-
.appending(component: "shims"))
1265-
} else {
1266-
return (toolchainRootPath.appending(component: "lib")
1267-
.appending(component: "swift")
1268-
.appending(component: driver.targetTriple.osNameUnversioned),
1269-
toolchainRootPath.appending(component: "lib")
1270-
.appending(component: "swift")
1271-
.appending(component: "shims"))
1272-
}
1273-
}
1274-
1275-
private func getDriverArtifactsForScanning() throws -> (stdLibPath: AbsolutePath,
1276-
shimsPath: AbsolutePath,
1277-
toolchain: Toolchain,
1278-
hostTriple: Triple) {
1279-
// Just instantiating to get at the toolchain path
1280-
let driver = try Driver(args: ["swiftc", "-explicit-module-build",
1281-
"-module-name", "testDependencyScanning",
1282-
"test.swift"])
1283-
let (stdLibPath, shimsPath) = try getStdlibShimsPaths(driver)
1284-
XCTAssertTrue(localFileSystem.exists(stdLibPath),
1285-
"expected Swift StdLib at: \(stdLibPath.description)")
1286-
XCTAssertTrue(localFileSystem.exists(shimsPath),
1287-
"expected Swift Shims at: \(shimsPath.description)")
1288-
return (stdLibPath, shimsPath, driver.toolchain, driver.hostTriple)
1289-
}
1290-
12911291
/// Test the libSwiftScan dependency scanning (import-prescan).
12921292
func testDependencyImportPrescan() throws {
12931293
let (stdLibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning()

0 commit comments

Comments
 (0)