-
Notifications
You must be signed in to change notification settings - Fork 210
Add SDK and platform paths to plugin executables #1377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,26 @@ fileprivate func shouldColorDiagnostics() -> Bool { | |
return TerminalController.isTTY(stderrStream) | ||
} | ||
|
||
extension VirtualPath { | ||
// Given a virtual path pointing into a toolchain/SDK/platform, produce the | ||
// path to `swift-plugin-server`. | ||
fileprivate var pluginServerPath: VirtualPath { | ||
self.appending(components: "usr", "swift-plugin-server") | ||
} | ||
|
||
// Given a virtual path pointing into a toolchain/SDK/platform, produce the | ||
// path to the plugins. | ||
fileprivate var pluginPath: VirtualPath { | ||
self.appending(components: "lib", "swift", "host", "plugins") | ||
} | ||
|
||
// Given a virtual path pointing into a toolchain/SDK/platform, produce the | ||
// path to the plugins. | ||
fileprivate var localPluginPath: VirtualPath { | ||
self.appending(component: "local").pluginPath | ||
} | ||
} | ||
|
||
extension Driver { | ||
/// How the bridging header should be handled. | ||
enum BridgingHeaderHandling { | ||
|
@@ -261,18 +281,46 @@ extension Driver { | |
try commandLine.appendLast(.emitMacroExpansionFiles, from: &parsedOptions) | ||
} | ||
|
||
if isFrontendArgSupported(.pluginPath) { | ||
// Emit user-provided plugin paths, in order. | ||
if isFrontendArgSupported(.externalPluginPath) { | ||
try commandLine.appendAll(.pluginPath, .externalPluginPath, from: &parsedOptions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't we passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think those also need to be handled in this same group, yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Woah, those aren't being passed at all! |
||
} else if isFrontendArgSupported(.pluginPath) { | ||
try commandLine.appendAll(.pluginPath, from: &parsedOptions) | ||
} | ||
|
||
if isFrontendArgSupported(.externalPluginPath), let sdkPath = frontendTargetInfo.sdkPath?.path { | ||
// Default paths for compiler plugins found within an SDK (accessed via | ||
// that SDK's plugin server). | ||
let sdkPathRoot = VirtualPath.lookup(sdkPath).appending(components: "usr") | ||
commandLine.appendFlag(.externalPluginPath) | ||
commandLine.appendFlag("\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())#\(sdkPathRoot.pluginPath.name)") | ||
|
||
commandLine.appendFlag(.externalPluginPath) | ||
commandLine.appendFlag("\(sdkPathRoot.pluginServerPath.name.spm_shellEscaped())#\(sdkPathRoot.localPluginPath.name)") | ||
|
||
let defaultPluginPath = try toolchain.executableDir.parentDirectory | ||
.appending(components: "lib", "swift", "host", "plugins") | ||
// Default paths for compiler plugins within the platform (accessed via that | ||
// platform's plugin server). | ||
let platformPathRoot = VirtualPath.lookup(sdkPath) | ||
.parentDirectory | ||
.parentDirectory | ||
.parentDirectory | ||
.appending(components: "Developer", "usr") | ||
commandLine.appendFlag(.externalPluginPath) | ||
commandLine.appendFlag("\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())#\(platformPathRoot.pluginPath.name)") | ||
|
||
commandLine.appendFlag(.externalPluginPath) | ||
commandLine.appendFlag("\(platformPathRoot.pluginServerPath.name.spm_shellEscaped())#\(platformPathRoot.localPluginPath.name)") | ||
} | ||
|
||
if isFrontendArgSupported(.pluginPath) { | ||
// Default paths for compiler plugins found within the toolchain | ||
// (loaded as shared libraries). | ||
let pluginPathRoot = VirtualPath.absolute(try toolchain.executableDir.parentDirectory) | ||
commandLine.appendFlag(.pluginPath) | ||
commandLine.appendPath(defaultPluginPath) | ||
commandLine.appendPath(pluginPathRoot.pluginPath) | ||
|
||
let localPluginPath = try toolchain.executableDir.parentDirectory | ||
.appending(components: "local", "lib", "swift", "host", "plugins") | ||
commandLine.appendFlag(.pluginPath) | ||
commandLine.appendPath(localPluginPath) | ||
commandLine.appendPath(pluginPathRoot.localPluginPath) | ||
} | ||
|
||
if isFrontendArgSupported(.externalPluginPath) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6798,14 +6798,16 @@ final class SwiftDriverTests: XCTestCase { | |
} | ||
|
||
func testPluginPaths() throws { | ||
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift"]) | ||
guard driver.isFrontendArgSupported(.pluginPath) else { | ||
let sdkRoot = testInputsPath.appending(component: "SDKChecks").appending(component: "iPhoneOS.sdk") | ||
var driver = try Driver(args: ["swiftc", "-typecheck", "foo.swift", "-sdk", VirtualPath.absolute(sdkRoot).name]) | ||
guard driver.isFrontendArgSupported(.pluginPath) && driver.isFrontendArgSupported(.externalPluginPath) else { | ||
return | ||
} | ||
|
||
let jobs = try driver.planBuild().removingAutolinkExtractJobs() | ||
XCTAssertEqual(jobs.count, 1) | ||
let job = jobs.first! | ||
XCTAssertTrue(job.commandLine.contains(.flag("-external-plugin-path"))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth checking the path here 😅 |
||
XCTAssertTrue(job.commandLine.contains(.flag("-plugin-path"))) | ||
XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "lib", "swift", "host", "plugins"))))) | ||
XCTAssertTrue(job.commandLine.contains(.path(.absolute(try driver.toolchain.executableDir.parentDirectory.appending(components: "local", "lib", "swift", "host", "plugins"))))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usr/bin
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though seems like the rest don't have
usr
, so is this actually intended to bebin
?EDIT: Yeah, the root path below is
"Developer", "usr"
so I assume this should bebin
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right.