Skip to content

Commit

Permalink
Merge pull request #1502 from tshortli/check-dwarf-version-supported
Browse files Browse the repository at this point in the history
Only specify -dwarf-version if the frontend supports it
  • Loading branch information
tshortli committed Dec 11, 2023
2 parents 0c846ef + 8b9b1b0 commit 01e8375
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 3 additions & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ extension Driver {
try commandLine.appendLast(in: .g, from: &parsedOptions)
if debugInfo.level != nil {
commandLine.appendFlag("-debug-info-format=\(debugInfo.format)")
commandLine.appendFlag("-dwarf-version=\(debugInfo.dwarfVersion)")
if isFrontendArgSupported(.dwarfVersion) {
commandLine.appendFlag("-dwarf-version=\(debugInfo.dwarfVersion)")
}
}
try commandLine.appendLast(.importUnderlyingModule, from: &parsedOptions)
try commandLine.appendLast(.moduleCachePath, from: &parsedOptions)
Expand Down
27 changes: 17 additions & 10 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,17 +582,29 @@ final class SwiftDriverTests: XCTestCase {
$1.expect(.error("invalid value '6' in '-dwarf-version="))
}

try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-g", "-debug-info-format=dwarf", "-dwarf-version=4") { driver in
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
}

try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-file-compilation-dir", ".") { driver in
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
XCTAssertTrue(jobs[0].commandLine.contains(.flag(".")))
}

try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-c", "-file-compilation-dir", ".") { driver in
let jobs = try driver.planBuild()
XCTAssertFalse(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
}
}

func testDwarfVersionSetting() throws {
let driver = try Driver(args: ["swiftc", "foo.swift"])
guard driver.isFrontendArgSupported(.dwarfVersion) else {
throw XCTSkip("Skipping: compiler does not support '-dwarf-version'")
}

try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-emit-module", "-g", "-debug-info-format=dwarf", "-dwarf-version=4") { driver in
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
}

try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-g", "-c", "-target", "x86_64-apple-macosx10.10") { driver in
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=2")))
Expand Down Expand Up @@ -625,11 +637,6 @@ final class SwiftDriverTests: XCTestCase {
let jobs = try driver.planBuild()
XCTAssertTrue(jobs[0].commandLine.contains(.flag("-dwarf-version=4")))
}

try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-c", "-file-compilation-dir", ".") { driver in
let jobs = try driver.planBuild()
XCTAssertFalse(jobs[0].commandLine.contains(.flag("-file-compilation-dir")))
}
}

func testCoverageSettings() throws {
Expand Down

0 comments on commit 01e8375

Please sign in to comment.