@@ -456,29 +456,52 @@ public final class DarwinToolchain: Toolchain {
456456 }
457457
458458 if driver. isFrontendArgSupported ( . externalPluginPath) {
459- // Determine the platform path. For simulator platforms, look into the
460- // corresponding device platform instance.
461- let origPlatformPath = VirtualPath . lookup ( sdkPath)
462- . parentDirectory
463- . parentDirectory
464- . parentDirectory
465- let platformPath : VirtualPath
466- if let simulatorRange = origPlatformPath. basename. range ( of: " Simulator.platform " ) {
467- let devicePlatform = origPlatformPath. basename. replacingCharacters ( in: simulatorRange, with: " OS.platform " )
468- platformPath = origPlatformPath. parentDirectory. appending ( component: devicePlatform)
469- } else {
470- platformPath = origPlatformPath
471- }
459+ // Determine the platform path based on the SDK path.
460+ addPluginPaths (
461+ forPlatform: VirtualPath . lookup ( sdkPath)
462+ . parentDirectory
463+ . parentDirectory
464+ . parentDirectory,
465+ commandLine: & commandLine
466+ )
472467
473- // Default paths for compiler plugins within the platform (accessed via that
474- // platform's plugin server).
475- let platformPathRoot = platformPath. appending ( components: " Developer " , " usr " )
476- commandLine. appendFlag ( . externalPluginPath)
477- commandLine. appendFlag ( " \( platformPathRoot. pluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
468+ // If the PLATFORM_DIR environment variable is set, also add plugin
469+ // paths into it.
470+ if let platformDir = env [ " PLATFORM_DIR " ] ,
471+ let platformPath = try ? VirtualPath ( path: platformDir) {
472+ addPluginPaths (
473+ forPlatform: platformPath,
474+ commandLine: & commandLine
475+ )
476+ }
477+ }
478+ }
478479
479- commandLine. appendFlag ( . externalPluginPath)
480- commandLine. appendFlag ( " \( platformPathRoot. localPluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
480+ /// Given the platform path (e.g., a path into something like iPhoneOS.platform),
481+ /// add external plugin path arguments for compiler plugins that are distributed
482+ /// within that path.
483+ func addPluginPaths(
484+ forPlatform origPlatformPath: VirtualPath ,
485+ commandLine: inout [ Job . ArgTemplate ]
486+ ) {
487+ // For simulator platforms, look into the corresponding device platform instance,
488+ // because they share compiler plugins.
489+ let platformPath : VirtualPath
490+ if let simulatorRange = origPlatformPath. basename. range ( of: " Simulator.platform " ) {
491+ let devicePlatform = origPlatformPath. basename. replacingCharacters ( in: simulatorRange, with: " OS.platform " )
492+ platformPath = origPlatformPath. parentDirectory. appending ( component: devicePlatform)
493+ } else {
494+ platformPath = origPlatformPath
481495 }
496+
497+ // Default paths for compiler plugins within the platform (accessed via that
498+ // platform's plugin server).
499+ let platformPathRoot = platformPath. appending ( components: " Developer " , " usr " )
500+ commandLine. appendFlag ( . externalPluginPath)
501+ commandLine. appendFlag ( " \( platformPathRoot. pluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
502+
503+ commandLine. appendFlag ( . externalPluginPath)
504+ commandLine. appendFlag ( " \( platformPathRoot. localPluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
482505 }
483506}
484507
0 commit comments