Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24837] Fixed handling of sim runtimes that are associated to m… #63

Merged
merged 2 commits into from
Jun 16, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
127 changes: 80 additions & 47 deletions lib/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ function detect(options, callback) {
return callback(err);
}

// create a lookup of runtimes from simctl
var simctlRuntimes = {};
info.runtimes.forEach(function (runtime) {
simctlRuntimes[runtime.identifier] = runtime;
});

var coreSimDir = appc.fs.resolvePath('~/Library/Developer/CoreSimulator/Devices');
Object.keys(info.devices).forEach(function (type) {
info.devices[type].forEach(function (device) {
Expand All @@ -192,53 +198,75 @@ function detect(options, callback) {
xcodeIds.forEach(function (id) {
var xc = xcodeInfo.xcode[id],
deviceType = xc.simDeviceTypes[plist.deviceType],
runtime = simctlRuntimes[plist.runtime];

// This code finds the sim runtime and builds the list of associated
// iOS SDKs which may be different based which Xcode's simctl is run.
// For example, sim runtime 8.3 is associated with iOS 10.3 and 10.3.1.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably mean sim runtime 10.3?

// Because of this, we define the same simulator for each associated
// iOS SDK version.
if (!runtime) {
runtime = xc.simRuntimes[plist.runtime];
if (runtime) {
runtime.versions = [ runtime.version ];
}
} else if (xc.simRuntimes[plist.runtime]) {
runtime.versions = [ runtime.version ];
var ver = xc.simRuntimes[plist.runtime].version;
if (ver !== runtime.version) {
runtime.versions.push(ver);
}
}

if (!deviceType || !runtime) {
// wrong xcode, skip
return;
}

var family = deviceType.model.replace(/[\W0-9]/g, '').toLowerCase(),
type = family === 'iphone' || family === 'ipad' ? 'ios' : 'watchos',
sim;
type = family === 'iphone' || family === 'ipad' ? 'ios' : 'watchos';

results.simulators[type][runtime.version] || (results.simulators[type][runtime.version] = []);
results.simulators[type][runtime.version].some(function (s) {
if (s.udid === plist.UDID) {
sim = s;
return true;
}
});
// for each runtime iOS SDK version, define the simulator
runtime.versions.forEach(function (runtimeVersion) {
var sim;

if (!sim) {
results.simulators[type][runtime.version].push(sim = {
udid: plist.UDID,
name: plist.name,
version: runtime.version,
type: type,

deviceType: plist.deviceType,
deviceName: deviceType.name,
deviceDir: path.join(coreSimDir, device.udid),
model: deviceType.model,
family: family,
supportsXcode: {},
supportsWatch: {},
watchCompanion: {},

runtime: plist.runtime,
runtimeName: runtime.name,

systemLog: appc.fs.resolvePath('~/Library/Logs/CoreSimulator/' + device.udid + '/system.log'),
dataDir: path.join(coreSimDir, device.udid, 'data')
results.simulators[type][runtimeVersion] || (results.simulators[type][runtimeVersion] = []);
results.simulators[type][runtimeVersion].some(function (s) {
if (s.udid === plist.UDID) {
sim = s;
return true;
}
});
}

sim.supportsXcode[id] = true;
if (type === 'ios') {
sim.supportsWatch[id] = deviceType.supportsWatch;
}
if (!sim) {
results.simulators[type][runtimeVersion].push(sim = {
udid: plist.UDID,
name: plist.name,
version: runtimeVersion,
type: type,

deviceType: plist.deviceType,
deviceName: deviceType.name,
deviceDir: path.join(coreSimDir, device.udid),
model: deviceType.model,
family: family,
supportsXcode: {},
supportsWatch: {},
watchCompanion: {},

runtime: plist.runtime,
runtimeName: runtime.name,

systemLog: appc.fs.resolvePath('~/Library/Logs/CoreSimulator/' + device.udid + '/system.log'),
dataDir: path.join(coreSimDir, device.udid, 'data')
});
}

sim.supportsXcode[id] = true;
if (type === 'ios') {
sim.supportsWatch[id] = deviceType.supportsWatch;
}
});
});
});
});
Expand Down Expand Up @@ -595,9 +623,12 @@ function findSimulators(options, callback) {

// loop through xcodes
for (var i = 0; !simHandle && i < xcodeIds.length; i++) {
var xc = xcodeInfo.xcode[xcodeIds[i]],
var xcodeId = xcodeIds[i],
xc = xcodeInfo.xcode[xcodeId],
simVers = xc.sims.sort().reverse();

logger(__('Scanning Xcode %s sims: %s', xcodeIds[i], simVers.join(', ')));

// loop through each xcode simulators
for (var j = 0; !simHandle && j < simVers.length; j++) {
if ((!options.simVersion || simVers[j] === options.simVersion) &&
Expand All @@ -609,18 +640,8 @@ function findSimulators(options, callback) {
// loop through each simulator
for (var k = 0; !simHandle && k < sims.length; k++) {
if (!options.simType || sims[k].family === options.simType) {
if (!options.appBeingInstalled || !options.watchAppBeingInstalled) {
logger(__('No app being installed, so picking first Simulator'));
simHandle = new SimHandle(sims[k]);
Object.keys(simHandle.supportsXcode).sort().reverse().forEach(function (id) {
if (simHandle.supportsXcode[id]) {
selectedXcode = xcodeInfo.xcode[id];
return true;
}
});

// if we're installing a watch extension, make sure we pick a simulator that supports the watch
} else if (options.watchAppBeingInstalled) {
if (options.watchAppBeingInstalled) {
if (watchSimHandle) {
Object.keys(sims[k].supportsWatch).forEach(function (xcodeVer) {
if (watchSimHandle.supportsXcode[xcodeVer]) {
Expand All @@ -640,6 +661,18 @@ function findSimulators(options, callback) {
}
});
}
} else {
// no watch app
logger(__('No watch app being installed, so picking first Simulator'));
simHandle = new SimHandle(sims[k]);

// fallback to the newest supported Xcode version
xcodeIds.some(function (id) {
if (simHandle.supportsXcode[id]) {
selectedXcode = xcodeInfo.xcode[id];
return true;
}
});
}
}
}
Expand Down