diff --git a/Sources/SwiftDriver/Driver/Driver.swift b/Sources/SwiftDriver/Driver/Driver.swift index 9a0e18458..f42b164f3 100644 --- a/Sources/SwiftDriver/Driver/Driver.swift +++ b/Sources/SwiftDriver/Driver/Driver.swift @@ -2875,19 +2875,19 @@ extension Driver { // Validate the SDK if we found one. if let sdkPath = sdkPath { - let path: AbsolutePath + let path: VirtualPath // FIXME: TSC should provide a better utility for this. if let absPath = try? AbsolutePath(validating: sdkPath) { - path = absPath - } else if let cwd = fileSystem.currentWorkingDirectory, let absPath = try? AbsolutePath(validating: sdkPath, relativeTo: cwd) { - path = absPath + path = .absolute(absPath) + } else if let relPath = try? RelativePath(validating: sdkPath) { + path = .relative(relPath) } else { diagnosticsEngine.emit(.warning_no_such_sdk(sdkPath)) return nil } - if !fileSystem.exists(path) { + if (try? fileSystem.exists(path)) != true { diagnosticsEngine.emit(.warning_no_such_sdk(sdkPath)) } else if (targetTriple?.isDarwin ?? (defaultToolchainType == DarwinToolchain.self)) { if isSDKTooOld(sdkPath: path, fileSystem: fileSystem, @@ -2897,7 +2897,7 @@ extension Driver { } } - return .absolute(path) + return path } return nil @@ -2906,15 +2906,15 @@ extension Driver { // SDK checking: attempt to diagnose if the SDK we are pointed at is too old. extension Driver { - static func isSDKTooOld(sdkPath: AbsolutePath, fileSystem: FileSystem, + static func isSDKTooOld(sdkPath: VirtualPath, fileSystem: FileSystem, diagnosticsEngine: DiagnosticsEngine) -> Bool { - let sdkInfoReadAttempt = DarwinToolchain.readSDKInfo(fileSystem, VirtualPath.absolute(sdkPath).intern()) + let sdkInfoReadAttempt = DarwinToolchain.readSDKInfo(fileSystem, sdkPath.intern()) guard let sdkInfo = sdkInfoReadAttempt else { - diagnosticsEngine.emit(.warning_no_sdksettings_json(sdkPath.pathString)) + diagnosticsEngine.emit(.warning_no_sdksettings_json(sdkPath.name)) return false } guard let sdkVersion = try? Version(string: sdkInfo.versionString, lenient: true) else { - diagnosticsEngine.emit(.warning_fail_parse_sdk_ver(sdkInfo.versionString, sdkPath.pathString)) + diagnosticsEngine.emit(.warning_fail_parse_sdk_ver(sdkInfo.versionString, sdkPath.name)) return false } if sdkInfo.canonicalName.hasPrefix("macos") { diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index f48b14df2..1fc27396b 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -7262,23 +7262,31 @@ final class SwiftDriverTests: XCTestCase { // Inputs with relative paths with no -working-directory flag should remain relative var driver = try Driver(args: ["swiftc", "-target", "arm64-apple-ios13.1", + "-resource-dir", "relresourcepath", + "-sdk", "relsdkpath", "foo.swift"]) let plannedJobs = try driver.planBuild() let compileJob = plannedJobs[0] XCTAssertEqual(compileJob.kind, .compile) XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-primary-file", try toPathOption("foo.swift", isRelative: true)])) + XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-resource-dir", try toPathOption("relresourcepath", isRelative: true)])) + XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-sdk", try toPathOption("relsdkpath", isRelative: true)])) } do { // Inputs with relative paths with -working-directory flag should prefix all inputs var driver = try Driver(args: ["swiftc", "-target", "arm64-apple-ios13.1", + "-resource-dir", "relresourcepath", + "-sdk", "relsdkpath", "foo.swift", "-working-directory", "/foo/bar"]) let plannedJobs = try driver.planBuild() let compileJob = plannedJobs[0] XCTAssertEqual(compileJob.kind, .compile) XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-primary-file", try toPathOption("/foo/bar/foo.swift", isRelative: false)])) + XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-resource-dir", try toPathOption("/foo/bar/relresourcepath", isRelative: false)])) + XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-sdk", try toPathOption("/foo/bar/relsdkpath", isRelative: false)])) } try withTemporaryFile { fileMapFile in @@ -7331,7 +7339,6 @@ final class SwiftDriverTests: XCTestCase { XCTAssertEqual(compileJob.kind, .compile) XCTAssertTrue(compileJob.commandLine.contains(subsequence: ["-o", try toPathOption("/tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.o", isRelative: false)])) } - } func testRelativeResourceDir() throws {