diff --git a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift index 3cbff2106..cf099be5b 100644 --- a/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift +++ b/Sources/SwiftDriver/Toolchains/DarwinToolchain.swift @@ -429,23 +429,33 @@ public final class DarwinToolchain: Toolchain { // that SDK's plugin server). let sdkPathRoot = VirtualPath.lookup(sdkPath).appending(components: "usr") commandLine.appendFlag(.externalPluginPath) - commandLine.appendFlag("\(sdkPathRoot.pluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())") + commandLine.appendFlag("\(sdkPathRoot.pluginPath.name)#\(sdkPathRoot.pluginServerPath.name)") commandLine.appendFlag(.externalPluginPath) - commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())") + commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name)") - // Default paths for compiler plugins within the platform (accessed via that - // platform's plugin server). - let platformPathRoot = VirtualPath.lookup(sdkPath) + // Determine the platform path. For simulator platforms, look into the + // corresponding device platform instance. + let origPlatformPath = VirtualPath.lookup(sdkPath) .parentDirectory .parentDirectory .parentDirectory - .appending(components: "Developer", "usr") + let platformPath: VirtualPath + if let simulatorRange = origPlatformPath.basename.range(of: "Simulator.platform") { + let devicePlatform = origPlatformPath.basename.replacingCharacters(in: simulatorRange, with: "OS.platform") + platformPath = origPlatformPath.parentDirectory.appending(component: devicePlatform) + } else { + platformPath = origPlatformPath + } + + // Default paths for compiler plugins within the platform (accessed via that + // platform's plugin server). + let platformPathRoot = platformPath.appending(components: "Developer", "usr") commandLine.appendFlag(.externalPluginPath) - commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())") + commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name)") commandLine.appendFlag(.externalPluginPath) - commandLine.appendFlag("\(platformPathRoot.localPluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())") + commandLine.appendFlag("\(platformPathRoot.localPluginPath.name)#\(platformPathRoot.pluginServerPath.name)") } } } diff --git a/TestInputs/Platform Checks/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk/SDKSettings.json b/TestInputs/Platform Checks/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk/SDKSettings.json new file mode 100644 index 000000000..9c61188fb --- /dev/null +++ b/TestInputs/Platform Checks/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.0.sdk/SDKSettings.json @@ -0,0 +1,4 @@ +{ + "Version": "13.0", + "CanonicalName": "iphoneos13.0" +} diff --git a/TestInputs/Platform Checks/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk/SDKSettings.json b/TestInputs/Platform Checks/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk/SDKSettings.json new file mode 100644 index 000000000..bf57dcd27 --- /dev/null +++ b/TestInputs/Platform Checks/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.0.sdk/SDKSettings.json @@ -0,0 +1,4 @@ +{ + "Version": "15.0", + "CanonicalName": "iphonesimulator15.0" +} diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index 6a62ad7a3..f8e8a070b 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -6869,8 +6869,14 @@ final class SwiftDriverTests: XCTestCase { } func testPluginPaths() throws { - let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk") - var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift", "-sdk", VirtualPath.absolute(sdkRoot).name, "-plugin-path", "PluginA", "-external-plugin-path", "PluginB#Bexe", "-load-plugin-library", "PluginB2", "-plugin-path", "PluginC"]) + try pluginPathTest(platform: "iPhoneOS", sdk: "iPhoneOS13.0", searchPlatform: "iPhoneOS") + try pluginPathTest(platform: "iPhoneSimulator", sdk: "iPhoneSimulator15.0", searchPlatform: "iPhoneOS") + } + + func pluginPathTest(platform: String, sdk: String, searchPlatform: String) throws { + let sdkRoot = testInputsPath.appending( + components: ["Platform Checks", "\(platform).platform", "Developer", "SDKs", "\(sdk).sdk"]) + var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift", "-sdk", VirtualPath.absolute(sdkRoot).name, "-plugin-path", "PluginA", "-external-plugin-path", "Plugin~B#Bexe", "-load-plugin-library", "PluginB2", "-plugin-path", "PluginC"]) guard driver.isFrontendArgSupported(.pluginPath) && driver.isFrontendArgSupported(.externalPluginPath) else { return } @@ -6883,7 +6889,7 @@ final class SwiftDriverTests: XCTestCase { let pluginAIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginA")))) XCTAssertNotNil(pluginAIndex) - let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginB#Bexe")))) + let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("Plugin~B#Bexe")))) XCTAssertNotNil(pluginBIndex) XCTAssertLessThan(pluginAIndex!, pluginBIndex!) @@ -6909,7 +6915,11 @@ final class SwiftDriverTests: XCTestCase { XCTAssertNotNil(sdkLocalPluginPathIndex) XCTAssertLessThan(sdkPluginPathIndex!, sdkLocalPluginPathIndex!) - let platformPath = sdkRoot.parentDirectory.parentDirectory.parentDirectory.appending(components: "Developer", "usr") + let origPlatformPath = + sdkRoot.parentDirectory.parentDirectory.parentDirectory.parentDirectory + .appending(component: "\(searchPlatform).platform") + + let platformPath = origPlatformPath.appending(components: "Developer", "usr") let platformServerPath = platformPath.appending(components: "bin", "swift-plugin-server").pathString let platformPluginPath = platformPath.appending(components: "lib", "swift", "host", "plugins")