Skip to content

Commit d230d68

Browse files
committed
Add support for -no-warnings-as-errors
1 parent d768c7a commit d230d68

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public struct Driver {
4949
case relativeFrontendPath(String)
5050
case subcommandPassedToDriver
5151
case integratedReplRemoved
52+
case conflictingOptions(Option, Option)
5253

5354
public var description: String {
5455
switch self {
@@ -65,6 +66,8 @@ public struct Driver {
6566
return "subcommand passed to driver"
6667
case .integratedReplRemoved:
6768
return "Compiler-internal integrated REPL has been removed; use the LLDB-enhanced REPL instead."
69+
case .conflictingOptions(let one, let two):
70+
return "conflicting options '\(one.spelling)' and '\(two.spelling)'"
6871
}
6972
}
7073
}
@@ -307,6 +310,8 @@ public struct Driver {
307310
self.numThreads = Self.determineNumThreads(&parsedOptions, compilerMode: compilerMode, diagnosticsEngine: diagnosticEngine)
308311
self.numParallelJobs = Self.determineNumParallelJobs(&parsedOptions, diagnosticsEngine: diagnosticEngine, env: env)
309312

313+
try Self.validateWarningControlArgs(&parsedOptions)
314+
310315
// Compute debug information output.
311316
(self.debugInfoLevel, self.debugInfoFormat, shouldVerifyDebugInfo: self.shouldVerifyDebugInfo) =
312317
Self.computeDebugInfo(&parsedOptions, diagnosticsEngine: diagnosticEngine)
@@ -1457,6 +1462,16 @@ extension Diagnostic.Message {
14571462
}
14581463
}
14591464

1465+
// MARK: Miscellaneous Argument Validation
1466+
extension Driver {
1467+
static func validateWarningControlArgs(_ parsedOptions: inout ParsedOptions) throws {
1468+
if parsedOptions.hasArgument(.suppressWarnings) &&
1469+
parsedOptions.hasFlag(positive: .warningsAsErrors, negative: .noWarningsAsErrors, default: false) {
1470+
throw Error.conflictingOptions(.warningsAsErrors, .suppressWarnings)
1471+
}
1472+
}
1473+
}
1474+
14601475
extension Triple {
14611476
func toolchainType(_ diagnosticsEngine: DiagnosticsEngine) throws -> Toolchain.Type {
14621477
switch os {

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ extension Driver {
118118
try commandLine.appendLast(.profileGenerate, from: &parsedOptions)
119119
try commandLine.appendLast(.profileUse, from: &parsedOptions)
120120
try commandLine.appendLast(.profileCoverageMapping, from: &parsedOptions)
121-
try commandLine.appendLast(.warningsAsErrors, from: &parsedOptions)
121+
try commandLine.appendLast(.warningsAsErrors, .noWarningsAsErrors, from: &parsedOptions)
122122
try commandLine.appendLast(.sanitizeCoverageEQ, from: &parsedOptions)
123123
try commandLine.appendLast(.static, from: &parsedOptions)
124124
try commandLine.appendLast(.swiftVersion, from: &parsedOptions)

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,39 @@ final class SwiftDriverTests: XCTestCase {
15451545
}
15461546
}
15471547

1548+
func testDiagnosticOptions() throws {
1549+
do {
1550+
var driver = try Driver(args: ["swift", "-no-warnings-as-errors", "-warnings-as-errors", "foo.swift"])
1551+
let plannedJobs = try driver.planBuild()
1552+
XCTAssertEqual(plannedJobs.count, 1)
1553+
let job = plannedJobs[0]
1554+
XCTAssertTrue(job.commandLine.contains(.flag("-warnings-as-errors")))
1555+
}
1556+
1557+
do {
1558+
var driver = try Driver(args: ["swift", "-warnings-as-errors", "-no-warnings-as-errors", "foo.swift"])
1559+
let plannedJobs = try driver.planBuild()
1560+
XCTAssertEqual(plannedJobs.count, 1)
1561+
let job = plannedJobs[0]
1562+
XCTAssertTrue(job.commandLine.contains(.flag("-no-warnings-as-errors")))
1563+
}
1564+
1565+
do {
1566+
var driver = try Driver(args: ["swift", "-warnings-as-errors", "-no-warnings-as-errors", "-suppress-warnings", "foo.swift"])
1567+
let plannedJobs = try driver.planBuild()
1568+
XCTAssertEqual(plannedJobs.count, 1)
1569+
let job = plannedJobs[0]
1570+
XCTAssertTrue(job.commandLine.contains(.flag("-no-warnings-as-errors")))
1571+
XCTAssertTrue(job.commandLine.contains(.flag("-suppress-warnings")))
1572+
}
1573+
1574+
do {
1575+
XCTAssertThrowsError(try Driver(args: ["swift", "-no-warnings-as-errors", "-warnings-as-errors", "-suppress-warnings", "foo.swift"])) {
1576+
XCTAssertEqual($0 as? Driver.Error, Driver.Error.conflictingOptions(.warningsAsErrors, .suppressWarnings))
1577+
}
1578+
}
1579+
}
1580+
15481581
func testPCHGeneration() throws {
15491582
do {
15501583
var driver = try Driver(args: ["swiftc", "-typecheck", "-import-objc-header", "TestInputHeader.h", "foo.swift"])

0 commit comments

Comments
 (0)