Skip to content
Open
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
15 changes: 9 additions & 6 deletions Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ extension Driver {
jobNeedPathRemap = false
}

if isPlanJobForExplicitModule && forObject && isFrontendArgSupported(.debugModulePath),
let explicitModulePlanner {
let mainModule = explicitModulePlanner.dependencyGraph.mainModule
let pathHandle = moduleOutputInfo.output?.outputPath ?? mainModule.modulePath.path
let path = VirtualPath.lookup(pathHandle)
try addPathOption(option: .debugModulePath, path: path, to: &commandLine, remap: jobNeedPathRemap)
// Add the -debug-module-path option to the compile job.
// If modulePathHandle is nil, this build doesn't produce a Swift module.
if forObject && isFrontendArgSupported(.debugModulePath),
var modulePathHandle = moduleOutputInfo.output?.outputPath {
// Recompute the module path based on the module name, because this is effectively passing the output
// of the module merge action which depends on the compile action.
let moduleBase : VirtualPath = VirtualPath.lookup(modulePathHandle).parentDirectory.appending(component: moduleOutputInfo.name)
modulePathHandle = try moduleBase.replacingExtension(with: .swiftModule).intern()
try addPathOption(option: .debugModulePath, path: VirtualPath.lookup(modulePathHandle), to: &commandLine, remap: jobNeedPathRemap)
}

// Check if dependency scanner has put the job into direct clang cc1 mode.
Expand Down
54 changes: 32 additions & 22 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
for job in jobs {
XCTAssertEqual(job.outputs.count, 1)
let outputFilePath = job.outputs[0].file
if job.kind == .compile && driver.isFrontendArgSupported(.debugModulePath) {
XCTAssertTrue(job.commandLine.contains(subsequence: ["-debug-module-path", try toPathOption("testExplicitModuleBuildJobs.swiftmodule")]))

}

// Swift dependencies
if let outputFileExtension = outputFilePath.extension,
Expand Down Expand Up @@ -782,6 +778,38 @@ final class ExplicitModuleBuildTests: XCTestCase {
}
}

/// Test the -debug-module-path option in expilicit builds.
func testExplicitModuleBuildDebugModulePath() throws {
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
try withTemporaryDirectory { path in
let main = path.appending(component: "testExplicitModuleBuildJobs.swift")
try localFileSystem.writeFileContents(main, bytes:
"""
import C;
"""
)

let swiftModuleInterfacesPath: AbsolutePath =
try testInputsPath.appending(component: "ExplicitModuleBuilds")
.appending(component: "Swift")
let sdkArgumentsForTesting = (try? Driver.sdkArgumentsForTesting()) ?? []
var driver = try Driver(args: ["swiftc",
"-g",
"-I", swiftModuleInterfacesPath.nativePathString(escaped: false),
"-I", stdlibPath.nativePathString(escaped: false),
"-I", shimsPath.nativePathString(escaped: false),
"-explicit-module-build",
"-disable-implicit-concurrency-module-import",
"-disable-implicit-string-processing-module-import",
main.nativePathString(escaped: false)] + sdkArgumentsForTesting)
guard driver.isFrontendArgSupported(.debugModulePath) else { return }
let jobs = try driver.planBuild()
try jobs.filter { $0.kind == .compile }.forEach { job in
XCTAssertTrue(job.commandLine.contains(subsequence: ["-debug-module-path", try toPathOption("testExplicitModuleBuildJobs.swiftmodule")]))
}
}
}

func testRegisterModuleDependencyFlag() throws {
let (stdlibPath, shimsPath, _, _) = try getDriverArtifactsForScanning()
try withTemporaryDirectory { path in
Expand Down Expand Up @@ -1100,24 +1128,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
let baseName = "testExplicitModuleVerifyInterfaceJobs"
XCTAssertTrue(matchTemporary(outputFilePath, basename: baseName, fileExtension: "o") ||
matchTemporary(outputFilePath, basename: baseName, fileExtension: "autolink"))
if outputFilePath.extension == FileType.object.rawValue && driver.isFrontendArgSupported(.debugModulePath) {
// Check that this is an absolute path pointing to the temporary directory.
var found : Bool = false
for arg in job.commandLine {
if !found && arg == "-debug-module-path" {
found = true
} else if found {
if case let .path(vpath) = arg {
XCTAssertTrue(vpath.isTemporary)
XCTAssertTrue(vpath.extension == FileType.swiftModule.rawValue)
} else {
XCTFail("argument is not a path")
}
break
}
}
XCTAssertTrue(found)
}
default:
XCTFail("Unexpected module dependency build job output: \(outputFilePath)")
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4129,6 +4129,26 @@ final class SwiftDriverTests: XCTestCase {
}
}


func testDebugModulePath() throws {
do {
var driver = try Driver(args: ["swiftc", "-target", "arm64-unknown-macos26", "-g", "foo.swift"])
let plannedJobs = try driver.planBuild()
let compileJob = try plannedJobs.findJob(.compile)
// This needs to be "foo.swiftmodule", not the unmerged "foo-1.swiftmodule".
XCTAssertJobInvocationMatches(compileJob, .flag("-debug-module-path"), .path(try .temporary(RelativePath(validating: "foo")).replacingExtension(with: .swiftModule)))
}
// Unfortunately this depends on dsymutil.
#if os(macOS)
do {
var driver = try Driver(args: ["swiftc", "-target", "arm64-unknown-macos26", "-g", "foo.swift"])
let plannedJobs = try driver.planBuild()
let compileJob = try plannedJobs.findJob(.compile)
XCTAssertJobInvocationMatches(compileJob, .flag("-debug-module-path"), .path(try .temporary(RelativePath(validating: "foo")).replacingExtension(with: .swiftModule)))
}
#endif
}

func testModuleWrapJob() throws {
// FIXME: These tests will fail when run on macOS, because
// swift-autolink-extract is not present
Expand Down
Loading