Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[Driver] For immediate mode prefer using the default SDK over the SDKROOT variable" #1510

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2752,17 +2752,13 @@ extension Driver {

if let arg = parsedOptions.getLastArgument(.sdk) {
sdkPath = arg.asSingle
} else if let SDKROOT = env["SDKROOT"] {
sdkPath = SDKROOT
} else if compilerMode == .immediate || compilerMode == .repl {
// In immediate modes, query the toolchain for a default SDK.
// We avoid using `SDKROOT` because that may be set to a compilation platform (like iOS)
// that is different than the host.
sdkPath = try? toolchain.defaultSDKPath(targetTriple)?.pathString
}

if sdkPath == nil, let SDKROOT = env["SDKROOT"] {
sdkPath = SDKROOT
}

// An empty string explicitly clears the SDK.
if sdkPath == "" {
sdkPath = nil
Expand Down
19 changes: 2 additions & 17 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3689,17 +3689,7 @@ final class SwiftDriverTests: XCTestCase {

func testImmediateMode() throws {
do {
var env: [String: String] = ProcessEnv.vars
#if os(macOS)
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
processSet: ProcessSet(),
fileSystem: localFileSystem,
env: ProcessEnv.vars)
let iosSDKPath = try executor.checkNonZeroExit(
args: "xcrun", "-sdk", "iphoneos", "--show-sdk-path").spm_chomp()
env["SDKROOT"] = iosSDKPath
#endif
var driver = try Driver(args: ["swift", "foo.swift"], env: env)
var driver = try Driver(args: ["swift", "foo.swift"])
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 1)
let job = plannedJobs[0]
Expand All @@ -3713,12 +3703,7 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(job.commandLine.contains(.flag("foo")))

if driver.targetTriple.isMacOSX {
let sdkIdx = try XCTUnwrap(job.commandLine.firstIndex(of: .flag("-sdk")))
if case .path(let path) = job.commandLine[sdkIdx + 1] {
XCTAssertTrue(path.name.contains("MacOSX.platform"))
} else {
XCTFail("Missing SDK path")
}
XCTAssertTrue(job.commandLine.contains(.flag("-sdk")))
}

XCTAssertFalse(job.commandLine.contains(.flag("--")))
Expand Down