Skip to content

Commit 3ce3d3d

Browse files
committed
1. Add new flag -debug-compilation-dir
2. Forward the flag and its associated variable to frontend 3. Add a test case to validate that the flag is forwarded to frontend correctly
1 parent 749dca1 commit 3ce3d3d

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extension Driver {
205205
try commandLine.appendAll(.coveragePrefixMap, from: &parsedOptions)
206206
try commandLine.appendLast(.warnConcurrency, from: &parsedOptions)
207207
try commandLine.appendAll(.moduleAlias, from: &parsedOptions)
208+
try commandLine.appendAll(.debugCompilationDir, from: &parsedOptions)
208209

209210
// Expand the -experimental-hermetic-seal-at-link flag
210211
if parsedOptions.hasArgument(.experimentalHermeticSealAtLink) {

Sources/SwiftOptions/Options.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extension Option {
6565
public static let c: Option = Option("-c", .flag, alias: Option.emitObject, attributes: [.frontend, .noInteractive], group: .modes)
6666
public static let debugAssertAfterParse: Option = Option("-debug-assert-after-parse", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Force an assertion failure after parsing", group: .debugCrash)
6767
public static let debugAssertImmediately: Option = Option("-debug-assert-immediately", .flag, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Force an assertion failure immediately", group: .debugCrash)
68+
public static let debugCompilationDir: Option = Option("-debug-compilation-dir", .separate, attributes: [.frontend, .argumentIsPath], metaVar: "<path>", helpText: "The compilation directory to embed in the debug info.")
6869
public static let debugConstraintsAttempt: Option = Option("-debug-constraints-attempt", .separate, attributes: [.helpHidden, .frontend, .noDriver], helpText: "Debug the constraint solver at a given attempt")
6970
public static let debugConstraintsOnLineEQ: Option = Option("-debug-constraints-on-line=", .joined, alias: Option.debugConstraintsOnLine, attributes: [.helpHidden, .frontend, .noDriver])
7071
public static let debugConstraintsOnLine: Option = Option("-debug-constraints-on-line", .separate, attributes: [.helpHidden, .frontend, .noDriver], metaVar: "<line>", helpText: "Debug the constraint solver for expressions on <line>")
@@ -700,6 +701,7 @@ extension Option {
700701
Option.c,
701702
Option.debugAssertAfterParse,
702703
Option.debugAssertImmediately,
704+
Option.debugCompilationDir,
703705
Option.debugConstraintsAttempt,
704706
Option.debugConstraintsOnLineEQ,
705707
Option.debugConstraintsOnLine,

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,12 @@ final class SwiftDriverTests: XCTestCase {
489489
try assertDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-gdwarf-types", "-debug-info-format=codeview") {
490490
$1.expect(.error("argument '-debug-info-format=codeview' is not allowed with '-gdwarf-types'"))
491491
}
492+
493+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-debug-compilation-dir", ".") { driver in
494+
let jobs = try driver.planBuild()
495+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-debug-compilation-dir")))
496+
XCTAssertTrue(jobs[0].commandLine.contains(.path(.relative(.init(".")))))
497+
}
492498
}
493499

494500
func testCoverageSettings() throws {

0 commit comments

Comments
 (0)