Skip to content

Commit 2ad3407

Browse files
koenpuntfacebook-github-bot
authored andcommitted
Xcode 9 supports running multiple simulators
Summary: Since Xcode 9 you can run multiple simultaneously. And since I believe React Native advocates using the latest version of Xcode, we can safely remove this constraint. Updated the unit tests. Furthermore it can be found in the [Xcode release notes](https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/WhatsNewXcode/xcode_9/xcode_9.html#//apple_ref/doc/uid/TP40004626-CH8-SW12) that multiple simulators are now supported. This can be tested with the CLI by running `react-native run-ios` twice, but with a different `--simulator` flag, e.g.; react-native run-ios --simulator "iPhone SE" react-native run-ios --simulator "iPhone X" [IOS] [ENHANCEMENT] [local-cli/runIOS/findMatchingSimulator.js] - Allow running multiple simulators Closes #17284 Differential Revision: D7102790 Pulled By: hramos fbshipit-source-id: 750e7039201e28a1feda2bec1e78144fd9deff98
1 parent 2dc559d commit 2ad3407

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

local-cli/runIOS/__tests__/findMatchingSimulator-test.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('findMatchingSimulator', () => {
5555
)).toEqual({
5656
udid: 'BA0D93BD-07E6-4182-9B0A-F60A2474139C',
5757
name: 'iPhone 6',
58+
booted: false,
5859
version: 'iOS 9.2'
5960
});
6061
});
@@ -145,6 +146,7 @@ describe('findMatchingSimulator', () => {
145146
)).toEqual({
146147
udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB',
147148
name: 'iPhone 5',
149+
booted: false,
148150
version: 'iOS 9.2'
149151
});
150152
});
@@ -216,6 +218,7 @@ describe('findMatchingSimulator', () => {
216218
)).toEqual({
217219
udid: '1CCBBF8B-5773-4EA6-BD6F-C308C87A1ADB',
218220
name: 'iPhone 5',
221+
booted: false,
219222
version: 'iOS 9.2'
220223
});
221224
});
@@ -261,11 +264,12 @@ describe('findMatchingSimulator', () => {
261264
)).toEqual({
262265
udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508',
263266
name: 'iPhone 6s',
267+
booted: true,
264268
version: 'iOS 9.2'
265269
});
266270
});
267271

