@@ -553,7 +553,7 @@ exports.detect = function detect(options, callback) {
553
553
554
554
Object . keys ( simulatorDevicePairCompatibility ) . some ( function ( xcodeRange ) {
555
555
if ( appc . version . satisfies ( xc . version , xcodeRange ) ) {
556
- xc . simDevicePairs = simulatorDevicePairCompatibility [ xcodeRange ] ;
556
+ xc . simDevicePairs = simulatorDevicePairCompatibility [ xcodeRange ] ;
557
557
558
558
// use the device pair compatibility to see if the simruntime is supported by
559
559
// this Xcode as there isn't a way to programmatically do it
@@ -576,71 +576,48 @@ exports.detect = function detect(options, callback) {
576
576
}
577
577
} ) ;
578
578
579
- var deviceTypesPaths = [
580
- path . join ( xc . path , 'Platforms' , 'iPhoneSimulator.platform' , 'Developer' , 'Library' , 'CoreSimulator' , 'Profiles' ) ,
581
- path . join ( xc . path , 'Platforms' , 'WatchSimulator.platform' , 'Developer' , 'Library' , 'CoreSimulator' , 'Profiles' ) ,
582
-
583
- // Xcode 9 moved CoreSimulator into the "OS" directory instead of the "Simulator" directory
584
- path . join ( xc . path , 'Platforms' , 'iPhoneOS.platform' , 'Developer' , 'Library' , 'CoreSimulator' , 'Profiles' ) ,
585
- path . join ( xc . path , 'Platforms' , 'WatchOS.platform' , 'Developer' , 'Library' , 'CoreSimulator' , 'Profiles' ) ,
586
-
587
- // Xcode 11 moved CoreSimulator into the "Library/Developer" directory instead of the "Developer/Library" directory
588
- path . join ( xc . path , 'Platforms' , 'iPhoneOS.platform' , 'Library' , 'Developer' , 'CoreSimulator' , 'Profiles' ) ,
589
- path . join ( xc . path , 'Platforms' , 'WatchOS.platform' , 'Library' , 'Developer' , 'CoreSimulator' , 'Profiles' )
590
- ] ;
591
-
592
- deviceTypesPaths . forEach ( function ( deviceTypePath ) {
593
- // read in the device types
594
- var deviceTypesDir = path . join ( deviceTypePath , 'DeviceTypes' ) ;
595
- fs . existsSync ( deviceTypesDir ) && fs . readdirSync ( deviceTypesDir ) . forEach ( function ( name ) {
596
- var plist = readPlist ( path . join ( deviceTypesDir , name , 'Contents' , 'Info.plist' ) ) ,
597
- devId = plist && plist . CFBundleIdentifier ;
598
- if ( plist ) {
599
- var deviceType = xc . simDeviceTypes [ devId ] = {
600
- name : plist . CFBundleName ,
601
- model : 'unknown' ,
602
- supportsWatch : false
603
- } ;
604
-
605
- plist = readPlist ( path . join ( deviceTypesDir , name , 'Contents' , 'Resources' , 'profile.plist' ) ) ;
606
- if ( plist ) {
607
- deviceType . model = plist . modelIdentifier ;
608
- }
579
+ // Read the device types and devices in one call using the `xcrun simctl list --json`
580
+ // command. This not only improves performance (no device I/O required), but also combines
581
+ // two command (`simctl list` and `simctl list devices`) into one.
582
+ simctl . list ( { simctl : xc . executables . simctl } , function ( err , info ) {
583
+ if ( err ) {
584
+ return next ( err ) ;
585
+ }
609
586
610
- plist = readPlist ( path . join ( deviceTypesDir , name , 'Contents' , 'Resources' , 'capabilities.plist' ) ) ;
611
- if ( plist ) {
612
- deviceType . supportsWatch = ! ! plist . capabilities [ 'watch-companion' ] ;
613
- }
587
+ const devices = info . devices ;
588
+ const deviceTypes = info . devicetypes ;
589
+
590
+ deviceTypes . forEach ( function ( deviceType ) {
591
+ if ( ! xc . simDeviceTypes [ deviceType . identifier ] ) {
592
+ xc . simDeviceTypes [ deviceType . identifier ] = {
593
+ name : deviceType . name ,
594
+ model : deviceType . modelIdentifier || 'unknown' ,
595
+ // Assume devices with Watch in name or model support watch pairing
596
+ supportsWatch : / w a t c h / i. test ( deviceType . name ) ? false : true
597
+ } ;
614
598
}
615
599
} ) ;
616
600
617
- simctl . listDevices ( { simctl : xc . executables . simctl } , function ( err , info ) {
618
- if ( err ) {
619
- return next ( err ) ;
620
- }
621
-
622
- // Map the platform and version from CoreSimulator string like:
623
- // - com.apple.CoreSimulator.SimRuntime.iOS-17-0
624
- // - com.apple.CoreSimulator.SimRuntime.watchOS-10-0
625
- for ( const key of Object . keys ( info . devices ) ) {
626
- const [ _ , platform , rawVersion ] = key . match ( / \. S i m R u n t i m e \. ( .* ?) \- ( .* ) $ / ) ;
627
- const version = rawVersion . replace ( / - / g, '.' ) ;
628
-
629
- const mapping = {
630
- name : `${ platform } ${ version } ` ,
631
- version
632
- }
633
- appc . util . mix ( xc . simRuntimes , { [ key ] : mapping } ) ;
601
+ // Map the platform and version from CoreSimulator string like:
602
+ // - com.apple.CoreSimulator.SimRuntime.iOS-17-0
603
+ // - com.apple.CoreSimulator.SimRuntime.watchOS-10-0
604
+ for ( const key of Object . keys ( devices ) ) {
605
+ const [ _ , platform , rawVersion ] = key . match ( / \. S i m R u n t i m e \. ( .* ?) \- ( .* ) $ / ) ;
606
+ const version = rawVersion . replace ( / - / g, '.' ) ;
634
607
608
+ const mapping = {
609
+ name : `${ platform } ${ version } ` ,
610
+ version
635
611
}
636
- } ) ;
612
+ appc . util . mix ( xc . simRuntimes , { [ key ] : mapping } ) ;
613
+ }
637
614
} ) ;
638
615
639
616
[ 'Simulator' , 'iOS Simulator' ] . some ( function ( name ) {
640
617
var p = path . join ( dir , 'Applications' , name + '.app' , 'Contents' , 'MacOS' , name ) ;
641
618
if ( fs . existsSync ( p ) ) {
642
619
xc . executables . simulator = p ;
643
- return true ;
620
+ return true ;
644
621
}
645
622
} ) ;
646
623
@@ -669,7 +646,7 @@ exports.detect = function detect(options, callback) {
669
646
dest . push ( ver ) ;
670
647
}
671
648
}
672
- } ) ;
649
+ } ) ;
673
650
674
651
xc . sims . sort ( ) ;
675
652
xc . watchos . sims . sort ( ) ;
0 commit comments