Skip to content

Commit 9dd6657

Browse files
authored
Merge pull request #1711 from rmaz/relsdkpath
Maintain relative SDK paths with no -working-directory flag
2 parents 175e0ba + 681c56b commit 9dd6657

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,19 +2875,19 @@ extension Driver {
28752875

28762876
// Validate the SDK if we found one.
28772877
if let sdkPath = sdkPath {
2878-
let path: AbsolutePath
2878+
let path: VirtualPath
28792879

28802880
// FIXME: TSC should provide a better utility for this.
28812881
if let absPath = try? AbsolutePath(validating: sdkPath) {
2882-
path = absPath
2883-
} else if let cwd = fileSystem.currentWorkingDirectory, let absPath = try? AbsolutePath(validating: sdkPath, relativeTo: cwd) {
2884-
path = absPath
2882+
path = .absolute(absPath)
2883+
} else if let relPath = try? RelativePath(validating: sdkPath) {
2884+
path = .relative(relPath)
28852885
} else {
28862886
diagnosticsEngine.emit(.warning_no_such_sdk(sdkPath))
28872887
return nil
28882888
}
28892889

2890-
if !fileSystem.exists(path) {
2890+
if (try? fileSystem.exists(path)) != true {
28912891
diagnosticsEngine.emit(.warning_no_such_sdk(sdkPath))
28922892
} else if (targetTriple?.isDarwin ?? (defaultToolchainType == DarwinToolchain.self)) {
28932893
if isSDKTooOld(sdkPath: path, fileSystem: fileSystem,
@@ -2897,7 +2897,7 @@ extension Driver {
28972897
}
28982898
}
28992899

2900-
return .absolute(path)
2900+
return path
29012901
}
29022902

29032903
return nil
@@ -2906,15 +2906,15 @@ extension Driver {
29062906

29072907
// SDK checking: attempt to diagnose if the SDK we are pointed at is too old.
29082908
extension Driver {
2909-
static func isSDKTooOld(sdkPath: AbsolutePath, fileSystem: FileSystem,
2909+
static func isSDKTooOld(sdkPath: VirtualPath, fileSystem: FileSystem,
29102910
diagnosticsEngine: DiagnosticsEngine) -> Bool {
2911-
let sdkInfoReadAttempt = DarwinToolchain.readSDKInfo(fileSystem, VirtualPath.absolute(sdkPath).intern())
2911+
let sdkInfoReadAttempt = DarwinToolchain.readSDKInfo(fileSystem, sdkPath.intern())
29122912
guard let sdkInfo = sdkInfoReadAttempt else {
2913-
diagnosticsEngine.emit(.warning_no_sdksettings_json(sdkPath.pathString))
2913+
diagnosticsEngine.emit(.warning_no_sdksettings_json(sdkPath.name))
29142914
return false
29152915
}
29162916
guard let sdkVersion = try? Version(string: sdkInfo.versionString, lenient: true) else {
2917-
diagnosticsEngine.emit(.warning_fail_parse_sdk_ver(sdkInfo.versionString, sdkPath.pathString))
2917+
diagnosticsEngine.emit(.warning_fail_parse_sdk_ver(sdkInfo.versionString, sdkPath.name))
29182918
return false
29192919
}
29202920
if sdkInfo.canonicalName.hasPrefix("macos") {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7262,23 +7262,31 @@ final class SwiftDriverTests: XCTestCase {
72627262
// Inputs with relative paths with no -working-directory flag should remain relative
72637263
var driver = try Driver(args: ["swiftc",
72647264
"-target", "arm64-apple-ios13.1",
7265+
"-resource-dir", "relresourcepath",
7266+
"-sdk", "relsdkpath",
72657267
"foo.swift"])
72667268
let plannedJobs = try driver.planBuild()
72677269
let compileJob = plannedJobs[0]
72687270
XCTAssertEqual(compileJob.kind, .compile)
72697271
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-primary-file", try toPathOption("foo.swift", isRelative: true)]))
7272+
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-resource-dir", try toPathOption("relresourcepath", isRelative: true)]))
7273+
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-sdk", try toPathOption("relsdkpath", isRelative: true)]))
72707274
}
72717275

72727276
do {
72737277
// Inputs with relative paths with -working-directory flag should prefix all inputs
72747278
var driver = try Driver(args: ["swiftc",
72757279
"-target", "arm64-apple-ios13.1",
7280+
"-resource-dir", "relresourcepath",
7281+
"-sdk", "relsdkpath",
72767282
"foo.swift",
72777283
"-working-directory", "/foo/bar"])
72787284
let plannedJobs = try driver.planBuild()
72797285
let compileJob = plannedJobs[0]
72807286
XCTAssertEqual(compileJob.kind, .compile)
72817287
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-primary-file", try toPathOption("/foo/bar/foo.swift", isRelative: false)]))
7288+
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-resource-dir", try toPathOption("/foo/bar/relresourcepath", isRelative: false)]))
7289+
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-sdk", try toPathOption("/foo/bar/relsdkpath", isRelative: false)]))
72827290
}
72837291

72847292
try withTemporaryFile { fileMapFile in
@@ -7331,7 +7339,6 @@ final class SwiftDriverTests: XCTestCase {
73317339
XCTAssertEqual(compileJob.kind, .compile)
73327340
XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-o", try toPathOption("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.o", isRelative: false)]))
73337341
}
7334-
73357342
}
73367343

73377344
func testRelativeResourceDir() throws {

0 commit comments

Comments
 (0)