Skip to content

Commit 3219033

Browse files
authored
Merge pull request #246 from tidev/fix/xcode-16.3-compatibility
fix: use “simctl list” to fetch device types, not file i/o
2 parents e4c748c + 4b3be7c commit 3219033

File tree

1 file changed

+29
-52
lines changed

1 file changed

+29
-52
lines changed

lib/xcode.js

+29-52
Original file line numberDiff line numberDiff line change
@@ -576,64 +576,41 @@ exports.detect = function detect(options, callback) {
576576
}
577577
});
578578

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+
}
609586

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: /watch/i.test(deviceType.name) ? false : true
597+
};
614598
}
615599
});
616600

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(/\.SimRuntime\.(.*?)\-(.*)$/);
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(/\.SimRuntime\.(.*?)\-(.*)$/);
606+
const version = rawVersion.replace(/-/g, '.');
634607

608+
const mapping = {
609+
name: `${platform} ${version}`,
610+
version
635611
}
636-
});
612+
appc.util.mix(xc.simRuntimes, { [key]: mapping });
613+
}
637614
});
638615

639616
['Simulator', 'iOS Simulator'].some(function (name) {

0 commit comments

Comments
 (0)