Skip to content

Commit c21e733

Browse files
committed
Change attempted compilation condition assignment and bad -F argument diagnostics from errors to warnings
1 parent c9f696d commit c21e733

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ public struct Driver {
2828
case unableToDecodeFrontendTargetInfo
2929
case failedToRetrieveFrontendTargetInfo
3030
case missingProfilingData(String)
31-
case cannotAssignToConditionalCompilationFlag(String)
3231
case conditionalCompilationFlagHasRedundantPrefix(String)
3332
case conditionalCompilationFlagIsNotValidIdentifier(String)
34-
case frameworkSearchPathIncludesExtension(String)
3533
// Explicit Module Build Failures
3634
case malformedModuleDependency(String, String)
3735
case missingPCMArguments(String)
@@ -62,14 +60,10 @@ public struct Driver {
6260
return "failed to retrieve frontend target info"
6361
case .missingProfilingData(let arg):
6462
return "no profdata file exists at '\(arg)'"
65-
case .cannotAssignToConditionalCompilationFlag(let name):
66-
return "conditional compilation flags do not have values in Swift; they are either present or absent (rather than '\(name)')"
6763
case .conditionalCompilationFlagHasRedundantPrefix(let name):
6864
return "invalid argument '-D\(name)'; did you provide a redundant '-D' in your build settings?"
6965
case .conditionalCompilationFlagIsNotValidIdentifier(let name):
7066
return "conditional compilation flags must be valid Swift identifiers (rather than '\(name)')"
71-
case .frameworkSearchPathIncludesExtension(let arg):
72-
return "framework search path ends in \".framework\"; add directory containing framework instead: \(arg)"
7367
// Explicit Module Build Failures
7468
case .malformedModuleDependency(let moduleName, let errorDescription):
7569
return "Malformed Module Dependency: \(moduleName), \(errorDescription)"
@@ -1575,6 +1569,12 @@ extension Diagnostic.Message {
15751569
static var error_bridging_header_module_interface: Diagnostic.Message {
15761570
.error("using bridging headers with module interfaces is unsupported")
15771571
}
1572+
static func warning_cannot_assign_to_compilation_condition(name: String) -> Diagnostic.Message {
1573+
.warning("conditional compilation flags do not have values in Swift; they are either present or absent (rather than '\(name)')")
1574+
}
1575+
static func warning_framework_search_path_includes_extension(path: String) -> Diagnostic.Message {
1576+
.warning("framework search path ends in \".framework\"; add directory containing framework instead: \(path)")
1577+
}
15781578
}
15791579

15801580
// MARK: Miscellaneous Argument Validation
@@ -1611,7 +1611,7 @@ extension Driver {
16111611
diagnosticEngine: DiagnosticsEngine) {
16121612
for arg in parsedOptions.arguments(for: .D).map(\.argument.asSingle) {
16131613
if arg.contains("=") {
1614-
diagnosticEngine.emit(Error.cannotAssignToConditionalCompilationFlag(arg))
1614+
diagnosticEngine.emit(.warning_cannot_assign_to_compilation_condition(name: arg))
16151615
} else if arg.hasPrefix("-D") {
16161616
diagnosticEngine.emit(Error.conditionalCompilationFlagHasRedundantPrefix(arg))
16171617
} else if !arg.sd_isSwiftIdentifier {
@@ -1624,7 +1624,7 @@ extension Driver {
16241624
diagnosticEngine: DiagnosticsEngine) {
16251625
for arg in parsedOptions.arguments(for: .F, .Fsystem).map(\.argument.asSingle) {
16261626
if arg.hasSuffix(".framework") || arg.hasSuffix(".framework/") {
1627-
diagnosticEngine.emit(Error.frameworkSearchPathIncludesExtension(arg))
1627+
diagnosticEngine.emit(.warning_framework_search_path_includes_extension(path: arg))
16281628
}
16291629
}
16301630
}

Tests/SwiftDriverTests/Helpers/AssertDiagnostics.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import XCTest
1414
import SwiftDriver
1515
import TSCBasic
16-
import TSCUtility
1716

1817
func assertDriverDiagnostics(
1918
args: [String],

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ final class SwiftDriverTests: XCTestCase {
16901690

16911691
func testConditionalCompilationArgValidation() throws {
16921692
try assertDriverDiagnostics(args: ["swiftc", "foo.swift", "-DFOO=BAR"]) {
1693-
$1.expect(.error(Driver.Error.cannotAssignToConditionalCompilationFlag("FOO=BAR")))
1693+
$1.expect(.warning("conditional compilation flags do not have values in Swift; they are either present or absent (rather than 'FOO=BAR')"))
16941694
}
16951695

16961696
try assertDriverDiagnostics(args: ["swiftc", "foo.swift", "-D-DFOO"]) {
@@ -1706,15 +1706,15 @@ final class SwiftDriverTests: XCTestCase {
17061706

17071707
func testFrameworkSearchPathArgValidation() throws {
17081708
try assertDriverDiagnostics(args: ["swiftc", "foo.swift", "-F/some/dir/xyz.framework"]) {
1709-
$1.expect(.error(Driver.Error.frameworkSearchPathIncludesExtension("/some/dir/xyz.framework")))
1709+
$1.expect(.warning("framework search path ends in \".framework\"; add directory containing framework instead: /some/dir/xyz.framework"))
17101710
}
17111711

17121712
try assertDriverDiagnostics(args: ["swiftc", "foo.swift", "-F/some/dir/xyz.framework/"]) {
1713-
$1.expect(.error(Driver.Error.frameworkSearchPathIncludesExtension("/some/dir/xyz.framework/")))
1713+
$1.expect(.warning("framework search path ends in \".framework\"; add directory containing framework instead: /some/dir/xyz.framework/"))
17141714
}
17151715

17161716
try assertDriverDiagnostics(args: ["swiftc", "foo.swift", "-Fsystem", "/some/dir/xyz.framework"]) {
1717-
$1.expect(.error(Driver.Error.frameworkSearchPathIncludesExtension("/some/dir/xyz.framework")))
1717+
$1.expect(.warning("framework search path ends in \".framework\"; add directory containing framework instead: /some/dir/xyz.framework"))
17181718
}
17191719

17201720
try assertNoDriverDiagnostics(args: "swiftc", "foo.swift", "-Fsystem", "/some/dir/")
@@ -1723,7 +1723,7 @@ final class SwiftDriverTests: XCTestCase {
17231723
func testMultipleValidationFailures() throws {
17241724
try assertDiagnostics { engine, verifier in
17251725
verifier.expect(.error(Driver.Error.conditionalCompilationFlagIsNotValidIdentifier("not-an-identifier")))
1726-
verifier.expect(.error(Driver.Error.frameworkSearchPathIncludesExtension("/some/dir/xyz.framework")))
1726+
verifier.expect(.warning("framework search path ends in \".framework\"; add directory containing framework instead: /some/dir/xyz.framework"))
17271727
_ = try Driver(args: ["swiftc", "foo.swift", "-Dnot-an-identifier", "-F/some/dir/xyz.framework"], diagnosticsEngine: engine)
17281728
}
17291729
}

0 commit comments

Comments
 (0)