Skip to content

Commit d01fb4c

Browse files
authored
Merge pull request #1400 from DougGregor/macro-platform-paths-simulator-to-device
2 parents e98ddbd + b80dade commit d01fb4c

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
@@ -6869,8 +6869,14 @@ final class SwiftDriverTests: XCTestCase {
68696869
}
68706870

68716871
func testPluginPaths() throws {
6872-
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk")
6873-
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"])
6872+
try pluginPathTest(platform: "iPhoneOS", sdk: "iPhoneOS13.0", searchPlatform: "iPhoneOS")
6873+
try pluginPathTest(platform: "iPhoneSimulator", sdk: "iPhoneSimulator15.0", searchPlatform: "iPhoneOS")
6874+
}
6875+
6876+
func pluginPathTest(platform: String, sdk: String, searchPlatform: String) throws {
6877+
let sdkRoot = testInputsPath.appending(
6878+
components: ["Platform Checks", "\(platform).platform", "Developer", "SDKs", "\(sdk).sdk"])
6879+
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"])
68746880
guard driver.isFrontendArgSupported(.pluginPath) && driver.isFrontendArgSupported(.externalPluginPath) else {
68756881
return
68766882
}
@@ -6883,7 +6889,7 @@ final class SwiftDriverTests: XCTestCase {
68836889
let pluginAIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginA"))))
68846890
XCTAssertNotNil(pluginAIndex)
68856891

6886-
let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("PluginB#Bexe"))))
6892+
let pluginBIndex = job.commandLine.firstIndex(of: .path(VirtualPath.relative(.init("Plugin~B#Bexe"))))
68876893
XCTAssertNotNil(pluginBIndex)
68886894
XCTAssertLessThan(pluginAIndex!, pluginBIndex!)
68896895

@@ -6909,7 +6915,11 @@ final class SwiftDriverTests: XCTestCase {
69096915
XCTAssertNotNil(sdkLocalPluginPathIndex)
69106916
XCTAssertLessThan(sdkPluginPathIndex!, sdkLocalPluginPathIndex!)
69116917

6912-
let platformPath = sdkRoot.parentDirectory.parentDirectory.parentDirectory.appending(components: "Developer", "usr")
6918+
let origPlatformPath =
6919+
sdkRoot.parentDirectory.parentDirectory.parentDirectory.parentDirectory
6920+
.appending(component: "\(searchPlatform).platform")
6921+
6922+
let platformPath = origPlatformPath.appending(components: "Developer", "usr")
69136923
let platformServerPath = platformPath.appending(components: "bin", "swift-plugin-server").pathString
69146924

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

0 commit comments

Comments
 (0)