Skip to content

Commit 843aea1

Browse files
committed
Implement -debug-module-path for implicit modules in swift-driver
There is no fundamental technical reason to restrict this feature to explict module only, so this patch adds support for passing the correct -debug-module-path also to implicit builds. rdar://168256846
1 parent 8e61f52 commit 843aea1

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,23 @@ extension Driver {
109109
jobNeedPathRemap = false
110110
}
111111

112+
// Add the -debug-module-path option to the compile job.
112113
if isPlanJobForExplicitModule && forObject && isFrontendArgSupported(.debugModulePath),
113114
let explicitModulePlanner {
114115
let mainModule = explicitModulePlanner.dependencyGraph.mainModule
115116
let pathHandle = moduleOutputInfo.output?.outputPath ?? mainModule.modulePath.path
116117
let path = VirtualPath.lookup(pathHandle)
117118
try addPathOption(option: .debugModulePath, path: path, to: &commandLine, remap: jobNeedPathRemap)
119+
} else if !isPlanJobForExplicitModule && isFrontendArgSupported(.debugModulePath),
120+
let pathHandle = moduleOutputInfo.output?.outputPath {
121+
// Recompute the module path based on the module name, because
122+
// this is effectively passing the ouput of the module merge
123+
// action which depends on the compile action.
124+
let path = try VirtualPath.lookup(pathHandle)
125+
.parentDirectory.appending(component: moduleOutputInfo.name)
126+
.replacingExtension(with: .swiftModule)
127+
.intern()
128+
try addPathOption(option: .debugModulePath, path: VirtualPath.lookup(path), to: &commandLine, remap: jobNeedPathRemap)
118129
}
119130

120131
// Check if dependency scanner has put the job into direct clang cc1 mode.

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4118,6 +4118,21 @@ final class SwiftDriverTests: XCTestCase {
41184118
}
41194119
}
41204120

4121+
4122+
func testDebugModulePath() throws {
4123+
do {
4124+
var driver = try Driver(args: ["swiftc", "-target", "arm64-apple-macos26", "-g", "foo.swift"])
4125+
let plannedJobs = try driver.planBuild()
4126+
let mergeJob = try plannedJobs.findJob(.emitModule)
4127+
XCTAssertGreaterThan(mergeJob.outputs.count, 0)
4128+
let moduleFile = mergeJob.outputs[0]
4129+
XCTAssertEqual(moduleFile.type, .swiftModule)
4130+
let compileJob = try plannedJobs.findJob(.compile)
4131+
// This needs to be "foo.swiftmodule", not the unmerged "foo-1.swiftmodule".
4132+
XCTAssertJobInvocationMatches(compileJob, .flag("-debug-module-path"), .path(try .temporary(RelativePath(validating: "foo")).replacingExtension(with: .swiftModule)))
4133+
}
4134+
}
4135+
41214136
func testModuleWrapJob() throws {
41224137
// FIXME: These tests will fail when run on macOS, because
41234138
// swift-autolink-extract is not present

0 commit comments

Comments
 (0)