@@ -456,29 +456,53 @@ 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
459+ // If the PLATFORM_DIR environment variable is set, also add plugin
460+ // paths into it. Since this is a user override, it comes beore the
461+ // default platform path that's based on the SDK.
462+ if let platformDir = env [ " PLATFORM_DIR " ] ,
463+ let platformPath = try ? VirtualPath ( path: platformDir) {
464+ addPluginPaths (
465+ forPlatform: platformPath,
466+ commandLine: & commandLine
467+ )
471468 }
472469
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) " )
470+ // Determine the platform path based on the SDK path.
471+ addPluginPaths (
472+ forPlatform: VirtualPath . lookup ( sdkPath)
473+ . parentDirectory
474+ . parentDirectory
475+ . parentDirectory,
476+ commandLine: & commandLine
477+ )
478+ }
479+ }
478480
479- commandLine. appendFlag ( . externalPluginPath)
480- commandLine. appendFlag ( " \( platformPathRoot. localPluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
481+ /// Given the platform path (e.g., a path into something like iPhoneOS.platform),
482+ /// add external plugin path arguments for compiler plugins that are distributed
483+ /// within that path.
484+ func addPluginPaths(
485+ forPlatform origPlatformPath: VirtualPath ,
486+ commandLine: inout [ Job . ArgTemplate ]
487+ ) {
488+ // For simulator platforms, look into the corresponding device platform instance,
489+ // because they share compiler plugins.
490+ let platformPath : VirtualPath
491+ if let simulatorRange = origPlatformPath. basename. range ( of: " Simulator.platform " ) {
492+ let devicePlatform = origPlatformPath. basename. replacingCharacters ( in: simulatorRange, with: " OS.platform " )
493+ platformPath = origPlatformPath. parentDirectory. appending ( component: devicePlatform)
494+ } else {
495+ platformPath = origPlatformPath
481496 }
497+
498+ // Default paths for compiler plugins within the platform (accessed via that
499+ // platform's plugin server).
500+ let platformPathRoot = platformPath. appending ( components: " Developer " , " usr " )
501+ commandLine. appendFlag ( . externalPluginPath)
502+ commandLine. appendFlag ( " \( platformPathRoot. pluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
503+
504+ commandLine. appendFlag ( . externalPluginPath)
505+ commandLine. appendFlag ( " \( platformPathRoot. localPluginPath. name) # \( platformPathRoot. pluginServerPath. name) " )
482506 }
483507}
484508
0 commit comments