@@ -404,53 +404,6 @@ public final class UserToolchain: Toolchain {
404
404
}
405
405
#endif
406
406
407
- /// On MacOS toolchain can shadow SDK content. This method is intended
408
- /// to locate and include swift-testing library from a toolchain before
409
- /// sdk content which to sure that builds that use a custom toolchain
410
- /// always get a custom swift-testing library as well.
411
- static func deriveMacOSSpecificSwiftTestingFlags(
412
- derivedSwiftCompiler: AbsolutePath ,
413
- fileSystem: any FileSystem
414
- ) -> ( swiftCFlags: [ String ] , linkerFlags: [ String ] ) {
415
- // If this is CommandLineTools all we need to add is a frameworks path.
416
- if let frameworksPath = try ? AbsolutePath (
417
- validating: " ../../Library/Developer/Frameworks " ,
418
- relativeTo: resolveSymlinks ( derivedSwiftCompiler) . parentDirectory
419
- ) , fileSystem. exists ( frameworksPath. appending ( " Testing.framework " ) ) {
420
- return ( swiftCFlags: [
421
- " -F " , frameworksPath. pathString
422
- ] , linkerFlags: [
423
- " -rpath " , frameworksPath. pathString
424
- ] )
425
- }
426
-
427
- guard let toolchainLibDir = try ? toolchainLibDir (
428
- swiftCompilerPath: derivedSwiftCompiler
429
- ) else {
430
- return ( swiftCFlags: [ ] , linkerFlags: [ ] )
431
- }
432
-
433
- let testingLibDir = toolchainLibDir. appending (
434
- components: [ " swift " , " macosx " , " testing " ]
435
- )
436
-
437
- let testingPluginsDir = toolchainLibDir. appending (
438
- components: [ " swift " , " host " , " plugins " , " testing " ]
439
- )
440
-
441
- guard fileSystem. exists ( testingLibDir) , fileSystem. exists ( testingPluginsDir) else {
442
- return ( swiftCFlags: [ ] , linkerFlags: [ ] )
443
- }
444
-
445
- return ( swiftCFlags: [
446
- " -I " , testingLibDir. pathString,
447
- " -L " , testingLibDir. pathString,
448
- " -plugin-path " , testingPluginsDir. pathString
449
- ] , linkerFlags: [
450
- " -rpath " , testingLibDir. pathString
451
- ] )
452
- }
453
-
454
407
internal static func deriveSwiftCFlags(
455
408
triple: Triple ,
456
409
swiftSDK: SwiftSDK ,
@@ -673,14 +626,33 @@ public final class UserToolchain: Toolchain {
673
626
var swiftCompilerFlags : [ String ] = [ ]
674
627
var extraLinkerFlags : [ String ] = [ ]
675
628
676
- if triple. isMacOSX {
677
- let ( swiftCFlags, linkerFlags) = Self . deriveMacOSSpecificSwiftTestingFlags (
678
- derivedSwiftCompiler: swiftCompilers. compile,
679
- fileSystem: fileSystem
680
- )
629
+ let swiftTestingPath : AbsolutePath ? = try Self . deriveSwiftTestingPath (
630
+ derivedSwiftCompiler: swiftCompilers. compile,
631
+ swiftSDK: self . swiftSDK,
632
+ triple: triple,
633
+ environment: environment,
634
+ fileSystem: fileSystem
635
+ )
636
+
637
+ if triple. isMacOSX, let swiftTestingPath {
638
+ // swift-testing in CommandLineTools, needs extra frameworks search path
639
+ if swiftTestingPath. extension == " framework " {
640
+ swiftCompilerFlags += [ " -F " , swiftTestingPath. pathString]
641
+ }
681
642
682
- swiftCompilerFlags += swiftCFlags
683
- extraLinkerFlags += linkerFlags
643
+ // Otherwise we must have a custom toolchain, add overrides to find its swift-testing ahead of any in the
644
+ // SDK. We expect the library to be in `lib/swift/macosx/testing` and the plugin in
645
+ // `lib/swift/host/plugins/testing`
646
+ if let pluginsPath = try ? AbsolutePath (
647
+ validating: " ../../host/plugins/testing " ,
648
+ relativeTo: swiftTestingPath
649
+ ) {
650
+ swiftCompilerFlags += [
651
+ " -I " , swiftTestingPath. pathString,
652
+ " -L " , swiftTestingPath. pathString,
653
+ " -plugin-path " , pluginsPath. pathString,
654
+ ]
655
+ }
684
656
}
685
657
686
658
swiftCompilerFlags += try Self . deriveSwiftCFlags (
@@ -774,19 +746,6 @@ public final class UserToolchain: Toolchain {
774
746
)
775
747
}
776
748
777
- let swiftTestingPath : AbsolutePath ?
778
- if case . custom( _, let useXcrun) = searchStrategy, !useXcrun {
779
- swiftTestingPath = nil
780
- } else {
781
- swiftTestingPath = try Self . deriveSwiftTestingPath (
782
- swiftSDK: self . swiftSDK,
783
- triple: triple,
784
- environment: environment,
785
- fileSystem: fileSystem
786
- )
787
- }
788
-
789
-
790
749
self . configuration = . init(
791
750
librarianPath: librarianPath,
792
751
swiftCompilerPath: swiftCompilers. manifest,
@@ -1006,58 +965,75 @@ public final class UserToolchain: Toolchain {
1006
965
. appending ( " bin " )
1007
966
}
1008
967
}
1009
- return . none
968
+ return nil
1010
969
}
1011
970
971
+ /// Find the swift-testing path if it is within a path that will need extra search paths.
1012
972
private static func deriveSwiftTestingPath(
973
+ derivedSwiftCompiler: AbsolutePath ,
1013
974
swiftSDK: SwiftSDK ,
1014
975
triple: Triple ,
1015
976
environment: Environment ,
1016
977
fileSystem: any FileSystem
1017
978
) throws -> AbsolutePath ? {
1018
- guard triple. isWindows ( ) else {
1019
- return nil
1020
- }
979
+ if triple. isDarwin ( ) {
980
+ // If this is CommandLineTools all we need to add is a frameworks path.
981
+ if let frameworksPath = try ? AbsolutePath (
982
+ validating: " ../../Library/Developer/Frameworks " ,
983
+ relativeTo: resolveSymlinks ( derivedSwiftCompiler) . parentDirectory
984
+ ) , fileSystem. exists ( frameworksPath. appending ( " Testing.framework " ) ) {
985
+ return frameworksPath
986
+ }
1021
987
1022
- guard let ( platform, info) = getWindowsPlatformInfo (
1023
- swiftSDK: swiftSDK,
1024
- environment: environment,
1025
- fileSystem: fileSystem
1026
- ) else {
1027
- return nil
1028
- }
988
+ guard let toolchainLibDir = try ? toolchainLibDir ( swiftCompilerPath: derivedSwiftCompiler) else {
989
+ return nil
990
+ }
1029
991
1030
- guard let swiftTestingVersion = info. defaults. swiftTestingVersion else {
1031
- return nil
1032
- }
992
+ let testingLibDir = toolchainLibDir. appending ( components: [ " swift " , " macosx " , " testing " ] )
993
+ if fileSystem. exists ( testingLibDir) {
994
+ return testingLibDir
995
+ }
996
+ } else if triple. isWindows ( ) {
997
+ guard let ( platform, info) = getWindowsPlatformInfo (
998
+ swiftSDK: swiftSDK,
999
+ environment: environment,
1000
+ fileSystem: fileSystem
1001
+ ) else {
1002
+ return nil
1003
+ }
1033
1004
1034
- let swiftTesting : AbsolutePath =
1035
- platform. appending ( " Developer " )
1036
- . appending ( " Library " )
1037
- . appending ( " Testing- \( swiftTestingVersion) " )
1038
-
1039
- let binPath : AbsolutePath ? = switch triple. arch {
1040
- case . x86_64: // amd64 x86_64 x86_64h
1041
- swiftTesting. appending ( " usr " )
1042
- . appending ( " bin64 " )
1043
- case . x86: // i386 i486 i586 i686 i786 i886 i986
1044
- swiftTesting. appending ( " usr " )
1045
- . appending ( " bin32 " )
1046
- case . arm: // armv7 and many more
1047
- swiftTesting. appending ( " usr " )
1048
- . appending ( " bin32a " )
1049
- case . aarch64: // aarch6 arm64
1050
- swiftTesting. appending ( " usr " )
1051
- . appending ( " bin64a " )
1052
- default :
1053
- nil
1054
- }
1005
+ guard let swiftTestingVersion = info. defaults. swiftTestingVersion else {
1006
+ return nil
1007
+ }
1055
1008
1056
- guard let path = binPath, fileSystem. exists ( path) else {
1057
- return nil
1009
+ let swiftTesting : AbsolutePath =
1010
+ platform. appending ( " Developer " )
1011
+ . appending ( " Library " )
1012
+ . appending ( " Testing- \( swiftTestingVersion) " )
1013
+
1014
+ let binPath : AbsolutePath ? = switch triple. arch {
1015
+ case . x86_64: // amd64 x86_64 x86_64h
1016
+ swiftTesting. appending ( " usr " )
1017
+ . appending ( " bin64 " )
1018
+ case . x86: // i386 i486 i586 i686 i786 i886 i986
1019
+ swiftTesting. appending ( " usr " )
1020
+ . appending ( " bin32 " )
1021
+ case . arm: // armv7 and many more
1022
+ swiftTesting. appending ( " usr " )
1023
+ . appending ( " bin32a " )
1024
+ case . aarch64: // aarch6 arm64
1025
+ swiftTesting. appending ( " usr " )
1026
+ . appending ( " bin64a " )
1027
+ default :
1028
+ nil
1029
+ }
1030
+
1031
+ if let path = binPath, fileSystem. exists ( path) {
1032
+ return path
1033
+ }
1058
1034
}
1059
1035
1060
- return path
1036
+ return nil
1061
1037
}
1062
1038
1063
1039
public var sdkRootPath : AbsolutePath ? {
@@ -1084,7 +1060,7 @@ public final class UserToolchain: Toolchain {
1084
1060
configuration. xctestPath
1085
1061
}
1086
1062
1087
- public var swiftTestingPathOnWindows : AbsolutePath ? {
1063
+ public var swiftTestingPath : AbsolutePath ? {
1088
1064
configuration. swiftTestingPath
1089
1065
}
1090
1066
0 commit comments