Skip to content

Commit cdcd4de

Browse files
authored
Merge pull request swiftlang#1401 from DougGregor/macro-platform-paths-simulator-to-device-5.9
2 parents 0363bc6 + a70c099 commit cdcd4de

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

Sources/SwiftDriver/Toolchains/DarwinToolchain.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,33 @@ public final class DarwinToolchain: Toolchain {
429429
// that SDK's plugin server).
430430
let sdkPathRoot = VirtualPath.lookup(sdkPath).appending(components: "usr")
431431
commandLine.appendFlag(.externalPluginPath)
432-
commandLine.appendFlag("\(sdkPathRoot.pluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())")
432+
commandLine.appendFlag("\(sdkPathRoot.pluginPath.name)#\(sdkPathRoot.pluginServerPath.name)")
433433

434434
commandLine.appendFlag(.externalPluginPath)
435-
commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())")
435+
commandLine.appendFlag("\(sdkPathRoot.localPluginPath.name)#\(sdkPathRoot.pluginServerPath.name)")
436436

437-
// Default paths for compiler plugins within the platform (accessed via that
438-
// platform's plugin server).
439-
let platformPathRoot = VirtualPath.lookup(sdkPath)
437+
// Determine the platform path. For simulator platforms, look into the
438+
// corresponding device platform instance.
439+
let origPlatformPath = VirtualPath.lookup(sdkPath)
440440
.parentDirectory
441441
.parentDirectory
442442
.parentDirectory
443-
.appending(components: "Developer", "usr")
443+
let platformPath: VirtualPath
444+
if let simulatorRange = origPlatformPath.basename.range(of: "Simulator.platform") {
445+
let devicePlatform = origPlatformPath.basename.replacingCharacters(in: simulatorRange, with: "OS.platform")
446+
platformPath = origPlatformPath.parentDirectory.appending(component: devicePlatform)
447+
} else {
448+
platformPath = origPlatformPath
449+
}
450+
451+
// Default paths for compiler plugins within the platform (accessed via that
452+
// platform's plugin server).
453+
let platformPathRoot = platformPath.appending(components: "Developer", "usr")
444454
commandLine.appendFlag(.externalPluginPath)
445-
commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())")
455+
commandLine.appendFlag("\(platformPathRoot.pluginPath.name)#\(platformPathRoot.pluginServerPath.name)")
446456

447457
commandLine.appendFlag(.externalPluginPath)
448-
commandLine.appendFlag("\(platformPathRoot.localPluginPath.name)#\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())")
458+
commandLine.appendFlag("\(platformPathRoot.localPluginPath.name)#\(platformPathRoot.pluginServerPath.name)")
449459
}
450460
}
451461
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Version": "13.0",
3+
"CanonicalName": "iphoneos13.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"Version": "15.0",
3+
"CanonicalName": "iphonesimulator15.0"
4+
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6780,8 +6780,14 @@ final class SwiftDriverTests: XCTestCase {
67806780
}
67816781

67826782
func testPluginPaths() throws {
6783-
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk")
6784-
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"])
6783+
try pluginPathTest(platform: "iPhoneOS", sdk: "iPhoneOS13.0", searchPlatform: "iPhoneOS")
6784+
try pluginPathTest(platform: "iPhoneSimulator", sdk: "iPhoneSimulator15.0", searchPlatform: "iPhoneOS")
6785+
}
6786+
6787+
func pluginPathTest(platform: String, sdk: String, searchPlatform: String) throws {
6788+
let sdkRoot = testInputsPath.appending(
6789+
components: ["Platform Checks", "\(platform).platform", "Developer", "SDKs", "\(sdk).sdk"])
6790+
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"])
67856791
guard driver.isFrontendArgSupported(.pluginPath) && driver.isFrontendArgSupported(.externalPluginPath) else {
67866792
return
67876793
}
@@ -6794,7 +6800,7 @@ final class SwiftDriverTests: XCTestCase {
67946800
let pluginAIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginA"))))
67956801
XCTAssertNotNil(pluginAIndex)
67966802

6797-
let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginB#Bexe"))))
6803+
let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("Plugin~B#Bexe"))))
67986804
XCTAssertNotNil(pluginBIndex)
67996805
XCTAssertLessThan(pluginAIndex!, pluginBIndex!)
68006806

@@ -6820,7 +6826,11 @@ final class SwiftDriverTests: XCTestCase {
68206826
XCTAssertNotNil(sdkLocalPluginPathIndex)
68216827
XCTAssertLessThan(sdkPluginPathIndex!, sdkLocalPluginPathIndex!)
68226828

6823-
let platformPath = sdkRoot.parentDirectory.parentDirectory.parentDirectory.appending(components: "Developer", "usr")
6829+
let origPlatformPath =
6830+
sdkRoot.parentDirectory.parentDirectory.parentDirectory.parentDirectory
6831+
.appending(component: "\(searchPlatform).platform")
6832+
6833+
let platformPath = origPlatformPath.appending(components: "Developer", "usr")
68246834
let platformServerPath = platformPath.appending(components: "bin", "swift-plugin-server").pathString
68256835

68266836
let platformPluginPath = platformPath.appending(components: "lib", "swift", "host", "plugins")

0 commit comments

Comments
 (0)