@@ -60,6 +60,8 @@ public final class UserToolchain: Toolchain {
60
60
61
61
private let environment : EnvironmentVariables
62
62
63
+ public let isSwiftDevelopmentToolchain : Bool
64
+
63
65
/// Returns the runtime library for the given sanitizer.
64
66
public func runtimeLibrary( for sanitizer: Sanitizer ) throws -> AbsolutePath {
65
67
// FIXME: This is only for SwiftPM development time support. It is OK
@@ -452,6 +454,22 @@ public final class UserToolchain: Toolchain {
452
454
self . swiftCompilerPath = swiftCompilers. compile
453
455
self . architectures = destination. architectures
454
456
457
+ #if canImport(Darwin)
458
+ let toolchainPlistPath = self . swiftCompilerPath. parentDirectory. parentDirectory. parentDirectory
459
+ . appending ( component: " Info.plist " )
460
+ if localFileSystem. exists ( toolchainPlistPath) , let toolchainPlist = try ? NSDictionary (
461
+ contentsOf: URL ( fileURLWithPath: toolchainPlistPath. pathString) ,
462
+ error: ( )
463
+ ) , let overrideBuildSettings = toolchainPlist [ " OverrideBuildSettings " ] as? NSDictionary ,
464
+ let isSwiftDevelopmentToolchainStringValue = overrideBuildSettings [ " SWIFT_DEVELOPMENT_TOOLCHAIN " ] as? String {
465
+ self . isSwiftDevelopmentToolchain = isSwiftDevelopmentToolchainStringValue == " YES "
466
+ } else {
467
+ self . isSwiftDevelopmentToolchain = false
468
+ }
469
+ #else
470
+ self . isSwiftDevelopmentToolchain = false
471
+ #endif
472
+
455
473
// Use the triple from destination or compute the host triple using swiftc.
456
474
var triple = try destination. targetTriple ?? Triple . getHostTriple ( usingSwiftCompiler: swiftCompilers. compile)
457
475
@@ -535,10 +553,13 @@ public final class UserToolchain: Toolchain {
535
553
environment: environment
536
554
)
537
555
556
+ let swiftPluginServerPath : AbsolutePath ?
538
557
let xctestPath : AbsolutePath ?
539
558
if case . custom( _, let useXcrun) = searchStrategy, !useXcrun {
559
+ swiftPluginServerPath = nil
540
560
xctestPath = nil
541
561
} else {
562
+ swiftPluginServerPath = try Self . derivePluginServerPath ( triple: triple)
542
563
xctestPath = try Self . deriveXCTestPath (
543
564
destination: self . destination,
544
565
triple: triple,
@@ -553,7 +574,8 @@ public final class UserToolchain: Toolchain {
553
574
swiftCompilerEnvironment: environment,
554
575
swiftPMLibrariesLocation: swiftPMLibrariesLocation,
555
576
sdkRootPath: self . destination. pathsConfiguration. sdkRootPath,
556
- xctestPath: xctestPath
577
+ xctestPath: xctestPath,
578
+ swiftPluginServerPath: swiftPluginServerPath
557
579
)
558
580
}
559
581
@@ -625,6 +647,17 @@ public final class UserToolchain: Toolchain {
625
647
return . init( swiftCompilerPath: swiftCompilerPath)
626
648
}
627
649
650
+ private static func derivePluginServerPath( triple: Triple ) throws -> AbsolutePath ? {
651
+ if triple. isDarwin ( ) {
652
+ let xctestFindArgs = [ " /usr/bin/xcrun " , " --find " , " swift-plugin-server " ]
653
+ if let path = try ? TSCBasic . Process. checkNonZeroExit ( arguments: xctestFindArgs, environment: [ : ] )
654
+ . spm_chomp ( ) {
655
+ return try AbsolutePath ( validating: path)
656
+ }
657
+ }
658
+ return . none
659
+ }
660
+
628
661
// TODO: We should have some general utility to find tools.
629
662
private static func deriveXCTestPath(
630
663
destination: Destination ,
@@ -747,4 +780,8 @@ public final class UserToolchain: Toolchain {
747
780
public var xctestPath : AbsolutePath ? {
748
781
configuration. xctestPath
749
782
}
783
+
784
+ public var swiftPluginServerPath : AbsolutePath ? {
785
+ configuration. swiftPluginServerPath
786
+ }
750
787
}
0 commit comments