Skip to content

Commit effb4e5

Browse files
authored
Merge pull request #1680 from artemcm/FixTestsEBM
Fix ExplicitModuleBuildTests: `testExplicitLinkLibraries` & `testDependencyGraphDotSerialization` & CachingBuildTests: `testSeparateModuleJob` & `testModuleOnlyJob`
2 parents 4b6c86a + 601f3d6 commit effb4e5

File tree

2 files changed

+69
-63
lines changed

2 files changed

+69
-63
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

+60-60
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 {
@@ -391,9 +445,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
391445

392446
let checkForLinkLibrary = { (info: ModuleInfo, linkName: String, isFramework: Bool, shouldForceLoad: Bool) in
393447
let linkLibraries = try XCTUnwrap(info.linkLibraries)
394-
XCTAssertEqual(linkLibraries.count, 1)
395-
let linkLibrary = try XCTUnwrap(linkLibraries.first)
396-
XCTAssertEqual(linkLibrary.linkName, linkName)
448+
let linkLibrary = try XCTUnwrap(linkLibraries.first { $0.linkName == linkName })
397449
XCTAssertEqual(linkLibrary.isFramework, isFramework)
398450
XCTAssertEqual(linkLibrary.shouldForceLoad, shouldForceLoad)
399451
}
@@ -1339,60 +1391,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
13391391
}
13401392
}
13411393

1342-
func getStdlibShimsPaths(_ driver: Driver) throws -> (AbsolutePath, AbsolutePath) {
1343-
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
1344-
.parentDirectory // bin
1345-
.parentDirectory // toolchain root
1346-
if driver.targetTriple.isDarwin {
1347-
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
1348-
processSet: ProcessSet(),
1349-
fileSystem: localFileSystem,
1350-
env: ProcessEnv.vars)
1351-
let sdkPath = try executor.checkNonZeroExit(
1352-
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
1353-
let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr")
1354-
.appending(component: "lib")
1355-
.appending(component: "swift")
1356-
return (stdLibPath, stdLibPath.appending(component: "shims"))
1357-
} else if driver.targetTriple.isWindows {
1358-
if let sdkroot = try driver.toolchain.defaultSDKPath(driver.targetTriple) {
1359-
return (sdkroot.appending(components: "usr", "lib", "swift", "windows"),
1360-
sdkroot.appending(components: "usr", "lib", "swift", "shims"))
1361-
}
1362-
return (toolchainRootPath
1363-
.appending(component: "lib")
1364-
.appending(component: "swift")
1365-
.appending(component: driver.targetTriple.osNameUnversioned),
1366-
toolchainRootPath
1367-
.appending(component: "lib")
1368-
.appending(component: "swift")
1369-
.appending(component: "shims"))
1370-
} else {
1371-
return (toolchainRootPath.appending(component: "lib")
1372-
.appending(component: "swift")
1373-
.appending(component: driver.targetTriple.osNameUnversioned),
1374-
toolchainRootPath.appending(component: "lib")
1375-
.appending(component: "swift")
1376-
.appending(component: "shims"))
1377-
}
1378-
}
1379-
1380-
private func getDriverArtifactsForScanning() throws -> (stdLibPath: AbsolutePath,
1381-
shimsPath: AbsolutePath,
1382-
toolchain: Toolchain,
1383-
hostTriple: Triple) {
1384-
// Just instantiating to get at the toolchain path
1385-
let driver = try Driver(args: ["swiftc", "-explicit-module-build",
1386-
"-module-name", "testDependencyScanning",
1387-
"test.swift"])
1388-
let (stdLibPath, shimsPath) = try getStdlibShimsPaths(driver)
1389-
XCTAssertTrue(localFileSystem.exists(stdLibPath),
1390-
"expected Swift StdLib at: \(stdLibPath.description)")
1391-
XCTAssertTrue(localFileSystem.exists(shimsPath),
1392-
"expected Swift Shims at: \(shimsPath.description)")
1393-
return (stdLibPath, shimsPath, driver.toolchain, driver.hostTriple)
1394-
}
1395-
13961394
/// Test the libSwiftScan dependency scanning (import-prescan).
13971395
func testDependencyImportPrescan() throws {
13981396
let (stdLibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning()
@@ -2090,9 +2088,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
20902088
XCTAssertTrue(contents.contains("\"G\" [style=bold, color=orange"))
20912089
XCTAssertTrue(contents.contains("\"E\" [style=bold, color=orange, style=filled"))
20922090
XCTAssertTrue(contents.contains("\"C (C)\" [style=bold, color=lightskyblue, style=filled"))
2093-
XCTAssertTrue(contents.contains("\"Swift\" [style=bold, color=orange, style=filled"))
2091+
XCTAssertTrue(contents.contains("\"Swift\" [style=bold, color=orange, style=filled") ||
2092+
contents.contains("\"Swift (Prebuilt)\" [style=bold, color=darkorange3, style=filled"))
20942093
XCTAssertTrue(contents.contains("\"SwiftShims (C)\" [style=bold, color=lightskyblue, style=filled"))
2095-
XCTAssertTrue(contents.contains("\"Swift\" -> \"SwiftShims (C)\" [color=black];"))
2094+
XCTAssertTrue(contents.contains("\"Swift\" -> \"SwiftShims (C)\" [color=black];") ||
2095+
contents.contains("\"Swift (Prebuilt)\" -> \"SwiftShims (C)\" [color=black];"))
20962096
}
20972097
}
20982098

@@ -2237,7 +2237,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
22372237
let moduleCachePath = path.appending(component: "ModuleCache")
22382238
try localFileSystem.createDirectory(moduleCachePath)
22392239
let main = path.appending(component: "testTraceDependency.swift")
2240-
try localFileSystem.writeFileContents(main, bytes:
2240+
try localFileSystem.writeFileContents(main, bytes:
22412241
"""
22422242
import C;\
22432243
import E;\

0 commit comments

Comments
 (0)