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