@@ -226,12 +226,12 @@ public final class UserToolchain: Toolchain {
226
226
// Windows uses a variable named SDKROOT to determine the root of
227
227
// the SDK. This is not the same value as the SDKROOT parameter
228
228
// in Xcode, however, the value represents a similar concept.
229
- if let SDKROOT = environment [ " SDKROOT " ] , let root = try ? AbsolutePath ( validating: SDKROOT) {
229
+ if let SDKROOT = environment [ " SDKROOT " ] , let sdkroot = try ? AbsolutePath ( validating: SDKROOT) {
230
230
var runtime : [ String ] = [ ]
231
231
var xctest : [ String ] = [ ]
232
232
var extraSwiftCFlags : [ String ] = [ ]
233
233
234
- if let settings = WindowsSDKSettings ( reading: root . appending ( component: " SDKSettings.plist " ) ,
234
+ if let settings = WindowsSDKSettings ( reading: sdkroot . appending ( component: " SDKSettings.plist " ) ,
235
235
diagnostics: nil , filesystem: localFileSystem) {
236
236
switch settings. defaults. runtime {
237
237
case . multithreadedDebugDLL:
@@ -245,43 +245,44 @@ public final class UserToolchain: Toolchain {
245
245
}
246
246
}
247
247
248
- if let DEVELOPER_DIR = environment [ " DEVELOPER_DIR " ] ,
249
- let root = try ? AbsolutePath ( validating: DEVELOPER_DIR)
250
- . appending ( component: " Platforms " )
251
- . appending ( component: " Windows.platform " ) {
252
- if let info = WindowsPlatformInfo ( reading: root. appending ( component: " Info.plist " ) ,
253
- diagnostics: nil , filesystem: localFileSystem) {
254
- let path : AbsolutePath =
255
- root. appending ( component: " Developer " )
256
- . appending ( component: " Library " )
257
- . appending ( component: " XCTest- \( info. defaults. xctestVersion) " )
258
-
259
- xctest = [
260
- " -I " , AbsolutePath ( " usr/lib/swift/windows/ \( triple. arch) " , relativeTo: path) . pathString,
261
- " -L " , AbsolutePath ( " usr/lib/swift/windows/ \( triple. arch) " , relativeTo: path) . pathString,
262
- ]
263
-
264
- // Migration Path
265
- //
266
- // In order to support multiple parallel
267
- // installations of an SDK, we need to ensure that
268
- // we can have all the architecture variant
269
- // libraries available. Prior to this getting
270
- // enabled (~5.7), we always had a singular
271
- // installed SDK. Prefer the new variant which has
272
- // an architecture subdirectory in `bin` if
273
- // available.
274
- let implib : AbsolutePath =
275
- AbsolutePath ( " usr/lib/swift/windows/XCTest.lib " , relativeTo: path)
276
- if localFileSystem. exists ( implib) {
277
- xctest. append ( contentsOf: [ " -L " , implib. parentDirectory. pathString] )
278
- }
279
-
280
- extraSwiftCFlags = info. defaults. extraSwiftCFlags ?? [ ]
248
+ // The layout of the SDK is as follows:
249
+ //
250
+ // Library/Developer/Platforms/[PLATFORM].platform/Developer/Library/XCTest-[VERSION]/...
251
+ // Library/Developer/Platforms/[PLATFORM].platform/Developer/SDKs/[PLATFORM].sdk/...
252
+ //
253
+ // SDKROOT points to [PLATFORM].sdk
254
+ let platform = sdkroot. parentDirectory. parentDirectory. parentDirectory
255
+
256
+ if let info = WindowsPlatformInfo ( reading: platform. appending ( component: " Info.plist " ) ,
257
+ diagnostics: nil , filesystem: localFileSystem) {
258
+ let installation : AbsolutePath =
259
+ platform. appending ( component: " Developer " )
260
+ . appending ( component: " Library " )
261
+ . appending ( component: " XCTest- \( info. defaults. xctestVersion) " )
262
+
263
+ xctest = [
264
+ " -I " , AbsolutePath ( " usr/lib/swift/windows/ \( triple. arch) " , relativeTo: installation) . pathString,
265
+ " -L " , AbsolutePath ( " usr/lib/swift/windows/ \( triple. arch) " , relativeTo: installation) . pathString,
266
+ ]
267
+
268
+ // Migration Path
269
+ //
270
+ // In order to support multiple parallel installations
271
+ // of an SDK, we need to ensure that we can have all the
272
+ // architecture variant libraries available. Prior to
273
+ // this getting enabled (~5.7), we always had a singular
274
+ // installed SDK. Prefer the new variant which has an
275
+ // architecture subdirectory in `bin` if available.
276
+ let implib : AbsolutePath =
277
+ AbsolutePath ( " usr/lib/swift/windows/XCTest.lib " , relativeTo: installation)
278
+ if localFileSystem. exists ( implib) {
279
+ xctest. append ( contentsOf: [ " -L " , implib. parentDirectory. pathString] )
281
280
}
281
+
282
+ extraSwiftCFlags = info. defaults. extraSwiftCFlags ?? [ ]
282
283
}
283
284
284
- return [ " -sdk " , root . pathString, ] + runtime + xctest + extraSwiftCFlags
285
+ return [ " -sdk " , sdkroot . pathString, ] + runtime + xctest + extraSwiftCFlags
285
286
}
286
287
}
287
288
@@ -385,7 +386,7 @@ public final class UserToolchain: Toolchain {
385
386
if case let . custom( _, useXcrun) = searchStrategy, !useXcrun {
386
387
xctestPath = nil
387
388
} else {
388
- xctestPath = try Self . deriveXCTestPath ( triple: triple, environment: environment)
389
+ xctestPath = try Self . deriveXCTestPath ( destination : self . destination , triple: triple, environment: environment)
389
390
}
390
391
391
392
self . configuration = . init(
@@ -462,79 +463,90 @@ public final class UserToolchain: Toolchain {
462
463
}
463
464
464
465
// TODO: We should have some general utility to find tools.
465
- private static func deriveXCTestPath( triple: Triple , environment: EnvironmentVariables ) throws -> AbsolutePath ? {
466
+ private static func deriveXCTestPath( destination : Destination , triple: Triple , environment: EnvironmentVariables ) throws -> AbsolutePath ? {
466
467
if triple. isDarwin ( ) {
467
468
// XCTest is optional on macOS, for example when Xcode is not installed
468
469
let xctestFindArgs = [ " /usr/bin/xcrun " , " --sdk " , " macosx " , " --find " , " xctest " ]
469
470
if let path = try ? Process . checkNonZeroExit ( arguments: xctestFindArgs, environment: environment) . spm_chomp ( ) {
470
471
return try AbsolutePath ( validating: path)
471
472
}
472
473
} else if triple. isWindows ( ) {
473
- if let DEVELOPER_DIR = environment [ " DEVELOPER_DIR " ] ,
474
- let root = try ? AbsolutePath ( validating: DEVELOPER_DIR)
475
- . appending ( component: " Platforms " )
476
- . appending ( component: " Windows.platform " ) {
477
- if let info = WindowsPlatformInfo ( reading: root. appending ( component: " Info.plist " ) ,
478
- diagnostics: nil ,
479
- filesystem: localFileSystem) {
480
-
481
- let installation : AbsolutePath =
482
- root. appending ( component: " Developer " )
483
- . appending ( component: " Library " )
484
- . appending ( component: " XCTest- \( info. defaults. xctestVersion) " )
485
-
486
- // Migration Path
487
- //
488
- // In order to support multiple parallel installations of an
489
- // SDK, we need to ensure that we can have all the
490
- // architecture variant libraries available. Prior to this
491
- // getting enabled (~5.7), we always had a singular
492
- // installed SDK. Prefer the new variant which has an
493
- // architecture subdirectory in `bin` if available.
494
- switch triple. arch {
495
- case . x86_64, . x86_64h:
496
- let path : AbsolutePath =
497
- installation. appending ( component: " usr " )
498
- . appending ( component: " bin64 " )
499
- if localFileSystem. exists ( path) {
500
- return path
501
- }
474
+ let sdkroot : AbsolutePath
475
+
476
+ if let sdk = destination. sdk {
477
+ sdkroot = sdk
478
+ } else if let SDKROOT = environment [ " SDKROOT " ] , let sdk = try ? AbsolutePath ( validating: SDKROOT) {
479
+ sdkroot = sdk
480
+ } else {
481
+ return . none
482
+ }
502
483
503
- case . i686:
504
- let path : AbsolutePath =
505
- installation. appending ( component: " usr " )
506
- . appending ( component: " bin32 " )
507
- if localFileSystem. exists ( path) {
508
- return path
509
- }
484
+ // The layout of the SDK is as follows:
485
+ //
486
+ // Library/Developer/Platforms/[PLATFORM].platform/Developer/Library/XCTest-[VERSION]/...
487
+ // Library/Developer/Platforms/[PLATFORM].platform/Developer/SDKs/[PLATFORM].sdk/...
488
+ //
489
+ // SDKROOT points to [PLATFORM].sdk
490
+ let platform = sdkroot. parentDirectory. parentDirectory. parentDirectory
491
+
492
+ if let info = WindowsPlatformInfo ( reading: platform. appending ( component: " Info.plist " ) ,
493
+ diagnostics: nil , filesystem: localFileSystem) {
494
+ let xctest : AbsolutePath =
495
+ platform. appending ( component: " Developer " )
496
+ . appending ( component: " Library " )
497
+ . appending ( component: " XCTest- \( info. defaults. xctestVersion) " )
510
498
511
- case . armv7:
512
- let path : AbsolutePath =
513
- installation. appending ( component: " usr " )
514
- . appending ( component: " bin32a " )
515
- if localFileSystem. exists ( path) {
516
- return path
517
- }
499
+ // Migration Path
500
+ //
501
+ // In order to support multiple parallel installations of an
502
+ // SDK, we need to ensure that we can have all the architecture
503
+ // variant libraries available. Prior to this getting enabled
504
+ // (~5.7), we always had a singular installed SDK. Prefer the
505
+ // new variant which has an architecture subdirectory in `bin`
506
+ // if available.
507
+ switch triple. arch {
508
+ case . x86_64, . x86_64h:
509
+ let path : AbsolutePath =
510
+ xctest. appending ( component: " usr " )
511
+ . appending ( component: " bin64 " )
512
+ if localFileSystem. exists ( path) {
513
+ return path
514
+ }
518
515
519
- case . arm64:
520
- let path : AbsolutePath =
521
- installation. appending ( component: " usr " )
522
- . appending ( component: " bin64a " )
523
- if localFileSystem. exists ( path) {
524
- return path
525
- }
516
+ case . i686:
517
+ let path : AbsolutePath =
518
+ xctest. appending ( component: " usr " )
519
+ . appending ( component: " bin32 " )
520
+ if localFileSystem. exists ( path) {
521
+ return path
522
+ }
523
+
524
+ case . armv7:
525
+ let path : AbsolutePath =
526
+ xctest. appending ( component: " usr " )
527
+ . appending ( component: " bin32a " )
528
+ if localFileSystem. exists ( path) {
529
+ return path
530
+ }
526
531
527
- default :
528
- // Fallback to the old-style layout. We should really
529
- // report an error in this case - this architecture is
530
- // unavailable.
531
- break
532
+ case . arm64:
533
+ let path : AbsolutePath =
534
+ xctest. appending ( component: " usr " )
535
+ . appending ( component: " bin64a " )
536
+ if localFileSystem. exists ( path) {
537
+ return path
532
538
}
533
539
534
- // Assume that we are in the old-style layout.
535
- return installation. appending ( component: " usr " )
536
- . appending ( component: " bin " )
540
+ default :
541
+ // Fallback to the old-style layout. We should really
542
+ // report an error in this case - this architecture is
543
+ // unavailable.
544
+ break
537
545
}
546
+
547
+ // Assume that we are in the old-style layout.
548
+ return xctest. appending ( component: " usr " )
549
+ . appending ( component: " bin " )
538
550
}
539
551
}
540
552
return . none
0 commit comments