Skip to content

Commit 97c24cc

Browse files
Merge pull request #1557 from cachemeifyoucan/eng/PR-file-compilation-dir
Compute and append -file-compilation-dir when -g options are used
2 parents eab7910 + c7bb2ca commit 97c24cc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,14 @@ extension Driver {
368368
commandLine.appendFlag(.enableAnonymousContextMangledNames)
369369
}
370370

371+
// Always try to append -file-compilation-dir when debug info is used.
371372
// TODO: Should we support -fcoverage-compilation-dir?
372-
try commandLine.appendAll(.fileCompilationDir, from: &parsedOptions)
373+
commandLine.appendFlag(.fileCompilationDir)
374+
if let compilationDir = parsedOptions.getLastArgument(.fileCompilationDir)?.asSingle {
375+
commandLine.appendFlag(compilationDir)
376+
} else if let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory {
377+
commandLine.appendFlag(cwd.pathString)
378+
}
373379
}
374380

375381
// CAS related options.

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,17 @@ final class SwiftDriverTests: XCTestCase {
598598
XCTAssertTrue(jobs[0].commandLine.contains(.flag(".")))
599599
}
600600

601+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-working-directory", "/tmp") { driver in
602+
let jobs = try driver.planBuild()
603+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
604+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("/tmp")))
605+
}
606+
607+
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c") { driver in
608+
let jobs = try driver.planBuild()
609+
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
610+
}
611+
601612
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-c", "-file-compilation-dir", ".") { driver in
602613
let jobs = try driver.planBuild()
603614
XCTAssertFalse(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))

0 commit comments

Comments
 (0)