268-
it('should return the booted simulator in list even if another device is defined', () => {
272+
it('should return the defined simulator in list even if another device is booted', () => {
269273
expect(findMatchingSimulator({
270274
'devices': {
271275
'iOS 9.2': [
@@ -304,8 +308,9 @@ describe('findMatchingSimulator', () => {
304308
},
305309
'iPhone 6'
306310
)).toEqual({
307-
udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508',
308-
name: 'iPhone 6s',
311+
udid: 'BA0D93BD-07E6-4182-9B0A-F60A2474139C',
312+
name: 'iPhone 6',
313+
booted: false,
309314
version: 'iOS 9.2'
310315
});
311316
});
@@ -377,11 +382,12 @@ describe('findMatchingSimulator', () => {
377382
)).toEqual({
378383
udid: '3A409DC5-5188-42A6-8598-3AA6F34607A5',
379384
name: 'iPhone 7',
385+
booted: true,
380386
version: 'iOS 10.0'
381387
});
382388
});
383389

384-
it('should return the booted simulator in list even if another device is defined (multi ios versions)', () => {
390+
it('should return the defined simulator in list even if another device is booted (multi ios versions)', () => {
385391
expect(findMatchingSimulator({
386392
'devices': {
387393
'iOS 9.2': [
@@ -446,9 +452,10 @@ describe('findMatchingSimulator', () => {
446452
},
447453
'iPhone 6s'
448454
)).toEqual({
449-
udid: '3A409DC5-5188-42A6-8598-3AA6F34607A5',
450-
name: 'iPhone 7',
451-
version: 'iOS 10.0'
455+
udid: 'D0F29BE7-CC3C-4976-888D-C739B4F50508',
456+
name: 'iPhone 6s',
457+
booted: false,
458+
version: 'iOS 9.2'
452459
});
453460
});
454461

@@ -481,6 +488,7 @@ describe('findMatchingSimulator', () => {
481488
)).toEqual({
482489
udid: '816C30EA-38EA-41AC-BFDA-96FB632D522E',
483490
name: 'Apple TV',
491+
booted: true,
484492
version: 'tvOS 11.2'
485493
});
486494
});

local-cli/runIOS/findMatchingSimulator.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ function findMatchingSimulator(simulators, simulatorName) {
3434
if (simulator.availability !== '(available)') {
3535
continue;
3636
}
37-
// If there is a booted simulator, we'll use that as instruments will not boot a second simulator
38-
if (simulator.state === 'Booted') {
39-
if (simulatorName !== null) {
40-
console.warn("We couldn't boot your defined simulator due to an already booted simulator. We are limited to one simulator launched at a time.");
41-
}
37+
let booted = simulator.state === 'Booted';
38+
if (booted && simulatorName === null) {
4239
return {
4340
udid: simulator.udid,
4441
name: simulator.name,
42+
booted,
4543
version
4644
};
4745
}
4846
if (simulator.name === simulatorName && !match) {
4947
match = {
5048
udid: simulator.udid,
5149
name: simulator.name,
50+
booted,
5251
version
5352
};
5453
}
@@ -57,6 +56,7 @@ function findMatchingSimulator(simulators, simulatorName) {
5756
match = {
5857
udid: simulator.udid,
5958
name: simulator.name,
59+
booted,
6060
version
6161
};
6262
}

local-cli/runIOS/runIOS.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,30 @@ function runOnSimulator(xcodeProject, args, scheme) {
113113
throw new Error(`Could not find ${args.simulator} simulator`);
114114
}
115115

116-
const simulatorFullName = formattedDeviceName(selectedSimulator);
117-
console.log(`Launching ${simulatorFullName}...`);
118-
try {
119-
child_process.spawnSync('xcrun', ['instruments', '-w', selectedSimulator.udid]);
120-
} catch (e) {
121-
// instruments always fail with 255 because it expects more arguments,
122-
// but we want it to only launch the simulator
116+
if (!selectedSimulator.booted) {
117+
const simulatorFullName = formattedDeviceName(selectedSimulator);
118+
console.log(`Booting ${simulatorFullName}...`);
119+
try {
120+
child_process.execFileSync('xcrun', ['simctl', 'boot', selectedSimulator.udid]);
121+
} catch (e) {
122+
throw new Error(
123+
`Could not boot ${args.simulator} simulator. Is there already a simulator running?
124+
Running multiple simulators is only supported from Xcode 9 and up.
125+
Try closing the simulator or run the command again without specifying a simulator.`
126+
);
127+
}
123128
}
124-
resolve(selectedSimulator.udid);
129+
130+
buildProject(xcodeProject, selectedSimulator.udid, scheme, args.configuration, args.packager, args.verbose)
131+
.then((appName) => resolve(selectedSimulator.udid, appName));
125132
})
126-
.then((udid) => buildProject(xcodeProject, udid, scheme, args.configuration, args.packager, args.verbose, args.port))
127-
.then((appName) => {
133+
.then((udid, appName) => {
128134
if (!appName) {
129135
appName = scheme;
130136
}
131137
let appPath = getBuildPath(args.configuration, appName);
132138
console.log(`Installing ${appPath}`);
133-
child_process.spawnSync('xcrun', ['simctl', 'install', 'booted', appPath], {stdio: 'inherit'});
139+
child_process.spawnSync('xcrun', ['simctl', 'install', udid, appPath], {stdio: 'inherit'});
134140

135141
const bundleID = child_process.execFileSync(
136142
'/usr/libexec/PlistBuddy',
@@ -139,7 +145,7 @@ function runOnSimulator(xcodeProject, args, scheme) {
139145
).trim();
140146

141147
console.log(`Launching ${bundleID}`);
142-
child_process.spawnSync('xcrun', ['simctl', 'launch', 'booted', bundleID], {stdio: 'inherit'});
148+
child_process.spawnSync('xcrun', ['simctl', 'launch', udid, bundleID], {stdio: 'inherit'});
143149
});
144150
}
145151

0 commit comments

Comments
 (0)