Skip to content

Commit 39c654e

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 39c654e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ extension Driver {
255255
if shouldSupportAnonymousContextMangledNames {
256256
commandLine.appendFlag(.enableAnonymousContextMangledNames)
257257
}
258+
259+
try commandLine.appendAll(.debugCompilationDir, from: &parsedOptions)
258260
}
259261

260262
// Pass through any subsystem flags.

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ 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+
}
498+
499+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-c", "-debug-compilation-dir", ".") { driver in
500+
let jobs = try driver.planBuild()
501+
XCTAssertFalse(jobs[0].commandLine.contains(.flag("-debug-compilation-dir")))
502+
}
492503
}
493504

494505
func testCoverageSettings() throws {

0 commit comments

Comments
 (0)