diff --git a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift index e82beab26..0624cf8f9 100644 --- a/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift +++ b/Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift @@ -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) diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index b48e70b1d..5eacd2e41 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -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"))) @@ -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 {