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-15717] Fixed CLI error if running an ios sim app and the simulator is reset. #4969

Merged
merged 1 commit into from
Nov 15, 2013
Merged
Changes from all commits
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
69 changes: 40 additions & 29 deletions iphone/cli/hooks/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ exports.init = function (logger, config, cli) {
simProcess,
simErr = [],
stripLogLevelRE = new RegExp('\\[(?:' + logger.getLevels().join('|') + ')\\] '),
logProcess,
simStarted = false,
simEnv = path.join(build.xcodeEnv.path, 'Platforms', 'iPhoneSimulator.platform', 'Developer', 'Library', 'PrivateFrameworks') +
':' + afs.resolvePath(build.xcodeEnv.path, '..', 'OtherFrameworks');
Expand Down Expand Up @@ -107,7 +106,6 @@ exports.init = function (logger, config, cli) {

simProcess.on('exit', function (code, signal) {
clearTimeout(findLogTimer);
logProcess && logProcess.kill();

if (simStarted) {
var endLogTxt = __('End simulator log');
Expand Down Expand Up @@ -163,37 +161,50 @@ exports.init = function (logger, config, cli) {
lastLogger = 'debug';

(function readChanges () {
var stats = fs.statSync(file),
fd, bytesRead, lines, m,line, i, len;

if (position < stats.size) {
fd = fs.openSync(file, 'r');
do {
bytesRead = fs.readSync(fd, buf, 0, 16, position);
position += bytesRead;
buffer += buf.toString('utf-8', 0, bytesRead);
} while (bytesRead === 16);
fs.closeSync(fd);

lines = buffer.split('\n');
buffer = lines.pop(); // keep the last line because it could be incomplete
for (i = 0, len = lines.length; i < len; i++) {
line = lines[i];
if (line) {
m = line.match(logLevelRE);
if (m) {
lastLogger = m[2].toLowerCase();
line = m[4].trim();
}
if (levels.indexOf(lastLogger) == -1) {
logger.log(('[' + lastLogger.toUpperCase() + '] ').cyan + line);
} else {
logger[lastLogger](line);
try {
var stats = fs.statSync(file),
fd, bytesRead, lines, m,line, i, len;

if (position < stats.size) {
fd = fs.openSync(file, 'r');
do {
bytesRead = fs.readSync(fd, buf, 0, 16, position);
position += bytesRead;
buffer += buf.toString('utf-8', 0, bytesRead);
} while (bytesRead === 16);
fs.closeSync(fd);

lines = buffer.split('\n');
buffer = lines.pop(); // keep the last line because it could be incomplete
for (i = 0, len = lines.length; i < len; i++) {
line = lines[i];
if (line) {
m = line.match(logLevelRE);
if (m) {
lastLogger = m[2].toLowerCase();
line = m[4].trim();
}
if (levels.indexOf(lastLogger) == -1) {
logger.log(('[' + lastLogger.toUpperCase() + '] ').cyan + line);
} else {
logger[lastLogger](line);
}
}
}
}
readChangesTimer = setTimeout(readChanges, 30);
} catch (ex) {
if (ex.code == 'ENOENT') {
clearTimeout(readChangesTimer);
if (simStarted) {
var endLogTxt = __('End simulator log');
logger.log(('-- ' + endLogTxt + ' ' + (new Array(75 - endLogTxt.length)).join('-')).grey);
}
logger.log();
process.exit(0);
}
throw ex;
}
readChangesTimer = setTimeout(readChanges, 30);
}());

simProcess.on('exit', function() {
Expand Down