Skip to content

Commit 8e47ffe

Browse files
authored
Merge pull request #1510 from akyrtzi/akyrtzi/pr/revert-sdkroot-immediate-mode
Revert "[Driver] For immediate mode prefer using the default SDK over the `SDKROOT` variable"
2 parents 2e355ae + ef730db commit 8e47ffe

File tree

2 files changed

+4
-23
lines changed

2 files changed

+4
-23
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,17 +2752,13 @@ extension Driver {
27522752

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

2762-
if sdkPath == nil, let SDKROOT = env["SDKROOT"] {
2763-
sdkPath = SDKROOT
2764-
}
2765-
27662762
// An empty string explicitly clears the SDK.
27672763
if sdkPath == "" {
27682764
sdkPath = nil

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,17 +3689,7 @@ final class SwiftDriverTests: XCTestCase {
36893689

36903690
func testImmediateMode() throws {
36913691
do {
3692-
var env: [String: String] = ProcessEnv.vars
3693-
#if os(macOS)
3694-
let executor = try SwiftDriverExecutor(diagnosticsEngine: DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler]),
3695-
processSet: ProcessSet(),
3696-
fileSystem: localFileSystem,
3697-
env: ProcessEnv.vars)
3698-
let iosSDKPath = try executor.checkNonZeroExit(
3699-
args: "xcrun", "-sdk", "iphoneos", "--show-sdk-path").spm_chomp()
3700-
env["SDKROOT"] = iosSDKPath
3701-
#endif
3702-
var driver = try Driver(args: ["swift", "foo.swift"], env: env)
3692+
var driver = try Driver(args: ["swift", "foo.swift"])
37033693
let plannedJobs = try driver.planBuild()
37043694
XCTAssertEqual(plannedJobs.count, 1)
37053695
let job = plannedJobs[0]
@@ -3713,12 +3703,7 @@ final class SwiftDriverTests: XCTestCase {
37133703
XCTAssertTrue(job.commandLine.contains(.flag("foo")))
37143704

37153705
if driver.targetTriple.isMacOSX {
3716-
let sdkIdx = try XCTUnwrap(job.commandLine.firstIndex(of: .flag("-sdk")))
3717-
if case .path(let path) = job.commandLine[sdkIdx + 1] {
3718-
XCTAssertTrue(path.name.contains("MacOSX.platform"))
3719-
} else {
3720-
XCTFail("Missing SDK path")
3721-
}
3706+
XCTAssertTrue(job.commandLine.contains(.flag("-sdk")))
37223707
}
37233708

37243709
XCTAssertFalse(job.commandLine.contains(.flag("--")))

0 commit comments

Comments
 (0)