Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0 🍒] Fix CachingBuildTests: testSeparateModuleJob & testModuleOnlyJob #1689

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Tests/SwiftDriverTests/CachingBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ final class CachingBuildTests: XCTestCase {
let casPath = path.appending(component: "cas")
let swiftModuleInterfacesPath: AbsolutePath =
try testInputsPath.appending(component: "ExplicitModuleBuilds")
.appending(component: "Swift")
.appending(component: "Swift")
let cHeadersPath: AbsolutePath =
try testInputsPath.appending(component: "ExplicitModuleBuilds")
.appending(component: "CHeaders")
Expand Down Expand Up @@ -334,6 +334,7 @@ final class CachingBuildTests: XCTestCase {
}

func testModuleOnlyJob() throws {
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
try withTemporaryDirectory { path in
let main = path.appending(component: "testModuleOnlyJob.swift")
try localFileSystem.writeFileContents(main) {
Expand All @@ -355,10 +356,11 @@ final class CachingBuildTests: XCTestCase {
let modulePath: AbsolutePath = path.appending(component: "testModuleOnlyJob.swiftmodule")
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
var driver = try Driver(args: ["swiftc",
"-target", "x86_64-apple-macosx11.0",
"-module-name", "Test",
"-I", cHeadersPath.nativePathString(escaped: true),
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
"-I", stdlibPath.nativePathString(escaped: true),
"-I", shimsPath.nativePathString(escaped: true),
"-emit-module-interface-path", swiftInterfacePath.nativePathString(escaped: true),
"-emit-private-module-interface-path", privateSwiftInterfacePath.nativePathString(escaped: true),
"-explicit-module-build", "-emit-module-separately-wmo", "-disable-cmo", "-Rcache-compile-job",
Expand Down Expand Up @@ -390,6 +392,7 @@ final class CachingBuildTests: XCTestCase {
}

func testSeparateModuleJob() throws {
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
try withTemporaryDirectory { path in
let main = path.appending(component: "testSeparateModuleJob.swift")
try localFileSystem.writeFileContents(main) {
Expand All @@ -407,16 +410,19 @@ final class CachingBuildTests: XCTestCase {
let modulePath: AbsolutePath = path.appending(component: "testSeparateModuleJob.swiftmodule")
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
var driver = try Driver(args: ["swiftc",
"-target", "x86_64-apple-macosx11.0",
"-module-name", "Test",
"-I", cHeadersPath.nativePathString(escaped: true),
"-I", swiftModuleInterfacesPath.nativePathString(escaped: true),
"-I", stdlibPath.nativePathString(escaped: true),
"-I", shimsPath.nativePathString(escaped: true),
"-emit-module-path", modulePath.nativePathString(escaped: true),
"-emit-module-interface-path", swiftInterfacePath.nativePathString(escaped: true),
"-emit-private-module-interface-path", privateSwiftInterfacePath.nativePathString(escaped: true),
"-explicit-module-build", "-experimental-emit-module-separately", "-Rcache-compile-job",
"-enable-library-evolution", "-O",
"-cache-compile-job", "-cas-path", casPath.nativePathString(escaped: true),
"-Xfrontend", "-disable-implicit-concurrency-module-import",
"-Xfrontend", "-disable-implicit-string-processing-module-import",
main.nativePathString(escaped: true)] + sdkArgumentsForTesting,
env: ProcessEnv.vars,
interModuleDependencyOracle: dependencyOracle)
Expand Down
108 changes: 54 additions & 54 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,60 @@ private func checkExplicitModuleBuildJobDependencies(job: Job,
}
}

internal func getDriverArtifactsForScanning() throws -> (stdLibPath: AbsolutePath,
shimsPath: AbsolutePath,
toolchain: Toolchain,
hostTriple: Triple) {
// Just instantiating to get at the toolchain path
let driver = try Driver(args: ["swiftc", "-explicit-module-build",
"-module-name", "testDependencyScanning",
"test.swift"])
let (stdLibPath, shimsPath) = try getStdlibShimsPaths(driver)
XCTAssertTrue(localFileSystem.exists(stdLibPath),
"expected Swift StdLib at: \(stdLibPath.description)")
XCTAssertTrue(localFileSystem.exists(shimsPath),
"expected Swift Shims at: \(shimsPath.description)")
return (stdLibPath, shimsPath, driver.toolchain, driver.hostTriple)
}

func getStdlibShimsPaths(_ driver: Driver) throws -> (AbsolutePath, AbsolutePath) {
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
.parentDirectory // bin
.parentDirectory // toolchain root
if driver.targetTriple.isDarwin {
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
processSet: ProcessSet(),
fileSystem: localFileSystem,
env: ProcessEnv.vars)
let sdkPath = try executor.checkNonZeroExit(
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr")
.appending(component: "lib")
.appending(component: "swift")
return (stdLibPath, stdLibPath.appending(component: "shims"))
} else if driver.targetTriple.isWindows {
if let sdkroot = try driver.toolchain.defaultSDKPath(driver.targetTriple) {
return (sdkroot.appending(components: "usr", "lib", "swift", "windows"),
sdkroot.appending(components: "usr", "lib", "swift", "shims"))
}
return (toolchainRootPath
.appending(component: "lib")
.appending(component: "swift")
.appending(component: driver.targetTriple.osNameUnversioned),
toolchainRootPath
.appending(component: "lib")
.appending(component: "swift")
.appending(component: "shims"))
} else {
return (toolchainRootPath.appending(component: "lib")
.appending(component: "swift")
.appending(component: driver.targetTriple.osNameUnversioned),
toolchainRootPath.appending(component: "lib")
.appending(component: "swift")
.appending(component: "shims"))
}
}

/// Test that for the given JSON module dependency graph, valid jobs are generated
final class ExplicitModuleBuildTests: XCTestCase {
func testModuleDependencyBuildCommandGeneration() throws {
Expand Down Expand Up @@ -1234,60 +1288,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
}
}

func getStdlibShimsPaths(_ driver: Driver) throws -> (AbsolutePath, AbsolutePath) {
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
.parentDirectory // bin
.parentDirectory // toolchain root
if driver.targetTriple.isDarwin {
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
processSet: ProcessSet(),
fileSystem: localFileSystem,
env: ProcessEnv.vars)
let sdkPath = try executor.checkNonZeroExit(
args: "xcrun", "-sdk", "macosx", "--show-sdk-path").spm_chomp()
let stdLibPath = try AbsolutePath(validating: sdkPath).appending(component: "usr")
.appending(component: "lib")
.appending(component: "swift")
return (stdLibPath, stdLibPath.appending(component: "shims"))
} else if driver.targetTriple.isWindows {
if let sdkroot = try driver.toolchain.defaultSDKPath(driver.targetTriple) {
return (sdkroot.appending(components: "usr", "lib", "swift", "windows"),
sdkroot.appending(components: "usr", "lib", "swift", "shims"))
}
return (toolchainRootPath
.appending(component: "lib")
.appending(component: "swift")
.appending(component: driver.targetTriple.osNameUnversioned),
toolchainRootPath
.appending(component: "lib")
.appending(component: "swift")
.appending(component: "shims"))
} else {
return (toolchainRootPath.appending(component: "lib")
.appending(component: "swift")
.appending(component: driver.targetTriple.osNameUnversioned),
toolchainRootPath.appending(component: "lib")
.appending(component: "swift")
.appending(component: "shims"))
}
}

private func getDriverArtifactsForScanning() throws -> (stdLibPath: AbsolutePath,
shimsPath: AbsolutePath,
toolchain: Toolchain,
hostTriple: Triple) {
// Just instantiating to get at the toolchain path
let driver = try Driver(args: ["swiftc", "-explicit-module-build",
"-module-name", "testDependencyScanning",
"test.swift"])
let (stdLibPath, shimsPath) = try getStdlibShimsPaths(driver)
XCTAssertTrue(localFileSystem.exists(stdLibPath),
"expected Swift StdLib at: \(stdLibPath.description)")
XCTAssertTrue(localFileSystem.exists(shimsPath),
"expected Swift Shims at: \(shimsPath.description)")
return (stdLibPath, shimsPath, driver.toolchain, driver.hostTriple)
}

/// Test the libSwiftScan dependency scanning (import-prescan).
func testDependencyImportPrescan() throws {
let (stdLibPath, shimsPath, toolchain, _) = try getDriverArtifactsForScanning()
Expand Down