@@ -27,6 +27,26 @@ fileprivate func shouldColorDiagnostics() -> Bool {
27
27
return TerminalController . isTTY ( stderrStream)
28
28
}
29
29
30
+ extension VirtualPath {
31
+ // Given a virtual path pointing into a toolchain/SDK/platform, produce the
32
+ // path to `swift-plugin-server`.
33
+ fileprivate var pluginServerPath : VirtualPath {
34
+ self . appending ( components: " usr " , " swift-plugin-server " )
35
+ }
36
+
37
+ // Given a virtual path pointing into a toolchain/SDK/platform, produce the
38
+ // path to the plugins.
39
+ fileprivate var pluginPath : VirtualPath {
40
+ self . appending ( components: " lib " , " swift " , " host " , " plugins " )
41
+ }
42
+
43
+ // Given a virtual path pointing into a toolchain/SDK/platform, produce the
44
+ // path to the plugins.
45
+ fileprivate var localPluginPath : VirtualPath {
46
+ self . appending ( component: " local " ) . pluginPath
47
+ }
48
+ }
49
+
30
50
extension Driver {
31
51
/// How the bridging header should be handled.
32
52
enum BridgingHeaderHandling {
@@ -261,18 +281,46 @@ extension Driver {
261
281
try commandLine. appendLast ( . emitMacroExpansionFiles, from: & parsedOptions)
262
282
}
263
283
264
- if isFrontendArgSupported ( . pluginPath) {
284
+ // Emit user-provided plugin paths, in order.
285
+ if isFrontendArgSupported ( . externalPluginPath) {
286
+ try commandLine. appendAll ( . pluginPath, . externalPluginPath, from: & parsedOptions)
287
+ } else if isFrontendArgSupported ( . pluginPath) {
265
288
try commandLine. appendAll ( . pluginPath, from: & parsedOptions)
289
+ }
290
+
291
+ if isFrontendArgSupported ( . externalPluginPath) , let sdkPath = frontendTargetInfo. sdkPath? . path {
292
+ // Default paths for compiler plugins found within an SDK (accessed via
293
+ // that SDK's plugin server).
294
+ let sdkPathRoot = VirtualPath . lookup ( sdkPath) . appending ( components: " usr " )
295
+ commandLine. appendFlag ( . externalPluginPath)
296
+ commandLine. appendFlag ( " \( sdkPathRoot. pluginServerPath. name. spm_shellEscaped ( ) ) # \( sdkPathRoot. pluginPath. name) " )
297
+
298
+ commandLine. appendFlag ( . externalPluginPath)
299
+ commandLine. appendFlag ( " \( sdkPathRoot. pluginServerPath. name. spm_shellEscaped ( ) ) # \( sdkPathRoot. localPluginPath. name) " )
266
300
267
- let defaultPluginPath = try toolchain. executableDir. parentDirectory
268
- . appending ( components: " lib " , " swift " , " host " , " plugins " )
301
+ // Default paths for compiler plugins within the platform (accessed via that
302
+ // platform's plugin server).
303
+ let platformPathRoot = VirtualPath . lookup ( sdkPath)
304
+ . parentDirectory
305
+ . parentDirectory
306
+ . parentDirectory
307
+ . appending ( components: " Developer " , " usr " )
308
+ commandLine. appendFlag ( . externalPluginPath)
309
+ commandLine. appendFlag ( " \( platformPathRoot. pluginServerPath. name. spm_shellEscaped ( ) ) # \( platformPathRoot. pluginPath. name) " )
310
+
311
+ commandLine. appendFlag ( . externalPluginPath)
312
+ commandLine. appendFlag ( " \( platformPathRoot. pluginServerPath. name. spm_shellEscaped ( ) ) # \( platformPathRoot. localPluginPath. name) " )
313
+ }
314
+
315
+ if isFrontendArgSupported ( . pluginPath) {
316
+ // Default paths for compiler plugins found within the toolchain
317
+ // (loaded as shared libraries).
318
+ let pluginPathRoot = VirtualPath . absolute ( try toolchain. executableDir. parentDirectory)
269
319
commandLine. appendFlag ( . pluginPath)
270
- commandLine. appendPath ( defaultPluginPath )
320
+ commandLine. appendPath ( pluginPathRoot . pluginPath )
271
321
272
- let localPluginPath = try toolchain. executableDir. parentDirectory
273
- . appending ( components: " local " , " lib " , " swift " , " host " , " plugins " )
274
322
commandLine. appendFlag ( . pluginPath)
275
- commandLine. appendPath ( localPluginPath)
323
+ commandLine. appendPath ( pluginPathRoot . localPluginPath)
276
324
}
277
325
278
326
if isFrontendArgSupported ( . externalPluginPath) {
0 commit comments