Skip to content

Commit

Permalink
Warn when a target environment is inferred to be a simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
owenv committed Oct 17, 2020
1 parent d4b91be commit b6215b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Expand Up @@ -1941,6 +1941,13 @@ extension Driver {
}
}

// Check if the simulator environment was inferred for backwards compatibility.
if let explicitTarget = explicitTarget,
explicitTarget.environment != .simulator && info.target.triple.environment == .simulator {
diagnosticsEngine.emit(.warning_inferring_simulator_target(originalTriple: explicitTarget,
inferredTriple: info.target.triple))
}

return (toolchain, info, swiftCompilerPrefixArgs)
} catch let JobExecutionError.decodingError(decodingError,
dataToDecode,
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftDriver/Utilities/Diagnostics.swift
Expand Up @@ -29,6 +29,10 @@ extension Diagnostic.Message {
.error("invalid value '\(value)' in '\(arg.spelling)'")
}

static func warning_inferring_simulator_target(originalTriple: Triple, inferredTriple: Triple) -> Diagnostic.Message {
.warning("inferring simulator environment for target '\(originalTriple.triple)'; use '-target \(inferredTriple.triple)' instead")
}

static func error_argument_not_allowed_with(arg: String, other: String) -> Diagnostic.Message {
.error("argument '\(arg)' is not allowed with '\(other)'")
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Expand Up @@ -1672,6 +1672,16 @@ final class SwiftDriverTests: XCTestCase {
}
}

func testEnvironmentInferenceWarning() throws {
try assertDriverDiagnostics(args: ["swiftc", "-target", "x86_64-apple-ios13.0", "foo.swift"]) {
$1.expect(.warning("inferring simulator environment for target 'x86_64-apple-ios13.0'; use '-target x86_64-apple-ios13.0-simulator'"))
}
try assertDriverDiagnostics(args: ["swiftc", "-target", "x86_64-apple-watchos6.0", "foo.swift"]) {
$1.expect(.warning("inferring simulator environment for target 'x86_64-apple-watchos6.0'; use '-target x86_64-apple-watchos6.0-simulator'"))
}
try assertNoDriverDiagnostics(args: "swiftc", "-target", "x86_64-apple-ios13.0-simulator", "foo.swift")
}

func testDarwinToolchainArgumentValidation() throws {
XCTAssertThrowsError(try Driver(args: ["swiftc", "-c", "-target", "x86_64-apple-ios6.0",
"foo.swift"])) { error in
Expand Down

0 comments on commit b6215b4

Please sign in to comment.